The code so bad you won't hire

Y'know, other stuff, Sinclair related.
EdToo
Manic Miner
Posts: 228
Joined: Thu Nov 03, 2022 4:23 pm

Re: The code so bad you won't hire

Post by EdToo »

Vampyre wrote: Wed Jan 03, 2024 2:42 pm Didn't matter - it's far too quick so it has to be inaccurate. Okay, leave it with me...

I added a Sleep thread to the very end. 15 minutes of the application doing absolutely naff all. Everyone's now happy.

F**king people...
Making people happy by making things worse, no wonder crap coders find work.
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 »

equinox wrote: Wed Jan 03, 2024 2:57 pm Relax, I was apologising for my own story, not yours.
Apologies, equinox. I completely misread that and I'm being a bit too sensitive in my sleep-deprived state (I've been running on 2-3 hour kip per night for the last two weeks due to some ill health).

Again, please accept my apologies for my tone. I'm going to redact what I said.
ZX Spectrum Reviews REST API: http://zxspectrumreviews.co.uk/
AndyC
Dynamite Dan
Posts: 1408
Joined: Mon Nov 13, 2017 5:12 am

Re: The code so bad you won't hire

Post by AndyC »

Ah, that reminds me of one of my favourite optimization stories. Company I worked at had various SQL table build processes that ran periodically to produce reporting data. Nothing unusual there.

Except one process would take a backup of the entire database, restore it to a separate SQL Server l, run a bunch of calculations that took about 6 hours before finally using that to update data in the original source system. Nobody would touch this process because it was "complicated" and couldn't be sped up. Only, as time passed it started to creep up nearer 8 hours and that became problematic because the data was hopelessly out of date by the time it finished.

So I stupidly volunteered to have a look as I hadn't been working there long and how hard could it be? It was an absolute mess of cursors wrapped in cursors processing every row in the most agonizing way. I just spent a couple of days picking it apart without ever really understanding any of it and replicating each step with some cursor-free updates.

End result: run time of about 6 seconds, one less SQL Server to maintain and I was elevated to some kind of legendary status. I still have no idea what the code was actually doing or whether it was correct, but it certainly did whatever it was a lot faster.
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 3:01 pm Nobody would touch this process because it was "complicated"
the job of everybody on this forum
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 »

To bring this back to something retro-related, Andrew Braybrook recently tweeted that he didn't use a VCS since he was afraid it would one day prevent him from accessing his code, and he prefers to use his own backups. The guy is a legend of course, but this seemed a very strange point of view. (I don't have Twatter at work so I can't currently link to it).
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 »

Cursors are the work of the devil. But cursors within cursors - jesus... RBAR at it's finest.

The company I'm currently doing work for has a section of the system that's database driven. The guy who created this section has long since gone, but he's legendary for a being a developer who followed the exact opposite of the YAGNI principle (You Ain't Gonna Need It). Talk about code-bloat. He also had a habit of going through three nested functions just to display a simple thing on a web page (ASP).

But his best work is within SQL. I was looking at this section he wrote a few months ago as no-one has the slightest clue how it works. What a rabbit-hole. He has Views that call Views that call Views that call Views. Yup, a View that nests down three times.

Absolutely impossible to debug.
ZX Spectrum Reviews REST API: http://zxspectrumreviews.co.uk/
AndyC
Dynamite Dan
Posts: 1408
Joined: Mon Nov 13, 2017 5:12 am

Re: The code so bad you won't hire

Post by AndyC »

Vampyre wrote: Wed Jan 03, 2024 3:08 pm But his best work is within SQL. I was looking at this section he wrote a few months ago as no-one has the slightest clue how it works. What a rabbit-hole. He has Views that call Views that call Views that call Views. Yup, a View that nests down three times.

Absolutely impossible to debug.
Ugh. I once found a view that referenced a second view that referenced the first view again. If you were careful about how you queried it, it would (slowly) give you the answer. If, however, you just tried to SELECT * from it, you got an error about too many nested views.

