Long Codes vs. Short Codes: What’s Better for My Use Case?
Long Codes vs. Short Codes: What’s Better for My Use Case?
Excellent coding techniques and programming practices are indications of a professional app developer. Successfully programming an application requires making an extensive number of little decisions while trying to solve a greater set of problems.
How wisely you make those decisions, whether with long lines of codes or short lines of code, relies more on your preferences, skills and expected outcomes.
Between long code vs. short code, which one could be better?
Here are some factors to consider before deciding whether to use many or fewer lines of code.
1. Readability
Martin Fowler, an expert software developer, once said, “Any fool can write code that a computer can understand. Good programmers write code that humans can understand”.
You should ensure your short code texting is designed with other people in mind. As much as it will be processed by a machine, which doesn’t care whether you use long codes or short codes, your source code will evolve in people’s hands who need to understand how the code operates and improvements needed.
So, when building mobile apps, the readability of the source code could be more important than the number of lines of the code.
Here is example of a code written in two different ways:
First version:
var result = planOne(planTwo(w, planThree(x)), y, z);
Second version:
var result3 = planThree(x);
var result2 = planTwo(w, result3);
var result = planOne(result2, y, z);
While the second programming style consists of many lines of code than the first one, it is definitely easier to read and interpret. Since the second version enables you to name intermediate values, it is much easier to tell the parameters passed to every method. Nonetheless, the first version could enable you to obfuscate your code and protect it from reverse engineering.
Importantly, if you are working on a project with other programming teams, ensuring code readability is crucial—that is, if you care for the long-term sustainability of the project. You need to consider that other developers may not easily interpret your source code; therefore, you need to make your code easily and quickly understandable.
If you are developing a mobile app that requires collaboration with other developers, then it is better to use long, clear lines of code than short lines of codes, which will only show your peers that are you are “smart” and their input is not useful.
2. Maintainability
Short and confusing codes are usually difficult to maintain and can result in problems like bugs and more overhead costs during quality maintenance. Furthermore, they can result in motivational issues and plain hullabaloo moments for you as a developer.
What if you write a short code and discover that you are unable to interpret it four months from now? A long code could assist you reacquaint yourself with what you wrote and why you wrote it in that particular style.
With a long code, debugging a program becomes much easier since you will have variables to scrutinize and more places to insert breakpoints.
Worse still, short and unclear codes could lead to time and money wastages used to re-factor or rewrite the existing code to include new features that are easier to maintain in the long run.
This code is shorter:
var decentSize = (height > 200) && (height 400) && (width minHeight) && (height minWidth) && (width