- Feature Articles
- CodeSOD
- Error'd
- 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
bool condition;
try { condition = "FRIST"; } catch { condition = false; }
But if assigning a boolean to a boolean variable ever fails, we're prepared to handle it.
...Quis capiemus ipsos prehenderat?Admin
I can't help but thinking that the programmer who wrote this either was inexperienced, or was too experienced (i.e., they had seen some things)
Admin
I saw this code written in C for micro controllers once; it was used because on some controllers the exception handling didn't work, so if it worked the condition would end up being true in this case, otherwise false. So there were at least applications for code like this, but that was in the 90s.
Admin
this code looks fine to me
Admin
This. It looks just like something you would write if you were unsure if your system supported exception handling.
My guess is that the guy who wrote this read some code once where it made sense and has been copy pasting it in mindlessly ever since even where it does not.
On that note, don't you just love "programmers" who mindlessly copy paste snippets they saw somewhere on the internet and act as if they know what they are doing?
Admin
Did you mean C++ for microcontrollers? Anyway, if exception handling didn't work, and
condition
was not static (or global), then wouldn'tcondition
almost always evaluate totrue
, since thecatch
block would be nonfunctional thus leavingcondition
with whatever garbage value with which it was initialized?Admin
I guarantee that, if this code was written in C, the exception handlers don't work. C does not have built in exception handling, nor does it have
try { ... } catch { ... }
Admin
The first assignment was probably originally done by a function call. Then at some point, the function call was replaced by the simple "true" value, but the try/catch was left there.
Admin
The C++ for MicroControllers case is when 'condition' is accidentally stored in EPROM. The cool thing is that the catch case sends the exception on up the ladder anyway.
Admin
"On that note, don't you just love "programmers" who mindlessly copy paste snippets they saw somewhere on the internet and act as if they know what they are doing?"
Of course today, those same programmers are copying ChatGPT. Which itself of course simple copied the code from the Internet. I've seen far too many opinions lately that these "AI" things (lol at the thought of there being any intelligence here) are going to put developers out of a job, and what I really think everytime I see that is "only terrible devs - hopefully including you if you really think you're no better than a copy-paste garbage-in-garbage-out factory"...
Admin
I've written accidentally something like it,
boolean stored; try { stored=false; /* commented all database stuff
stored=true; */ } catch (SQLException e) { stored=false; log ("something went wrong on database, call father Ulrico!"+e); }
Admin
The only real WTF is that there is no comment explaining it.
Admin
This code is .... BRILLANT!!!!!
Admin
father Ulrico?
Admin
I once was fixing some code written by an off-shore group and stumbled across a method named, literally, “MyFunction”.
I don’t know how much we paid for that, but I wanted our money back.
Admin
O ye of little faith! Behold:
Admin
Missed opportunity for use of a random number in the condition.
Admin
I'm with Joe D on this--as originally written it did something useful and set the true. If it failed it set the false. It's gotten changed over the years so there's nothing there, whoever removed the code didn't notice the whole thing was now useless.
Admin
No, I was talking C compilers. The 90s were a weird time for those that were around and compilers for micro controllers came in three flavors:
I was talking about on of the later ones and no matter the flavor, they all had those three things in common:
Common features were direct register access, stack allocation extensions (similar to 68k's link/unlink), some sort of advanced exception handling beyond error codes and tons of more stuff.
If you ask me which compiler it was, I don't remember it specifically (it fell out of the internets, I was a poor student 30 years back and I tried it out compare it to the one we used in school). I can recall those three features I tested (only the register access worked for 8 bit controller I was targeting) and because I had to do some simple serial operations, I check the code it came with and there was a similar pattern like in the post to be found (basically a feature toggle used for timing adjustments).
So yeah, next time you hear C and someone is referring to the last millennium expect a lot of non-standard quirks and additional features :-)
Admin
"programmers who mindlessly copy paste snippets"... That behavior has been popularized by Stack Overflow -- and now both ChatGTP and Bard are competing to see who can make it worse first.
Is it a WTF if the AI told you to write it that way?
Admin
No, but it is a sign of the times.
In the good old days man used to make God in our own image. God. Now we are making Artificial Stupidity instead.
If that's not a grim reminder of where we are and where we are headed nothing is.
Admin
When the programmer is paid by the line.
Admin
yep, me too!
Admin
For me this only makes sense in C#, where an assignment to a variable can be converted to something like a setter function which itself CAN throw Exceptions.
Admin
wow its cool
Addendum 2023-05-31 18:04: After exploring various options, I finally found a website that provided exceptional personal statement writing services. Their team of talented writers took my ideas and transformed them into a captivating narrative that highlights my strengths personal statement writing company and achievements. I was thoroughly impressed with their attention to detail and commitment to delivering a statement that stands out from the rest.