Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
I prefer his style.
Many times it ended in "Oh no, variables bad, performance micro optimization bullshit" and thus reversal to your style. -
@IntrusionCM just comment with the assembly to show it was optimised away anyway, and mark the comment resolved
-
@IntrusionCM The variable naming describes what the comparison is for. So it documents itself. The compiler, in a lot of cases, will optimize those all away so there won't be much impact. Readability for the win.
-
@Demolishun My thought exactly.
And in my opinion readability over micro optimizations.
Especially in chained comparisons....
Logical fuckity can lead to lots of fun in debugging. -
Pointless checks though.
Obviously if the functions called here are efficient (they seem to be) then it's not a big deal, but generally speaking short-circuits exist for a good reason, and long logical expressions do make code more efficient.
@Demolishun in Java every method is virtual and their bodies are generally not known so the compiler can never short-circuit a function before a method call unless the language spec says so. -
@alexbrooklyn Not sure how to explain it well, but every country has a type of people that follow a pretty similar pattern, "drink, smoke, wear a similar type of clothes, badly mannered, I'll stab you, flock together, etc" sort of "the bad boys", many times small criminals are also within this group.
-
his vs yours equals - i don't agree.
his... maybe compiler optmizes all the extra bool allocations out, but still... my brain doesn't. my brain puts them on a stack and expects something meaty happening to them, which clutters my capacity.
yours LOOKS worse as text, but READS better as concepts: oh yeah, a sequence of equals checks in an equals function, of course.
his is: ...defining some bools, what are we gonna do with those? i'm still waiting for what are we gonna do with those...?
...oh. waste of expectations. -
also, isIn...
both of the versions are equally confusing, just differently worded, for me.
WHO THE HELL USES North/South/East/West for screen directions? It's Up/Down/Left/Right!
isUnder/IsLeft etc, ...okay, i could live with that, but... WHY?
i'm in programming mode, why are you giving me an extra step of having to parse words back into the appropriate math signs? -
my point is - there's a huge difference between visual aesthetics (how the text on the screen looks) and conceptual aesthetics (how easily and nicely your brain parses the text into logical concepts).
for me, his approach is visually aesthetic, but conceptually ugly.
in yours isEqual, i see a return, which has a few nested comparisons joined by AND. i can immediately see that, and then skip to any of the comparisons to immediately see what it does.
in his version, I see variable definitions and assignments, linear, with not much implied structure, and then a composite compare/return using those assigned variables, so i need to think/look back to see what those vars actually contain, before I can finally realize that "oh, he's just doing some useless pseudo-declarations just so that his return line can look nicer visually, for the cost of being less obvious". -
of course there's a cutoff point, above a certain number of composite checks, i would go for what he did too, because it becomes less taxing on brainstack than the flat approach, but 3 checks definitely ISN'T that cutoff point.
-
At first, I thought his style is utopian. But then I remembered, since I'm putting a lot of attention these days to writing my own course, that variables' names, each for keeping the result of single n-ary operation, are *not* telling enough.
Other than that - just perfect. Not only did he make it all without breaking any line, but also simplified the debugging. -
I don't like his way because it doesn't add anything of value, but destroys shorthand evaluation in languages that have this feature, i.e. it costs performance for nothing.
-
Your and his versions are just matters of personal taste.
Both are readable and should produce roughly the same byte or machine code. -
@Oktokolo They don't produce the same machine code, the "pretty" code can't short circuit.
-
I like variables, the company sent me to plc programming course, so memory management exists again in my life, DO NOT create variables for no reason.
-
@lbfalvy Except if the compiler is smart enough to optimise the superfluous evaluations away, but that relies on compiler optimisations while direct shorthand is part of the language standard and thus ensured.
-
kiki353243y@Floydimus imagine stereotypical American street gangsta from movies, but white, in adidas tracksuit and also not real gangsta. This will be gopnik
As for the looks, all “slav” parodies on YouTube are spot on -
@Fast-Nop In Java all methods are virtual so most of their bodies aren't known at compile time, therefore the compiler can't short-circuit before a method call.
-
I would have flipped the order of the isIn() checks to avoid the negation - that to me would have been cleaner.
Other than that I could take or leave the style really, I prefer yours but wouldn't fail either at code review. -
If I would have to be afraid of adding some variables for readability because of the performance impact that they may cause, I would go crazy.
In almost all of the cases, the performance increase doesn’t matter (premature optimization).
In the cases where it would matter, it will be optimized by the compiler anyway.
The remaining cases are where it matters (e.g. embedded systems) and cannot be optimized away, but how would you end up in such a situation? You would need to use something like Java for something very close to the hardware. In this case, you have much bigger problems than extra variables.
Related Rants
-
Angry21The first time I realized I wasn't as good as I thought I was when I met the smartest dev I've ever known (to ...
-
Flink9122Professor: "Who here regularly backs up all their data?" *Some people raise their hands* Professor: "Who has a...
-
sagemaker32I was looking for about a month for a laptop. Then on this one magical day I open kijiji and see a Toshiba Thi...
!rant, TL;DR at the bottom
Holy fuck, Yesterday, I got absolutely schooled by a literal newbie.
And I mean, NEWBIE newbie, the dude just started a Computer Science degree, and has been learning Java only for a MONTH. He has 0 prior experience with code or anything of the like, and he's somewhat of an Ars(Israel's version of a Gopnik).
So I was helping him with some stuff he didn't understand, and lo and behold his code was probably the most aesthetically pleasing and organized code I have seen in my 8 years of programming(I know 8 is not much, but It's at least above beginner level). The dude's a perfectionist, so I was like, "Okay, very impressive, but makes sense for perfectionism"(I straight up told him: "Damn, I've seen people with years of programming experience who can't learn to write this well, and you do this by default? I envy whoever's going to work with you"), and then I saw the way he writes checks(as in, methods that return a boolean) and I think I came.
The code was:
[First method in the picture]
And I know, it doesn't look as ✨ WOW✨ as I make it sound, but in my personal opinion this both looks much better and is much more readable than what I normally write:
[Second method in the picture]
and whenever there are longer or more complicated checks it makes it look like a simple puzzle that just fits in all the pieces nicely, for example in a rectangle class we had to write an 'isIn' method, this is how I wrote it:
[Third method in the picture]
His way of writing the same thing was:
[Fourth method in the picture]
Which I think is soooooo much better and readable and organized,
It's enough just looking at the short return statement to immediately understand everything that's going on.
"Oh, so it just checks if the SW(South West, i.e. Bottom Left) corner is above and to the right, and if the NE(North East, i.e. Top Right) corner is bellow and to the left"
Point of the story? Some people are just fucking awesome. And sometimes the youngest/most inexperienced people can teach you new tricks.
And to all of you dinosaurs here with like, 20+ years of experience, y'all can still learn even from us stupid ones. If 8 years can get schooled by a 1 month, 20 years can get schooled by a 1 year.
Listen to everyone everybody, never know where you might learn something new.
TL;DR: Got schooled by a local "Gopnik" who only started learning programming a month ago with 0 prior experience with his insane level of organization and readability.
rant
long
newbie
story
bottom tl;dr
!rant