Getting Fancy with Code Just Makes You Look Stupid

Let’s talk about code or more specifically about fancy code and the fact that it is not necessary. Code is a utility, not a work of art. There are some people that are probably going to disagree with me here on this one and by all means, please let me know in the comments section. But in my opinion, code is supposed to do one thing and one thing only and that is to just execute and do some task.

The outcome of the code is what is important, not necessarily what it looks like. What it looks like can actually be detrimental to what we are trying to do. Let’s say you write a piece of code that is an extremely fancy work of art that only senior developers will understand. Maybe it uses non-descriptive, but short variable names, unnecessary recursion or other constructs that would not affect the outcome. All that is ridiculous, that is just ridiculous.

That fancy code, sure it may run just as fine as some “utility code” would do, but what happens if someone else has to maintain it and look at it and be like, “what in the hell is this? I do not understand why you are doing this like this. This just does not make any sense.” And it takes an hour or so just to comprehend what you are doing. That kind of code does not make you look smart, it makes you look stupid. It almost makes you look egotistical if you write code that is just way too complicated for what you are doing.

Now, there are times when somebody, such as some senior developers, honestly are so used to doing it this way, they may do this unintentionally and that’s fine. It is all about doing the bare minimum to get the job done, to get the code right, and to build it in a way that it is easily extensible, easily changeable over time. Plus, that other people can actually understand it. I might argue that they need to be trained to not create code that’s supposed to account for every, single situation, but that’s beside the point.

One big beef that I usually have is we are talking about PowerShell. I know a lot about PowerShell and I always take everything back to this. So, for example, I know PowerShell is a very powerful language and it can do a lot of stuff, and when necessary, you can drop down to doing things in .NET by instantiating objects or by embedding C# in a script. But why?

I have been writing PowerShell for almost ten years now, and I can count on one hand, maybe two hands, how many times I had to go down in to query Win32 API with pinvoke or call some static .NET class. 9.5 times out of 10, PowerShell itself will be able to perform the same task. Why complicate it?

It just drives me crazy when people try to get fancy and they think or they just assume PowerShell can’t do something. They just go back to their roots of “well I will just do it in C# really quick.” If you are writing PowerShell keep your C# out of my PowerShell!

Writing fancy code is not necessary. It is a waste of time, and for other people’s time to try and understand your stuff. It does not make you look smart. it makes you look stupid and egotistical. Do not write fancy code. Keep it simple. Code is a utility not art!

This post was brought to you by a YouTube #CarTalks video. Check out all of the other video content on the Adam the Automator YouTube channel!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store