5 ms·
Modern programming languages require generics
- Rochus 4y agoI agree; there are a lot of reasons to have generics in a language, performance one of them as demonstrated; but anyway it doesn't make sense if in a strictly, statically typed language we are forced to do dynamic typing to make data structures and algorithms reusable; however, i don't understand why everyone always goes for generic types; generic modules can do that too and are much easier to understand and implement.
- ayende 4y agoCan you explain what you mean by generics modules?
- Rochus 4y agoHere is an example: https://oberon-lang.github.io/ https://oberon-lang.github.io/, see section Generic Programming; note how the modules have type parameters and how generic module is instantiated by the import declaration in the example of section Object Oriented Programming. Here is the specification: https://github.com/oberon-lang/specification/blob/master/The_Programming_Language_Oberon%2B.adoc#generics https://github.com/oberon-lang/specification/blob/master/The... Here is a discussion why it is designed like this: https://oberon-lang.github.io/2021/07/17/considering-generics.html https://oberon-lang.github.io/2021/07/17/considering-generic...
- ayende 4y agoThat reminds me very strongly how Zig does it
- Rochus 4y agoI'm not familiar with Zig, but a quick look at https://ziglang.org/documentation/master/#Generic-Data-Structures https://ziglang.org/documentation/master/#Generic-Data-Struc... makes me doubt that Zig does genericity on module level; looks rather like parametric polymorphism.
- mncharity 4y agoNot GP, and I'm just surfing unfamiliar docs, but it looks like, yes, there's general parameter polymorphism,[1] but also "modules" presented as structs,[2] and the polymorphism of struct constructors can have nontrivial impacts[3](eg Map(KeyType,void) loses value setters). Fwiw. [1] https://ziglang.org/documentation/master/#comptime https://ziglang.org/documentation/master/#comptime "Compile-time parameters is how Zig implements generics. It is compile-time duck typing." [2] https://ziglang.org/documentation/master/#import https://ziglang.org/documentation/master/#import [3] https://ziglang.org/documentation/master/#void https://ziglang.org/documentation/master/#void "By using void as the type of the value, the hash map entry type has no value field, and thus the hash map takes up less space. Further, all the code that deals with storing and loading the value is deleted, as seen above."
- Rochus 4y agointeresting, thanks
- mncharity 4y agoThanks for this. By coincidence, I was sketching out a polymorphism kludge this evening, and this was food for thought.
- nine_k 4y agoI'd say that no matter where, but you have to add generic parameters to algorithms to make them reusable across domains. Doing so at type / function level allows to introduce them gradually and with low ceremony, compared to parametrized modules (likely you mean OCaml here?). Gradual approaches seem to work best in real world, hence the prevalence of generic functions and parametrized types.
- Rochus 4y ago> likely you mean OCaml here No, I was thinking of Ada or Oberon+. Here is a discussion: https://oberon-lang.github.io/2021/07/17/considering-generics.html https://oberon-lang.github.io/2021/07/17/considering-generic...
- nfbyte 4y agoThis is such crap. Modern programming languages (or any other tools) need to be well suited for a specific problem domain, not meet some generalized arbitrary criterion. And modern systems (as in actual low-level software, not web browsers or databases or games) suffer from a severe lack of security and reliability, not performance.
- nine_k 4y agoDo you enjoy your code base using 5 languages? 10? Have you done some ops support recently? Code review? Hired developers? There are very real advantages in the use of the fewest languages that cover your spectrum of problems. If you can limit the spectrum of languages you use to, for instance, Typescript (with react native on mobile), SQL, and Kubernetes config YAML, it's a big win for productivity and growth.
- nfbyte 4y agoI would rather just have one code base per problem rather than one abomination per spectrum of problems.
- fulafel 4y agoThis kind of mindset and mode of organising a dev team is a common, and has the advantage of more interchangeable developers and more long term tech stability. Basically the "Java house" way. But it's far from the only one.
- fulafel 4y agoThis kind of mindset and mode of organising a dev team is a common, and has the advantage of interchangeable developers, not a lot of need for on the job learning, and more long term tech stability. Basically the "we area a Java house with big teams" way. But it's far from the only one.
- adrianmsmith 4y agoThis is a great article but... it may be just me but I'm allergic to the word "modern". I feel it's a word trying to manipulate my emotions (who wants to be out-of-date?) without actually contributing anything objective to the discussion. For example the sentence > A modern language that is aiming for performance should take this very important aspect of language design into account. could have been rewritten as > A language that is aiming for performance should take this very important aspect of language design into account. and been clearer and more objective for it.
- b3morales 4y agoWould "contemporary" work better for you? There certainly is a cluster of languages that have developed and gained (more or less) traction in the last 10-15 years. I've even heard it referred to as a "generation" -- specifically I think it's the fifth. Rust, Go, Nim, Clojure, Swift, Elixir; to a lesser extent, Zig. I'm probably forgetting a few. (We might also include Crystal or Pony though I'm not sure they are widely used at all. And Hare is an open question.)
- jhbadger 4y agoUnfortunately that's another word that dates itself. Think of the "Contemporary Resort" in Disney World. It has its charm to be sure, but it is very much a period piece evoking the early 1970s when it was built. Every time thinks it has the definitive opinion on design whether architecture or programming language design. History says otherwise, and it is unclear if any actual progress as opposed to simple shifting fashion is responsible.
- ssivark 4y agoI think Julia (built around multiple-dispatch) also ought to be mentioned in any discussion of generic programming in contemporary languages.
- ayende 4y agoA better term might be state of the art, but that has its own issues. In this case, I mean, recent
- UncleEntity 4y agoI guess nobody would call it “modern” but it is quite possible to have the compiler do type inference and automagically specialize functions with the user not even knowing it is happening behind the scenes. No generics needed.
- shirogane86x 4y agoIs it? To me it seemed like any potentially powerful enough type system starts needing at least some degree of type annotations at some point. Something something typechecking halting problem? Don't know the specifics though.
- UncleEntity 4y agoThe papers I read would keep a running tally of the types of the variables and if they were all the same could optimize and/or specialize the called functions. If not they would just fall back to checking the types before performing whatever operations. Basically the theory behind the Futamura projections. I’m sure you could write some code which could keep an abstract interpreter or however type checking is implemented busy forever especially with a dynamic language with eval but, you know, you get what you pay for. Or I’m completely wrong since I just read about this stuff for fun…
- zokier 4y ago> The counter for this argument is that we can always specialize the code for our needs, right? Except… that this isn’t something that happens. This feels like a weird assertion, especially when immediately followed by an example where such manual specialization happens