Jump to content



Photo

Is dynamic typing on its way out?


  • Please log in to reply
24 replies to this topic

#1 Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 10
  • Joined: 26-October 05

Posted 02 October 2013 - 00:06

I tend to think that dynamically typed languages are on their way out. Here's my reasoning:

 

Dynamic languages were designed to have very expressive, succint syntax, in reaction to the 80-90s tendency towards verbose OOP languages (C++, Objective-C, Java). To this day the main argument people invoke to advocate Python, Ruby, etc., is their high signal-to-noise ratio.

 

Dynamic typing in itself has little or no demonstrable advantages versus static typing. Dynamically typed programs still have a type system, only type errors are caught are run-time rather than compile-time. This makes dynamically typed programs much more brittle, and much harder to provide good tooling for (i.e. static analysis is very limited).

 

However, the main argument in favor of dynamic languages, is itself largely made moot by the emergence of new, statically typed languages that are about as succint and expressive. In the Java and .NET world, Scala and F# are slowly rising, and they're every bit as succint and expressive as Ruby or Python.

 

Here's for example a recursive implementation of QuickSort in Python (from http://en.literatepr..._comprehensions):

def qsort(list):
    if list == []: 
        return []
    else:
        pivot = list[0]
        lesser = qsort([x for x in list[1:] if x < pivot])
        greater = qsort([x for x in list[1:] if x >= pivot])
        return lesser + [pivot] + greater

Here's an equivalent implementation in F# (from http://fsharpforfuna...fvsc-quicksort/):

let rec quicksort = function
   | [] -> []                         
   | first::rest -> 
        let smaller,larger = List.partition ((>=) first) rest 
        List.concat [quicksort smaller; [first]; quicksort larger]

Even more concise, yet statically typed.

 

Some might point out the rise of Javascript as a counter-example. Yet TypeScript, a statically-typed superset of Javascript, is seeing rave adoption due to its ability to provide the same power, compatibility and expressiveness as Javascript yet make large-scale application development much more manageable.

 

Another argument for dynamic languages is their natural ability to interact with intrisically untyped APIs, like Web services. And yet, F# proves with Type Providers that a statically typed language can provide an even better experience there with full auto-completion.

 

Static typing has long been associated with high syntactic overhead and old-school OOP, yet this needs not be the case. New statically typed languages like Scala, F# and TypeScript demonstrate that succintness and expressivety need not to come at the expense of static typing, and its many advantages: performance, tooling, large-scale project management and robustness.

 

What do you think?




#2 Max Norris

Max Norris

    Neowinian Senior

  • Tech Issues Solved: 15
  • Joined: 20-February 11
  • OS: Windows 8.1, BSD Unix
  • Phone: HTC One (Home) Lumia 1020 (Work)

Posted 02 October 2013 - 00:30

What do you think?

I'm no expert in Python, been dabbling with it off and on out of curiosity for the past few months and I do rather like it a lot, get a lot done with very little code.. wish I picked up on it sooner. But for me anyway, static typing just overall makes a lot more sense as it sets clear rules as to what something is supposed to be, no guesswork, IDE tools can be a lot more helpful at pointing out dumbassery and no "why the fudge isn't this working" debugging sessions, never mind the end result I'd suspect is a lot more streamlined performance wise. I'm biased though, that's what I'm used to since the late '70s, dynamic typing just doesn't sit right with me. Ok, the Python indent vs blocks thing is just weird too, but that's another thread.

#3 jwmcpeak

jwmcpeak

    Neowinian

  • Joined: 19-January 02
  • Location: Texas

Posted 03 October 2013 - 21:15

No--although I think the perception differs depending upon if you're a conventional application developer or a Web developer. Conventional applications are the stronghold of statically typed languages; whereas, Web applications are home to (primarily) dynamic languages. But one only needs to look at most web technologies and see that dynamic languages are increasing in popularity.

 

I can't really comment on F# or Scala because my experience is either very limited or non-existent, but I can on TypeScript. It's really only popular with those who:

 

