152 points · by jashkenas · 12y ago · 118 comments
I don't buy it.
It's a tacit assumption that, somehow, everything is on the Pareto frontier. Profoundly implausible. In the background, it's basically a hybrid appeal to moderation (all extreme positions are wrong) and popularity (if so many people are doing something, it can't be wrong). Never mind the fact that popularity is almost meaningless, driven by fashion more than anything, and that what's "extreme" is arbitrary and largely driven by popularity itself...
This is how we get "worse is better"; this is how we get standards that are compromises ideal for nobody but still widely adopted because they're standard or because that seems like the thing to do or because that's what everyone else is doing or because " engineering".
The worst part is that this all goes unsaid, assumed correct by default. Just the fact that we're having the discussion the article wants, and not this meta-discussion, implicitly elevates its premise!
Some things are better than others. A strong debate between strong positions is healthier than an artificial social force reverting everyone back to mean.
Now, all this is not to say the usual message about types is perfect. It could definitely be improved in many different ways. But not by muzzling, weakening or qualifying: not by most of the argument's suggestions.
Especially ironic is the rhetorical techniques the author uses to argue against rhetoric. The one I personally find the most grating—beyond the ambient implication that everything is equal that I've just written about—is establishing cheap credibility by aligning himself with the camp he's arguing against. "I like X, but..." Or, in this case, "I use OCaml, but..."
Then again, my pointing this out is probably ironic in the same way. Or is it?
I feel you've missed the point of the article.
The author isn't making a judgement on whether static type systems are better than dynamic type systems, instead he's suggesting we increase the quality of the debate by discarding poor arguments.
I agree in principle, but the fact that there are good arguments on either side of the debate, and neither of them has been able to conclusively prove that one approach is decidedly better than the other, turns the debate into an argument over preference rather than absolutes, which is a very different kind of debate.
But I would even say something stronger: when it comes to programming languages, much (if not most or even practically all) of the arguments must eventually come down to psychology. If a programming language that can produce no bugs and still express useful programs were ever to be created, if that language is hard for people to use (because of human psychology), or even if people don't like using it -- I would say that that language is nearly useless, except for research purposes or maybe some domains where this property is important over all others (say, safety-critical embedded systems). So even if there is a "right answer" like you imply, the debate is in the realm of psychology -- not math or computer science -- and psychology, as we all know, does not usually yield hard answers even when it has answers at all. So while studying the properties of programming languages is computer science, their overall utility is (almost) purely within the realm of the social sciences.
To repeat an example I've made a few times, if your job is to catch a ball you can't argue that teaching you to compute the ball's trajectory with a Newtonian formula is better than practicing a few times simply because the former is more mathematically rigorous. Which is best depends on which approach better fits your psychology.
So here's my strong position: if someone debating programming languages denies that their general utility is mostly a matter of psychology rather than math, then that person is wrong!
If you ignore the "dissenters" then you effectively dis-empower those people & silence their perspective. Is that "better"?
There's a cost of reducing potential novelty. There's a benefit of increasing focus (perhaps increasing implemented novelty of downstream scopes).
> Fetishising Curry-Howard
Hey, I happen to find Curry-Howard sexy, you have no right to shame me!
> To specify and check liveness or reachability, we need to represent programs as some kind of flow graph, where flows are very likely to span multiple functions and multiple modules.
But no, this is exactly what basing systems on Curry-Howard (with terminating functions) buys you. If I give a HTTP response handler in Coq the type
HttpRequest -> HttpResponse
I know it is live, because the function is total. And similarly, dead code paths can be gotten rid of by eliminating a proof of False.So this lets you state liveness and unreachability. Of course, the proofs of those statements is very different from program-analysis-style systems. In a whole-program analysis, the analyser goes over the entire program, and at the end it says "well, I could not find anything calling this function, so I guess it's dead". In a Curry-Howard-style system, you need to look at the function and figure out when it should be called and what preconditions need to be true for it to work properly. But this is exactly why people like type systems, you can think about programs modularly rather than all at once.
HttpRequest -> IO HttpResponse
where IO is some type allowing nontermination (e.g. defined coinductively along the lines of http://www.cs.swan.ac.uk/~csetzer/slides/goeteborg2009AgdaIn...).Having a type for total functions gives you the option to state and prove totality properties, even if you maybe don't want to go through the effort of doing that for every function you write.
data Partial a = Now a | Later (Partial a)
It's straightforward to do things in Partial, since it's a Functor, Applicative and Monad: instance Functor Partial where
fmap f (Now x) = Now (f x)
fmap f (Later x) = Later (fmap f x)
instance Applicative Partial where
pure x = Now x
(Now f) <*> (Now x) = Now (f x)
(Later f) <*> x = Later (f <*> x)
f <*> (Later x) = Later (f <*> x)
instance Monad Partial where
return = pure
f >>= (Now x) = f x
f >>= (Later x) = Later (f x)
Partial is so trivial that everything can be made co-recursive by wrapping all function bodies in "Later". All of the "Later" wrappers will get nested together by the Applicative/Monad; everything will "just work". The one missing piece is the following function, which isn't total: runPartial :: Partial a -> a
runPartial (Now x) = x
runPartial (Later x) = runPartial x
We could name it `unsafeForcePartial` and treat it with care, like we currently do with `unsafePerformIO`.> No sane person can argue that we want to bifurcate a programming language into distinct base-level and type-level fragments.
Well, I must be insane then. I much prefer writing type expressions in a language free from, say, mutation and iteration.
Restricting languages aids not only computers which analyze programs, but also humans which create programs. It's much easier to remember, say, "I'm not allowed to mutate anything, there's no syntax for it", than, "I can use mutation, but if I use it in such-and-such a way, then compiler won't be able to statically determine the type, unless I have version 4.2.3 or later".
Until there are studies that clearly demonstrate that projects written in statically typed languages have statistically less defects, are developed faster, or are easier to maintain, it's all anecdotal evidence.
There are tons of large real world projects developed in both static and dynamic languages, there's very little indication that projects developed in dynamic languages have significantly more defects or that they're more difficult to maintain.
In fact, some of the largest and most robust applications are written in Erlang. See the paper from Joe Armstrong as an example (https://www.sics.se/~joe/thesis/armstrong_thesis_2003.pdf).
We do have some evidence that if there are differences in safety, they appear to be less than overwhelming, see http://blog.metaobject.com/2014/06/the-safyness-of-static-ty...
One can debate how viable the evidence is, but at least it is some evidence.
However, there does appear to be some evidence that static typing helps with program comprehension/navigation, for example: http://dl.acm.org/citation.cfm?id=2568299
Again, not overwhelming, but some evidence.
> * data abstraction
> * data type
> * predicate, proposition
> * proof, proof system
> * interface specification [language]
> * [compile-time] checker
> * specification, verification
> * invariant (the thing that “types” are usually specifying!)
I add precondition, postcondition, state. As well, I think the space in between has importance: map, transformer, relation, command. Formalization is tricky, from my understanding.
I haven't watched his talk, but Rich Hickey also commented on /r/Haskell with the types. It doesn't seem like it was that difficult to capture. There are also other comments that approach the types from different angles and achieve some success. Maybe this isn't a good example for this thesis?
http://www.reddit.com/r/haskell/comments/2cv6l4/clojures_tra...
[1] https://www.youtube.com/watch?v=6mTbuzafcII
[2] http://en.wikipedia.org/wiki/Substructural_type_system#Linea...
That said, I think the more general formulation is something like Fold or Traversal in Lens which operates polymorphically over the whole thing with a type that a refinement of
Profunctor p => p a b -> p s t
where such a type generalizes all of the concrete Haskell formulations.- Most of that discussion happened before a full description of transducers was up anywhere, so a lot of these details are just completely missing. - Haskell's type system is not expressive enough to capture certain interesting properties, like linearity. (To be clear, it's quite possible to translate any arbitrary transducer into Haskell -- but the type system will not prevent all the mistakes it is possible to make.) - There are different classes of transducers that Haskell people actively would not want to have identical types. (ie. stateful vs. stateless, early-terminating vs. unbounded) Many of the discussions revolve only one or a few of these classes -- typically the stateless unbounded version, which turns out to have a particularly simple encoding, but it definitely varies.
I certainly agree that there were a few points that I didn’t substantiate or provide sufficient evidence for—I was deliberately intending to be broad and wanting people to think about these things, rather than going down rabbit holes. I’m afraid that half an hour really isn’t long to talk about such things in detail.
I thought it was worthwhile, so I submitted it again. We got lucky this time ;)
* Less typing (there is freedom in being able to cobble together a reasonably complex program in a single file of a few hundred lines in an editor, vs a number of files and thousands of lines in a IDE).
* Advanced features! It is only now that closures, first-class functions, etc, start to trickle down to mainstream, statically typed languages. And they do make for shorter programs (see, eg, the post on expired links on HN).
Of course, it's not to say that non-statically typed programs don't suffer from a number of drawbacks, but dismissing conciseness as something trivial does not, I think, accurately reflect reasons for why people use this kind of language.
Note that auto-conversion and error on mismatch are both evidence of strong typing in action, because both behaviors rely on type information in order to occur.
But I could only identify with four of the seven. Mostly because I couldn't make sense of his rhetoric for the other three.
> I imagine that my passions are still rather thinly veiled in places
You got that right. But I don't deny you your right to be as passionate about it as you like. It's a debate after all.
These people who stay away from typed languages, who are they and what are they using?
Shell? Awk? Assembler?
When is a language untyped: is it when you can misuse an operand by applying the wrong operation, with no diagnosis and strange, non-portable consequences? Or is when the character string "1.3" can be used as an arithmetic operand, automatically becoming a floating-point approximation of "1.3"? (If that is "untyped", how is it that "1.3" is identified as a character string, and how is the context identified as requiring an arithmetic operand?)
Or is it untyped when wrong type operands do something unpredictable, but dumb?
Bash:
$ string=abcd
echo $(( string + 3 ))
3
$ number=4
$ echo $(( number + 3 ))
7
That must be untyped. No?There's the formal definition of type and there's the colloquial definition of type. A type in the context of the article means a formal type, it is an syntactic classifier that is part of the static semantics of the language. The properties you describe ( string/number exceptions ) are part of the dynamics of the language, which is a separate concept. Dynamically typed languages quite often use boxed values with an attached runtime tags which are colloquially referred to as "types" even though they have nothing to do with static types.
If you read the article in the context of "type" meaning "static type" it will make more sense.
Are you sure dynamic types have nothing to do with static types? What about compilers for dynamic languages which reason about type, like that if the program calls (symbol-name x), it is inferred that x must hold a string, so that a subsequent (cos x) is inconsistent? Is such a compiler is reasoning about something which has nothing to do with static type?
That's irrelevant; if the program containing (symbol-name x) and (cos x) works in an interpreter but not in the compiler then the compiler is broken. Note that throwing-exceptions/triggering-errors/etc. is "working", since it's a valid form of control flow which the program could intercept and carry on. Aborting immediately (like a segfault) isn't "working". Triggering undefined behaviour also isn't "working", but since most of these languages lack any real defined behaviour, it's assumed that "whatever the official interpreter does" is correct.
Usually, these compilers completely acknowledge that their behaviour is incorrect WRT the interpreter. They embrace this and define a new, static language which just-so-happens to share a lot of syntax and semantics with that dynamic language. For example, HipHop for PHP could not compile PHP; it could only compile a static language which looks like PHP. Likewise for ShedSkin and Python. PyPy even gives its static language a name: RPython.
Hence, these compilers don't show that runtime tags and static types are the same/similar. Instead, they show that sometimes programmers without static types will use tags to do some things that static types are often used for.
"Static type" does not really mean "class of values." That is a common use of static types, but they can also be used for things like tracking what resources are available/released or describing what exceptions a function might raise.
So the proof and the tag are related in that one is about the other, but that does not mean they are the same thing.
I had it as: "The Seven Deadly Sins of Talking About Types", which also happens to be the title of the blog post itself, give or take a definite article.
What gives?
>If the original title begins with a number or number + gratuitous adjective, we'd appreciate it if you'd crop it. E.g. translate "10 Ways To Do X" to "How To Do X," and "14 Amazing Ys" to "Ys." Exception: when the number is meaningful, e.g. "The 5 Platonic Solids."
> Exception: when the number is meaningful
As it is in this case: http://en.wikipedia.org/wiki/Seven_deadly_sinsIf a (some might say, literary) allusion has no place on Hacker News, just because it happens to have a number in it, then the small-minded literalists have really taken over this joint.
Father knows best.
Patronising those outside the faith
If somebody stays away from typed languages, it doesn't mean they're stupid,
or lack education, or are afraid of maths. There are
entirely valid practical reasons for staying away.
Please drop the condescending tone.And overall I agree with this: http://www.reddit.com/r/programming/comments/2ijt11/seven_de...
> People who I enjoy discussing issues with bow out of the discussion the same way they do when people bring up emacs vs. vim. They know they aren't going to hear anything new, so why bother?
That's how I felt after reading this: "why did I bother?"
Then there's the 'types' vs 'tags' issue...
I dispute this.
First of all, I think that most programmers use a one-axis system of strong/weak, where "strong" means approximately "the safety that I like", and "weak" means approximately "lacking the safety that I like", a system in which they have no words for "additional safety that I do not value". I'm not aware of any useful definition of these words, nor any specific definition widely agreed upon by any meaningful non-partisan class of speakers (e.g. "working programmers" or "published academic type theorists"). Can you correct me?
As such, I think that saying "very, very few languages are 'weakly' typed" is unlikely to be understood by your audience in the sense that you intended it (whatever sense that was).
I agree that the dynamic/static axis seems to be in wide use, and I'm unaware of massive divergences in usage. Although note that many people spell the word "static" using the letters ['s', 't', 'r', 'o', 'n', 'g'].
The sense in which that post intended "weakly typed" is the one in which it means that types are checked neither at compile-time (statically) or at runtime (dynamically). For instance, (most?) assembly is "weakly" typed, because I can "pass" whatever data I want into a subroutine without it noticing whether or not that data has the correct type. On the other hand, Ruby is "strongly" typed, because I get "NoMethodError" if I try to call a method on a type that doesn't implement that method. And Rust is also "strongly" typed because I get an error from the compiler if I try to call a method on a type that doesn't implement that method. But Ruby is "dynamically" typed because I get that "NoMethodError" at runtime, while Rust is "statically" typed because I get that compiler error at compile-time.
I guess you know all this stuff, but you seem to think the terminology is less common than I do!
How are "academic type theorists" partisan exactly? That sounds a lot like saying "I haven't seen a definition of medicine that is widely agreed upon by both biologists and homeopaths". Of course not, but those are not equal opposite sides. One side is correct, and the other is not.
Like Perl and PHP? Perhaps few (in number) languages are weakly typed, but they're also a few of the most commonly used languages in existence.
In many "variable can be anything" languages, you cannot for instance add the character string "3" to the number 3 to obtain 6. You get an error, like "the string '3' is not an arithmetic operand".
So even though the variable which holds that "3" can be anything, the arithmetic add operation doesn't take any kind of value.
Languages of this type can be subject to static checking, which can identify potential programs. Mature dynamic languages have good compilers with such checks. Instead of being told "you cannot run this program because of such and such a type mismatch", you get a softer diagnostic like "there is probably a type mismatch here". (And if the program is run anyway, the mismatch is still caught at run time and turned into an exception---if the execution of the program steps into the code with the values which trigger the problem.)
Thank God.