Terrible coding examples

Associate
Joined
9 Jun 2004
Posts
423
This is language dependent. Great plan iff resources associated with the stack clean up on return. Without some variant of with() or raii, early return implies leak. Always bad in C, often bad in garbage collected languages, great plan for modern C++ :)

goto cleanup :cool:
 
Soldato
Joined
30 Jan 2007
Posts
15,466
Location
PA, USA (Orig UK)
My personal favourite is going through live code, and finding comments that say things like " // Fix this before release ". Sometimes I find comments as questions in the code like "//Is this correct ? " or "// Should this be null" etc. Kinda worrying, especially when sometimes those are connected to FIX ME's or TODO's (Which get highlighted in the IDE.)
 
Man of Honour
Joined
13 Oct 2006
Posts
92,043
One I (sort of) fell foul of - a bad practise is passing passwords on to where they are actually needed in the code rather than verifying them at the point they are actually needed. (Sometimes you don't have much choice) but its a potential security weakness especially if you are passing them on to an external component rather than reading/checking within that component.

In my defence in my case it was wrapped inside another security layer which if they had got that far, being able to read that specific password would have been the least of the worries heh.

(Likewise working with plaintext passwords but sometimes you don't have a choice on that).
 
Last edited:
Soldato
Joined
14 Mar 2011
Posts
5,423
My personal favourite is going through live code, and finding comments that say things like " // Fix this before release ". Sometimes I find comments as questions in the code like "//Is this correct ? " or "// Should this be null" etc. Kinda worrying, especially when sometimes those are connected to FIX ME's or TODO's (Which get highlighted in the IDE.)

Bonus points if:

A. It's an old enough comment that it actually no longer makes any sense at all in the context of where it appears

B. It's an annoying attempt to indicate/preserve information about previous behaviour in-spite of version control which does that for you (i.e. "changed at v2.0")
 
Soldato
Joined
14 Oct 2003
Posts
7,831
I'm not a dev, but I hate it when someone writes a script on my team and instead of breaking it down into functions, its all in the body of the code, with horrendous amounts of nested loops.
 
Associate
Joined
2 Jul 2003
Posts
2,442
My personal favourite is going through live code, and finding comments that say things like " // Fix this before release ". Sometimes I find comments as questions in the code like "//Is this correct ? " or "// Should this be null" etc. Kinda worrying, especially when sometimes those are connected to FIX ME's or TODO's (Which get highlighted in the IDE.)

I do stuff like that all the time! I'm no developer though so I'm the only one whose likely to see it. I've found comments where I've insulted myself with comments pointing how dumb/inefficient a block of code is and to come back and figure a better way of doing it. Rarely do.

I'm not a dev, but I hate it when someone writes a script on my team and instead of breaking it down into functions, its all in the body of the code, with horrendous amounts of nested loops.

Same, I try to make everything I do as plain as possible. Normally so that when I come back to something 8 months later I can make heads or tails of what I've done.
Love powershell and the crazy piping you can do but sometimes I'll go back and blow it out a bit to make it easier to follow or amend. Can do an awful lot in a single line.
 
Last edited:
Associate
Joined
21 May 2013
Posts
1,991
My personal favourite is going through live code, and finding comments that say things like " // Fix this before release ". Sometimes I find comments as questions in the code like "//Is this correct ? " or "// Should this be null" etc. Kinda worrying, especially when sometimes those are connected to FIX ME's or TODO's (Which get highlighted in the IDE.)

In my experience this is often a result of "Right in the middle of working on a feature? Nope, we have to launch RIGHT NOW or they might think we haven't been doing any work"
 
Soldato
Joined
20 Dec 2004
Posts
16,027
Commented out code is my personal pet hate.

If it's not needed, delete it. If it's needed again, you can get it from source control.
 
Soldato
Joined
23 Feb 2009
Posts
4,976
Location
South Wirral
This is doing the rounds on linkedin at the moment:

0c7c65dd-8a14-4f53-b5d4-6a414b1d6db5-medium.jpeg
 
Soldato
Joined
14 Oct 2003
Posts
7,831
Or you hear "this isn't supposed to work, not sure how it does, but oh well".

In a few of the places I've worked I've often heard the case of the business taking on a contractor for 6 months to write a part of the app and find after they have left that the code is a compete mess and have to rewrite it.
 
Last edited:
Soldato
Joined
30 Jan 2007
Posts
15,466
Location
PA, USA (Orig UK)
The one I remember was having to refactor and rewrite some archaic code I'd never seen before. The lead developer went away for two weeks who knew about it, and left vague instructions. That wasn't so bad, until I looked at the code.

Upon examination, whilst having to deal with something like 7 levels of inheritance (where the naming convention they had used made no logical sense), they had this thing called 'isFlag'. There was no indication of what isFlag was meant to be, where it came from, what it was meant to be assigned as.

Aside from doing an damn good job at rewriting this crap (which I still can't believe I did it, given I spent my time on an emotional rollercoaster, almost crying, laughing, head in hands, joking, shouting etc), I still to this day have no idea what the hell isFlag was meant to be, and neither did/do any of my colleagues.
 
Back
Top Bottom