What is the difference between dynamic languages ​​and functional languages?

I often find that developers use the terms functional language and dynamic language together, and wonder why they are always combined. What are the differences between the two? Can a language be dynamic and functional? Do they complement each other? Why do we need them? I am a C # programmer and still do not understand this dynamic / functional thing (C # will have some dynamic functions in version 4. Will it also function? What is happening here?).

Thanks Abraham

+7
functional-programming dynamic-languages
source share
5 answers

Dynamic typing, a type system, is orthogonal to the “functional” programming paradigm.

Dynamic "languages" are actually dynamically typed. This means that you do not have time to compile your types of variables.

Functional languages ​​offer a lot of support, for example. lambda calculus are anonymous functions.

An example of a language that performs dynamic typing and supports anonymous functions: javascript. Ruby also supports a functional style. And there are others.

+8
source share

To express this with a simple (but not exact) answer

  • Dynamic languages are those in which Type (Class Name) is not so important compared to its hostile statically typed languages. A variable can have objects of different types assigned to it at any given moment in time. Method calls are resolved at run time. This means that you lose the benefits of static input (compiler warnings), but simple methods become common - sort(list) works for a list of strings, as well as for an int list. e.g. Ruby et. everything
  • Functional languages ​​are immutable values. Programs are written in terms of large and large functions (usually from bottom to top). The concept of object state and variability is not approved . Function in this context, it is self-sufficient (the term "Clean" according to Wikipedia): all that he needs to create a result is what he gets. It also creates no side effects (unless it explicitly mentions this) and returns consistent output for the given input. This can lead to elegant code (see: Free Interfaces), where the input is pipelined through diff functions to get the final output, for example. LISP et.all

However, borders are mixed with languages ​​that the best of all worlds collect ... You can have a language that is one at the same time or not.
for example predominantly static C #, collecting lambda expressions in version 3.0 and including dynamic features with 4.0

+8
source share

If you are interested in paradigms, then they are described by Programming paradigms for dummies: what every programmer should know .

In functional programming, the state is implicit - the program makes calls to functions that call other functions. In imperative programming and object-oriented programming, the state is explicit - you change the value of the field of a variable or object.

In a sense, functional and imperative systems can be regarded as doubles - that which is fixed in one is a dynamic meaning in the other.

Closures that catch some kind of explicit mutable state in an object that can be called as a function are somewhere in between, not being pure functional programming, but not quite full-fledged objects; they are more like anonymous objects than functions.

"Dynamic languages" is an indefinite term, usually meaning one of the following:

  • Dynamically typed languages ​​are languages ​​that delay type determination at runtime, but the set of types is fixed. Examples are Smalltalk, Lisps, current versions of Fortress. Some otherwise statically typed languages ​​also allow some dynamic type checks — Java, C #, C ++, and Ada. (it was an unsuccessful dynamic type cast from float to int in Ada that broke Ariane 5)

  • Languages ​​with dynamic types are languages ​​where new types can be created at run time. The most popular is JavaScript. Since you must run the program to determine the types, it is more difficult to make them an IDE with auto-creation of the type.

  • Languages ​​that are dynamically compiled are languages ​​where new scripts can be compiled at runtime. This is true for bash, JSP, PHP, and ASP at the page scale, and for thinner ones, for lisps and JavaScript, which support the eval function, which compiles and runs the expression.

Functional languages ​​that are strongly typed often carry a large amount of type inference, so there is often less explicit typing for their programs than poorly implemented static typed languages. This can confuse people who saw only the lack of explicit typing in dynamically typed languages, believing that type inference is the same as dynamic typing.

+3
source share

Dynamic typing and functional programming are independent concepts. You can have either or both in the same language.

Static typing means that object types are known at compile time. With dynamic typing, they are known at runtime.

Functional programming means a programming style in which computation is performed by evaluating functions, avoiding state changes. (example: you use recursion instead of for-loops, because the loop will require changing the counter variable, etc.). This helps to avoid errors and simplifies parallel programming. Pure languages ​​require you to program in a functional style; others just turn it on.

Examples of languages:

 |----------------+---------+---------| | | Dynamic | Static | |----------------+---------+---------| | Functional | LISP | Haskell | | Not functional | PHP | Java | |----------------+---------+---------| 

Dynamic languages, on the other hand, are a broader concept. There is no exact definition, but usually , the more compiler functions are transferred at runtime, the more dynamic it is . This means that in dynamic languages ​​you can usually evaluate expressions, change the structure of objects, etc. At runtime.

+3
source share

xtofl already offered a good overall picture. I can talk with C # point.

C # has now started working in a functional way for a while:

  • Anonymous methods were introduced in C # 2, which simplified the creation of delegates who used state that was local to the method
  • C # 3 introduces lambda expressions that are mostly similar to anonymous methods, but even more compact
  • LINQ support in both C # 3 and .NET 3.5 has simplified the query of data in a functional way, combining predicates, forecasts, etc.
  • None of the C # 4 functions directly contributes to functional IMO programming, although named arguments and optional parameters can simplify the creation / use of immutable types, which is one of the largest functions missing from a functional IMO image.

(There are other functions that often have functional languages, such as pattern matching and more impressive type inference, but you can easily write functional style code in C #.)

C # 4 will get some dynamic abilities using the dynamic type (which in itself is a static type with which you can do something). This will be a little “choose” - if you never use the dynamic type, C # will still be a fully static language. There is no language support for a dynamic response, but DLR supports this - if you implement IDynamicMetaObjectProvider or get from DynamicObject , for example, you can add dynamic behavior.

I would say that C # does not become a functional language or a dynamic language, but that you can code in a functional style and interact with dynamic platforms.

+2
source share

All Articles