Coding Commandments

Can there ever be such a thing as a “coding commandment”? Some rule that is so universally true that it should be applied in every situation?

I don’t think so. I think if you stay in this business long enough you get to watch “best practices” turn into “anti-patterns” and then become “best practices” again.

Author’s Note: The following is an excerpt from my weekly Dev Mastery newsletter. It was originally sent to Dev Mastery subscribers on September 8, 2016.

When I started with JavaScript in the nineties, for example, we wrote JavaScript code directly inside our HTML files. We just opened a <SCRIPT> tag and went to town. Adding a separate “.js” file was frowned upon because it caused the client to do a second round-trip to the server which added latency. Then, Internet speeds increased and web sites starting having a lot more JavaScript in them, so putting code in a separate file was seen as proper “separation of concerns”. You NEVER mixed JavaScript and HTML in the same file, that was heresy! Now, enter React and JSX and it’s suddenly a good idea to mix JS and HTML again.

Object Oriented Programming used to be seen as the silver bullet, best ever way to code, now people are poo-pooing it in favour of Functional programming.

That’s the game, it ebbs and flows. So, what do we do? Is it realistic to start from first principles every time? Attack every problem as if it’s our responsibility to solve it from scratch and treat all other solutions or advice with a large dose of skepticism?

I think the time to be most skeptical of a particular convention or established practice, the time to challenge the status quo is when we are facing a new problem that hasn’t been seen or solved before (very rare). Or when we are trying to build a product or a company whose purpose is to disrupt an established norm.

Other than that, I think most of the time we have to rely on the best advice and guidance available to us in the moment.

Find trusted sources, engage in the community, follow conventional wisdom. But don’t become a fanatic about it. Don’t close your mind to other possibilities. It’s a tricky balance. But an important one.

On that topic, here are three links that I think you’ll enjoy.

#1. Six Commandments of Good Code 
I don’t love the title, but given what we know today, these so-called “commandments” represent good practices in most situations.

#2 Separation of Concerns Rant

This video by MPJ addresses the HTML in JS example I gave earlier. It’s a good exploration of some of the complexity and problems we have faced with web apps from the very beginning.

#3 The Cook and The Chef: Musk’s Secret Sauce
This one is not about programming, but it’s a very good read that gives you insights into where and how to apply first-principles thinking, based on the example of Elon Musk. Fair warning, this is a very long post, you may have to read it in chunks. It’s also part of an even longer series on Musk that is very worthwhile, if you have time.

The post you just read was originally sent to Dev Mastery newsletter subscribers on September 8, 2016. I send out stuff like this every week. Sign up below to get in on the action.

I hate spam as much as you. I will NEVER share your email or send you irrelevant nonsense.