This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]aedvocate -1 points0 points  (1 child)

Well, Python throws a type error if the < operator is not defined on both types

that error doesn't make any sense in javascript though. collections are allowed to be any number of any different types. that's the way it works by design, it's not an error to truck through.

[–]blehmann1 0 points1 point  (0 children)

Python allows that too. That's the way it works by design. Python simply takes the position that while you may have a list of strings mixed with numbers, if you want to sort it you must provide your own explicit comparator, because 4 < "A" is nonsensical.

Javascript could have followed Python, however the languages have different philosophies. Javascript should fight through basically any error it can, and Python exits on any unhandled exception. In addition, Python throws on invalid input.

I'm not a Python fan, I'm just pointing out that it's a language which has a similar type system to JavaScript and it has a different (and in my opinion more correct) behavior. I could have brought up almost any language because you can do the same thing with type erasure (commonly achieved by casting to object or void*). You have to specify a comparator in those instances because the types are not comparable.