The code so bad you won't hire

Y'know, other stuff, Sinclair related.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

The code so bad you won't hire

Post by equinox »

Earlier today I was asking some people: what line of code would make you never hire someone?
My anti-hire line was:
s = s.replace("&", "&");

Let us see if we can find Speccy equivalents.
What line of BASIC or asm might occur, but would raise the "clueless" flag with you?
Perhaps somebody trying to save bytes with VAL "BIN 1001"...
or the famous demoscene party DI HALT.

Share bad code you have seen, or don't want to see.
Timmy
Manic Miner
Posts: 230
Joined: Sat Apr 23, 2022 7:13 pm
Location: The Netherlands

Re: The code so bad you won't hire

Post by Timmy »

I certainly won't hire managers who do things like this. Because you know these are bad managers and can't code themselves.



However, if I see code that starts with:

10 POKE 53280,0 ;)

Then they're even poor managers. :lol:
User avatar
Einar Saukas
Bugaboo
Posts: 3145
Joined: Wed Nov 15, 2017 2:48 pm

Re: The code so bad you won't hire

Post by Einar Saukas »

10 CLEAR 30000: LOAD "" CODE 30000
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: The code so bad you won't hire

Post by equinox »

Timmy wrote: Wed Jan 03, 2024 11:34 am However, if I see code that starts with:
10 POKE 53280,0 ;)
Then they're even poor managers. :lol:
What the hell, we have a C64 guy here... light the torches!
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: The code so bad you won't hire

Post by equinox »

Einar Saukas wrote: Wed Jan 03, 2024 11:37 am 10 CLEAR 30000: LOAD "" CODE 30000
This made me laugh out loud, but tell me you've never counted back 8 bytes on your fingers and then wondered if it was right or not.
Precisely the same as "what date is next Wednesday".
"measure twice and cut once"
User avatar
R-Tape
Site Admin
Posts: 6409
Joined: Thu Nov 09, 2017 11:46 am

Re: The code so bad you won't hire

Post by R-Tape »

Einar Saukas wrote: Wed Jan 03, 2024 11:37 am 10 CLEAR 30000: LOAD "" CODE 30000
Nowt wrong with that. Saves a byte, and who wants to return to BASIC anymore :mrgreen:
AndyC
Dynamite Dan
Posts: 1409
Joined: Mon Nov 13, 2017 5:12 am

Re: The code so bad you won't hire

Post by AndyC »

I've seen a few head scratches in real production code at times, my favourite was along the lines of:

Code: Select all

BOOLEAN x = (SELECT flag FROM table);

IF x=2 THEN ...
Genuinely no idea what the coder was trying to achieve.

Another close contender was a 4 page function to determine what the date on the first of the month is (yes it was always the 1st!), followed by a single line of code that just set the end of the month to be the 28th...

Im sure you could reproduce such fine work in Sinclair BASIC, but I don't think you should. :lol:
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: The code so bad you won't hire

Post by ParadigmShifter »

Should have just borrowed this. EDIT: I see that they aren't trying to work out the weekday though.

viewtopic.php?p=132534#p132534

EDIT: I think some code in Windows may have tri-state booleans? (Check boxes rings a bell).

EDIT: Tons of them, and BOOL is a synonym for int anyway. GetMessage returns a BOOL but it can return 0, 1 or -1 lol
Last edited by ParadigmShifter on Wed Jan 03, 2024 12:00 pm, edited 3 times in total.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: The code so bad you won't hire

Post by equinox »

AndyC wrote: Wed Jan 03, 2024 11:51 am I've seen a few head scratches in real production code at times, my favourite was along the lines of:
Mate you can't post SQL here, I searched all the forums and there was nothing for SQL.
So I had to tweak my post and say "what if it was on a Spectrum".

See also: my forthcoming post: who's your favourite Harry Potter character IF IT WAS ON A SPECTRUM.

Of course if it's code in "TasSQL: The 128K Database" then we are happy to see it. Haha CP/M they said. Future-proof!
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: The code so bad you won't hire

Post by equinox »

