What qualifies a programming language as dynamic?

19,570

Solution 1

I don't think there is black and white here - there is a whole spectrum between dynamic and static.

Let's take two extreme examples for each side of the spectrum, and see where that takes us.

Haskell is an extreme in the static direction.

  • It has a powerful type system that is checked at compile time: If your program compiles it is free from common and not so common errors.
  • The compiled form is very different from the haskell program (it is a binary). Consequently runtime reflection and modification is hard, unless you have foreseen it. In comparison to interpreting the original, the result is potentially more efficient, as the compiler is free to do funky optimizations.

So for static languages I usually think: fairly lengthy compile-time analysis needed, type system will prevent me from making silly mistakes but also from doing some things that are actually valid, and if I want to do any manipulation of a program at runtime, it's going to be somewhat of a pain because the runtime representation of a program (i.e. its compiled form) is different from the actual language itself. Also it could be a pain to modify things later on if I have not foreseen it.

Clojure is an extreme in the dynamic direction.

  • It too has a type system, but at compile time there is no type checking. Many common errors can only be discovered by running the program.
  • Clojure programs are essentially just Clojure lists (the data structure) and can be manipulated as such. So when doing runtime reflection, you are actually processing a Clojure program more or less as you would type it - the runtime form is very close to the programming language itself. So you can basically do the same things at runtime as you could at "type time". Consequently, runtime performance may suffer because the compiler can't do many up-front optimizations.

For dynamic languages I usually think: short compilation step (basically just reading syntax), so fast and incremental development, practically no limits to what it will allow me to do, but won't prevent me from silly mistakes.

As other posts have indicated, other languages try to take more of a middle ground - e.g. static languages like F# and C# offer reflection capabilities through a separate API, and of course can offer incremental development by using clever tools like F#'s REPL. Dynamic languages sometimes offer optional typing (like Racket, Strongtalk), and generally, it seems, have more advanced testing frameworks to offset the lack of any sanity checking at compile time. Also type hints, while not checked at compile time, are useful hints to generate more efficient code (e.g. Clojure).

If you are looking to find the right tool for a given problem, then this is certainly one of the dimensions you can look at - but by itself is not likely to force a decision either way. Have a think about the other properties of the languages you are considering - is it a functional or OO or logic or ... language? Does it have a good framework for the things I need? Do I need stability and binary backwards compatibility, or can I live with some churn in the compiler? Do I need extensive tooling?Etc.

Solution 2

Dynamic language does many tasks at runtime where a static language would do them at compile-time.
The tasks in question are usually one or more of: type system, method dispatch and code generation.

Which also pretty much answers the questions about their usage.

Solution 3

There are a lot of different definitions in use, but one possible difference is:

  • A dynamic language typically uses dynamic typing.
  • A static language typically uses static typing.

Some languages are difficult to classify as either static or dynamically typed. For example, C# is traditionally regarded as a statically typed language, but C# 4.0 introduced a static type called dynamic which behaves in some ways more like a dynamic type than a static type.

Solution 4

What qualifies a programming language to be called dynamic language.

Dynamic languages are generally considered to be those that offer flexibility at run-time. Note that this does not necessarily conflict with static type systems. For example, F# was recently voted "favorite dynamic language on .NET" at a conference even though it is statically typed. Many people consider F# to be a dynamic language because it offers run-time features like meta-circular evaluation, a Read-Evaluate-Print-Loop (REPL) and dynamic typing (of sorts). Also, type inference means that F# code is not littered with type declarations like most statically typed languages (e.g. C, C++, Java, C# 2, Scala).

What are the problems for which I should go for dynamic language to solve.

In general, provided time and space are not of critical importance you probably always want to use languages with run-time flexibility and capabilities like run-time compilation.

Solution 5

This thread covers the issue pretty well:

Static/Dynamic vs Strong/Weak

Share:
19,570

Related videos on Youtube

Gainster
Author by

Gainster

Updated on February 13, 2020

Comments

  • Gainster
    Gainster over 4 years

    What qualifies a programming language to be called dynamic language? What sort of problems should I use a dynamic programming language to solve? What is the main difference between static programming languages and dynamic programming languages?

    • Admin
      Admin over 13 years
      (1) Dynamic Language != Dynamic Programming. (2) Wikipedia or several questions here.
    • Prasoon Saurav
      Prasoon Saurav over 13 years
      This question has got nothing at all to do with Dynamic Programming whatsoever.
    • stakx - no longer contributing
      stakx - no longer contributing over 13 years
      @Huzaifa, I updated your question's title; as the above comments state, "dynamic programming" has a quite different meaning from "programming with a dynamic programming language".
  • Marc Gravell
    Marc Gravell over 13 years
    in your "no conversions" example, are you counting inheritance as a conversion? As any common type between foo and bar (including "object") will allow that to compile
  • Totti
    Totti over 13 years
    To many people, static vs dynamic language refers to more than just the type system. Features like run-time compilation and a REPL also make languages more dynamic.
  • Mark Byers
    Mark Byers over 13 years
    @Jon Harrop: Yes, I hear that one a lot. Another definition a lot of people use is static = compiled, dynamic = interpreted. Python which is generally regarded as a dynamic language includes a compiler that compiles to byte code - similar to Java class files. The pyc files are the compiled files. Therefore I think this definition is unsuitable since it would imply that Python is a static language. Since the terms have no official definition I guess you can't really say who is right or wrong though.
  • Totti
    Totti over 13 years
    "the result is more efficient". Haskell is many things but efficient is not one of them. Both compile and run times are generally among the worst of any language. Haskell has even been beaten by Python in benchmarks. flyingfrogblog.blogspot.com/2009/04/…
  • Totti
    Totti over 13 years
    "no compilation step necessary". Compilation is never necessary.
  • Totti
    Totti over 13 years
    "So when doing runtime reflection, you are actually processing a Clojure program more or less as you would type it - the runtime form is very close to the programming language itself". Are you not just referring to quotations, a feature also found in quite static languages (e.g. OCaml).
  • Salma b
    Salma b over 13 years
    I updated a couple of things in response to your first two comments. On you third comment: yes, I am referring to quotations. In my experience, Lisp-y quotations are a lot easier to understand and process than e.g. the quotations in F#, exactly because the more static a language becomes, the bigger the gap between the quotation and what you would type in. In Clojure, you're essentially typing in the AST and getting it back as such - in F#, e.g. a match statement is transformed to a matching tree (if-then-else) in the quotation. Plus there is no eval, etc.
  • doubleOrt
    doubleOrt almost 6 years
    It is very easy to confuse this with statically-typed/dynamically-typed, thanks for unconfusing me :)