When I look at the solution to puzzles, often the highest rated one employs the use of lines like this:
“.sorted((a,b) -> abs(a) != abs(b) ? abs(a)-abs(b) : b-a)”
Is this considered the “best” way to write code? Is it preferable to writing out the same code in a more easily understood format? Granted, I’m not familiar with how that type works exactly, but it still seems like it would be harder for anyone to read than the alternative. If it is better, why? To save space?
Temperatures puzzles is special case. You have a golf puzzle for temperatures. So i believe many people just upvote this solution because they copy/pasted this code into their golf solution
For other puzzles, you can’t really defined what is the best solution. Because this is “one shot code”. Once you have 100%, there’s no reason to touch your code again.
In real life, when you write some code, you may have to read your own code many years later. So you should prefer to use the most readable version.
In addition I’ll point out that, at least for me, many solutions were written before it was even possible to publish them. That feature is relatively recent, circa February 2016. Before it came along, I considered what I wrote to be for my eyes only. Now, I tend to spend a little bit more time considering how my code will look to an audience before I submit it.
I also am not super impressed with what solutions tend to get upvoted. Among my own solutions, the ones that seem to be most popular are certainly not the ones I am most proud of. My impression is that people vote for ones that are clever, or that they learned something from. There’s also the fact that once a solution gets a few votes, it goes to the head of the pack, and so there’s a momentum factor to this as well. Few people are willing to look through hundreds of code listings to determine which is truly “the best”.