- 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
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.Admin
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.
Admin
No they didn't
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.
Admin
No they didn't
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.
Admin
Are you sure you didn't not press it less than twice?
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
"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 }
Admin
"Now, that'd be annoying but tolerable."
Admin
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.
Admin
Applause!
Admin
The pythonic way to walk is to slide in wavy motions.
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
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!