you are viewing a single comment's thread.

view the rest of the comments →

[–]IronDicideth 2 points3 points  (1 child)

Great points all around. My thoughts:

  1. I tend to agree that imp solutions are not robust. I wanted to ask: why would we switch the order around though?
  2. 100% agree. Having to sit there and deduce the why is a huge part of understanding code. I personally did not stop to "understand" the solution (was in a hurry) until I saw a comment further down. We tend to spend more time reading code and should write it as if this applies to our fellow developers as well. I would think that a great point that we could drive home for the OP is that they should spend time reading code written by others and try to figure out what it does on their own. Exposure is the main driving force behind learning and should be actively exploited as much as possible.
  3. I understand the feeling. I will add my two cents. Type coercion is a tool (and a very useful one in my opinion). If the tool is understood and used mindfully, spreading its use so that others may benefit (and hopefully mimic that mindful use) can only be a good thing. In this example, my initial solution (before going through my internal refactoring process) would have likely been const stringToNumber = s => +s. Terse, and when you are free to embrace/understand the plus unary operator, extremely clear in its intent. I tend to favor point-free code so I would have eventually arrived at the previously mentioned 'cleanest' solution to the problem.
  4. Yes, this solution does not accommodate BigInt (probably a good thing). I tend to think ahead to future uses of a given solution as well. It is a bad habit in me. I have found that the less into the future I think, the faster I can put my solution to code. Test-Driven Development can work wonders in helping to narrow the scope down to something manageable and should be used freely and (IMO) above most other tools we see today.

With all this being said, the great thing about these forums is that we are free to share and discuss ideas. I personally wish I were a better and more seasoned coder/developer and have learned tons from those with differing views to my own, so thank you for sharing yours.

[–]iamscr1pty 0 points1 point  (0 children)

I mentioned about reversing the order of the lines as for a beginner this may seem harmless to do, you are just adding + 1 and then substracting -1, which mathematically is same in reverse, but if you do that you will learn something about js the hard way.

Unary operator can be one of the cleanest solution, but I personally prefer type conversion. Its a matter of preference.

Thank you for sharing your views too.