The Most Important Language in Programming
toBe || !toBe
Feb 28, 2019
Scenario
What do you think the following function does?
Maybe you immediately realised what this function does, maybe you’re still not sure. Perhaps you’ve even written something like this before.
Let’s make a few minor changes to see if we can make it a bit clearer:
All of a sudden, it’s crystal clear what this function does: It calculates a net amount, given a gross amount and a tax rate. All we did was improve our naming, and the intent became obvious. Nice 😎
This is a super easy win, and serves as an example of the importance of having your function and variable names stem from your intent and/or the associated domain.
Now imagine a slightly more complex function, which determines whether a given request is valid based on a small set of rules. In fact, you don’t need to imagine it, because here’s one I prepared earlier:
Don’t get me wrong, this function is reasonable and relatively easy to understand. But why stop at relatively easy? Let’s take it all the way to simple:
This is known as abstraction: The particulars of each condition have been moved out into their own functions, leaving simple function calls in their place. It’s so simple in fact that it could even be read by a non-technical associate if they needed to recall what the validation rules are for a request.
It should be noted that while doing this has added a few more lines to our solution, it has also allowed us to move all the conditions into a single if-statement to save on the duplicate return false;
statements. You would have to have been crazy to attempt to do this with the previous solution! 😜
What I’m Getting At
Communication is key when it comes to pretty much every job on the planet, and programming is no exception. Ensuring that your colleagues, or even future you, can read and understand the intent of your code is vital for many different reasons, whether it’s identification and prevention of bugs; ease of extension; or enabling a reviewer to clearly map requirements to your implementation.
When you communicate with your team-mates, via email or slack for example, or even speaking face-to-face 🙀, do you make up fake words? Do you begin to describe something at a high level and then halfway through go off on a tangent regarding one of the low-level details, even though they aren’t relevant to the person you’re talking to? If the answer to those questions is yes, you’d likely find that you will be running into some difficulties getting your message across.
Lastly, what language do you use when you do communicate with your peers …?
The Realisation
That’s right, the most important language in programming isn’t a programming language at all — it’s English! (or whatever your spoken/written language happens to be).
Individual programming languages will come and go throughout time and throughout your career as a developer. Regardless of your current language of choice, your most important linguistic skill is your ability to express yourself within your code as if you were writing in plain English.
There are obviously going to be many instances where it’s just not possible to express your code’s intent in ‘plain English’ — after all, we’re not actually coding in English (maybe one day 🤞). However; you should always aim to get as close as you can, to gain all of the benefits mentioned in the previous sections — and more!
When your code starts to read more like a simple English sentence than a mysterious hieroglyph, you can be confident that it will be more extensible, maintainable, reliable and of course — readable! 📖
Thanks for reading!
Read more posts like this