News for hackers. Stuff that matters.
Re:Ask HN: Why choose a dynamically typed language? by chc on Saturday August 07, 2010 @03:57PM (#1584186)
The reason most people choose dynamic languages is because the most popular static languages have fairly weak and unhelpful static type systems. The benefit of confirming that a variable is an int isn't worth the effort needed to support that analysis in most static languages, and where it is we can shove the trouble into unit tests.

C# is a little better than the big 3 (C, C++ and Java), but you still trade off between helpfulness and verbosity. F# is a lot better IMO, but it's still fairly obscure, so of course not many people are going to be using it.

Re:Ask HN: Why choose a dynamically typed language? by pbz on Saturday August 07, 2010 @10:41PM (#1584774)
Whether it's worth the effort is debatable. When you (not you specifically, in general) design a database, do you use types, do you mark a field as int or let everything be a string? Yes, when you code you can make sure to only put "integers" (as string) in that field and everything will work. Maybe it's not the perfect analogy, but I think it touches an important point. From a statically-typed point of view it "feels" dirty. When I look at a method declaration, I want to know that it only works with integers, the same way I look at a field in the database I want to be sure to expect only integers, and nothing else.
Re:Ask HN: Why choose a dynamically typed language? by anamax on Sunday August 08, 2010 @12:59AM (#1584892)
> When I look at a method declaration, I want to know that it only works with integers, the same way I look at a field in the database I want to be sure to expect only integers, and nothing else.

That's fine, but it doesn't help me with the errors that I make.

I don't make representation errors. I make kind errors. The difference is that the number of apples and the number of bananas are both non-negative integers, but a check for non-negative integers doesn't keep me from adding apples to my bananas inventory. Remember that I do want to add both apples and bananas to my fruit inventory.

Yes, I care about representation, but things shouldn't go south if I happen to have half an apple.

Re:Ask HN: Why choose a dynamically typed language? by aristidb on Sunday August 08, 2010 @07:48AM (#1585233)
In some statically typed languages, it is possible to have an "Apples" and a "Bananas" type. And it's good to hear that you don't make "representation errors", because I do make these errors - which then blow up precisely after 3 hours of running the Python program.
Re:Ask HN: Why choose a dynamically typed language? by pbz on Sunday August 08, 2010 @12:32PM (#1585577)
No quite sure what you mean, if you write something like this:

void DoSomething(Fuit fruit, uint quantity) { .. }

Inside that method you will be guaranteed to receive only apples or bananas and a non-negative integer for quantity.

Re:Ask HN: Why choose a dynamically typed language? by chc on Saturday August 07, 2010 @11:15PM (#1584801)
But noting types is not the same as the specifics of a type system. Merely marking what types a function accepts can be accomplished just as easily with a comment like "# function foo : (int, int) -> int".

But anyway, in many cases, structural typing can make more sense than name-based typing.

Re:Ask HN: Why choose a dynamically typed language? by gclaramunt on Saturday August 07, 2010 @11:42PM (#1584818)
And the point is, with a static type system you get automatic verification that the "comment" is accurate
Re:Ask HN: Why choose a dynamically typed language? by chc on Sunday August 08, 2010 @10:43PM (#1586843)
Indeed, that is the definition of a static type system. And that's a useful thing to have. But it's not infinitely useful. In some cases, the burden of pleasing the type system can be bigger than the burden of checking types yourself where necessary. Static typing can actually get in the way of useful algorithms if (for example) your type system doesn't support generics.

Due to these tradeoffs, in some cases, people can be more productive in a language without the help of a typechecker than they can in certain languages' static type systems.