News for hackers. Stuff that matters.
Re:Ask HN: Why choose a dynamically typed language? by Goladus on Saturday August 07, 2010 @04:43PM (#1584270)
A big advantage of Python versus C# is not having to think about types unless you have to, and if the code is less verbose that's a side benefit. (And honestly, I'd be surprised to find a whole lot of C# code that couldn't be written to be more concise in Python, if performance wasn't an issue)

    def foo(lst):
        if type(lst) is str:
             #return do_string_stuff_to(lst)
        else:
             #handle do_list_stuff_to(lst)
And I'm done. There's a good chance I'll throw the function away or re-write it before I ever care about the sort of edge cases that would get caught by a static compiler. If the algorithm works on a dictionary or set just as well as the list I had in mind, so much the better. In the meantime it's doing its work and helping me get other things done.
Re:Ask HN: Why choose a dynamically typed language? by prodigal_erik on Saturday August 07, 2010 @04:59PM (#1584297)
> If the algorithm works on a dictionary or set just as well as the list I had in mind, so much the better.

This is the key difference in attitude. I don't want a language that frictionlessly helps me screw up. If what I'm doing might work but nobody actually knows, I want some kind of warning. At the very least I need to add your code to my test coverage.

Re:Ask HN: Why choose a dynamically typed language? by Rusky on Saturday August 07, 2010 @04:54PM (#1584290)
That example, in a statically-typed language could be handled with overloading or polymorphism, which are both far more concise IMO.

C#'s standard library, for example, has common interfaces for collections so the code will still work on all kinds of lists, arrays, etc.

Re:Ask HN: Why choose a dynamically typed language? by swolchok on Saturday August 07, 2010 @05:00PM (#1584303)
I believe you meant

    if isinstance(lst, str):
Re:Ask HN: Why choose a dynamically typed language? by pufuwozu on Saturday August 07, 2010 @08:45PM (#1584662)
If you really want to be pedantic, it should be:

    if isinstance(obj, basestring):
So that it works with unicode in Python >= 2.3