News for hackers. Stuff that matters.
Re:Ask HN: Why choose a dynamically typed language? by drblast on Saturday August 07, 2010 @03:36PM (#1584144)
If you're a new programmer, remember that most programmers aren't trying to figure this out. They're already substantially invested in the language they chose years ago, with a large base of knowledge and already written code.

Static vs. dynamic typing is nearly orthogonal to my programming language choice. Much more important to me are functional features. And all other things being equal, I'd rather have the flexibility of the dynamic languages than the performance and compiler-checking of static ones.

Haskell has some killer features that make me want to use it more. Static types are not on the list.

Maybe it's because all of my projects are small and I don't have to program defensively, but I've never been bitten by a type error that took anywhere near as long to fix than I would have spent using a static type system.

I'm sure in some circumstances there are dynamic language projects that are plagued by type errors, but in my case static typing is a solution looking for a problem.

Re:Ask HN: Why choose a dynamically typed language? by Groxx on Saturday August 07, 2010 @05:28PM (#1584363)
>Maybe it's because all of my projects are small and I don't have to program defensively, but I've never been bitten by a type error that took anywhere near as long to fix than I would have spent using a static type system.

One of my projects for school turned into a 9k LOC Ruby project. I had precisely zero errors during the entire development cycle that static typing would've detected. Meanwhile, attempting a bit of dynamic code in VB.Net recently resulted in easily a couple hours worth of total waste dodging types while not going totally type-less. And then there's the crappy lambdas and total lack of anonymous or inner functions, so you end up polluting your namespace massively in many cases. (stuck in 3.5 + VS 2008, 2010 adds those) Gah!

I do occasionally miss IDE hinting, which is drop-dead easy in statically-typed languages. But dynamically typed languages allow such ridiculously simple APIs I find it's rarely necessary.

Re:Ask HN: Why choose a dynamically typed language? by Confusion on Sunday August 08, 2010 @04:17AM (#1585050)
I had precisely zero errors during the entire development cycle that static typing would've detected.

You never get a

  NoMethodError: undefined method `[]' for :foo:Symbol
or similar? Then you are either a much better programmer than me, or we are dealing with confirmation bias[1]. I get such errors regularly. They are trivial to fix and are caught early by tests/specs, but they are still there on a first iteration.

[1] http://en.wikipedia.org/wiki/Confirmation_bias

Re:Ask HN: Why choose a dynamically typed language? by Groxx on Sunday August 08, 2010 @02:00PM (#1585750)
No doubt that accounts for some of it, yes. But I'm extremely careful what I put into my variables, especially in larger projects, and especially in this one because everything was extremely highly connected. Chuck something in wrong once, and it could take me hours of hunting to find it; it wasn't worth being tricky.
Re:Ask HN: Why choose a dynamically typed language? by shadowfox on Saturday August 07, 2010 @07:40PM (#1584574)
Not to argue. 9K is comparatively small.
Re:Ask HN: Why choose a dynamically typed language? by Groxx on Saturday August 07, 2010 @07:56PM (#1584592)
As compared to a lot of commercial products, absolutely. But it was still a significantly larger project than I'd attempted before, and I probably ended up writing a good 30k or 40k through the whole time (attempting lots of new things).

It's also still over 10x larger than the .Net project with which I've been fighting. And given my patterns of code, I see no reason why making my previous project 10x larger would have any more difficulties with typing than I had before. In a few years of Ruby coding, I can only recall a few immediately-identified type problems. Static typing seems to me to cost significantly more than its value.

Re:Ask HN: Why choose a dynamically typed language? by gaius on Sunday August 08, 2010 @04:43AM (#1585075)
You can get a lot done in 9 kLOC Ruby/Python/etc. Possibly 10x what you could get done in as much Java.
Re:Ask HN: Why choose a dynamically typed language? by gclaramunt on Saturday August 07, 2010 @04:07PM (#1584213)
I wonder what features do you like from Haskell, as everything seems to be tied to its type system
Re:Ask HN: Why choose a dynamically typed language? by drblast on Saturday August 07, 2010 @08:57PM (#1584676)
I've only written a few small programs in Haskell; one was a basic parser.

The pattern matching syntax made a lot of things trivial to express that would require switch statements or if/else chains in just about any other language, so I loved that. Actually, once I got used to the function definition syntax, I like that too and felt it was very concise.

I like the flexibility that strings are lists (arrays?) of characters, which was incredibly useful for implementing a parser. I'm sure that would come in handy in just about any project.

The type system...eh. I did a bit of fighting with it which apparently is normal for newbies, and I can see the advantage of having it during the compilation stage from a performance perspective. It just didn't grab me by the collar like the other features did.

Re:Ask HN: Why choose a dynamically typed language? by p4bl0 on Saturday August 07, 2010 @04:30PM (#1584255)
+1 for "static typing is a solution looking for a problem".
Re:Ask HN: Why choose a dynamically typed language? by cageface on Saturday August 07, 2010 @04:49PM (#1584281)
I don't think I can completely agree with this. There are tradeoffs and the issue isn't that simple. Dynamic typing is better than bad static typing but so far I'm finding my Scala code is every bit as expressive as Ruby and a lot easier to maintain.
Re:Ask HN: Why choose a dynamically typed language? by KirinDave on Saturday August 07, 2010 @05:13PM (#1584327)
Why is it easier to maintain? What specifically about static typing makes it easier to maintain?
Re:Ask HN: Why choose a dynamically typed language? by cageface on Saturday August 07, 2010 @05:48PM (#1584397)
I think it's three things:

First, it's a lot easier to quickly figure out what a function does when it has a type signature. It's strongly self-documenting.

Second, it's easier to figure out what kinds of datastructures are used in a program, because you can see the types of the variables and functions you're working with. For me understanding the underlying datatypes is a big help in getting to grips with a codebase.

Third, the compiler catches a lot of dumb mistakes early. It's no substitute for testing, but a quick compile cycle will rule out a common class of errors and helps me make changes with more confidence.

It's not all roses and there is a price to be paid but I do thing there's a strong benefit.

Re:Ask HN: Why choose a dynamically typed language? by KirinDave on Monday August 09, 2010 @11:45AM (#1588321)
> First, it's a lot easier to quickly figure out what a function does when it has a type signature. It's strongly self-documenting.

I submit to you that I can show just as many examples where the type signature is of no help. Self-documenting functions existing in all paradigms, and it is a stylistic choice rather than one enforced by any technical considerations.

> Second, it's easier to figure out what kinds of datastructures are used in a program, because you can see the types of the variables and functions you're working with. For me understanding the underlying datatypes is a big help in getting to grips with a codebase.

Interesting point. In languages like Ruby and Clojure, you tend to use a standardized set of highly-optimized and standard structures as opposed to using generics to spin out a lot of them. They tend to conform to high level protocols (interfaces) much like statically typed languages do.

The flipside to this is that dynamic languages tend to have a lot more ease changing data structures down the road.

> Third, the compiler catches a lot of dumb mistakes early. It's no substitute for testing, but a quick compile cycle will rule out a common class of errors and helps me make changes with more confidence.

This is true, but I'd like to point out that lots of Lisp compilers already do this. They use optional static type inference for optimization and error checking but do not enforce those constraints, merely observe them and react to them.

Personally, I think that's the best of both worlds.

Re:Ask HN: Why choose a dynamically typed language? by cageface on Tuesday August 10, 2010 @09:52PM (#1593554)
Interesting point. In languages like Ruby and Clojure, you tend to use a standardized set of highly-optimized and standard structures as opposed to using generics to spin out a lot of them. They tend to conform to high level protocols (interfaces) much like statically typed languages do.

True, but what happens when you decide you really need a list of maps instead of a list of lists? You better hope you have good test coverage when you do this in a dynamic language.

I made a similar change in a fundamental datatype in a Scala program from a list to a symbol -> string map and once I fixed all the compiler errors the whole thing worked correctly on the very first run.