- can't wrap their head around ECMAScript 5-

- don't want to wrap their head around ECMAScript 5-

 

As someone who loves both static and dynamic languages, I get TypeScript's merits but I also see it as unnecessary. I know the primary drive behind TypeScript was to provide better tooling, but that edge dulls as JavaScript tooling gets better.

 

Static languages can play with dynamic typing, but doing so nearly always adds extra complexity.



#4 OP Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 10
  • Joined: 26-October 05

Posted 03 October 2013 - 21:43

No--although I think the perception differs depending upon if you're a conventional application developer or a Web developer. Conventional applications are the stronghold of statically typed languages; whereas, Web applications are home to (primarily) dynamic languages. But one only needs to look at most web technologies and see that dynamic languages are increasing in popularity.

There's more development getting done in Javascript which happens to be a dynamic language, but if Javascript was statically typed then all web development would be statically typed. There's nothing intrinsically advantageous about using a dynamically typed language for web development; it just so happened, for a variety of historical reasons, that a dynamic language initially intended for lightweight HTML manipulation has become the lingua franca of the Web.

I can't really comment on F# or Scala because my experience is either very limited or non-existent, but I can on TypeScript. It's really only popular with those who:
 
- can't wrap their head around ECMAScript 5-
- don't want to wrap their head around ECMAScript 5-
 
As someone who loves both static and dynamic languages, I get TypeScript's merits but I also see it as unnecessary. I know the primary drive behind TypeScript was to provide better tooling, but that edge dulls as JavaScript tooling gets better.
This is like saying that C++ is for programmers who can't wrap their head around C. TypeScript is just EcmaScript with optional type annotations, and type annotations (i.e. optional static typing) proves useful for large-scale application development and static analysis of code. It's not a coincidence that dynamic language tooling is bad: it's a direct consequence of the lack of type information present in the source code. In order to understand what your variables are, tooling for a dynamic language would have to run the program indefinitely which is impossible (i.e. the Halting Problem).


#5 +Majesticmerc

Majesticmerc

    Resident Idealist

  • Tech Issues Solved: 8
  • Joined: 24-August 05
  • Location: United Kingdom
  • OS: Arch Linux / Win 7
  • Phone: HTC One X

Posted 03 October 2013 - 22:07

I don't think that there's been a major shift away from dynamic typing yet (Ruby is bigger than ever), but I think/hope that a lot of people are realising the error of their ways :p. Static typing provides a lot of advantages to dynamic typing, and when the language is well constructed encompasses most of the advantages of dynamic typing too. Static typing solves a lot of problems even before the code is usable by allowing the compiler to stop you running off a cliff.

Dynamic typing also poses an enormous issue on mission critical software insofar that static analysis is almost impossible, leaving it entirely to runtime tests to find issues with the type system. So much so that, apparently, the US Army doesn't allow the running of dynamically typed programs. Dynamic languages always pose the risk that (for example), you'll end up trying to call a method on the wrong type, but given a sufficiently large system it's not until you run it that you find out such nonsense.

That said, I think that dynamically typed languages often get a lot of bad press because many of the most popular ones are also fairly weakly typed. One only has to look at the JavaScript truth table to see how ###### weak typing can make a language.

I'm a big static typing fanboy (can that be a thing?), but I do love me some Ruby. Great language IMO.

#6 jwmcpeak

jwmcpeak

    Neowinian

  • Joined: 19-January 02
  • Location: Texas

Posted 03 October 2013 - 23:44

if Javascript was statically typed then all web development would be statically typed.


You couldn't be more wrong. Well before Eich created LiveScript, dynamic languages, such as PERL and Python, were used to create Web applications. Sure, you could find CGI programs written in C and C++, but PERL-based CGI programs were far more common. PHP, the most popular server-side language/platform today, was introduced in 1995 (development started in 1994--a year before Eich created LiveScript), and it was created because PERL was (is?) too complicated. PHP didn't grow in popularity because of JavaScript; it became popular because it was simple and easy to use. PHP did more to firmly entrench dynamic languages in the web space than JavaScript ever has.
 