It was back in the SQL 2000 days, before recursion was supported, so it was either genius or madness. I left it well alone.
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 3:08 pm To bring this back to something retro-related, Andrew Braybrook recently tweeted that he didn't use a VCS since he was afraid it would one day prevent him from accessing his code, and he prefers to use his own backups. The guy is a legend of course, but this seemed a very strange point of view. (I don't have Twatter at work so I can't currently link to it).
IMO there are two points here: (i) the remote system will harm me or remove my material (which is a genuine threat if, say, you post politically unpopular material on Reddit), and (ii) I want my own backups.
(i) may be regarded as paranoid. And might be paranoid, or might not be.
(ii) is important because this means you have your stuff whether you were right or wrong in your paranoia.
I suspect the general "cloud" idea doesn't go down very well with most 8-bitters who were used to knowing every byte of their machine. I also suspect that the idea of having backups (and not assuming some benevolent ambient cloud that keeps every breath you ever breathed) is novel to some of the yoof.

ONTOPIC Hewson: "Anarchy" was and is one of my fave Speccy games. The perfect mid-point between puzzle and action.
User avatar
Guesser
Manic Miner
Posts: 641
Joined: Wed Nov 15, 2017 2:35 pm
Contact:

Re: The code so bad you won't hire

Post by Guesser »

SteveSmith wrote: Wed Jan 03, 2024 3:08 pm The guy is a legend of course, but this seemed a very strange point of view.
It's also a weak excuse because nothing stops you using and benefitting from all the features of modern version control, while also backing up your working copy to GPOZF

*(Giant Pile Of Zip Files)
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 »

Guesser wrote: Wed Jan 03, 2024 3:26 pm It's also a weak excuse because nothing stops you using and benefitting from all the features of modern version control, while also backing up your working copy to GPOZF

*(Giant Pile Of Zip Files)
May I interest you in the new 90s storage technology known as the ZIP DRIVE? It can store multiple versions of pirated AutoCAD, which would otherwise require dozens of floppies. And as long as you use your files quickly -- CLICK -- CLICK -- CLICK -- uh oh!! Run!!!

I was way ahead of the curve because I had a BBC Micro 5.25" floppy drive that pretty much killed any disk you put in it. Well, I don't know. Those things had a lifetime of about 4 weeks. Whereas my good ol' Speccy +D 3.5" interface was rock-solid (a term we don't usually associate with Sinclair, don't ban me).
User avatar
Guesser
Manic Miner
Posts: 641
Joined: Wed Nov 15, 2017 2:35 pm
Contact:

Re: The code so bad you won't hire

Post by Guesser »

You don't have to rely on the cloud somebody else's computer to still benefit hugely from version control.
I have loads of personal projects in git that just live here on my own machines and I'm the only person acessing, but when I do want to collaborate with someone else it takes all of five minutes to move it to "the cloud" (most of which is the time it takes to log into github :lol:)
User avatar
ParadigmShifter
Manic Miner
Posts: 670
Joined: Sat Sep 09, 2023 4:55 am

Re: The code so bad you won't hire

Post by ParadigmShifter »

Yup you can keep your repository local.

It's a good idea to backup remotely as well of course (in case machine goes kaboom). And you can just encrypt it when you backup remotely if you don't want other people to be able to read it.
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 »

OK, time for more code:

Code: Select all

    Iterator<String> it = rolesDesc.iterator();
    while (it.hasNext()) {
        sb.append( " ? " );
        if (it.hasNext()) {
            sb.append(", ");
        }
    }
For those unfamiliar with Java: method hasNext() only checks if next element exists, without advancing the cursor. Therefore the code above will loop forever...

Once again extracted from actual code running in production.
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 »

Not code, but funny (??):

Work client sets up an account somewhere.
They use the name of the person, like john.smith@whatever.

