• (nodebb)

    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?

  • Allie C (unregistered)

    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)

  • (nodebb)

    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.

  • Brillant Paula (unregistered)

    this code looks fine to me

  • LZ79LRU (unregistered) in reply to MaxiTB

    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?

  • (nodebb) in reply to MaxiTB

    Did you mean C++ for microcontrollers? Anyway, if exception handling didn't work, and condition was not static (or global), then wouldn't condition almost always evaluate to true, since the catch block would be nonfunctional thus leaving condition with whatever garbage value with which it was initialized?

  • (nodebb) in reply to MaxiTB

    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 { ... }

  • (nodebb)

    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.

  • LCrawford (unregistered)

    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.

  • Robin (unregistered) in reply to LZ79LRU

    "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"...

  • MIKE (unregistered)

    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); }

  • dpm (unregistered)

    The only real WTF is that there is no comment explaining it.

  • (nodebb)

    This code is .... BRILLANT!!!!!

  • (nodebb) in reply to MIKE

    father Ulrico?

  • Richard Brantley (unregistered) in reply to LZ79LRU

    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.

  • (nodebb) in reply to jeremypnet

    C does not have built in exception handling, nor does it have try { ... } catch { ... }

    O ye of little faith! Behold:

    #define try if(1)
    #define catch else
  • (nodebb) in reply to dkf

    Missed opportunity for use of a random number in the condition.

  • (nodebb)

    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.

  • (nodebb)

    Did you mean C++ for microcontrollers?

    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:

    • Micro controller specific C compilers
    • Micro controller family specific C compilers
    • Generic micro controller C compilers

    I was talking about on of the later ones and no matter the flavor, they all had those three things in common:

    • They generic very bloated code (compared to handcrafted assembler)
    • They had super expensive license business models attached to them, even for the times.
    • They added a ton of non-standard features

    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 :-)

  • (nodebb) in reply to LZ79LRU

    "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?

  • LZ79LRU (unregistered) in reply to Ralf

    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.

  • WTFGuy (unregistered)
    Comment held for moderation.
  • not the frist (unregistered)
    Comment held for moderation.
  • Mike (unregistered)

    When the programmer is paid by the line.

  • Complete Thesis (unregistered)
    Comment held for moderation.
  • Brilliant Paul (unregistered) in reply to Brillant Paula

    yep, me too!

  • Daniel (unregistered)

    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.

  • (nodebb)

    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.

  • Survey duniya (unregistered)
    Comment held for moderation.

Leave a comment on “Exceptional Assignment”

Log In or post as a guest

Replying to comment #:

« Return to Article