5 ms·
Obviously the ability to defer decisions to runtime is a strength - how could you possibly dispute that? And yes statically typed languages have this strength
by ridiculous_fish 7y ago
Obviously the ability to defer decisions to runtime is a strength - how could you possibly dispute that?
And yes statically typed languages have this strength if they use dynamic types. The article's point is that static and dynamic types are fundamentally unrelated to each other. Many languages can and do use both.
When you make a web page you have no idea what "only must" be deferred. There's no way to enforce that the JS you write today will be statically compatible with the libraries and browsers that it touches tomorrow. That's why JS uses dynamic types.
> That's patently false. The whole engine running every browser is statically typed
My point is not about building web browsers, it is about building the web. The web has JS which must coexist with arbitrary other JS, running on many different browsers with many more versions. How could you possibly build this without dynamic typing?
- naasking 7y ago> The article's point is that static and dynamic types are fundamentally unrelated to each other Not unrelated. You can embed dynamic types into a statically typed language, but not vice versa. Formerly dynamically typed languages that pull in static types, like Racket or TypeScript, become statically typed languages with embedded dynamic types. > There's no way to enforce that the JS you write today will be statically compatible with the libraries and browsers that it touches tomorrow This has nothing to do with dynamic types but with standardisation. C# is a language that is considerably different from its first release, and yet v1.0 C# still compiles on the latest compiler. The converse is not true, for either JS or C#. Dynamic types don't help with this problem. > The web has JS which must coexist with arbitrary other JS, running on many different browsers with many more versions. How could you possibly build this without dynamic typing? How do all the arbitrary programs on your computer coexist? The programs that interact do so via protocols or standard interfaces, and the ones that don't interact are isolated. This is no different than any other software.
- deleted 7y ago[deleted]
- ridiculous_fish 7y ago> Formerly dynamically typed languages that pull in static types, like Racket or TypeScript, become statically typed languages with embedded dynamic types. These languages are not "formerly dynamically typed." These languages are fully dynamically typed. Dynamic typing does not mean the absence of static types! That's the main point of the article. I use and love statically typed languages. Dynamic types are a "yes and", enabling new things. ObjC and TypeScript are examples of languages with static and dynamic types. > C# is a language that is considerably different from its first release, and yet v1.0 C# still compiles on the latest compiler. The converse is not true, for either JS or C#. Dynamic types don't help with this problem. Actually dynamic types help enormously with this problem. They enable testing for the presence of features at runtime, and conditionally invoking code that otherwise could not type check. Consider for example preventing event propagation in JS. This varies by browser so you might write: if (event.preventDefault) event.preventDefault(); dynamically checking for the presence of a field, and then invoking it as a function. This is where dynamic types shine. You can write this in C# or Java using reflection, because these languages have dynamic types. You can't write this in languages without dynamic types. > How do all the arbitrary programs on your computer coexist? The programs that interact do so via protocols or standard interfaces Every program on my computer is a conversation between the application code, the system libraries, and plugins. The browser I am using to type this dynamically interrogates the classes that it uses to discover their features, and conditionally invoke code. Example [1] - notice how this statically typed code is making a dynamic type query, illustrating that these concepts are completely compatible. My computer's programs rely on dynamic types. That's how they retain compatibility across different versions, and it's how the OS vendor keeps the programs working across system updates. 1: https://chromium.googlesource.com/chromium/src.git/+/62.0.3178.1/content/browser/accessibility/browser_accessibility_state_impl_mac.mm#26 https://chromium.googlesource.com/chromium/src.git/+/62.0.31...
- naasking 7y ago> These languages are not "formerly dynamically typed." These languages are fully dynamically typed. Dynamic typing does not mean the absence of static types! No, dynamically typed means the program has only one type: the universal value. > They enable testing for the presence of features at runtime, and conditionally invoking code that otherwise could not type check. [...] You can't write this in languages without dynamic types. That's incorrect. Extensible idioms don't look the same as they do in dynamically typed languages, but looking the same is immaterial. The same sort of behavioral extensibility is achievable with static typing without reflection, for instance, as found in the Yi editor [1]. Once again, it's about protocols and interfaces. > Example [1] - notice how this statically typed code is making a dynamic type query, illustrating that these concepts are completely compatible. That is merely one way to do it > My computer's programs rely on dynamic types. That's how they retain compatibility across different versions, and it's how the OS vendor keeps the programs working across system updates. That's not dynamic typing, compatibility is the advantage of standardized protocols and interfaces. [1] https://yi-editor.github.io/ https://yi-editor.github.io/