My 2 cents: the most important thing if you want to be productive is to develop an intuition for reducing both problems and their solutions into their building blocks.
I see so many programmers write the same code again and again only to figure out during refactoring that there might be some common aspect, when that should have been obvious by just looking at what the code does.
Don't write code that solves the current problem; find your solution, then analyse your solution and see if there's some core aspect to it that can be generalised. This takes some practise, but after a while, you'll get to the point where you have an idea, then just naturally see how the idea leads into more generalised building blocks.
A simple example that most of you will be familiar with:
I need a function that takes an array of strings and turns them all into uppercase
should quickly become
I need a function that takes an array of elements and applies some other function to them
And voilà: you've arrived at map :D
Why is this important? Because it naturally leads you to write more extensible code by putting interfaces not only around your solution, but inside it as well. If your requirement changes to making the strings lowercase, you can just change the function you pass into map instead of having to find a line of code inside a loop.
My 2 cents: the most important thing if you want to be productive is to develop an intuition for reducing both problems and their solutions into their building blocks.
I see so many programmers write the same code again and again only to figure out during refactoring that there might be some common aspect, when that should have been obvious by just looking at what the code does.
Don't write code that solves the current problem; find your solution, then analyse your solution and see if there's some core aspect to it that can be generalised. This takes some practise, but after a while, you'll get to the point where you have an idea, then just naturally see how the idea leads into more generalised building blocks.
A simple example that most of you will be familiar with:
should quickly become
And voilà: you've arrived at
map
:DWhy is this important? Because it naturally leads you to write more extensible code by putting interfaces not only around your solution, but inside it as well. If your requirement changes to making the strings lowercase, you can just change the function you pass into
map
instead of having to find a line of code inside a loop.such an amazing advice !
i like the part of generalizing => very good trick
thanks for sharing !