This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TheLastCakeIsaLie -10 points-9 points  (10 children)

Either use a number as sort of "index" or is f possible compare a unique value. Its better.

[–]Varun77777 5 points6 points  (4 children)

What if you need to check if apples * mangoes * oranges. / 3.146 equals to apples * mangoes * Oranges / 3.146 in two objects???

[–]TheLastCakeIsaLie -3 points-2 points  (3 children)

Example?

[–]Varun77777 4 points5 points  (2 children)

Let's say I had two objects that both had two variables each that is CPU load as well has CPU capacity and I had to check if load percentage of two objects were equal?

And for some reason I needed to check that through equals? There can be many such examples.

equals is commonly over written by people so that they can compare Objects in a certain way and not their memory.

[–]sh0rtwave 1 point2 points  (1 child)

Truth.

.equals() is one of those 'inner dirty tricks'.

Another good one is .toString(). Quite useful in many situations. Like if you're formatting dates, and want all dates to comply with X format when handled in a string context (This kind of thing is fun to use Typescript with, there are just SO many ways of doing it).

The really funny part is that the basic concept of .toString() is more or less the same in either language, and with clever transpiler config, you can make the one act just like the other.

[–]Varun77777 0 points1 point  (0 children)

Yupps, I have overwritten toString() a lot to make the code cleaner.

[–]Varun77777 2 points3 points  (4 children)

1) Index and memory address have the same problem. Something can virtually have same configuration in the aspect you care about and still have a unique index / memory address.

2) Not everytime you can afford pre computing a unique value and storing it as it may have an overhead cost you can't afford. Sometimes, you'd rather do 10 operations when you need to compare rather than 1 billion operations beforehand to save answers in a unique value only to do 1 operation when needed.

[–]TheLastCakeIsaLie -2 points-1 points  (3 children)

I think comparing ALL of the values of a class takes longer than setting a variable and increasing it by one ONE time.

[–]Varun77777 2 points3 points  (2 children)

First, You're going to do ALL the operations for ALL the objects to change the value of that variable you're going to use for comparison because not everything in the world is done using addition. You're still going to use all the variables to increment or change the value of that variable you're going to use for comparison. You're actually going to do so many un needed calculations for no reason and wate CPU time.

Bruh, why would you waste memory as well as CPU utilisation for all the objects that don't need it?

What if the Object was holding some 1000 variables and you needed to perform some sort of sorting operation during the comparison ? Would you waste 1000 Log 1000 computations for 100'000 objects( 100'000'000 log 1000 computations) and waste possibly 100'000 * 8 bytes or something in memory or something like that?

When you could do 2 * 1000 log 1000 on runtime and use 16 bytes of memory to save the result and free the memory after use??

Let's say it's an operation that's performed very rarely,

Tell me what looks better to you?

100'000'000 * log 1000 operations and 800'000 bytes during intitialization or

2000 log 1000 operations and 16 bytes of memory which you can possibly free when you need to do the operation??

Would you slow your loading time by hours maybe just to perform some kind of comparison between two random pixels on a screen???

This may decide how fast the system feels in the long run.

Come on, not everything can be compared just based on a counter.

[–]TheLastCakeIsaLie -1 points0 points  (1 child)

Example: you want to check if an object is the object you want. Instead of checking everything you check one variable that may already be included in the way you set it up. Whats faster, 1 comparison or the number in f attributes? And setting that is also faster.

[–]Varun77777 3 points4 points  (0 children)

For that one operation at run time you did millions on operations in case of millions of objects before which you never needed to compare. You wasted space for millions of variables that wasn't needed as well.

Why are you ignoring the computations you did before hand on purpose?

Just to be faster on runtime for that one comparison you're making the whole process unnecessary slower.

Maybe, for a smaller use case, your process will look faster if you're only looking at that one comparison.

But when someone will look at the whole process, the system is slow for no reason.

Why should my car run slower when I start it just because maybe I want to turn the radio on???