开发者

Dynamic languages Vs Static languages (can this two be together in the same place)

programming languages are grouped it 2 main classes "Dynamic" &am开发者_StackOverflowp; "Static". - Is this always the case a programming language is in one of them and not in both, I mean can a language be dynamic and static at the same time ?


The distinction static and dynamic language is quite ambiguous since it can refer to many different (more or less suitable) criteria. I'll try to answer for each case:

Interpretation/Compilation

This doesn't depend on the language itself but just on the implementation used. Therefore languages can be executed through both an interpreter and a compiler. Examples

  • Haskell (GHC / GHCI / Hugs)
  • C++ (G++ / Ch)
  • F#

Some compiled languages also have the possibility to compile their code at runtime (.NET).

Static/Dynamic typing

Static and dynamic typing (duck typing) can be combined in one language. See C#'s dynamic, VB with Option Explicit/Strict off or Boo. Structural typing can be used to formulate strict typing without explicit type hierarchies. Polymorphic base types (System.Object) support some kind of dynamic behaviour as well, though the type is given statically.

Meta constructs (e.g. Reflection, Runtime type generation)

Are available in Java and .NET too.

Functional techniques(eg. Higher-order functions, continuations)

Can be replicated in statically-typed languages as well. See Haskell or Scala.


C# 4.0 is a statically typed language that supports dynamic resolution as well. The dynamic keyword basically tells the compiler: don't worry about this for now. If it can't resolved the type at runtime an exception is thrown.


Objective-C is another example. It's a strict superset of C, and C is statically typed. But the "objective" stuff can be totally dynamic (all objects declared as type id). The compiler does some static type checking of Objective-C objects, although it is limited since many standard methods return id. For example, the NSArray collection returns objects of type id, so the compiler can't catch:

NSMutableArray *a = [NSMutableArray arrayWithObject:@"I am a string"];
NSNumber *n = [a objectAtIndex:0]; //assigning a string to a number!

although it could flag, NSNumber *n = @"I am a string", at compile time.


Yes. It's possible to have both static and dynamic together.

If one uses C#, then we are on static track and the movement we use a new System.linq.Expression tree API in VS 2010 (.NET 4.0). We are targeting our code towards the framework called DLR (Dynamic Language Runtime) a layer above CLR.

Even our code created by expression class can also be use by other Dynamic languages like IronPython etc..

Similarly, we can use the iron python code over CLR. All we need to make sure they emit expression tree and are targeted towards the DLR.


can a language be dynamic and static at the same time ?

Dynamic and static refer to many different things in quite a vague way. In particular, languages can be statically or dynamically typed meaning the type checking is either enforced to some extent at compilation or it is entirely deferred to run time. But people often refer to a language as "dynamic" because it has a REPL so definitions and expressions can be evaluated interactively. Indeed, F# is a statically typed language that was voted best dynamic language in a survey. Dynamic can also refer to the ability to do introspection/reflection.

So I suppose a language can be both dynamic and static at the same time. In particular, by being both statically type checked and supporting interactive evaluation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