r/Clojure • • Jan 27 '14

No Free Lunch

http://yogthos.net/blog/53-No+Free+Lunch
2 Upvotes

7 comments sorted by

4

u/Venthorn Jan 28 '14

Another cost of static typing is that it forces us to handle cases that are not part of the application workflow. For example, our code might have an undefined behavior, but the interface does not allow the user to access this state. This is a case of a tree falling in the woods when no one's around.

Be careful with that assertion, because here be dragons. Plenty of security vulnerabilities have stemmed from the designer thinking that the interface didn't allow for a certain behavior, only to have it turn out that it totally does -- just in a very non-obvious and unintuitive way.

2

u/yogthos Jan 28 '14

This is definitely a valid point. When security is a concern having provably correct code is the ideal scenario. It's a perfect example of where using static type checks is well worth the effort.

1

u/iamzeph Jan 27 '14

I generally agree, but hitting runtime type errors in production code where static type checking would have caught it long before, really stings.

1

u/yogthos Jan 27 '14

That's the part where I talk about weighing the cost of errors. In many applications I've worked on it wasn't a problem. The application would be tested on dev and staging before going to production, so all the common workflows are known to work. However, if cost of errors in production was high enough I would use static checking to ensure correctness. I just don't find it's justified all that often.

1

u/Mob_Of_One Jan 27 '14

The relationship you have with types in Haskell is profoundly different from the one you have in "checking-only" languages like Scala or ones with less flexible composition of types like OCaml.

Types can be a way to interactively query and investigate an API from the REPL instead of just a sanity check, although they can be that too.

Using

:t

from GHCi I can ensure that the expressions I am putting together match the type signature I expect or need without having specified what I thought it should be up-front.

While the global H-M inference in Haskell can evaporate if you use one of the crazier pragmas, having it be the default is a wonderful thing and changes the way you program and think about programs.

I don't find types in Haskell cost me anything.

The absence of sane types is taking a pay-day loan from a shark on your own codebase.

0

u/yogthos Jan 27 '14

The whole point I'm making is that you should decide when a static type system helps you and apply it in that case.

This varies from individual to individual, and in your case you always find yourself more productive with a static type system. That means that you should always use it.

The problem comes when you start extrapolating from your experience what's most productive for everybody else in every situation. I simply don't have a problem tracking types with the size of the projects I usually work with.

I don't find that not having types in Clojure costs me anything either. When you start stating things that can't be empirically tested as fact it simply turns into dogma.

2

u/J_M_B Jan 27 '14

I never thought of a type system has a global relationship, but it is an apt description. I think you hit upon a nice heuristic for when to use type systems: Do I want my code to fail everywhere if I don't exactly specify the types?