One liner or Clean code? | Sololearn: Learn to code for FREE!

+2

One liner or Clean code?

Do you think one liners are a good option to choose? Yeah it looks cool but hard to write as well as hard to troubleshoot? If you were a software engineer what would u prefer? Give reason.

11/9/2020 5:08:45 PM

Taran Grover

4 Answers

New Answer

+10

Clean code is better for maintenance which is usually 99.99% of the code's life :) However, one liners are always good brain teasers to practice: https://code.sololearn.com/c1O0SXDu2Nb0/?ref=app

+11

Clean code is always better. As it is easy to maintain and modify in future time. And it should not happen that you can't recognise your code after 6 months 😂. Clean code is best. Edit: One liner is good from point of view of security. But i think your code don't have and nuclear formula to make it so secure.

+7

@Taran Grover That is correct. One liners aren't necessarily faster than multiple lines for code that uses a compiler or Just in Time (JIT) compiler as these compilers will break the statement down into it's components and perform the necessary calculations, functions, or operations in as optimal a way as it can. In some interpreters a one liner can actually slow down the code due to multiple complex operations being required in a single line instead of highly optimised simple operations being performed across multiple lines. In some instances the simpler code can actually be faster, especially in a loop, since a peep hole optimiser may recognise the repeated operations and optimise them even further. The only way to be sure is to use a profiler on your code.

+5

In many languages the result in terms of execution speed is the same as the JIT compiler or optimizing compiler will optimise everything. So you may as well make it easy to read and maintain.