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

This example though perhaps not the best actually makes it pretty obvious that if you have immutable objects and variables that cannot change their type you already know that y will always be 1, since it is impossible for DoSomething to change what x is bound to. So the example does illustrate the authors point about being able to understand code without having to look at implementation details.



That can easily be explained by the following example, which is much more sensible:

var a_number = 10;

a_number = { blah: 10 };

var a_plus_two = a_number + 4;

Better yet you can simply say "Javascript does not have strict typing" and point people at the wiki article on strict typing. This is clear and concise as an explanation.

Showing confusing examples and saying "oh look this is horrible types can change" does not make the point stronger.

The article uses a whole lot of words and examples to point out problems that professional JS developers are aware of and work hard to avoid.

It also implies that such languages without strict typing are "unreasonable". It's not unreasonable. It's that way on purpose.




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

Search: