2016-08-14 7:29 GMT-07:00 Steven D'Aprano <steve+pyt...@pearwood.info>:
> On Thu, 11 Aug 2016 06:33 am, Juan Pablo Romero Méndez wrote: > > > I've been trying to find (without success so far) an example of a > > situation where the dynamic features of a language like Python provides a > > clear advantage over languages with more than one type. > > Python has more than one type. Don't confuse dynamic typing with weak > typing > or untyped (typeless) languages. More on this below. > Sorry I was not clear, I was thinking in something along these lines: https://existentialtype.wordpress.com/2011/03/19/dynamic-languages-are-static-languages/ (Warning: his pov is very different from yours) > > I don't believe that you will find "an example of a situation..." as you > say > above. There is a clear situation in my mind: both Python and JavaScript (the dynamic langs I'm most familiar with) provide an easy to use `eval` function. None of the static langs I know provide such functionality (that I'm aware of). Personally I don't have any use for eval, so I was thinking in situations other than that. > It sounds like you are hope to find a clear example of "If you do > This, then dynamic languages are the Clear Winner". But I don't think you > will. Dynamic languages tend to produce clear productivity improvements > over statically typed languages, but of course this is only "typically" > true, not a guarantee that applies to every single programmer or project. > The very few research done on the subject seems to indicate otherwise (here's a link if you are interested in such topics https://www.functionalgeekery.com/episode-55-andreas-stefik/#t=18:14.448). > > Typically: > > - dynamic languages are less verbose; > - dynamic languages are faster to develop in; many organisations > prototype applications in Python (say) before re-writing it in > C++/Java/whatever; > - far less time spent fighting the compiler; > - dynamic languages often have fewer bugs, because it is easier to > reason about the code (no "undefined behaviour" like in C!) and > fewer lines of code to reason about; - but statically typed languages allow you to prove the absence > of certain types of bugs. > > The exception is if you try to write statically typed code in a dynamic > language. Then you get the worst of both styles of coding: the verbose, > heavyweight style of many static languages, but without the automated > correctness proofs, plus the performance costs of dynamic typing, but > without the rapid development. > > > > Regarding types and type systems, if you haven't already read this, you > should: > > https://cdsmith.wordpress.com/2011/01/09/an-old-article-i-wrote/ Thanks for the link. I don't have one to give back, but what I can suggest is this book: http://haskellbook.com/. It seems to me that many of your opinions come from using C++ / Java. If that's the case they are completely understandable. Despite their popularity they are by no means good representatives of languages with modern and powerful type systems. F# (dot.net), Haskell, Scala (JVM / Browser), or Elm (Browser) provide much better examples. > > > "Static typing" (e.g. Pascal, C, Java, Haskell) and "dynamic typing" (e.g. > Python, Javascript, Ruby, Lua) differ on when and how values are checked > for type-compatibility. > > "Strong" and "weak" typing are ends of a continuum. Nearly all languages > are > a little bit weak (they allow automatic coercions between numeric types) > but mostly strong (they don't automatically coerce integers to arrays). > Javascript, Perl and PHP are weaker than Python because they'll coerce > strings to numbers automatically and Python won't. > > I don't know many untyped languages apart from machine code or maybe > assembly. Perhaps Forth? (Maybe not -- some Forths include a separate > floating point stack as well as the usual stack.) Hypertalk treated > everything as strings. Tcl treats nearly everything as strings, although it > also has arrays. > > So, Python has types, and it is a mostly strong typed language. It will do > relatively few automatic coercions. > > > > -- > Steve > “Cheer up,” they said, “things could be worse.” So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list