=> I point out that we should be using role-based addresses like director@
"We did perform an IT audit some years ago and one point was that people die but organisations remain -- so we wanted to set up socialmedia@, etc. etc. and focus on roles rather than individuals. Not the end of the world though. Let's stick with the chosen address for now and revisit later if we get a chance. Main point is to get the system set up!"

The guy responds:
=> People dying is inconvenient I agree - and they should be mindful of the chaos they cause when they do that. However, in order to agree to initial licencing and to receive OTP's and the like, I think using an individual's address is fine

AITA
are we causing gooey blob chaos
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 »

Einar Saukas wrote: Wed Jan 03, 2024 3:45 pm Once again extracted from actual code running in production.
And presumably still running. Unless it was wrapped in a try/catch to catch the inevitable OOMException?
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 »

equinox wrote: Wed Jan 03, 2024 3:55 pm The guy responds:
=> People dying is inconvenient I agree - and they should be mindful of the chaos they cause when they do that.
In my pre-developer career, working for Local Government as a young man, there was one senior management idiot who 100% thought like that.

There was another guy, a team leader of about 40, who's parents died within about two months of one another. This senior manager moron held meeting after meeting with his management team debating whether the team leader should be denied compassionate/bereavement leave as he would be being given far too much time off in too short a space of time (and they only gave two days anyway). Not one of the management team had the guts to tell him what a tactless buffoon he was being. It took the CEO of the council to step in and slap him down.
ZX Spectrum Reviews REST API: http://zxspectrumreviews.co.uk/
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 4:07 pm In my pre-developer career, working for Local Government as a young man, there was one senior management idiot who 100% thought like that.

There was another guy, a team leader of about 40, who's parents died within about two months of one another. This senior manager moron held meeting after meeting with his management team debating whether the team leader should be denied compassionate/bereavement leave as he would be being given far too much time off in too short a space of time (and they only gave two days anyway). Not one of the management team had the guts to tell him what a tactless buffoon he was being. It took the CEO of the council to step in and slap him down.
Thing is, I wasn't talking about any actual dead person. I was raising "people die" as an example. Because that's the most obvious-- you know, I could perhaps better have said "people get promoted, or married, or change their names", etc. Honestly I'm more annoyed that this guy pushed 365 really hard (like there was any other way to go from on-prem Office) but is now suddenly acting like role-based security is a sin and my fault. (Discount confessions available.)

I'm probably as tactless as your guy in local gov. Hmmm. Hopefully not. Death seems to follow me around.

Regarding "having some leave" it does strike me that people would probably just shuffle away and start ignoring the dork. Rather than the slap. Who knows. There are cultural taboos.
catmeows
Manic Miner
Posts: 718
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: The code so bad you won't hire

Post by catmeows »

Guesser wrote: Wed Jan 03, 2024 2:06 pm Still not come to a firm explanation on why the teletext adapter ROM is riddled with relative conditional jumps to other jumps/calls like these

Code: Select all

	LD (HL),A
	CP (HL)
	JR NZ,init_memory_0
	JP init_48k
init_memory_0:
	JP init_16k
Looks like direct translantion from 6502 to Z80.
Proud owner of Didaktik M
User avatar
Guesser
Manic Miner
Posts: 641
Joined: Wed Nov 15, 2017 2:35 pm
Contact:

Re: The code so bad you won't hire

Post by Guesser »

catmeows wrote: Wed Jan 03, 2024 4:28 pm Looks like direct translantion from 6502 to Z80.
There was a BBC micro version, though I can't imagine there'd be any commonality in the code between the two being such different architectures.
AndyC
Dynamite Dan
Posts: 1408
Joined: Mon Nov 13, 2017 5:12 am

Re: The code so bad you won't hire

Post by AndyC »

