Hacker News new | past | comments | ask | show | jobs | submit login

I think that whether the semantics of the language make sense to a particular person isn't really the criterion for type-safety. The language does define what should happen in the case of the expression ([]+{}), so no violation of the type system occurs and the behaviour of the program is well defined.



More examples of js insanity here (1:20):

https://www.destroyallsoftware.com/talks/wat

How about {} + [], is that deliberately zero, and why is addition not commutative in this case if it is allowed? Or {} + {}?

I think most people would infer type safety to mean that attempts to coerce types which are meaningless result in an error, not meaningless output, like the result of "string" - 1, or {} + "string" or {} + []. Otherwise your type system isn't going to stop you doing something insane by mistake, and is therefore not adding any safety.

{} + "string" or similar just shouldn't be allowed, and in most languages (let alone type safe ones), it is not.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: