Replies: 5 comments
-
Is less code always better? A good amount of the time, mainly on harder katas, the "short" solutions will either not be readable, have worse performance, or not have either. Of course, the easier the kata, the more likely it is that you can make a short solution that performs well and is readable, but not always Which one to choose: readability or efficiency I would say try to strike a balance between both. But shortcode isn't always faster or easier to read, and sometimes, the longer code is faster and more readable than the extremely short solutions. |
Beta Was this translation helpful? Give feedback.
-
readability should be top priority in real life here are 2 main differences popping to mind:
good luck with your learning :) |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I have seen one-liners of people using std functions to solve katas, it's easy to use a predefined function that already does what you should have coded, it solves the kata, but do you understand the underlying algorithm? I like writing the first thing that comes to my mind and then trying to optimize :) |
Beta Was this translation helpful? Give feedback.
-
I've been coding a few years but never professionally so been wondering the same. Although it's very impressive to see a solution that took me 26 lines of code being done with just one line (not counting first line function declaration and return code), I can't imagine trying to debug or collaborate through code like that. Good to see others also agree on the importance of readability in the real world. |
Beta Was this translation helpful? Give feedback.
-
Hi there!
I'm quite new to coding, and I see that the most upvoted solutions tend to be one-liner solutions, or those that take as few lines as possible. Sometimes, to my newbie mind at least, these solutions are harder to understand compared to those that are a bit lengthier. Some of these solutions even had tons of "best practices" upvotes, when they clearly shouldn't have (bitwise operators for a 6-7 kyu kata, seriously?). Every time I submit my solution I think something on the lines of "good, now lets see how others did it in less lines than me". It's always good to learn from others of course, but I'm worried I might be getting into the wrong mindset. Is less code always better? Which one to choose: readability or efficiency?
Thank you, and sorry if this has been asked before.
Beta Was this translation helpful? Give feedback.
All reactions