ParadigmShifter wrote: Wed Jan 03, 2024 11:54 am EDIT: I think some code in Windows may have tri-state booleans? (Check boxes rings a bell).
const int YES = 1;
const int NO = 0;
const int UNKNOWN_OR_MULTIPLE = 42;

Do you reckon we should tell them about bits
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: The code so bad you won't hire

Post by ParadigmShifter »

I've seen some bad "coding standards" documents which made me regret taking positions before.

Worst one had things like:

No use of break or continue (so have to use bools everywhere to check loop conditions)
No multiple return statements in a function (bad: return early from a function if you can)
No drop through case statements (so you can't use them as a jump table which is what they are designed for!)

I've seen some terrible code but that was from people already hired.

Worst 2 examples were someone changing the signature of a virtual function that was used everywhere (very bad idea) and changing all /*********/ comments at the top of functions into /////////////////////// on a whim which meant that when I came in to fix the bug (original programmer didn't do Saturday emergency bug fixes) I saw that nearly every file had changed.

EDIT: I also saw someone (although he was at school and on work experience, so I explained why it was a bad idea to him and that was that) use

if(a * b)

to do

if(a && b)

which is very bad if you overflow.
AndyC
Dynamite Dan
Posts: 1409
Joined: Mon Nov 13, 2017 5:12 am

Re: The code so bad you won't hire

Post by AndyC »

ParadigmShifter wrote: Wed Jan 03, 2024 11:54 am EDIT: I think some code in Windows may have tri-state booleans? (Check boxes rings a bell).

EDIT: Tons of them, and BOOL is a synonym for int anyway. GetMessage returns a BOOL but it can return 0, 1 or -1 lol
Yeah, but this was SQL and a real, single bit field. Was never going to branch...

equinox wrote: Wed Jan 03, 2024 11:55 am Mate you can't post SQL here, I searched all the forums and there was nothing for SQL.
So I had to tweak my post and say "what if it was on a Spectrum".

See also: my forthcoming post: who's your favourite Harry Potter character IF IT WAS ON A SPECTRUM.

Of course if it's code in "TasSQL: The 128K Database" then we are happy to see it. Haha CP/M they said. Future-proof!
Well now I intend to write a TasSQL, although it will be 48K Microdrive only. And then everyone can program their Spectrum in god's own programming language.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: The code so bad you won't hire

Post by equinox »

ParadigmShifter wrote: Wed Jan 03, 2024 12:13 pm No use of break or continue (so have to use bools everywhere to check loop conditions)
I've heard of KLOC (you are paid by how many lines of code you write), but "no use of break" is a whole new mystery. You are paid by how many lines of code you *execute*? Directly through Amazon AWS. (Yeah yeah I know about a C switch, but bear with me.)

If I want to forbid the use of break, then I do this: POKE 23659,0

By the way: in my first "real" job (which was porting Visual Basic 6 to C# -- dont judge), the senior programmer would set every reference-type variable to null at the end of every function. This drove me mad because I knew it was meaningless: even if you had to do something like a C free() -- which you don't in .NET because it's garbage-collected -- then you certainly wouldn''t do it by setting things to null, because that is merely making the referents inaccessible. You would call IDisposable::Dispose.

I was so ****ing mad. But I was 20 years old and he was about 40, and so it was put down as a "staff issue".
The day that L left, you better believe I took four hours removing all those ****ing nullings.

Then I checked in my changes to Visual SourceSafe. Oh god
Last edited by equinox on Wed Jan 03, 2024 12:32 pm, edited 1 time in total.
User avatar
Vampyre
Manic Miner
Posts: 839
Joined: Wed Nov 15, 2017 2:51 pm
Contact:

Re: The code so bad you won't hire

Post by Vampyre »

Not specific code examples but...

A developer asked us to write down what the function he was working on had to do exactly as he could not wrap his head around it. So myself and a manager painstakingly wrote out in pseudo-code exactly what it had to do (it wasn't complicated at all). Two days later the developer asked me why the code was highlighting syntax errors all over the place. He'd copied the pseudo-code verbatim into the IDE. This was a developer who had been part of the company for at least two years.

Another developer was your typical know-it-all-better-than-everyone-else idiot. He only lasted a year or so when it came to light that he'd not really developed anything at all (I was only a code-jockey at the time, not part of management so wasn't keeping an eye on him). The reason he hadn't developed anything, which he told them on the day of his termination, was that he didn't trust any of the components of Visual Studio. And I mean EVERY component. So he'd written his own framework for labels, textboxes and even Data Access Objects. But none of them worked properly and were constantly crashing. So in essence he tried making his own version of Visual Studio, on the companies dime, and failed spectacularly at it.

I can mention this one now as I've long since left the company. They have changed the infrastructure since but, put it this way, I would never, ever use a Diner's Club card as that company holds all the transactions and card details. None of the data was obfuscated. Absolutely everything was stored in SQL Server in plain-text. That's seriously bad and sufficient for GDPR/PCI to rip them to pieces but that's not the crowning turd. This was the SQL Server being on a public IP address and, here's the real kicker, the [sa] password being an empty string. There were no other users other than the [sa]. This was so the owner could look at the data from home whenever he wished and couldn't be arsed to remember a password (his exact words). An ethical hacker got in eventually and informed them he was contacting Diner's unless things were changed pronto. So a password was added to the [sa] user. How that company is still going I will never know.
ZX Spectrum Reviews REST API: http://zxspectrumreviews.co.uk/
AndyC
Dynamite Dan
Posts: 1409
Joined: Mon Nov 13, 2017 5:12 am

Re: The code so bad you won't hire

Post by AndyC »

equinox wrote: Wed Jan 03, 2024 12:30 pm I was so ****ing mad. But I was 20 years old and he was about 40, and so it was put down as a "staff issue".
The day that L left, you better believe I took four hours removing all those ****ing nullings.
Yeah, seen that. And wrapping every bit of code in a try {} catch {throw;} block in case something might cause exceptions to not bubble up if you don't write it explicitly....
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: The code so bad you won't hire

Post by equinox »

Vampyre wrote: Wed Jan 03, 2024 12:32 pm Not specific code examples but...
Jesus this really can't become "awful code that has nothing to do with a Spectrum", can it, but you just reminded me of ---
AHHHH. All right I'll stop.
Please play my Rockfall hack on the way out, it's just next to the gift shop.

POST ONLY BAD BASIC AND Z80 CODE
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: The code so bad you won't hire

Post by equinox »

Vampyre wrote: Wed Jan 03, 2024 12:32 pm [...] The reason he hadn't developed anything, which he told them on the day of his termination, was that he didn't trust any of the components of Visual Studio. And I mean EVERY component. So he'd written his own framework for labels, textboxes and even Data Access Objects. [...]
That's *almost* like us 80s kids refusing to use some cloud sh*t because it's cheaper and sensible locally. But:
Vampyre wrote: Wed Jan 03, 2024 12:32 pm But none of them worked properly and were constantly crashing.
oh lol.
If you build your own, maintain your own.

I like the "this is a company everybody knows" postscript. Ronald McDonald is comin out to shoot you tonight.
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: The code so bad you won't hire

Post by ParadigmShifter »

I once wrote a C macro which ended with the keyword else ;) I wouldn't do that nowadays (it was when Sony decided if you press and hold select and start for 2 seconds you have to quite back to the main menu, and I had pad read code all over the place at the time (which I wouldn't do now, read it once per frame), so I had to use a macro to change them all to check for start/select being held as well.

