Live data from Hacker News

Dynamic type systems are not inherently more open

lexi-lambda.github.io

81–90 of 286 posts

Re: Dynamic type systems are not inherently more open

#81
post #72

Having moved from Python to C# I'm still coming to terms with how I feel. It's really hard to express but I do have a nagging feeling that something has been lost that other commentators haven't quite put into words either. You just write different code in dynamic languages - even ignoring type declarations. And in many cases it feels like better, more humane code. One piece of evidence for this elusive difference is…

Unfortunately C# does not have a very nice type system compared to more modern typed languages - elm, haskell, ruby's sorbet. That is probably part of the reason you are feeling that way.

Re: Dynamic type systems are not inherently more open

#82
This is so predictable.

1. Author attacks premise of dynamic type systems argument.

2. Author presents premise for static type system (which is practically confluent/equivalent/equifinal to premise he just undermined).

>static type systems allow specifying exactly how much a component needs to know about the structure of its inputs, and conversely, how much it doesn’t. Indeed, in practice static type systems excel at processing data with only a partially-known structure, as they can be used to ensure application logic doesn’t accidentally assume too much.

Chances are you are wrong about 'how much you need to know' irrespective of your type system. Nobody gets it right the first time.

When we figure out that we were wrong about how much we need to know about the structure of our inputs (e.g we assumed too little) we do this thing we call... "extending our code" [1].

The question then is simply: which type-system is better at extensibility?

And I have no idea how to define "better".

[1] https://en.wikipedia.org/wiki/Extensibility

Re: Dynamic type systems are not inherently more open

#83
post #43

Earlier quoted context omitted.

Yes. Perhaps this is an indication that we actually need automated type annotation. E.g. you initially write/prototype your program in a dynamically typed form, then you click a "magic" button, and a tool converts your program into statically typed style.

Using Type inference[1] on a language could be able to figure out types in most situations. [1] https://en.wikipedia.org/wiki/Type_inference

Yes, but "Type inference has usability problems".

http://web.eecs.utk.edu/~azh/blog/typeinference.html

Re: Dynamic type systems are not inherently more open

#85
post #27

Earlier quoted context omitted.

> This "be liberal in what you accept" idea, applied to modern programming, always struck me as strange. Agreed. There's a reason that serious correctness-oriented languages, like Ada, do not use this approach.

Almost nobody uses Ada, though, while one of the most read programming language-related websites (lambda-the-ultimate) is written in a dynamic language. Also, in the day-to-day interactions of the real world we almost never carry out “validation”, we stop at “parsing” most of the time, otherwise almost nothing will ever be done. In other words “walks like a duck/quacks like a duck” is enough for most of the open worl…

[deleted]

Re: Dynamic type systems are not inherently more open

#86

Earlier quoted context omitted.

This is absolutely false. Not a single word you have written in this comment is true. This is a pervasive myth that you are perpetuating. If you had read the article, you would know that what you have said is demonstrably false. There is nothing stopping you from operating on arbitrary JSON in Haskell. Literally nothing.

I suspect the parent wants to convert between JSON and typed records without needing the JSON to conform to the type.

Ok, but this works just fine in Haskell. If you have a well-formed JSON string and you want to parse it as a generic value, you can parse it into the Value type. If you have a typed record (something less general than a Value) and a JSON string that has enough of the structure to be parsed into that typed record, you can parse it into that typed record. If the JSON string has extra structure/data/fields your parser didn't expect, it's fine. Your JSON parser in Haskell can ignore those extra things. Just like any dynamic language.

All of this was demonstrated in the article.

Re: Dynamic type systems are not inherently more open

#87
post #52
post #43

Earlier quoted context omitted.

Yes. Perhaps this is an indication that we actually need automated type annotation. E.g. you initially write/prototype your program in a dynamically typed form, then you click a "magic" button, and a tool converts your program into statically typed style.

This already exists in Haskell. Firstly, Haskell has type inference so you can write entire programs without any type annotations. Second of all, since type annotations actually help to document your code, it’s recommended as good Haskell style to annotate all top-level definitions. To aid you in the latter task, you can press a key in your editor to fetch an automatically-inferred type for the name under the cursor…

On what editor setup you get this kind of functionality with Haskell? I mean the auto-insert of the inferred types.

Re: Dynamic type systems are not inherently more open

#88
post #82

This is so predictable. 1. Author attacks premise of dynamic type systems argument. 2. Author presents premise for static type system (which is practically confluent/equivalent/equifinal to premise he just undermined). >static type systems allow specifying exactly how much a component needs to know about the structure of its inputs, and conversely, how much it doesn’t. Indeed, in practice static type systems excel at…

This is so predictable.

1. HN commenter misses the point of the article.

2. HN commenter even misgenders the article's author.

Re: Dynamic type systems are not inherently more open

#89
post #58
post #30

Earlier quoted context omitted.

In Clojure you generally accept any kind of map, do some operation and return 'copy' of that map, or pass it on. A simple example is a ring web stack, where request flow threw different functions that transform the http request. Each function just assumes the keys its needed are there, or to do input validation, you just validate that the incoming map has the keys that you require but does not care what else is in th…

But I believe this is also with the spirit of the article. Your functions still assume something about input and are polymorphic over everything else in it. AFAIK this can also be done in a type safe manner in languages which support extensible records/row polymorphism.

You don't need row polymorphism to write a function which operates on a collection of key/value pairs and expects a specific key to exist at runtime.

This works in Haskell, just as it does in Clojure.

Re: Dynamic type systems are not inherently more open

#90
Six notable things I took away from this post:

- Structural typing, i.e. instead of "you eagerly write a schema for the whole universe", just limit to what you need (basically, encode only the same kinds of assumptions you would make in a dynamically-typed language).

- It’s easy to discover the assumptions of the Haskell program [...] In the dynamically-typed program, we’d have to audit every code path — Left implicit in many debates about these topics are the "weights" that one attaches to these things, the importance and frequency of attempting such activities. Surely they vary, depending on everything from the application (Is it "code once and throw it away", or does it need to be maintained when the original programmers have left?) and down to the individual programmer's approach to life (What is the cost of an error: how bad would it be to have a bug? Etc).

- "This is a case of improper data modeling, but the static type system is not at fault—it has simply been misused." — To me this shows that bugs can exist in either the data modeling or the code: in a dynamically-typed language the two tend to coincide (with much less of the former) and in a statically-typed language they tend to be separate. (Is this good or bad? On the one hand you can think about them separately, on the other hand you have to look for bugs in two places / switch between two modes of thought, but then again maybe you need to do that anyway?)

- Structural versus nominal typing, where the latter involves giving a name to each new type ("If you wish to take a subselection of a struct’s fields, you must define an entirely new struct; doing this often creates an explosion of awkward boilerplate").

- "consider Python classes, which are quite nominal despite being dynamic, and TypeScript interfaces, which are structural despite being static." — This is highly illuminating, and just this bit (and the next) elaborated with some examples would make for a useful blog post on its own.

- "If you are interested in exploring static type systems with strong support for structural typing, I would recommend taking a look at any of TypeScript, Flow, PureScript, Elm, OCaml, or Reason [...] What I would not recommend for this purpose is Haskell, which [is] aggressively nominal"

For what it's worth, my opinion is that posts like this, on hotly debated topics, would do well to start with concrete examples and be written in the mode of conveying interesting information/ideas (of which there are a lot here) rather than being phrased as an argument for some position, which seems to elicit different sorts of responses — already most of the HN comments here are about static versus dynamic type systems in general, rather than about any specific ideas advanced by this post.

Post reply on HN