- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- Remember Remember
- Named And
- It's About Time
- Scrollpocalypse
- Fast Quick
- 12345
- Said Different
- Ai Dios Mio
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
i imagine the line immediately before reads:
generate a private keyAdmin
Ironically if this is C/C++/C# it won't matter because the compiler will optimize it away. Not sure about other languages, a lot of them have way less optimization going on that a lot people give them credit for...
But yeah, constructs like that are weird and I found them mostly in code with languages that enforce definition at declaration like Java.
Admin
You could argue that this is more of a WTF than a lot of the other code we get here. A 100-line mess could be the result of one developer that just can't keep in their head everything that's happening, or it could be the result of 10 different developers adding stuff over time and never really understanding what the code is doing.
But something like this should only take two seconds to see the stupidity.
Admin
Ummm... the thing that mattered in the first place wasn't the extra instructions that would be executed. A coding pattern that doesn't hurt performance but makes it difficult to understand what the code is doing is a very bad thing - even it it doesn't have any negative performance attributes.
Admin
Java doesn't enforce definition at declaration. It does enforce declaration before usage for locals, and undeclared fields will be initialized to a default value.
Admin
At least y and z per guaranteed to be random...
Admin
Is this a sample from Paula Bean?
Admin
As we've often said, there are TWO important audiences for the source code... the compiler, and the person having to maintain it!
Admin
I suspect the original version didn't have the x = y = z line, but someone wanted them set equal and some PHB disallowed removing lines or versioning code.
Admin
Some variables are more equal than others.
Admin
"I found them mostly in code with languages that enforce definition at declaration like Java."
Java doesn't enforce definition at declaration - it enforces definition before a read (or return) of the variable (so if you want it to be zero or null you have to set it to those values before you read it for the first time, rather than having a default null/0 value that was never intended).
But IME a lot of Java students learn that "rule" that definition is required at declaration because they get uninitialized variable compiler errors and doing that makes compiler errors "go away" (even if it doesn't actually fix their code) so they walk away from their intro classes thinking they need to do that. And this bit of code looks exactly like the kind of code I'd see an intro student learning Java do after they've learned that non-existent rule, so I suspect that this is code from someone who doesn't quite grasp the language they're using whatever language it is.
Admin
Honestly, could also just be a result of sloppy merging followed up by non-existing code reviews. 99% of times sloppiness is the cause of bad code, no stupidity. Humans are just incredible sloppy by default because it's energy efficient, but obviously it always results in technical debt someone else has to fix later.
Admin
Yeah, IK, I had to endure Java for years at the university and then later for decades professionally ;-)
I was just simplifying it, to not end up writing three paragraphs since most people these days don't even know the difference between a declaration and definition anymore.
Admin
In a 40 year career only about 5% of shops had any sort of code review.
Admin
Making it sound like it isn't a fun language to work with.
Admin
Yeah, it could be that too. That's probably the most reasonable explanation any time you see a line of code that's useless because of another line right after it.
Admin
You forgot "using the XKCD RNG"
Admin
"Why does x get set to 3 but then overwritten?"
Haven't you seen today's xkcd, the number "3" is vulnerable! (https://xkcd.com/3314/)
Admin
This looks like it was "left as an exercise to the reader."