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.
Don’t forget that article was written in 2008. I would imagine there’s a lot of better tools than RegexBuddy that have been created in the last 14 years.
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.)
i know that moment haha, pythonists make the worst one liners ever to exist. i thought shortening stuff helps because the bigger the stuff looks, the harder it is to remember relations between things and the more it looks overwhelming, atleast for me
because the bigger the stuff looks, the harder it is to remember relations between things and the more it looks overwhelming, atleast for me
This tends to improve as you gain expertise, because your brain learns relevant patterns, which it can use to chunk and store the information more efficiently.
But even then, that's still about optimizing for your working memory to remember all the moving parts, and not about optimizing how easy it is to understand how it works. The former is only a part of the latter.
But sometimes implicitly and short is the way to go for readability. Look at some Java:
Thing bla = new Thing();
Soooo much is done there behind the covers, but it stays the most readable because I couldn’t care less what’s going on back there. Pointers? Malloc? I don’t care, just give me a funky chunk o’ memory and do it right.
Simplifying code has gotta be one of the most nebulous and difficult to describe things.
That's true. Whenever I feel a piece of code is getting too complex, I will sketch it out high-level(UML diagram) and try to understand it better. Usually a more elegant solution will emerge. That said, I think most refactoring revolves around applying the single responsibility principle. E.g. "separate the processing/scheduling of tasks from the task implementation", stuff like that.
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.