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

> 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.31...




> 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/


>Consider for example preventing event propagation in JS. This varies by browser so you might write: > > if (event.preventDefault)

FWIW, that sort of field existence check (and much more) can be done fully at compile time in many mainstream programming languages.




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

Search: