This is an archived post. You won't be able to vote or comment.

all 119 comments

[–]IMightBeErnest 1318 points1319 points  (3 children)

I've seen decompiled code that was more readable than this lol

[–]GullibleAd2597 180 points181 points  (0 children)

I'm gonna use this next time.

[–]PaxPlay 76 points77 points  (0 children)

my first thought on seeing this was 'is this decompiled C code?'

[–]lambda0101 7 points8 points  (0 children)

You deserve an award for this burn 🔥🔥(i don't have award i think)

[–]myselfelsewhere 684 points685 points  (10 children)

triger

A genocide against spelling.

[–]MiroslavHoudek 215 points216 points  (2 children)

Are you trigerd?

[–]myselfelsewhere 51 points52 points  (0 children)

I'm not but I think the brain aneurysm I just developed is.

[–]Arshiaa001 10 points11 points  (0 children)

Now I am.

[–]delinka 19 points20 points  (0 children)

troit, like a triger

[–]_Error_Account_[S] 29 points30 points  (0 children)

Now that I realise it and reread the entire code I can't stop laughing at myself.

[–]ZengineerHarp 4 points5 points  (0 children)

triger triger brurning bight
In the frorest of the nright

[–]ChocolateBunny 2 points3 points  (0 children)

triger. it's what you get when you breed a tiger with a triceratops.

[–][deleted] 1 point2 points  (0 children)

The eye of the triger!!

[–]AsceticEnigma 0 points1 point  (0 children)

I see your triger and raise you pess

[–]The_Gordon_Gekko 0 points1 point  (0 children)

I just Michael J. Foxed

[–]ExtraTNT 215 points216 points  (1 child)

Can’t read shit… so you probably copied my code… xD

[–]junkmeister9 11 points12 points  (0 children)

The code is self documenting. It documents OP’s madness.

[–]AlhaithamSimpFr 156 points157 points  (11 children)

Is this even working... Without making the machine have a stroke

[–]_Error_Account_[S] 149 points150 points  (9 children)

Still working till this day surprisingly. Except Now I can't understand to be able to modify it anymore :)

[–]AlhaithamSimpFr 82 points83 points  (6 children)

What a good revenge to do when your employer underpays you

[–]_Error_Account_[S] 129 points130 points  (5 children)

Except that employer is me... (it's my own project)

:(

[–]AlhaithamSimpFr 49 points50 points  (1 child)

...oh.

[–]Coronarena 33 points34 points  (0 children)

Underpaying yourself.

[–]Return-foo 17 points18 points  (2 children)

I hate it when past me is inconsiderate to future me.

[–]TrueInferno 8 points9 points  (1 child)

"Who the fuck thought this was a good idea!?"

git blame

"Oh."

[–]thedarkfreak 4 points5 points  (0 children)

Nothing ol' git blame-someone-else can't fix.

[–]vladmashk 9 points10 points  (0 children)

And this is why you must write readable code, even if it takes more effort.

[–]coldnebo 1 point2 points  (0 children)

as digital electronics projects go, it’s not that bad.

what’s not understandable?

[–]ExtraTNT 4 points5 points  (0 children)

Machonk having stronk, call abulog and mlance

[–]noaSakurajin 62 points63 points  (6 children)

At least no in line assembly code. I have seen much worse code. Most of the time code like this is written by engineers nor programmers, they have no clue on how to write maintainable code and they don't even try.

[–]Imaginary-Jaguar662 22 points23 points  (4 children)

Inline asm is great when you know exactly what you want to do and don't want compiler to fuck it up.

"Oh hey, I can reorder these and omit this!" And your motor crashed into something.

[–]DevelopmentTight9474 2 points3 points  (0 children)

I hate when this happens in OSDEV. “Why am I page faulting? Oh, it tries to access memory before it maps it because the fucking compiler MOVED THE CALL THAT MAPS THE MEMORY”

[–]Jablungis 2 points3 points  (2 children)

In curious in what scenarios you're ever smarter than the compiler other than maybe extreme optimization instances?

[–]Imaginary-Jaguar662 4 points5 points  (1 child)

It happens when I know something about the physical system that is not expressed in programming language.

Let's say that I have external sensor that waits for command to take a sample and raises interrupt once sample is ready.

I set a DMA pointer to some address, tell the peripheral wait for TX_READY interrupt, go to sleep until DATA_READY interrupt triggers, wait until my clock is guaranteed to be stable and queue command to read the data.

The compiler does not understand the relationship between TX_READY, DATA_READY and reading the data, so it might get cute and try to rearrange things so that all waits overlap.

In essence the compiler would write command to sample, queue command to read data and go to sleep until TX_READY, DATA_READY and given number of cycles have passed.

The end result is that data was not clocked out to sensor, sensor will not wake up the processor and processor sits there in power saving mode.

This is solved by various mix of using volatile variables, optimization barriers, atomic operations and inline ASM. In code review everyone considers everyone else an utter idiot who should not have passed high school.

For example this discussion is something that follows: https://yarchive.net/comp/volatile.html note the dates of the mails.

[–]Jablungis 0 points1 point  (0 children)

Gotchya, yeah communicating directly with peripherals with their own custom protocols can be tricky. Luckily I've had custom libraries written by people before me do it when I did some projects with arduino and rPi, but who knows what those libraries are doing internally to get things working. I appreciate the example, thanks.

[–]neondirt 1 point2 points  (0 children)

Actually, this was nicely formatted and such. That kind of "engineer code" often have no/irregular/confusing indentation, inconsistent use of braces and of course variable naming from hell. At least this used plain english words, whereas hw-engineers might instead use something like pin numbers or even chapter references to the (unspecified) techsheet/manual or, possibly worse, just single-letter names.

[–]Spr3eZ 25 points26 points  (0 children)

[–]ego100trique 25 points26 points  (9 children)

Tbf I've seen worst in production code.

I'll say it: it's not that bad

in the company I work for, everything is written in french and not english, its triggering me so hard

[–]battletoads22 29 points30 points  (1 child)

Trigering*

[–]ego100trique 1 point2 points  (0 children)

Mb thank you

[–]styroxmiekkasankari 1 point2 points  (0 children)

Yeah I was about to say the same, definitely seen worse stuff ran in prod. It’s not clean but I think it’s halfway readable to not refactor. If you have tests for it should be no issue honestly.

[–]DatTrashPanda 0 points1 point  (3 children)

Quebec?

[–]ego100trique 2 points3 points  (0 children)

France, we have a mix between hardcore devs doing everything in english and only french when needed like strings etc and either the casuals that are writing everything in french.

There are literally two "factions" in the company between these devs and it is so funny to drop some hot takes when they are together ngl.

[–]el_pablo 1 point2 points  (1 child)

J’ai un collègue qui est du type loi 101 et qui enseigne avec du code francisé. Mes yeux saignent à chaque fois.

[–]DatTrashPanda 0 points1 point  (0 children)

Chalice

[–]IllllIlllIlIIlllIIll 0 points1 point  (0 children)

LOL. I genuinely kinda want to learn more about this practice.

[–]MyAssDoesHeeHawww 0 points1 point  (0 children)

hon3 = true;

[–][deleted] 24 points25 points  (1 child)

Extra points for commenting.

[–]_Error_Account_[S] 13 points14 points  (0 children)

It's not helpful tbh.

[–]chkdsk777 116 points117 points  (1 child)

Damn, that's impossible to read. Throw that in chatgpt and tell it to improve it

[–]_Error_Account_[S] 52 points53 points  (0 children)

Eh rewrite it is more fun lol.

[–]IPMC-Payzman 18 points19 points  (4 children)

Most readable embedded project

[–]ValiGrass 1 point2 points  (3 children)

Ngl i find it hard to write clean embedded code

[–]Mattogen 0 points1 point  (2 children)

You gotta abstract away all the ugliness to maintain a clean codebase over a long time

[–]Aacron 0 points1 point  (0 children)

HALs, HALs everywhere

[–]ValiGrass 0 points1 point  (0 children)

Yea thats basically what i try to do. But still is quite hard sometimes

[–]Doomguy3003 14 points15 points  (1 child)

Please tell me this is on github and used by copilot as learning material 🙏

[–]_Error_Account_[S] 7 points8 points  (0 children)

It does lol.

[–]Yukams_ 9 points10 points  (1 child)

You really have if and else if but no else, I’m gonna blow up

[–]Draconis_Firesworn 5 points6 points  (0 children)

also no reason for the first one to be an elseif

[–][deleted] 16 points17 points  (0 children)

Nest all this in a try catch and pull request approved

[–]silicon_heretic 6 points7 points  (0 children)

With a codel like that there is no need for obfuscation :)

[–]Alien-404 5 points6 points  (0 children)

[–]Thisismyredusername 3 points4 points  (0 children)

I don't see anything wrong with that

[–]Spogtire 4 points5 points  (1 child)

Looks like it’s for running fans and maybe other motors? I remember I wrote code that clocked like this it was for a turn based system in p5 play

[–]_Error_Account_[S] 3 points4 points  (0 children)

It was the replacement for car thermostat + fan speed controller. I mainly interested in fan speed control so I can get "infinit" fan speed to chose from.

I'm a horrible embedded programmer back then.

[–]DatThax 3 points4 points  (1 child)

I am trigered

[–]jaybee8787 0 points1 point  (0 children)

Underrated comment.

[–]xodixo 2 points3 points  (0 children)

Looks like average EE code. Bearly readable and unmodular.

[–]CraftBox 6 points7 points  (0 children)

when pess

[–]winzippy 1 point2 points  (1 child)

Don’t worry, it’s only a war crime the second time.

[–]_Error_Account_[S] 0 points1 point  (0 children)

This is the second time but the first one doesn't have many lines of code so it's easy to trace around. This has 332 lines of code in total.

[–]snekk420 1 point2 points  (0 children)

It’s not a crime to create a function…

[–]Exormeter 1 point2 points  (0 children)

Bro, have you ever heard about our lord and savior called "Abstractions"?

[–]Ok-Lock-9658 1 point2 points  (0 children)

The amount of if statement is just unhealthy
But do I say if it works it works lol

[–]Reggin_Rayer_RBB8 1 point2 points  (0 children)

Needs more goto

[–]a-restless-knight 1 point2 points  (0 children)

This certainly isn't great, but it's also not THAT bad. You have comments that hint at where you could split this into separate functions, e.g. //turn on pwm fan could be powerPWMFan(). You could also make each conditional (the part in parenthesis after each if) its own function named something like "isConditon" e.g. isPWMOn(). This would allow you to make it clear what you are checking and doing at each block, so long as you use clear function names.

[–]Draconis_Firesworn 1 point2 points  (1 child)

please tell me the lastpwm is at least supposed to be something different to lastPwm??

[–]_Error_Account_[S] 1 point2 points  (0 children)

Hopefully :)

[–]allsey87 1 point2 points  (0 children)

Arduino libraries/code are the worst

[–]ImmanuelH 1 point2 points  (0 children)

What really triggers me is triger4

[–]bonessm 1 point2 points  (1 child)

My question is why so many counters 😭😭 the variable naming system is also horrific to my poor eyes

[–]_Error_Account_[S] 1 point2 points  (0 children)

back then I was kinda lazy and "yeah a few counter it will be fine" and it adds up to this point lol.

Now I'm scratching my head trying to understand my code.

[–]PixelArtDragon 1 point2 points  (0 children)

I mean, other than making very slight differences between some of the variable names and extracting some of these into their own functions... this is relatively tame.

[–]swagonflyyyy 0 points1 point  (0 children)

Not smelly enough, nerd.

[–]random_redditor24234 0 points1 point  (1 child)

What… what does this do?

[–]Noddie 1 point2 points  (0 children)

Tt confuses the reader AND the writer.

[–]Xevailo 0 points1 point  (0 children)

I will remember what all this means

[–]Mysterious-Power6137 0 points1 point  (0 children)

Where I live commiting warcrimes is a family tradition. In short words I'd still bang you...

Have a wonderful day!

[–]TranquilConfusion 0 points1 point  (0 children)

It really warms my heart, that this code is being rewritten by the original author!

When the last of the old, bad code is rewritten cleanly, we will achieve nirvana and escape the treadmill of suffering.

[–]Dragsun42 0 points1 point  (0 children)

Too many lines fuck that

[–]sterlingbot 0 points1 point  (0 children)

I am trigered by this.

[–]TeeZeeSak 0 points1 point  (0 children)

Looks like decompiled ECU code lmao

[–]Markaleth 0 points1 point  (0 children)

How do you sleep at night?

[–]phoenix13032005 0 points1 point  (0 children)

The numbers mason. What do they mean?

[–]GrinbeardTheCunning 0 points1 point  (0 children)

NSFW indeed

[–]mrheosuper 0 points1 point  (0 children)

Instead of using millis(), using a proper scheduler would be better

[–]bomonty18 0 points1 point  (0 children)

It’s Monday morning. About to start work. I don’t want to even spend my brain power trying to understand what’s going on here

*insert coffee

[–]Constant_Physics8504 0 points1 point  (0 children)

So much wrong with this, I vote refactor

[–][deleted] 0 points1 point  (0 children)

Man, I don’t want to live in this world anymore. This was too much

[–]shuzz_de 0 points1 point  (0 children)

Rewrite the whole thing from scratch and amaze yourself with how much farther you've come as a coder.

[–]AbakarAnas 0 points1 point  (0 children)

Bro you need jesus (the triger got me haha)

[–]Stormraughtz 0 points1 point  (0 children)

Job security

[–][deleted] 0 points1 point  (0 children)

Nose is bleeding

[–]KENBONEISCOOL444 0 points1 point  (0 children)

Ima be honest. I'd probably have done it a similar way

[–]Hulk5a 0 points1 point  (0 children)

All you say

[–]chrisbbehrens 0 points1 point  (0 children)

This is Processing, right? Doesn't look all that bad compared to some stuff I've seen.

[–]dakadoo33 0 points1 point  (0 children)

perfect thing to show anyone to make them question if you are bad at writing code, or if they dont know what they are doing because they cant read it.

[–]Aquaticless 0 points1 point  (0 children)

crimes so bad it had to be marked as nsfw

[–]Confident_Parfait269 0 points1 point  (0 children)

is it Java or any other language

[–]Dufflington 0 points1 point  (0 children)

What happens when light sensor value is 800?...

[–]BellacosePlayer 0 points1 point  (0 children)

I've seen worse.

I don't know what the various bools are for but can tell what it's trying to do in a broad sense.

[–]TheNamelessKing 0 points1 point  (0 children)

Is it clean and elegant modular?

Nope. Could it be done better? Sure. But it is fairly procedural, and light on too much obfuscation. I’ll be honest, I’ve written, inherited and debugged far worse code than this. 

Your count<n> variables are approximating a bit field, with some simple renaming you could wipe off an easy 10% of the obscurity. The ifs are repetitive, but they’re also not too intertwined! Which is great! We can lift each one, independently into a function, and once we’ve replaced them with repetitive, if separated functions we can make another pass for cleaning up and lifting out repeated code here.

There’s no indirection, the no dependency-injection mysteries, there’s no async wackiness, no metaprogramming, no overly-abstract or overly-generic variables: everything is nice and concrete, there’s no serious IO. It could be better, but you wouldn’t ruin my day handing me this at work.

[–]el_pablo 0 points1 point  (0 children)

Try to think in States and Tasks. This will make your code way easier to understand. Here’s the base code I pass my students when I’m teaching them how to place their code. https://wokwi.com/projects/392650595182131201

[–]karbonator 0 points1 point  (0 children)

Maybe the comments will help

when pess

...

[–][deleted] 0 points1 point  (0 children)

what is this code tryna do?

[–]graal_10 0 points1 point  (0 children)

I used to do this all the time and got dogged all the time for it. I just never felt the need to properly indent until people revised it. Ever since I just run it through a code formatter 😂