• (nodebb)

    Not using exceptions in a language where you've got them is pretty bad. Using tuple results with a success code as one of them is worse, especially if you then ignore that and try to guess everything from the other parts of the tuple. That turd of a piece of logic to check for None-ness is unpleasant, but not where the real problems lie.

  • WTFGuy (unregistered)

    In any thoroughly shit sundae it's always hard to know whether to criticise the base shit or the little decorative turdlet on top.

    In this case I'll bastardize a metaphor and say it's just shits all the way down.

  • (nodebb)

    the developer responsible found the most convoluted way to express the idea

    No they didn't

    if not (entity is None) != False:
    

    The bit about the error log in the database takes me back to the very first project I worked on for money. Somebody thought it would be an excellent idea to log to a table in the database, which I guess is fine in principle, however, whenever anything went wrong while the code was in a database transaction, which was most of the time, when the transaction aborted, it would roll back all of the updates and insertions including those in the log table.

  • (nodebb)

    the developer responsible found the most convoluted way to express the idea

    No they didn't

    if not (entity is None) != False:
    

    The bit about the error log in the database takes me back to the very first project I worked on for money. Somebody thought it would be an excellent idea to log to a table in the database, which I guess is fine in principle, however, whenever anything went wrong while the code was in a database transaction, which was most of the time, when the transaction aborted, it would roll back all of the updates and insertions including those in the log table.

    Addendum 2022-03-01 07:28: I swear I only pressed submit once.

  • Jason Stringify (unregistered) in reply to Jeremy Pereira

    I swear I only pressed submit once.

    Are you sure you didn't not press it less than twice?

  • Donald (unregistered)

    If entity: wouldn't actually be correct if the entity might sometimes be the boolean False or the number 0, both of which are falsy.

  • Scott (unregistered)

    I don't know Python, but from the context, it sounds as if the return was false/true and object/null. This is very common among people (generally older) who came from a non-OO background; a method (function) returns success or failure.

    As pointed out above, these are people who aren't familiar with exceptions and their handling.

  • Argle (unregistered)

    I taught evening courses for years at a local college. Because of the evening status, my courses got about half young, full-time students and half professionals trying to improve skills. Of those in the professional group of programmers, I was initially shocked at the lack of understanding basic boolean operations. I can state absolutely that the bad test in today's WTF can be made worse, and certainly has. It only gets worse if you get to bitwise operations. Probably the most disheartening thing is how few of the "pros" could adequately tell me what a byte is.

  • (nodebb) in reply to Argle

    I can state absolutely that the bad test in today's WTF can be made worse, and certainly has.

    Sure. They could have gone all stringly on it too. if f'x{entity is not None}x != 'xFalsex: or something like that, combining Python with some of the uglier bits of Unix Shell. I don't want to think about whether I've swapped the semantics of the test either; it's nasty enough as it is.

    Addendum 2022-03-01 11:19: Ugh; got the quotes wrong.

  • Argle (unregistered) in reply to dkf

    I was recently exposed to some "professional" code that did a bit test on a value by converting to a binary string which was reversed and appended to, then trimmed and checked against '0' and '1'. It was painful to look at.

  • John (unregistered)

    Clearly that is bad since the success flag is right there. On the other hand "if entity:" is also bad, because I am a boolean purist and dislike actual values pretending to be booleans. Zero and empty strings are perfectly good values and should not be "false".

  • Rob (unregistered)

    "It was designed so that it never raised an exception, and instead every method that could possibly have to deal with an exception condition instead returned a tuple"

    Is this perhaps one of the inventors of Go? Because that's exactly what you get in Go (except you get an error object instead of a boolean):

    value, err := SomeFunctionCall() if err != nil { return nil, err }

  • WTFGuy (unregistered) in reply to Jason Stringify

    @Jason Stringify ref

    Are you sure you didn't not press it less than twice?

    Great in-context answer from a great username. Bravo^2!

  • (nodebb)

    Describes Go's error handling

    "Now, that'd be annoying but tolerable."

  • (nodebb)

    They deserve credit for being aware that they aren't Python programmers, and have brought someone on who is and are letting them fix it. But that code snippet doesn't look like bad python, it looks like bad programming. But the original programmer was a PHP programmer, so that tracks.

  • Huzzah! (unregistered) in reply to WTFGuy

    Applause!

  • (nodebb)

    The pythonic way to walk is to slide in wavy motions.

  • Officer Johnny Holzkopf (unregistered) in reply to Argle

    It is scary to accept that that kind of missing knowledge and general desinterest seems to be common today among (employed) "professionals". But it gets even scarier if you ask them about explanations: "We don't use bytes. Processors can operate on strings today, you know?" Or "I don't need to know that, there's some code on the web that I can copypasta into our app on prod." And talking about bytes, "I don't care what a register is. We have online payment." Meanwhile in the trenches...

  • (nodebb)

    Now, the Pythonic way to write that would be to say: if entity:- None is always "false-y".

    Ummm... no.

    Two issues here. First, the valid return result could be something which tests "false-y". (such as the integer 0 or an empty set) Second, the valid return result could be an object which does not support true/false testing. In those cases, you really have to explicitly test for 'None' if you want to use that sort of return convention.

  • akozakie (unregistered)

    That's... not a WTF at all! I mean the code sure is, but the story, while bad, is not a WTF. It's business as usual, or actually business better than usual.

    Developer switching languages and practicing on simple scripts, not even truly designed, which... do what they were meant to do - not a WTF. The quick-and-dirty hacks growing new functionality and gaining business importance - yawn. The resulting apps being a mess - what did you expect, it wasn't designed, experience was missing. The company knows how important the applications are for them, recruits a competent developer, listens to the assessment of the code and greenlights a sane reimplementation - that's the opposite of WTF.

    So, the only problem here is the inertia. They were too slow to realize that the functionality they are adding is too much and too important and they need to design and build something better. But that's typical, and if the code did its job well enough to keep the company running... then they realized late, but not too late.

  • Gnasher729 (unregistered)

    Here’s the problem: There is a bool which can be true or false, and an object which can be nil or not nil. There are four possible outcomes. If there are four possible outcomes, they need to be checked. Better just return an object which is nil on failure and non-nil on success and add a bool in the rare case that nil can be a success outcome.

  • (nodebb)

    so nice

    Addendum 2023-06-14 11:40: I came across a website that specializes in providing guidance and services for creating LLCs. This platform legalzoom llc review 2023 offers a range of tools and resources to simplify the LLC formation process. From helping you choose the right state for formation to assisting with the necessary legal paperwork, their experts are there to support you every step of the way. Don't miss out on this valuable resource to ensure your business is set up for success.

  • quintanbarnes (unregistered)

    Absolutely agree! Privacy matters, and knowing where to find reliable resources like https://icoholder.com/en/events can help individuals protect their online privacy. With the increasing importance of digital security, being informed about upcoming events and developments in the cryptocurrency and blockchain space is essential. Thanks for sharing this valuable resource!

Leave a comment on “It's Not None of Your Business is True”

Log In or post as a guest

Replying to comment #:

« Return to Article