News for hackers. Stuff that matters.
Re:Why Python is Slow: Looking Under the Hood by nly on Friday May 09, 2014 @03:29PM (#7722821)
Static typing makes it a lot easier to reason locally about code.

I can't understand what a function is doing in isolation when the types are unknown. A function takes a variable foo and returns foo[bar], what did it return? Is that even valid code? What does that even mean if foo is a string and bar is a database handle? Ok, this is a lookup of some kind... is it an index or a hash table? I have no way of knowing without reading the comments (which may or may not exist). The only other way to figure out what the function is used for is to trace the data all the way back to its creation... literally find every call site and slog my way up the call stack.

In a dynamic language you can't even tell if all your code will execute until you run it and test all the code paths, let alone attempting to convince yourself that it's correct. I don't understand why people want that cognitive burden when the compiler can tell you straight away that you've typed something nonsensical.

I've just never seen a code sample that made me want to throw away static typing. Not even one.

Re:Why Python is Slow: Looking Under the Hood by lispm on Saturday May 10, 2014 @03:58AM (#7724804)
If you use a language with type inference, you won't see what it returns either. Because it is not in the code. You would need an IDE which finds it out.

Sometimes it computes a type and you have no idea what the type is about.

Also dynamic typing does not mean you don't know what a function receives or returns. Many dynamically typed languages are object oriented and use classes.

For example in Lisp I would write:

    (defmethod collide ((s1 ship) (s2 submarine))
      ...
      (the collision-event (make-collision-event ...)))
Then I know that the arguments are objects of class ship and submarine and it returns an collision-event.

It's not statically typed, but the code is nicely readable and testable.

Re:Why Python is Slow: Looking Under the Hood by benjiweber on Saturday May 10, 2014 @05:24AM (#7724916)
With inferred types you still know that callers must be passing something for which the operations performed are valid.

Many languages allow you to specify types even when they may be inferred to add clarity/preconditions. This is useful for modelling the domain as well as local reasoning. Perhaps the current implementation is valid for all integers, but in the domain context it only makes sense for the range 0-100.

Re:Why Python is Slow: Looking Under the Hood by nly on Saturday May 10, 2014 @07:33AM (#7725091)
If the compiler can infer the type locally then so can I. At least for reasonably well structured code.
Re:Why Python is Slow: Looking Under the Hood by cousin_it on Saturday May 10, 2014 @08:39AM (#7725186)
I thought type inference in Haskell or ML was a global algorithm.