Software and the "Elegant Code" Trap
I love computer science and Software Engineering. I really do.
Being the sort of developer who loves poking around at other people's code as much as writing my own and having been through a few job changes recently I've come to appreciate how much of a nightmare "good" code is.
To be clear, by "good" here I mean stream-lined, elegant solutions. The kind you wish you had written in hindsight or are thankful you had the opportunity to write.
When facing a challenge in software there are generally an infinite number of ways of addressing the issue. Sure, you can probably dump them into a much smaller number of buckets and eliminate a goodly number of terribly suited solutions. And, if you're open and honest, you'll probably still be left with dozens. Granted, you likely won't have actually spent enough time to think of that many and you probably settled on an ideal approach shortly after starting. But, that doesn't eliminate the existence of the others.
From there you will whittle it down to a few that you might actually put some effort into.
If you find that magical answer, it will probably meet a few criteria; it will likely be short, sweet and completely out of sight.
I'm going to term this the "ASP.Net Core Pipeline Problem".
Dependency Injection is wonderful. Beautiful even. But, it is wonderful on an exuberant scale. Just about any .Net service of value is filled with hundreds of dependencies, if not more.
"But where are they?". Well, thanks to static extension methods you generally only see the "tip" of the iceberg. And in some cases you don't even see that. Some of it is simply baked in with no visible lines of code. This is how you end up with Minimal Apis. You can build an entire web application. In 1 file. In under 10 lines of code.
Elegant. Short. Sweet. AKA "Programming Perfection". Except, most people have absolutely no idea what is going on under the covers. New devs jumping into .Net 6 or 7 for the first time don't even know what questions to ask about what has been obfuscated for them.
I only got on the ASP.Net bandwagon at .Net Core 2.1. Who knows how much I'm oblivious too?
Anyway, today I was working on a project where I needed to override the default ILoggerFactory so that I could force some of my own functionality into the ILogger's it was generating. That logic of course... is nowehere to be found in my code. The sweet, elegant solution coded it under a rug. I am talking about .Net though, AND I knew exactly what I was attempting to do. So, it was fairly trivial to find a solution the information I needed to get it working.
But, this doesn't just happen in huge, well supported and well documented platforms and frameworks. It happens everywhere.
And what happens when the problem you need to solve is swept under a rug that NO ONE knows exists? Tech turnover is high enough. Most large companies will have large products where many core team members have left over time. Undoubtedly, some of those wrote this sort of sublime, invisible code. And sooner or later, an equal or lesser programmer will be tasked with doing something with that code.
I remember trying to debug into marshalled code in older .Net apps, and things that tied into lifecycle events deep in the .Net Architecture but did so in obscure places (or at least, obscure to me).
To be clear, I'm not complaining. I solved my problem and I have no experience to draw on where I could not solve such a problem. But, I have watched others stumble and fall over much more obvious issues. And I've watched teams choose to rewrite software knowing that these sorts of things, while never mentioned, were core reasons behind the choice.
I don't want to stop writing elegant code either. And not because of job security or anything like that. Good code just works better. But, it sucks that the best code is often "invisible". It finds that spot where it fits in so well you'd never think to look for it there if you hadn't been the one to write it. Because if you were the one to write it, and it fits in that well, you'll never have a reason to ponder anything of its existence.
No big moral or takeaway here. Just an annoying discovery that likely won't change a thing for me, or for anyone else either.
Comments
Post a Comment