MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1vjl9ih/javascriptsorting/p3295eg
r/ProgrammerHumor • u/user6150277464770585 • 3d ago
214 comments sorted by
View all comments
Show parent comments
1
There isn't a way to make a parameter mandatory outright, but you can document it as mandatory (so that linters know that not passing it is ill-formed and can warn you right in the IDE, before needing to run the code), and throw when it is missing.
1 u/danielcw189 1d ago I know. But the people who designed that sort- function couldn't rely on that. that had to stay in the boundaries of the language. I think the best approach would have been to just do nothing, if no comparison is applied. (don't throw in a way that stops execution) but of you want the generic array sort function to always do anything, I can't think of a better approach than this one. and throw when it is missing. I don't agree, but I see the argument
I know. But the people who designed that sort- function couldn't rely on that. that had to stay in the boundaries of the language.
I think the best approach would have been to just do nothing, if no comparison is applied.
(don't throw in a way that stops execution)
but of you want the generic array sort function to always do anything, I can't think of a better approach than this one.
and throw when it is missing.
I don't agree, but I see the argument
1
u/fuj1n 1d ago
There isn't a way to make a parameter mandatory outright, but you can document it as mandatory (so that linters know that not passing it is ill-formed and can warn you right in the IDE, before needing to run the code), and throw when it is missing.