6 ms·
> "static" languages are incorporating ideas from dynamic languages. So the end result is a symbiosis, not opposition. If I may ask, what ideas are static lang
by dade 5y ago
> "static" languages are incorporating ideas from dynamic languages. So the end result is a symbiosis, not opposition.
If I may ask, what ideas are static languages incorporating from dynamic languages? Could you help clarify?
- dbt00 5y agoGo's interfaces are a great example.
- wizhi 5y agoWhat makes Go's interfaces dynamic in nature?
- zmmmmm 5y agothey are "duck typed" .... so an object automatically implements an interface if it has methods with the right signatures to satisfy the interface. It's handy if you need to add interfaces onto code you don't control (say, library code) as you can avoid a whole layer of adapter types / functions that you need in true statically typed languages. But I'm curious if its a great idea in the long run to have interfaces being "accidentally" implemented by objects. Doesn't seem like it would stand up well to refactoring or various other scenarios.
- kaba0 5y agoThan it’s the age-old war between nominal and structural typing. The latter can be really comfortable and productive, but as you note, it may be less safe (eg. just because I have a next method doesn’t mean I want to make it an iterable or something like that. It can easily break class invariants)
- Zababa 5y agoIsn't this more "structurally typed" rather than "duck typed"? From what I've seen, duck typing implies dynamism, while structual typing implies static types. Go is clearly statically typed. So no, Go interfaces are not dynamically typed, they are structurally typed, which is static.
- IshKebab 5y agoGo interfaces aren't dynamically typed. They are statically duck typed, like C++ templates.
- gefhfff 5y agoDown voters may express the reason for their action?
- majjgepolja 5y agoI guess the word is structural typing.
- sidlls 5y agoNot really. It’s a terrible approach that permits some really, truly awful patterns that the designers should have known better than to permit. But it’s not really “go is dynamic!”
- eloisius 5y agoRust’s traits come to mind. If it quacks like an Iterable it’s an Interable
- zozbot234 5y agoOn the contrary, the point of type classes/traits is to provide a type-based alternative to simple overloading.
- shadowfox 5y agoWhat feature of rust traits make them "dynamic" as opposed to the traditional notion of typed interfaces? The latter had been part of static languages for quite a while.
- NtrllyIntrstd 5y agoEver heard of &dyn traits? (that's a joke)
- eloisius 5y agoI'm probably way in over my head with making a good case for how this resembles dynamic languages, but what I had in mind was trait objects. You can box a struct and refer to it as a trait object (aka type erasure). Thereafter, the receiver doesn't care _what_ concrete implementation it gets, just that it implements a certain trait.
- lmm 5y agoYeah that's traditional subtyping, not a dynamic language thing at all.
- 4ad 5y agoRust traits are not subtyping, Rust's type system is principal (although with subtyping you could achieve the same thing as described by the OP, e.g. in C++, C#, etc, which only have subtyping but no existentials exposed as a syntactic feature).
- kgeist 5y agoC# has "dynamic" type. All calls on it are late-bound.
- ComputerGuru 5y agoDynamic didn’t really go anywhere, but more appropriate examples that have now pervaded the language are await in general and IDisposable for ref struct. If it has a GetAwaiter it can be awaited, with no interface. If it has a Dispose() it can be disposed with no interface.
- Zababa 5y ago> If it has a GetAwaiter it can be awaited, with no interface. If it has a Dispose() it can be disposed with no interface. I don't know much about C# but how is this dynamic? Are those methods often added at runtime?
- useerup 5y agoIt's not dynamic. It is structural typing
- UglyToad 5y agoAs far as I understand it it went to wherever there are still poor souls writing COM Interop stuff primarily. Luckily I've never had to touch it so outside of Dapper for SQL I've never really had cause to use dynamic. I imagine there are Windows shops using it heavily though.
- mgdlbp 5y agoInterestingly, this sort of structural typing was already present in C# 1.0 with the foreach statement allowing anything with a GetEnumerator() method that returns something that looks like an IEnumerator. This was discussed in 2011 in a StackOverflow question [0], including a link to a blog post by one of the language designers [1]. [0] https://stackoverflow.com/questions/6368967/duck-typing-in-the-c-sharp-compiler https://stackoverflow.com/questions/6368967/duck-typing-in-t... [1] https://web.archive.org/web/20120126033827/http://blogs.msdn.com/b/ericlippert/archive/2011/06/30/following-the-pattern.aspx https://web.archive.org/web/20120126033827/http://blogs.msdn...
- native_samples 5y agoThe most obvious example is pervasive type inference. It's not really dynamic, but languages with it look a lot closer to dynamic languages, and the removal of repetitive type information is one of the benefits of dynamically typed languages. It gives them the clean, simple feel that it so attractive to many programmers. Also, over the past 20 years what you've seen is big advances in the 'semi-static' world like the JVM, where it runs statically typed languages but they have the ability to eval code, redefine their own code on the fly, reflect themselves, they're garbage collected etc. This is kind of a middle ground. It's worth remembering that when Python and Ruby were new, there weren't really any great options if you wanted lightweight syntax with garbage collection. Nowadays there is Kotlin and you can write code that looks very similar to say Ruby, but which often has the performance of entirely statically typed languages.
- Zababa 5y ago> This is kind of a middle ground. It's worth remembering that when Python and Ruby were new, there weren't really any great options if you wanted lightweight syntax with garbage collection. Nowadays there is Kotlin and you can write code that looks very similar to say Ruby, but which often has the performance of entirely statically typed languages. Lisps and MLs offered this before Ruby and Python got popular. Unless you don't consider them great options?
- native_samples 5y agoWell, getting into the question of why Lisps and MLs didn't take off is maybe too big a topic for this thread, but clearly the market didn't feel they were great options and still doesn't. Clojure remains a niche language for example. I suspect one issue is that Lisp never seemed to be well supported on Windows and never came out of the box on Linux, except perhaps for Guile, but Guile never reached any kind of critical mass despite being promoted by the GNU project. Maybe one reason is the lack of learning materials. Even today, although Guile has an initially pretty and appealing website, clicking "tutorials" reveals a complete lack of interest in growing that community - there is only one single tutorial, which is about how to embed Guile as a scripting language into a C program! https://www.gnu.org/software/guile/learn/#tutorials https://www.gnu.org/software/guile/learn/#tutorials I remember learning Python in the 1990s. The learning materials were excellent. Java was also famous for extensive tutorials and learning materials (they've lost that in recent years, the modern Java docsites are just piles of specifications, but when Java was interested in growth they had it). In the end these things matter more than the exact nature of a runtime or type system.