News for hackers. Stuff that matters.
Re:Learning Elm has gotten me confused about static vs. dyna... by lucisferre on Tuesday June 14, 2016 @06:04PM (#11905697)
Same can be said of static type checking so what is your point? Are you suggesting that those working in static languages don't need to write tests?

Static type checking generally represents an even lower form of error detection than functional and unit testing does. Sure, it can be convenient to have it, but lately I see a lot of static language novices around here talking about their recent and limited experience with type checking as if they are suddenly experts in the tradeoffs between static and dynamic languages.

Re:Learning Elm has gotten me confused about static vs. dyna... by pka on Tuesday June 14, 2016 @06:12PM (#11905747)
But, as you surely know, types prove something about a piece of code. This means they can very well prove the absence of (certain) bugs.

So generally, the more invariants you manage to capture in your types, the more categories of bugs you can statically prove will never happen.

Re:Learning Elm has gotten me confused about static vs. dyna... by jw- on Tuesday June 14, 2016 @07:25PM (#11906181)
This is all true, but is it not a problem that most static languages don't let you (easily) specify the kind of invariants people include in unit-tests.
Re:Learning Elm has gotten me confused about static vs. dyna... by acjohnson55 on Tuesday June 14, 2016 @07:56PM (#11906329)
Sure. But you write unit tests for those.
Re:Learning Elm has gotten me confused about static vs. dyna... by willtim on Tuesday June 14, 2016 @06:19PM (#11905801)
> Same can be said of static type checking so what is your point?

That isn't true. Static typing offers machine checked proofs of the absence of a whole class of trivial errors; and potentially any invariants you've managed to teach it.

My point was that testing does not negate the need for static types, as implied by the previous poster.

Re:Learning Elm has gotten me confused about static vs. dyna... by kazinator on Tuesday June 14, 2016 @08:58PM (#11906531)
Although "class" sounds big, in fact there is only a countable number of places (nodes in the program's tree) where you can have a type error. The space in which any error whatsoever can occur is astronomical.
Re:Learning Elm has gotten me confused about static vs. dyna... by TheDong on Tuesday June 14, 2016 @11:31PM (#11907033)
Let me give an analogy:

Claim: "Getting vaccinated stops a whole class of diseases which might kill you"

Your rebuttal: Although "class" sounds big, in fact there are only a countable number of viruses that vaccines save you from. The number of ways in which you can die is astronomical.

In the above analogy, as in your original statement, you're completely missing the point that the class of errors / class of diseases is an important class and easily preventable, therefore you should do it.

In fact, I think what you've said is the reverse of true. Static typing means that there's a chance of an error at each node in the program's tree because a statically typed and statically compiled language ensures that the program can be rendered as an AST before you ship it to your user.

A dynamically typed interpreted language can have an error at literally any character in the entire thing, and you don't have "compile-time" to tell you it's not an error.

The class of errors that you're saving yourself from is "every single character of this program could be wrong in a way that results in it not even being representable as an AST; there are astronomically many ways that can occur".

In addition, it now goes wrong much later. You have to ensure that you've hit every path with testing before you can be even somewhat confident it's valid code, let alone logically correct and bug-free in other ways. A compiled statically-typed language you waste no more time than a compile-cycle to get that minimal assurance.

Re:Learning Elm has gotten me confused about static vs. dyna... by kazinator on Wednesday June 15, 2016 @11:26AM (#11909881)
Let me give an analogy:

Claim: "Using a plastic liner stops urine from getting into the mattress".

My rebuttal: "That's well and good, but I'm sure I didn't wet my bed past the age of three."

Re:Learning Elm has gotten me confused about static vs. dyna... by dllthomas on Wednesday June 15, 2016 @12:32PM (#11910303)
But then you find yourself sharing a bed with an infant.

Source: I'm typing this from a bed I'm sharing with an infant.

(I don't actually mean this to be an argument, just fun. "Other people will make type errors" is not the argument I'd make.)

Re:Learning Elm has gotten me confused about static vs. dyna... by dllthomas on Wednesday June 15, 2016 @02:33AM (#11907515)
"Compiled" and "dynamically typed" are not opposites.
Re:Learning Elm has gotten me confused about static vs. dyna... by dllthomas on Wednesday June 15, 2016 @02:29AM (#11907507)
It seems like the reasoning here is exactly the wrong way round.

The number of possible programs is astronomical (though still countable!). The number of possible programs with the correct type is substantially smaller. If we can construct our types and type checking such that the errors we are likely to make are likely to result in ill-typed programs, then we can substantially reduce the number of uncaught errors.

More generally, in your comparison you seem to be expecting that a unique error be detected in a unique place. There is no particular reason multiple (or manifold) errors should not be expected to produce an error in the same "nodes in the program's tree".

Re:Learning Elm has gotten me confused about static vs. dyna... by kazinator on Wednesday June 15, 2016 @11:35AM (#11909940)
I'm looking at it as a search problem. I don't care about the likelihood of a randomly generated program with correct syntax being correctly typed because people don't program that way. But rather this: let's take a correct program of size N (N nodes in the syntax tree) and insert a single error into it and give the modified program to someone to find the error (without giving them the original, of course). If it's a type error, it can be found by searching the space of N nodes. If it can be any defect whatsoever, the search space is the entire state space of the program emanating from all combinations of all possible inputs.
Re:Learning Elm has gotten me confused about static vs. dyna... by dllthomas on Wednesday June 15, 2016 @02:58PM (#11911244)
> I don't care about the likelihood of a randomly generated program with correct syntax being correctly typed because people don't program that way.

Agreed!

> But rather this: let's take a correct program of size N (N nodes in the syntax tree) and insert a single error into it and give the modified program to someone to find the error (without giving them the original, of course).

I think that's a good approximation. There is some additional structure it discards; I care most about errors that people are likely to make, and about surfacing changes required in likely refactoring. But I expect something that does well at the one is likely to do well enough at the other.

> If it's a type error, it can be found by searching the space of N nodes. If it can be any defect whatsoever, the search space is the entire state space of the program emanating from all combinations of all possible inputs.

Which is exactly why we want to make as many errors "type errors" as possible (modulo tradeoffs). We'd much, much rather search that smaller space.

Re:Learning Elm has gotten me confused about static vs. dyna... by jdmichal on Tuesday June 14, 2016 @06:22PM (#11905823)
> Are you suggesting that those working in static languages don't need to write tests?

You certainly don't need to write tests that Math.floor will return NaN when you pass it something that's not a number...

Re:Learning Elm has gotten me confused about static vs. dyna... by kazinator on Tuesday June 14, 2016 @10:15PM (#11906802)
What? NaN is actually a number in the sense of being in the domain of the floating-point type. You seem to be mixing up "not a number" (as in character string or list) versus "not a number" as in a special IEEE representation that has special uses in numeric code.

A floor function that returns NaN when given a string, instead of throwing a type mismatch exception, is crap design, and a strawman example of that type of checking. It's not an appropriate use of NaN!

Re:Learning Elm has gotten me confused about static vs. dyna... by jdmichal on Tuesday June 14, 2016 @11:19PM (#11906997)
I agree with you [0], but that's what JavaScript gives us to work with.

[0] https://news.ycombinator.com/item?id=11898046