PS1 days were great

#define ONE 4096

#define TWO_PI ONE

:)

EDIT: I don't think many people are hiring ZX Basic or Z80 programmers (well there'll be a few of those around but very few these days).
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: The code so bad you won't hire

Post by equinox »

AndyC wrote: Wed Jan 03, 2024 12:33 pm Yeah, seen that. And wrapping every bit of code in a try {} catch {throw;} block in case something might cause exceptions to not bubble up if you don't write it explicitly....
Yes, can't trust the compiler to do a throw unless we write it ourselves.
The only reason they don't write a lot of null inherited methods is that they don't know the option is there.
Anyway it's 2024 and I doubt anybody does OOP any more. These days we just throw data somewhere, take a statistical average of what might possibly be there, and call the rest racist, right?
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: The code so bad you won't hire

Post by equinox »

ParadigmShifter wrote: Wed Jan 03, 2024 12:43 pm I once wrote a C macro which ended with the keyword else ;)
fairly sure this dude worked on WIPEOUT, don't ask how I know

He was ultimately fired from Rareware for writing a macro that ended with VAL$
User avatar
ParadigmShifter
Manic Miner
Posts: 671
Joined: Sat Sep 09, 2023 4:55 am

Re: The code so bad you won't hire

Post by ParadigmShifter »

