Excellent coding techniques and programming practices are indications of a professional app developer. In order to successfully program, an application requires a developer to make 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 code or short lines of code, relies more on your preferences, skills, and expected outcomes.
Between long code vs. short code, which one is the better option for you? Here are some factors to consider before deciding whether to use many or few lines of code.
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 code or short code, your source code will evolve in people’s hands who need to understand how the code operates and what improvements are 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 an example of a code written in two different ways:
While the second programming style consists of more 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 obscure your code and protect it from reverse engineering.
Importantly, if you’re 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, making your code conveniently and quickly understandable is crucial.
If you’re developing a mobile app that requires collaboration with other developers, then it is better to use long, clear lines of code as opposed to short lines of code. The latter will only show your peers that are you’re “smart” and that their input is not useful.
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 downright frustrating moments for you as a developer.
What if you write a short code and discover that you’re unable to interpret it four months from now? A long code could assist you with reacquainting 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:
However, it is easier to maintain the code below:
var decentSize = decentHeight && decentWidth;
Arguably, using shorter lines of code could lead to better efficiency than spreading the code over several lines. If you have more lines of code, there could be more places for bugs to hide and increase the difficulty of finding them.
Fewer lines of code could achieve the same results (and probably better) than many lines of code. If you reduce the amount of code in a task, you will lower the bug count, especially if the source code is clear, readable, and maintainable. Furthermore, writing long codes may require you to include too many local variables, since you have to formulate names for them. Several names to work with could lead to confusion and inefficient programs.
If you want to build efficient apps with less number of bugs to trouble you, then using fewer number of code lines could be your best solution.
4. Expected workload
Short code texting enables you to achieve more with less, and therefore drastically reduce the number of hours you spend developing your mobile app. With sufficient training and experience, you can learn how to build apps more quickly and with fewer lines of codes. On the other hand, long lines of code are sometimes demanding to write and could require you to put in long hours.
With short codes, for instance, you can lower the amount of code needed for repetitive statements and string manipulation. This way, instead of using verbose long codes, you can conveniently combine many steps into single steps and greatly reduce your workload and other associated costs.
Here is a code written using many lines:
And, here is the same code in a shorter format:
Clearly, the first example requires more time to write than the second example.
If workload is important for you and you have sufficient skills in app development, then using short codes could be preferable to long codes.
The Choice is Yours
Ultimately, the choice whether to use long code vs. short code does not matter. Instead, what matters is writing the code in a manner suitable for its intended use. A source code that is longer than it needs to be will result in more errors, increased unnecessary load, and waste of time and resources.
On the other hand, if you are writing shorter codes by replacing numerous simple lines of code with one complex line of code, or verbose statements with vague ones, or straightforward operations with strange hacks, then the loss in overall usefulness will normally outweigh the gain in conciseness.
So, when building an app, you should ensure every line of code serves its intended purpose. And, whether you use long lines of code or short lines of code should not be your key motivator. Your real objective for each case should be to achieve high standards of readability, maintainability, efficiency, and cost-friendliness—normally in that order, and the number of lines of code shouldn’t have a place in that list.
To get useful articles like this one delivered to your inbox, subscribe to this blog: