7

I'm trying to understand if a programming languages design is built on some a theoretical model.
I came across few links that was describing Programming Language Theory, Lambda Calculus, Formal Languages and Turing machine.

I got lost in all that theory, what I understood from all that is that (any ..?) programming language is built on lambda calculus, that boils down to few language constructs.

  1. is my understanding correct?
  2. are there any models other than lambda calculus?
  3. if the languages shares the same model, can we use that to convert a source code from one language to the other?
3
  • 5
    Programming languages are designed for humans, and there is no adequate model or theory describing humans yet. So it is much more an art than an exact science. A formalised part of the language design is only in language semantics (i.e., its strict behaviour definition, not its "design"), and yes, lambda calculus is one of the tools for formalising operational and denotational semantics. Although, there is a more fundamental tool - term rewrite systems. I'd recommend to read this book: amazon.co.uk/…
    – SK-logic
    Commented Nov 22, 2013 at 11:18
  • For the closest thing to a formal model of a usable programming language look at Jeremy Siek's article siek.blogspot.com/2012/07/…
    – user132043
    Commented May 21, 2014 at 9:47
  • 1
    @SK-logic I think it's misleading to say it's more of an art than an exact science. The only way to know if feature X or Y introduces any loopholes in your type system or improves/destroys your ability to write and reason about programs in a modular manner (which is ultimately the only way of creating arbitrary large programs) is through hard mathematics. I'm not saying there isn't an art, too, but to downplay the need for rigorous math is dangerous. On that note, this book may also be of interest to Mhd.Tahawi.
    – Doval
    Commented May 21, 2014 at 11:17

4 Answers 4

8

You're partially right.

Lambda calculus is base for understanding how functional programming WORK.

Turing machine is base for understanding how imperative programming WORK.

Formal languages are ways of WRITING programms.

Lambda calculus and Turing machine are totally different, but both in some way do the same as sentence "if you add two and three, you get five" for math.

Formal languages are ways of saying "2+2 means 'add two and two'".

PS. @SK-logic: yes, you are right. This above is simplification, realy close to being false. Still, answer was written for complete newbie in topic, it was intended to give him SLIGHTEST idea, so he can choose what is more interesting for him, and where he want to start learning.

1
  • 5
    Lambda calculus and turing machine are equivalent, and both are just specific term-rewriting systems. And imperative languages semantics is normally defined with lambda calculus (or, a more generic TRS), not with Turing machine. Turing machine is only useful for reasoning about algorithms complexity, but it's a totally inadequate tool for defining languages. For example of an imperative language formal definition, see this: code.google.com/p/c-semantics
    – SK-logic
    Commented Nov 22, 2013 at 11:21
1

I got lost in all that theory, what I understood from all that is that (any ..?) programming language is built on lambda calculus,

Not in the sense that a PL designer needs to know and start out with the lambda calculus, but see below.

are there any models other than lambda calculus?

Yes, sure. For example, the SKI combinator calculus. Or register machines (basically, the van Neumann model).

The point is that any turing complete system could serve as basic for programming languages. Or, to put it differently, you could explain any language in terms of any computational complete system.

if the languages shares the same model, can we use that to convert a source code from one language to the other?

It makes it certainly easier. Yet, from what I said above, it is rather the case that we can convert any language to any other language. (It's just not practical in most cases to do so.)

1

is my understanding correct?

Not really. Functional programming is more a set of features originally inspired by lambda calculus than a foundation for an entire language design. Some purely functional languages might come close but I suspect they'd still have to have some rules that don't relate directly to lambda calculus. And of course not all languages have the features required for functional programming.

are there any models other than lambda calculus?

If by that you mean feature sets inspired by other branches of mathematics, then absolutely, without a doubt. Basic features implemented in most languages are tied directly to all manner of specific branches of math. But not all features necessarily are. Object Oriented Programming, for instance, is a concept meant to help programmers structure and model code more intuitively while avoiding some of the pitfalls people tend to run into in procedural programming. If it has a direct branch of mathematics analogue, I've never seen that pointed out anywhere.

if the languages shares the same model, can we use that to convert a source code from one language to the other?

Well, what does "same model" mean. They follow all the same rules, varying slightly only in syntax? That would be easy enough. But a single core rule-change could make translating one to the other very messy. Strict vs dynamic types for instance. How would you write a JavaScript object's methods to follow all the same rules as a Java object? Other features like how scope works, or the absence/presence of closures would require a lot of overhead to emulate in universal way between language paradigms.

I think the closest thing to a common link you could find between all languages is that ultimately they all have to boil down to instructions that can somehow be broken down and executed in machine code terms on a given system (and machine code varies depending on architecture too). The complexity inherent in making a universal programming translator would be both insanely hard, if possible, but also massively fail to produce legible translated code between languages without massaging and special libraries that would make it fail the 'universal' test. I wouldn't be shocked if someone had proven this feat to be technically impossible.

0

I'm trying to understand if a programming languages design is built on some a theoretical model.

No unifying theory has surfaced, but different aspects of programming languages are studied separately and may introduce their own theories. To name a few:

  • Type systems
  • Exception handling mechanisms and models
  • Co-routines
  • Concurrency stuff (models and mechanisms)
  • Macros
  • Binding/composition/extensions (ex: aspects, subject-oriented, context-oriented, prototypes, traits, multi methods, predicate dispatch, etc)

I came across few links that was describing Programming Language Theory, Lambda Calculus, Formal Languages and Turing machine.

These are more used and appropriated to investigate limits of computation, etc. Though lambda calculus (and other calculi) is used as medium to model programming mechanisms to be used in practice.

I got lost in all that theory, what I understood from all that is that (any ..?) programming language is built on lambda calculus, that boils down to few language constructs.

Depends on how you interpret "built on lambda calculus". Many language are not designed from lambda calculus (or any other formal system), that is, a designer does not start with lambda calculus and end up with, say, Go. These two just share a theoretical correspondence, and when you want to investigate computational complexity, you go to these systems which are better suited for such study.

Not the answer you're looking for? Browse other questions tagged or ask your own question.