Author: Mihai Avram | Date: 1/30/2020
Many of us developers struggle with the ability to write quality code at a high speed. To some this may be a fun quest and a means to push themselves, while to others it can affect their livelihood or career prospects. This post is written for all developers who are looking to find ways to code even faster while also improving quality, or at least not compromising quality for speed. I hope that the insights found in this post can help us become faster coders that also write higher quality code. Or at the very least, improve in speed or quality! Let’s begin 🙂
The case for speed
I’m sure you remember a case in which you had a coding task given to you and a tight deadline. Because of this you may have had to stay up frantically coding most of the evening and night just so you can meet the project’s demands. It is 3 a.m. and you finally pushed the code and went to bed. The next morning you woke up, and while the deadline was met, not only did you compromise your health, but the code you wrote was also not the proudest member of your code family. What can you do to make sure this doesn’t happen again? You guessed it, increase the speed at which you code.
Here are some ways you can do this, sorted in the order of highest impact first:
Shut off all distractions
There is this concept called
flow in which your brain can very quickly move from one thought to another holding all relevant pieces of a problem in memory for you to quickly be able to muster a solution quickly. The moment this flow state is broken, your productivity diminishes. So tell your loved ones or friends to not bother you, mute your phone and all notifications, and pick a block of time (ideally a few hours to avoid burnout) in which only work happens without any social media or browsing the internet mindlessly. Instead, you should only be focusing on the problem at hand, then take a quick break and do it again! There are many tools to help you with being distraction-free. Check some out here and use what sticks!
Use shortcuts for everything you repeatedly do
When we were younger, likely in grade school or high school, we learned the magic of copy/paste and it greatly improved the speed at which we wrote information. The same analogy can be applied to anything as a coder, opening a browser window, switching between applications, writing a standard code statement (e.g. simple if statement or <div> tag), and launching scripts. Anything can be automated or can be done faster. If you take a few moments in your day to look up ways to navigate around your work environment faster, especially for repeated tasks, this will pay out in dividends.
Take a few moments and plan a basic architecture of how the problem will be solved
Your first impulse when facing a problem may be to start coding right away. However, this may lead inexperienced developers into rabbit holes where they get stuck with code that may not be able to get them at the end goal, or not easily anyway. This is why it is important to spend a few minutes and think about how the problem will be solved, and with which code paradigms, frameworks, and components so that the solution map is carved out at the high level. Afterward, the coding should be smooth sailing with very little chances of getting stuck. There is a catch here, however. If you spend too much time in the architecture stage, it can actually slow you down, so try to find a balance where you feel like you have the crux of the architecture down, and not a speck more so you can get to coding as fast as possible.
Become a good debugger
No developers can write large chunks of perfect code for the first time and not have it break. Hence, it becomes obvious that you will face a few errors and error statements in your application. At this point, it is important to find out what the problem is as soon as possible so you can continue finishing up your solution. You can do this by investing time to learn how a debugger works for your coding language/framework at hand, how the error stack trace works, and how to use Google to search for solutions. There are blogs and posts and courses about all this so I won’t go into detail how, but you should invest time to learn this so you can speed up your debugging process! Nick Karnik has a good post that covers this topic in more depth.
Increase your typing speed
Last but not least, increase your typing speed! Depending on the problem at hand, a developer may spend around 50% of the time coding and the rest of the time crafting a solution for the code by looking up documentation, creating the code architecture, etc. That being said, it seems obvious that someone that can write code twice as fast can achieve a notable increase in speed in how fast they finish the project. There are many resources that can help you do this and a good chunk of them are explained in this article.
The case for quality
In your frantic 3 a.m. coding deadline scenario you could have benefitted from being able to code faster. However, the next morning when you glance at your code and see the many ways you could have improved it, or worse, your colleagues find them and point them out. This is why it is also important to optimize for quality or at least not compromising minimal quality all while coding fast.
Here are some ways you can increase the quality of your code written in the order of the most impactful things you can do first:
Write test cases or test your code yourself
The best way to avoid bugs is by writing robust test cases for every function you write. Sometimes, however, this is not feasible when you want to code fast or are facing a deadline. In cases like these, it is still imperative to test every piece of code that you write yourself and making sure that it passes a sniff test whereby the code seems to be doing what it is supposed to do. Here’s a helpful resource to help you learn more about this – Intro to TDD.
Use a code linter
There are code linters for almost all coding languages and frameworks, and they provide a great way to ensure you write bug-free and high-quality code with very minimal effort. Setting up a linter does not take very long, and once set up (ideally with the latest standards for the coding language you are using), it is literally just one command to run the linter. For instance, in NodeJS, the command is often
npm run lint which will lint your code, and some linters will even fix your code for you. A good practice I recommend here is to browse at the results of the linter first yourself, which will teach you lessons about how your code is not up to standard. This may even help you find some glaring bugs such as declaring a variable twice in the same context. Once you understand the linting errors, either fix them yourself or fix them using the linter automatically.
Follow coding standards and best practices
There are many standards and best practices for virtually every coding paradigm you will use (e.g. agile programming, extreme programming, object-oriented programming), and every programming language you use. For instance, in object-oriented programming, some of the major rules involve ensuring that your code follows encapsulation, inheritance, abstraction, and polymorphism. In a similar vein, Python has a set of aphorisms called The Zen of Python which can help Pythonistas write better code. Understand which coding paradigms your project uses, as well as which languages, and devote some time to find and learn the standards and best practices!
Run your code through static and dynamic code analyzers
While a linter or testing library are examples of code analyzers, it goes without saying that there are a plethora of code analyzers out there that can not only test and check your static code, but also detect problems at runtime, do type checking for untyped languages, and even use machine learning to help you write code more efficiently such as Kite for Python. You should be on the lookout to find what are some of the best analyzers for your project’s coding stack, and try it!
Document your code
While most simple functions and statements can be easily understood by most developers, it is also important to leave helpful docstrings or comments. These additions can greatly help you understand the code when you take a look at it later and help other coders get up to speed faster as well. What is more, is that for more complex functions, these comments can be a lifesaver by mitigating the chance for bugs to be introduced. That being said you should also not over-comment the code as that can make the code more cluttered, thus decreasing readability.
The fusion between speed and quality
Now that we have a general idea of how to write code quickly, and write quality code as well, it is time to combine the two! You can, of course, take the sum of their parts and try to incorporate all of the bullets in this article in your coding routine. This should bring lots of success – though I would be remiss to bring up some things you can do that benefit both!
- Make time to learn new skills
- Prioritize working on and learning about what is important for you at this time given your goals, and not someone else’s goals
- Prioritize sleeping – many studies have shown that your ability to learn and remember new things become impaired if you habitually sleep less than 7 hours every night. This also affects your efficiency and decision-making skills and is one of the easiest things you can do to improve your coding prowess!
- Practice, practice, practice!
That’s all folks! I hope this post can help some of you become faster and better coders so that crunch time will no longer punch you in the face 🙂