March 1st, 2020 at 9:38 PM
My coding style has changed so, so much over the years.
I taught myself at a young age. That being said, I didn't realize just how much I didn't know until I started studying computer science at university. And oh my, do you learn so much. I occasionally dabble with old code of mine, and I realize that I've learned quite a bit over the years.
That being said, if there is one thing I learned, it's how to NOT one-line code. As it turns out, having fewer lines of code does not mean that the code is faster. (In many cases, it's actually slower. Some of the complex functions that can help you one-line sections of code are very heavy-weight under the hood. Even in python, I write my own code to multiply matrices, because Numpy's functions are far too slow for the task. )
As a result, I end up writing quite a few lines of code to do even a simple task. I try to make my code as readable as possible, and don't worry so much about the line count. I'm often told that my code is overkill (or that it takes too many lines to do something simple). yes, I know how to use complicated functions and language constructs. I just choose not to. I value stability and readability, and performance, over elegant forms of creatively one-lined code.
That being said, sometimes less code is advantageous. With larger files, it's often harder to pin-point sections of code that exist in a huge file with 2,000 lines. It also introduces more places where bugs could exist (more code is being used), so there is often a trade off. You find yourself limited by the speed that you can type.
What are your thoughts on code's line count? Do you find that you try to make your code compact, verbose, or somewhere in between?
I taught myself at a young age. That being said, I didn't realize just how much I didn't know until I started studying computer science at university. And oh my, do you learn so much. I occasionally dabble with old code of mine, and I realize that I've learned quite a bit over the years.
That being said, if there is one thing I learned, it's how to NOT one-line code. As it turns out, having fewer lines of code does not mean that the code is faster. (In many cases, it's actually slower. Some of the complex functions that can help you one-line sections of code are very heavy-weight under the hood. Even in python, I write my own code to multiply matrices, because Numpy's functions are far too slow for the task. )
As a result, I end up writing quite a few lines of code to do even a simple task. I try to make my code as readable as possible, and don't worry so much about the line count. I'm often told that my code is overkill (or that it takes too many lines to do something simple). yes, I know how to use complicated functions and language constructs. I just choose not to. I value stability and readability, and performance, over elegant forms of creatively one-lined code.
That being said, sometimes less code is advantageous. With larger files, it's often harder to pin-point sections of code that exist in a huge file with 2,000 lines. It also introduces more places where bugs could exist (more code is being used), so there is often a trade off. You find yourself limited by the speed that you can type.
What are your thoughts on code's line count? Do you find that you try to make your code compact, verbose, or somewhere in between?