I guess I’m beyond “beginner” level because I am frequently able to get intermediate- and advanced-type solutions for the JS algorithm problems.
But I wonder. Would more senior devs prefer to see the beginning solutions or the more advanced ones? It seems to me the beginning solutions, while longer, are easier to read and understand (and therefore, maintain). Maybe that’s because I’m still not used to reading the more advanced style. What do the senior devs here think?
I’m totally convinced that it’s good to know how to do the advanced solutions, but I wonder if, by calling them “advanced,” freeCodeCamp is not maybe encouraging people to write more obscure but “clever” code.
Surely this has been discussed in more depth somewhere. Where could I read about this issue?
The sample solutions are provided by the community, so there will be some variation in quality and understanding of what “advanced” entails. Can you give a couple of examples where you think the beginner solution is preferable?
There are a lot of trade-offs in coding. But I tend to favor readability. Sometimes you need something to be fast and lean, like if it is going to be done a few million times. But compact code isn’t always the same as fast. Unless there is a reason against it, I tend to favor readability. But also keep in mind that what someone considers readable will change - before I learned more, many prototype methods with arrow functions looked insane to me.
But I agree that there is a “cult of concision”. There are a lot of coders out there that think cramming 10 lines of code onto one line with an inscrutable tangle of syntax is “cool” and “clever”.
legitimately make the code shorter and more readable.
be exemplary by demonstrating the best practice.
use brilliant ideas to make the algorithm simpler with practical values. e.g. Using math-magic or smart programming technique to reduce time, space complexity.
A worthy advanced solution:
One solution incorporated well-established mathematics property to improve the algorithm on every aspect.
Not worthy advanced solution:
One advanced solution simply showed that the problem could be solved in more complicated way with Regexp.
I don’t really know about professional developers’ opinions, but books, Quora and StackOverflow are good places to peek a portion of their thought.