equinox wrote: Wed Jan 03, 2024 12:45 pm fairly sure this dude worked on WIPEOUT, don't ask how I know

He was ultimately fired from Rareware for writing a macro that ended with VAL$
Nope never worked on Wipeout (I would have made the sliding along walls thing work for a kickoff) :)

Sony introduced the hold select and start thing just before we had to submit, when I was developing it that was not a thing you had to do.

My macro also called longjmp() which I thought was bad at the time but hey that's basically how exceptions work :)

EDIT: So my macro was basically

#define CHECKSELECTSTARTHELD if(StartSelectHeldDownTime() > 2 seconds) longjmp(somewhere in main lol) else

usage

CHECKSELECTSTARTHELD
PadRead()
Last edited by ParadigmShifter on Wed Jan 03, 2024 1:03 pm, edited 1 time in total.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: The code so bad you won't hire

Post by equinox »

Reminds me of another good one. This was my first "real" job, in transport/logistics. They had this stupid huge postcode-checker stored procedure, which picked each letter or number from the postcode and compared it against the data, one by one. I knew this was bad and wrong, but it was extremely difficult to understand the thing. One day I printed it all out on a load of paper and studied it carefully in the work hotel and realised that about 80% of what it was doing was totally redundant. I also (HEY! LISTEN!) realised that there was a big bug here, and it didn't even work how it was supposed to. For example, it would confuse an N postcode (North London) with NR (Norwich). So I fixed that bug too.

Came back, proposed my "optimised" (not having a ton of redundant loops) code -- this was TransactSQL, by the way, Andy understands -- and we put it live. Guess what happened. We got the phone lines full of screams from people who had been relying on the ****ing bug, where Norwich and North London had the same transport planning.

Something died in me that day.

(And no, it wasn't a regex, this was slightly before regex was mainstream, and certainly way before you could do it in SQL Server. It was horrible string slicing in loops.)
SteveSmith
Manic Miner
Posts: 724
Joined: Mon Nov 26, 2018 1:07 pm
Location: UK
Contact:

Re: The code so bad you won't hire

Post by SteveSmith »

equinox wrote: Wed Jan 03, 2024 11:09 am Earlier today I was asking some people: what line of code would make you never hire someone?
My anti-hire line was:
s = s.replace("&", "&");
I'll probably regret asking this, but what's wrong with this code if you want to replace all occurrences of the specified string? I'd be looking to find out why a string has "&" in the first place.
equinox
Dynamite Dan
Posts: 1052
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: The code so bad you won't hire

Post by equinox »

SteveSmith wrote: Wed Jan 03, 2024 1:03 pm I'll probably regret asking this, but what's wrong with this code if you want to replace all occurrences of the specified string? I'd be looking to find out why a string has "&" in the first place.
Yeah, precisely, you'd be looking to find out, but the code is trying to bury it (and the author probably doesn't know or care what an XML entity is, but just wants to get rid of the thing). You're fine.
AndyC
Dynamite Dan
Posts: 1409
Joined: Mon Nov 13, 2017 5:12 am

Re: The code so bad you won't hire

Post by AndyC »

equinox wrote: Wed Jan 03, 2024 12:58 pm
Came back, proposed my "optimised" (not having a ton of redundant loops) code -- this was TransactSQL, by the way, Andy understands -- and we put it live. Guess what happened. We got the phone lines full of screams from people who had been relying on the ****ing bug, where Norwich and North London had the same transport planning.

Something died in me that day.
:lol:

I suspect 90% of the worst code ever created in the UK is dealing with Postcodes. Because they're stupid.

I feel your pain on though, having done the "We need you to rewrite this terrible code, but we need all the bugs to stay there because we've got other code reliant on them" more than once.

The whole industry is a sham.
Post Reply