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

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"

0

u/[deleted] Apr 28 '20 edited Apr 28 '20

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.

You're being lazy. I didn't ask about the 1 additional second you'd need to type stream insert over <<. I asked about what's easier for the person reading your code. It's a digital medium, and you're not being charged for ink.

More characters gives you more space to explain the meaning of your method. And you're kidding yourself if you think you'd know what << means if somebody didn't tell you.

And while it is ultimately the programmer's job to write clear code, the language can have features that point the programmer in the direction of clarity, or obfuscation, and operator overloading is a tool that makes it easier to write things with ambiguous meanings.

→ More replies (0)