Guesser wrote: Wed Jan 03, 2024 4:41 pm There was a BBC micro version, though I can't imagine there'd be any commonality in the code between the two being such different architectures.
There is more than one story of developers writing a quick "6502 to Z80" converter (or the other way around) to do a port quickly, so it's not entirely out of the question.
User avatar
Guesser
Manic Miner
Posts: 641
Joined: Wed Nov 15, 2017 2:35 pm
Contact:

Re: The code so bad you won't hire

Post by Guesser »

AndyC wrote: Wed Jan 03, 2024 5:06 pm There is more than one story of developers writing a quick "6502 to Z80" converter (or the other way around) to do a port quickly, so it's not entirely out of the question.
I don't mean the CPU architecture, but the machines are so completely different that I can't imagine much of the higher level functionality of the code would be relevant, let alone the actual code.
It seems silly that someone would write new software in 6502 then convert it to Z80, but it's possible if a 6502 programmer was all that was available!
AndyC
Dynamite Dan
Posts: 1408
Joined: Mon Nov 13, 2017 5:12 am

Re: The code so bad you won't hire

Post by AndyC »

Guesser wrote: Wed Jan 03, 2024 7:02 pm I don't mean the CPU architecture, but the machines are so completely different that I can't imagine much of the higher level functionality of the code would be relevant, let alone the actual code.
It seems silly that someone would write new software in 6502 then convert it to Z80, but it's possible if a 6502 programmer was all that was available!
Well business logic is going to be pretty similar regardless and it depends how abstracted other functionality is. And if you're given the job of converting a big blob of 6502 to Z80 as quickly as possible, with little care for optimization, then doing the bulk of it with a nasty batch conversion process might have been the least worst option.
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 »

SteveSmith wrote: Wed Jan 03, 2024 4:04 pm And presumably still running.
Nope.

All my examples are from code in production that I fixed.

SteveSmith wrote: Wed Jan 03, 2024 4:04 pm Unless it was wrapped in a try/catch to catch the inevitable OOMException?
Of course not! Neither this one:

Code: Select all

public DefaultConfigurableObject downStreamProcessEvent(
                ExpresionEvaluator evaluator, DefaultConfigurableObject eventParms,
                EventType eventType) {

        return downStreamProcessEvent(evaluator, eventParms, eventType);
}
User avatar
Guesser
Manic Miner
Posts: 641
Joined: Wed Nov 15, 2017 2:35 pm
Contact:

Re: The code so bad you won't hire

Post by Guesser »

AndyC wrote: Wed Jan 03, 2024 10:54 pm Well business logic is going to be pretty similar regardless and it depends how abstracted other functionality is. And if you're given the job of converting a big blob of 6502 to Z80 as quickly as possible, with little care for optimization, then doing the bulk of it with a nasty batch conversion process might have been the least worst option.
Yes, but again I'm specifically talking about this specific ROM for the spectrum having little in common with the functionality required on a bbc micro so there's nothing to "port"
catmeows
Manic Miner
Posts: 718
Joined: Tue May 28, 2019 12:02 pm
Location: Prague

Re: The code so bad you won't hire

Post by catmeows »

Guesser wrote: Thu Jan 04, 2024 2:24 am Yes, but again I'm specifically talking about this specific ROM for the spectrum having little in common with the functionality required on a bbc micro so there's nothing to "port"

Boss: Hey, you, programmer ...
Programmer: Me ?
Boss: We need to code this stuff... by Friday. Presto, presto.
Programmer: But... I program for 6502.
Boss: What ?
Programmer: This is Z80. I don't code for Z80.
Boss: What is the difference ?
Programmer: Well, for start ...
Boss: You are programmer, right ? You program things, right ?
Programmer: Yeeeeeah... I have Z80 instruction table somewhere.

-----------------------------------
6502 has short branches only and and unconditional long jump. The idiom you showed above would be typical for 6502 (or 6800). But it is just guess....
Proud owner of Didaktik M
Post Reply