Hacker News new | past | comments | ask | show | jobs | submit login

Unfortunately, everyone uses statically-typed languages wrong, so they get about the same protection with their compiler that you get with Ruby or Perl or Python.

Consider this common mistake:

   interface Greet {
       void sayHello(String firstName, String lastName)
   }

   class PrintGreeter implements Greet {
       public void sayHello(String lastName, String firstName) {
           ...
       }
   }
Where's your compiler NOW?



Haskell libraries and programmers are good about using type synonyms to avoid this problem.

Notice http://hackage.haskell.org/package/happstack-server-7.3.2/do... isn't a string like "GET" or "POST".


Yes. newtype and GeneralizedNewtypeDeriving eliminates pretty much every excuse for not writing type-safe code.


GeneralizedNewtypeDeriving is kinda terrifying though, you're better off dumping the derivations from GHC and inserting them yourself after having a look-over :)

-ddump-* is great for this kind of thing.


What, autogenerated code never has strange bugs! :)

That said, it works well enough for deriving monad from a transformer stack. Do people use monad transformer stacks? It's been a while since I've written any real Haskell code.


Monad transformers and stacks of them are pretty standard though it's something library writers engage with more often than "users".

There are more adventurous and specific ways being explored to handle things like "effects", but that exists mostly in SHE or Idris.

mtl is still the practical way to go for now.

I keep wanting an excuse to futz around with this: http://hackage.haskell.org/package/layers


It should also be noted that my specific example doesn't even use or need newtype. It's a sum type that derives a bunch of standard typeclasses.


And that's how to piss off staff engineers, bring down production bigtables, and get to write your first regression test :).

(I swapped key and value in a string, string API and ended up writing 5+ MB "keys".)


This is a classic example of when to use the Value type pattern. You are in fact arguing for stronger typing (String is too limited here).

If you language makes that problematic, it is the fault of the language implementation, not a problem with static typing.


The people writing "dynamic languages suck" blog posts are merely unaware of how much dynamic typing they do every day in their statically-typed languages. And yes, I am arguing for stronger typing. And for getting rid of null.

(I've seen plenty of Haskell programs that are not compile-time checked for, say, XSS problems, even though it's trivial to do that with the type system. The problem is that nothing is ever automatic; if you want to write the best possible code, you have to make it a goal and carefully execute that goal. There is no silver bullet.)


Most of my mistakes are elaborate versions of this:

  double :: Int -> Int
  double = (3*)
The only amount of typing that is going to help with that is an amount nobody is willing to use.


Ah yes, the other common misconception. You still have to have test coverage to be confident that your code actually works.


At least you won't be trying to add 15 to lastName...


That is a problem of weak typing, not dynamic typing.


In Javascript or Ruby, we'd just pass in a hash--named arguments lol.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: