Live data from Hacker News

Experiment: Unit testing isn't enough; You need static types, too

evanfarrer.blogspot.ca

81–90 of 276 posts

Re: Experiment: Unit testing isn't enough; You need static types, too

#81
post #74

Earlier quoted context omitted.

No, this is just common ignorance of static typing. That string is a perfectly acceptable String. But it isn't a perfectly acceptable Query, and you can't pass a String to the database, only a Query. In order to turn a String into a Query, it has to be passed to a function that escapes problem characters safely. You need to use such a function regardless of dynamic vs static typing, but static typing enforces that yo…

> but static typing enforces that you always use that function, and can't forget and accidently submit an unescaped string to the database. So you're saying it is impossible to do this without static typing?

To have the compiler trap accidents for you? How would you do this if a query and a string were the same thing?

Re: Experiment: Unit testing isn't enough; You need static types, too

#82

Earlier quoted context omitted.

I can't speak for/to java but C# has come along way. I used to feel just like you did (at the asp.net 1.x) days. I went to Ruby on Rails for awhile. But once NET 2.0 (generics/nullable types) and then 3.5 (LINQ), I was hooked on C# again. We also have the dynamic type now. I want the features a statically typed language gives me with minimal boilerplate. It's hard to give up IDE features like "find everyplace this me…

I like C# these days quite a bit, after ~10 years in both Java and C#, and now ~7 in Ruby, my language preference is Ruby first, then C#. I do a lot of Android development these days too, so I retain a strong connection to Java. But when I have to move from Rails to, say, ASP MVC (which is quite good, btw), generics are actually one of my biggest frustrations. Even with some of the quasi-dynamic typing available in C…

This is not complexity born of strict typing, this is complexity born of object oriented programming. This is what we do in OOP. We take a complex problem and attempt to map it to an even more complex hierarchy of objects and interfaces.

Re: Experiment: Unit testing isn't enough; You need static types, too

#83

The advantage of statically typed languages has a lot less to do with tests and everything to do with tools. IDE's can do very little when no type information is available, and most automatic refactorings require human supervision when performed on dynamically typed languages (read this for details: http://beust.com/weblog/2006/10/01/dynamic-language-refactor... ).

Tooling and performance are two largest advantages. Disadvantage is more verbosity, but it's a trade-off.

With dynamically typed languages I find that you still need to worry about types, but you have to trace through the code to figure out what type a particular variable is (esp. if you're not the only one working on a project). In a statically typed language that information is readily available.

Re: Experiment: Unit testing isn't enough; You need static types, too

#84

Earlier quoted context omitted.

I'm reasonably convinced that once my program has passed the typechecker, it is logically correct Yup, this is one of my favorite things about Haskell, that's how I know that http://bpaste.net/show/32033/ is a totally correct program.

He qualified with "reasonably convinced", and you countered with an unreasonable example. That is the definition of attacking a strawman.

It's not unreasonable, it only seems unreasonable because of the context. I've seen several really good programmers (and overall bright people) mix the implementation of the two up.

Re: Experiment: Unit testing isn't enough; You need static types, too

#85
post #63

Earlier quoted context omitted.

Personally I like Scala but I think it's too complex and a little too clever to escape the FP niche. I'd be happy to be wrong about this.

Interesting. I never perceived Scala to be in a functional niche. As far as I know most people consider it to be an object-oriented language first and foremost, with functional features. Removing inheritance would have made the language (and every other language, too) a lot easier, but seeing that people cope with C# or Java quite well I'm not sure about the merit of the "complex" claim. Comparing the C# and the Scal…

I don't think page counts of specs or feature lists really tell you that much. I didn't find it that hard too get up to speed in Scala but it seems to scare away too many Java people.

My main criticism is that it allows too much syntactic flexibility.

Re: Experiment: Unit testing isn't enough; You need static types, too

#86

Earlier quoted context omitted.

I pretty much lived in Rails from 2004-2011 but did a lot of Python and Perl before that. These days it's mostly C++/Obj-C but I'm keeping an eye on Haskell for iOS.

> I'm keeping an eye on Haskell for iOS. Really? Is that even possible? Can't imagine Apple being okay with that.

Apple's fine with such things… provided you don't let arbitrary code run in your system. If all your VM/runtime runs is what is in the application, it's fine.

Re: Experiment: Unit testing isn't enough; You need static types, too

#87

I'm convinced that dynamically typed languages are a transitional technology that will be superseded once we develop type systems that are both usefully strict but also flexible. After over ten years working in dynamic languages I'm very happy to have a compiler on my side again.

Amen, I've spent the last 3 years of my career working on an increasingly complicated Perl project and frankly, I've had enough. My pet projects now are all Haskell and I can't believe how fun it is. I spend most of my time these days fixing bugs and regressions due to the sheer scale of the project, and I'm a running meme at work for saying "a type checker could have caught that!". I can't imagine going back to a dy…

Are you having fun because you switched to a statically typed language or are you having fun because you switched to a functional language? Would you be having less fun had you chosen Clojure?

Re: Experiment: Unit testing isn't enough; You need static types, too

#88

Earlier quoted context omitted.

I pretty much lived in Rails from 2004-2011 but did a lot of Python and Perl before that. These days it's mostly C++/Obj-C but I'm keeping an eye on Haskell for iOS.

> I'm keeping an eye on Haskell for iOS. Really? Is that even possible? Can't imagine Apple being okay with that.

They've significantly relaxed their restrictions on iOS languages. It's not any weirder than running C# binaries via Mono.

Re: Experiment: Unit testing isn't enough; You need static types, too

#89

Static types or static analysis? * KLEE: Unassisted and Automatic Generation of High-Coverage Tests for Complex Systems Programs http://llvm.org/pubs/2008-12-OSDI-KLEE.html * Erlang Dialyzer http://www.erlang.org/doc/man/dialyzer.html * Datalog based systems http://www.cse.msu.edu/~cse914/Overheads/mmcgill-java-static-race-detector.pdf If you want static analysis hard coded into your language - what feature set do yo…

[deleted]

Re: Experiment: Unit testing isn't enough; You need static types, too

#90
post #74

Earlier quoted context omitted.

No, this is just common ignorance of static typing. That string is a perfectly acceptable String. But it isn't a perfectly acceptable Query, and you can't pass a String to the database, only a Query. In order to turn a String into a Query, it has to be passed to a function that escapes problem characters safely. You need to use such a function regardless of dynamic vs static typing, but static typing enforces that yo…

> but static typing enforces that you always use that function, and can't forget and accidently submit an unescaped string to the database. So you're saying it is impossible to do this without static typing?

I think he's saying it won't be automatically checked for you without static typing. Since, you know, that's what type checking is.
Post reply on HN