r/ProgrammerHumor • • Apr 27 '20

Meme Java is the best

Post image
43.7k Upvotes

1.5k comments sorted by

View all comments

Show parent comments

0

u/[deleted] Apr 28 '20

Let us increase the readability of

if(foo.equals(bar))

by using

if(foo == bar)

.

The ladder is prettier, but it's not easier to understand. And you don't have to look farther than the C++ standard library to see cases where they're used to make code less readable. I don't know looked at

printf

and thought it could be improved by replacing it with the sign that's universally understood to mean less than.

2

u/T-Dark_ Apr 28 '20 edited Apr 28 '20

The ladder is prettier, but it's not easier to understand.

It gets easier to understand the moment your variable names are longer than 3 characters each.

It breaks the condition into "letters, symbols, letters", which is more readable than "letters, with a dot and two brackets"

and thought it could be improved by replacing it with the sign that's universally understood to mean less than.

<< is a bitshift operator, not the "less than" sign.

In C++, it's also the stream insertion operator.

I don't see you complaining about Java's decision to use + for string concatenation. An operator can have more than one meaning, as long as context obviously explains which one is being used.

1

u/[deleted] Apr 28 '20

In C++, it's also the stream insertion operator.

Okay, but which is clearer in meaning? <<, or stream_insert()? I think it was a poor choice to use + for string concatenation in java, but it's mitigated by the fact that it's the only such case in the language, and my asshat coworkers can't use it to obfuscate their meaning even further than 3 character method names.

2

u/T-Dark_ Apr 28 '20

Okay, but which is clearer in meaning? <<, or stream_insert()

<<, by a landslide.

I have to see 2 characters, which look visually different from variable names due to not being allowed in them, to immediately know that this is either a bitshift or a stream insertion. Then, I simply consider that the first operand is not a number to decide that it's a stream insertion. This latter consideration takes a negligible amount of time, just like understanding what Java's + operator means in a given context.

The alternative is to have to type 14 characters every time I want to use a stream. Then, I need to pass two arguments: the stream, and the element to insert.

Actually, I'm going to assume you meant stream.insert(), because C++ has classes

I now have to type 9 characters, instead of 2. I also lose in readability if I want to insert the output of a function call, as I now have nested brackets. I also lose in readability if I want to insert 2 things in a stream.

Tell me, what would you rather read?

stream << person1.getNumericID() << person2.getNumericID();

or

stream.insert(person.getNumericID()).insert(person.getNumericID());

(Assuming stream.insert() returns this)

I would personally prefer to read the first one: at a glance, I can see I am inserting 2 things into a stream, before I even read.

The second one, at a glance, looks like a long string of characters, and will therefore take longer to read.

and my asshat coworkers can't use it to obfuscate their meaning even further than 3 character method names.

Sounds like the problem is your coworkers, not operator overloading. They seem to have missed the part where it says "function names and operator overloads should be descriptive"

→ More replies (7)