r/ProgrammerHumor • • Sep 23 '22

Refactoring "Just working solution ".

Post image
54.8k Upvotes

355 comments sorted by

View all comments

3.1k

u/TerriblyCoded Sep 23 '22

Past me: “Hahaha! I’M A GENIUS!”

Present me: “OH NO!”

313

u/omgFWTbear Sep 23 '22

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.

As they say, you can lead a horse to water …

107

u/derefr Sep 23 '22 edited Sep 23 '22

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.

1

u/Baardi Sep 23 '22

Also don't oversimplify. Sometime, things that feels like pointless extra complexity, can make your code a lot more flexible