Stefan Tilkov's Random Stuff

What's a Dynamic Language?

An interesting question arose in a discussion with Michael Stal today, as a side effect of both of us being part of the jury for OOP 2008’s Dynamic Language Shootout (German only): What, exactly, is a dynamic language?

Obviously, this is not really a meaningful question since the term is very much marketing, very little substance. But if anything, I would claim that the key factor for a language to qualify as “dynamic” is the ability to define new code at runtime as part of the core language (e.g. something like eval, define_method or similar).

Update: Wikipedia seems to agree (note to self: check before writing):

Dynamic programming language is a term used broadly in computer science to describe a class of high level programming languages that execute at runtime many common behaviors that other languages might perform during compilation, if at all. These behaviors could include extension of the program, by adding new code, by extending objects and definitions, or by modifying the type system, all during program execution. These behaviors can be emulated in nearly any language of sufficient complexity, but dynamic languages provide direct tools to make use of them.

What’s your definition of a “dynamic language”?

Comments

On January 7, 2008 9:42 PM, Karl Krukow said:

I was making slides for a talk about JavaScript when I started thinking about what it really means for a language to be dynamic. I realized that while one knows roughly at an intuitive level, it is not obvious how to define it precisely. Just as you, I followed wikipedia (don’t tell anyone), but then I noticed the paper by Meijer and Drayton (which was probably more authoritative than wikipedia) at the bottom http://pico.vub.ac.be/~wdmeuter/RDL04/papers/Meijer.pdf

I thought it was really interesting what they say in section 2.8.

<< Many people believe that the ability to dynamically eval strings as programs is what sets dynamic languages apart from static languages. This is simply not true; any language that can dynamically load code in some form or another, either via DLLs or shared libraries or dynamic class loading, has the ability to do eval. The real question is whether your really need runtime code generation, and if so, what is the best way to achieve this.

In many cases we think that people use eval as a poor man’s substitute for higher-order functions. Instead of passing around a function and call it, they pass around a string and eval it. Often this is unnecessary, but it is always dangerous especially if parts of the string come from an untrusted source. This is the classical script-code injection threat. >>

It goes on,

<< A final use of eval that we want to mention is for partial evaluation, multi-stage programming, or meta programming. We argue that in that case strings are not really the most optimal structure to represent programs and it is much better to use programs to represent programs, i.e. C++-style templates, quasiquote/unquote as in Lisp, or code literals as in the various multi-stage programming languages [20].>>

I think this is really interesting to think about ;-)

— Karl

On January 7, 2008 9:48 PM, Stefan Tilkov Author Profile Page said:

Thanks Karl, I followed that paper (just as you did). I would agree that being able to evaluate a string is not essential at all, and in Ruby, I much prefer moduleeval and instanceeval to plain eval. For the language to qualify as dynamic, it must be part of the language itself IMO — this distinction doesn’t really make much sense for languages like VB.NET as one can’t distinguish between platform and language, but it does for most other languages. And I really, really would have a hard time calling C++ a dynamic language.

On January 7, 2008 11:29 PM, Sebastian Stein said:

For me, a key characteristic is that you don’t have type safety, because you don’t compile the code upfront. This is both positive and negative, depending on the use case.

On January 7, 2008 11:31 PM, Santiago Gala Author Profile Page said:

I think having functions (code) as first class objects (and maybe having classes and metaclasses as regular objects) are the key features.

It makes sense that, once there are kinds of “data” that represent “code” (lambda, blocks, etc.), it makes sense to have the four kinds of operations on code (constructors, producers, observers and mutators), and so being able to construct or to mutate code is a side effect of it being equal to other data types or objects.

The ease with which code can be created or manipulated varies a lot between languages, but I think it is the essential feature of dynamic languages.

On January 7, 2008 11:41 PM, Stefan Tilkov Author Profile Page said:

@Sebastian: This is a notion that’s often mentioned, but I wonder what’s so dynamic or static about it?

On January 8, 2008 12:49 AM, Patrick Logan said:

Oh, dear.

I should learn by now to stay away from these dynamic vs. static things! They are kind of like “what is object-oriented”.

“For me, a key characteristic is that you don’t have type safety…”

Except when you do.

For example, is C dynamic? It does not have very good “type safety” although it does have some “compile-time type checking”.

Another example, is Smalltalk dynamic? It does have very good “type safety” in the sense that at runtime the presence of methods is detected and message sends that do not have corresponding method definitions result in exceptions.

There are no easy definitions that I am aware of. There are ranges of choices that form a multi-dimensional space of language design.

On January 8, 2008 8:46 AM, pik said:

I won’t tell you what I know about dynamic languages, I will anyway tell you what I know about dynamic fonts: fonts that resize when someone select a bigger text size on IE. Dynamic fonts are missing from this web site and I am going up and down from my rssreader to mozilla to see something. ;-)

On January 8, 2008 9:32 AM, Sebastian Stein said:

Stefan wrote:

@Sebastian: This is a notion that’s often mentioned, but I wonder what’s so dynamic or static about it?

Well, as long as you have not used the variable in any way, it is still open to be of any type you want. Of course this is just one criteria of a dynamic language and you will probably need a list of criteria.

On January 8, 2008 3:06 PM, Stefan Tilkov Author Profile Page said:

@pik: Sorry about that, I can resize using Safari on a Mac without problems :-) But I know I should switch to using em units.