I learned .. who was it, Knuth who said, “Never write code as clever as you can, because debugging is harder than coding, so …”
As many others, I received a full scholarship in my degree on that from the University of Hard Knocks, the School of Blood, Sweat, and Tears; later on, I shared this wisdom to my now-ex who started her career after me, she thought it was ridiculous to ever not be your cleverest.
If it took you 2 weeks to figure out complex system interactions at the height of your power, it’s probably going to take you 4 weeks now to figure out why the jank solution works and how to make a non-jank fix for it.
Put all your cleverness to the task of simplifying.
The cleverest solution is one that automates everything and hits all the edge-cases correctly but which uses no code at all, and has nothing to maintain or understand.
E.g. "the system you're describing to me as wanting to have built, has exactly the semantics of an XMPP server, just put to the use of machine-to-machine communication. Just install ejabberd, and point your machines at it using XMPP client libraries."
The "cleverness" in such cases, usually comes from realizing that your problem domain is a clean isomorphism of some other seemingly-completely-unrelated problem domain. Like a mathematician realizing that an existing proof of X also already proves Y as a corollary.
task of simplifying is kinda tough. i always misunderstand the simplifying part. it's not the "make the job very easy and clumsy" it's "make everything short and readable as hard as you can". there really should be an example of simplifiying a code, because withotu an example, stuff might be understood wrong
atleast that's what i think, i'm not really a programmer yet
Short does not mean readable. Common point of confusion.
You can shorten by simplifying, which does help with readability. But you can also shorten by making more implicit instead of explicit, and that hurts readability (which the writer often forgets in the moment, because in that moment the implicit is perfectly clear to them. For now.)
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
Always write code as if the next person is a murderous psychopath who knows where you live.
Usually that next person is me and I hate myself for it.
Seriously though I'll take code that is more verbose and self documenting over "clever" code any day of the week. If you think you're being clever when you're writing something it's time to do your due diligence to make sure your solution is something that is maintainable long term esp if you aren't going to be the one on the team maintaining things.
For me that's simplifying the code, I untangled and simplified one big function and now it turns out I'm slowly adding special cases into it back again. Ehh, it was a mess and it's slowly becoming a mess again.
3.1k
u/TerriblyCoded Sep 23 '22
Past me: “Hahaha! I’M A GENIUS!”
Present me: “OH NO!”