5 ms·
The TC39 has to step up their game and introduce static typing to JavaScript. I don't buy the bugs argument, but I firmly believe it would make the development
by pier25 9y ago
The TC39 has to step up their game and introduce static typing to JavaScript.
I don't buy the bugs argument, but I firmly believe it would make the development experience considerably better. Not only because of tooling, but specially because code would be more way more expressive.
Also in my almost 20 or so years writing Javascript and other dynamic languages I've never once changed the type of a variable. Changing a var from string to int or object is just wrong.
- yorwba 9y ago> ... I've never once changed the type of a variable. I only do that for functions that accept multiple types (accept liberally and all that), but internally convert them into a canonical representation. For example, if a plain string is to be treated the same as an object with a name property, I will have code like if(typeof(x) === "string") { x = {name: x} } I like how Rust just lets you declare a new variable with the same name but different type, which then shadows the previous declaration for the rest of the scope.
- pier25 9y agoIn those cases I usually create a new function depending on the type. So for example I have a "main" function that does something with a date and expects a date object: doSomething(date) And then if I want to pass a string I do something like: doSomethingString(date) { doSomething(new Date(date)) }
- cozuya 9y agoYou've never taken a value from a web input field that was supposed to be a number? You've never used parseInt?