There's nothing intrinsically advantageous about using a dynamically typed language for web development


And there's nothing intrinsically advantageous about using a statically-typed language for Web development. We can espouse the merits of both types of languages, but at the end of the day, neither of us would have the definitive winner.
 

This is like saying that C++ is for programmers who can't wrap their head around C. TypeScript is just EcmaScript with optional type annotations, and type annotations (i.e. optional static typing) proves useful for large-scale application development and static analysis of code. It's not a coincidence that dynamic language tooling is bad: it's a direct consequence of the lack of type information present in the source code. In order to understand what your variables are, tooling for a dynamic language would have to run the program indefinitely which is impossible (i.e. the Halting Problem).


A more apt analogy would be C programmers who can't/won't wrap their heads around C++ due to differing programming concepts. JavaScript's prototypal design is foreign to most people who use class-based languages (ie: different programming concepts), which is one of the reasons JavaScript draws ire from "computer sciency" people (there are other reasons, of course).

TypeScript is just a tad more than "JavaScript with type annotations". The annotations are optional, yes, but ironically, JavaScript tooling is better than TypeScript-sans-annotations tooling. But for large-scale applications, it's a toss up. Properly organized and with today's JavaScript tooling (especially in Visual Studio 2013), JavaScript application development is just fine.

It all boils down to this: millions of developers using dynamic languages can't be wrong, and millions of developers using statically typed languages can't be wrong, either. So pick your poison--you can't go wrong.

#7 OP Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 10
  • Joined: 26-October 05

Posted 04 October 2013 - 01:42

You couldn't be more wrong. Well before Eich created LiveScript, dynamic languages, such as PERL and Python, were used to create Web applications. Sure, you could find CGI programs written in C and C++, but PERL-based CGI programs were far more common. PHP, the most popular server-side language/platform today, was introduced in 1995 (development started in 1994--a year before Eich created LiveScript), and it was created because PERL was (is?) too complicated. PHP didn't grow in popularity because of JavaScript; it became popular because it was simple and easy to use. PHP did more to firmly entrench dynamic languages in the web space than JavaScript ever has.

I was talking about now and making a bit of a hyperbole. Obviously there are other languages used in web development (including statically typed ones), but Javascript can be considered the lingua franca of the web now, even on the server, as far as I know. I hope we can at least agree that PHP is a terrible language (if not I can point you to many informative reads on the topic) that succeeded because it provided a path of least resistance and that there was nothing better at the time.
 
 
And there's nothing intrinsically advantageous about using a statically-typed language for Web development. We can espouse the merits of both types of languages, but at the end of the day, neither of us would have the definitive winner.
The same advantages statically typed languages provide elsewhere apply equally to web development; I honestly don't see why web development would be an exception. Advantages of static typing: performance, robustness, maintainability, tooling (auto-completion, static analysis).
 
A more apt analogy would be C programmers who can't/won't wrap their heads around C++ due to differing programming concepts. JavaScript's prototypal design is foreign to most people who use class-based languages (ie: different programming concepts), which is one of the reasons JavaScript draws ire from "computer sciency" people (there are other reasons, of course).
 
TypeScript is just a tad more than "JavaScript with type annotations". The annotations are optional, yes, but ironically, JavaScript tooling is better than TypeScript-sans-annotations tooling. But for large-scale applications, it's a toss up. Properly organized and with today's JavaScript tooling (especially in Visual Studio 2013), JavaScript application development is just fine.

 

The main issue with Javascript is the dynamic nature of types and the intrinsically poor performance. Runtime engines have been making progress but they're running into a wall; there's only so much optimization to do on a language with so few compile-time guarantees. The nature of the language makes large-scale development problematic:

 

Nicholas Zakas: The “shared everything” nature of the language is the biggest JavaScript challenge. You can set up a system that is well designed, and an inexperienced engineer might come in and — accidentally or not — change some key piece of functionality. ECMAScript 5 helps with some of that by allowing you to lock down modification of objects, but the nature of the language remains largely the same and problematichttp://programming.o...apps-teams.html

 

 

This is why Google is pushing Dart, Microsoft is pushing TypeScript, and everyone else is creating static language compilers that output Javascript so you don't have to write it yourself ( http://haxe.org/ , http://jsil.org/ , etc.)
 
 
It all boils down to this: millions of developers using dynamic languages can't be wrong, and millions of developers using statically typed languages can't be wrong, either. So pick your poison--you can't go wrong.

 

What if they're using it because they don't have or don't know any better? Last time I checked, the only reason console developers used C++ was because that was the only language with good optimizing compilers for all their target platforms. Ecosystems, tools, portability, barrier of entry, all of these are better explanations for the success of certain dynamic languages like Javascript than the intrinsic value of dynamic typing, because it doesn't have any. 



#8 incendy

incendy

    Neowinian

  • Tech Issues Solved: 1
  • Joined: 21-October 05

Posted 04 October 2013 - 01:49

I hope so, was just commenting how typescript has made me finally enjoy js.



#9 astropheed

astropheed

    astropheed

  • Tech Issues Solved: 2
  • Joined: 08-December 11
  • Location: Sydney, AU

Posted 04 October 2013 - 03:59

I would say with significant confidence, 'probably not'.

 

I'm perfectly happy with Python's type system. There are some obvious speed benefits to using a statically typed language that Python isn't benefiting from, but, I'm not using Python for it's speed (although it's plenty fast). Also, I've yet to ever hear a solid argument that can directly attribute to the downfall of a dynamically typed language; it always boils down to a subjective bias with the general conclusion being an overly-glorified pro's and con's list.

 

I have no qualms with either statically or dynamically typed languages. They each have their place in the world. And this is a tired and futile argument akin to whether or not your language of choice is a programming language or a scripting language.



#10 Fahim S.

Fahim S.

    Neowinian Senior

  • Tech Issues Solved: 2
  • Joined: 15-April 02
  • OS: Windows 8 - OG
  • Phone: Google Nexus 4 16GB by LG

Posted 06 October 2013 - 09:39

Sounds like someone who prefers static typing trying to justify their point of view  :yes:  I kid, I appreciate a robust debate.  From a programming perspective I think I have a slight theoretical preference for statically typed languages whilst a practical preference for dynamically typed languages, so I apologise in advance for any biases I may display.

 

I don't think it is any coincidence that the most popular of web development languages to date all have a dynamic type system. The only language with a static type system that has made even the smallest inroads in the web development space is Java, but only really in the enterprise because it runs on enterprise grade platforms (or at least those that purport to be).  If you look at any real web success story, they are pretty much all written in languages with a dynamic type system.

 

If it wasn't JavaScript, it'd be something else like it was PHP before JavaScript and Perl before that.  Even Microsoft only made successful inroads to the web development space when they had a dynamically typed (and admittedly awful) language in ASP (I know ASP wasn't a language, but I don't know of many cases of people using jscript with ASP).

 

So why are these languages so popular?

 

I think it all comes down to productivity, which is not the same as the succinctness of a language.  I also think that the lack of tooling is actually not important to those that actually use this languages to create something 'important' as they don't have the rigour at the time - so that's not really a good reason not to use a statically typed language at the time that they are doing their work.  Frankly all testing is just user acceptance based rather than unit, integration etc.

 

I do also believe that dynamically typed languages have a shallower learning curve to do the basic stuff whilst a much steeper learning curve to do the hard stuff.  Statically typed languages, conversely, have a much steeper learning curve to do the basic stuff that gets flatter when doing the hard stuff.  I think that from a portability perspective, programmers that have a foundation in dynamically typed languages struggle more than those that with a foundation in statically typed languages when moving between different languages.

 

The fact that dynamically typed languages have a shallower learning curve to do the easy stuff, means that those using them are often heavily invested by the time they get round to doing the hard stuff which causes dynamically typed languages stick more that what I believe is logical.



#11 OP Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 10
  • Joined: 26-October 05

Posted 07 October 2013 - 21:07

I think it all comes down to productivity, which is not the same as the succinctness of a language.

How are dynamic languages more productive then? Especially since, as you admit, they have inferior tooling support. Tooling plays a big part in developer productivity. Auto-completion, compile-time type checking, refactorings, are all big productivity advantages of static typing.



#12 OP Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 10
  • Joined: 26-October 05

Posted 07 October 2013 - 21:15

If you look at any real web success story, they are pretty much all written in languages with a dynamic type system.

Twitter was recently rewritten in Scala for performance reasons, and also specifically to benefit from static typing.

 

Another thing we really like about Scala is static typing that’s not painful. Sometimes it would be really nice in Ruby to say things like, here’s an optional type annotation. This is the type we really expect to see here. And we find that really useful in Scala, to be able to specify the type information.  http://www.artima.co...r_on_scala.html

 

 



#13 Fahim S.

Fahim S.

    Neowinian Senior

  • Tech Issues Solved: 2
  • Joined: 15-April 02
  • OS: Windows 8 - OG
  • Phone: Google Nexus 4 16GB by LG

Posted 08 October 2013 - 20:04

Twitter was recently rewritten in Scala for performance reasons, and also specifically to benefit from static typing.

 

 

That is all very well, but Twitter was a success before it re-written in a a statically typed language - it was originally written in a dynamically typed language.  You have to ask why they originally chose a dynamically typed language.  What's your answer to this?



#14 OP Andre S.

Andre S.

    Asik

  • Tech Issues Solved: 10
  • Joined: 26-October 05

Posted 08 October 2013 - 20:22

That is all very well, but Twitter was a success before it re-written in a a statically typed language - it was originally written in a dynamically typed language.  You have to ask why they originally chose a dynamically typed language.  What's your answer to this?

Probably because Ruby On Rails was a great, mature development framework, and at the time Scala was relatively unknown, so to get static typing they would have had to use the very verbose and inexpressive Java. With Scala around they've realized they can have the flexibility and expressiveness, and the robustness, performance and productivity of the JVM. I think web developers ought to take heed.

 

Another example is Facebook which was written in PHP, but in order to get the performance they needed, they wrote a PHP-to-C++ automatic code translator. So technically, Facebook runs on a C++ backend. Had Facebook been written in a more expressive statically typed language like F# or Scala, I doubt there would have been a need to write a code translator.



#15 Fahim S.

Fahim S.

    Neowinian Senior

  • Tech Issues Solved: 2
  • Joined: 15-April 02
  • OS: Windows 8 - OG
  • Phone: Google Nexus 4 16GB by LG

Posted 08 October 2013 - 21:05

Probably because Ruby On Rails was a great, mature development framework, and at the time Scala was relatively unknown, so to get static typing they would have had to use the very verbose and inexpressive Java. With Scala around they've realized they can have the flexibility and expressiveness, and the robustness, performance and productivity of the JVM. I think web developers ought to take heed.

 

Another example is Facebook which was written in PHP, but in order to get the performance they needed, they wrote a PHP-to-C++ automatic code translator. So technically, Facebook runs on a C++ backend. Had Facebook been written in a more expressive statically typed language like F# or Scala, I doubt there would have been a need to write a code translator.

 

Are you serious? robustness, performance and productivity of the JVM?

I've introduced Java as a web development platform in several enterprises I have worked in, despite one of my first bosses (in 1998) saying, and I quote 'Java will never fly in the enterprise' - I did win him over eventually.  Today I wouldn't touch it with a very very very long stick.  It is not performant at all and is incredibly wasteful on resources.

 

Lightweight platforms (i.e. not Java) that play nice on PaaS environments are the future.