201

Sometimes while programming in different languages (C/C++, C#), this thought comes to my mind:

  • Is each and every language written in the C programming language?
  • Is the C language the mother/father of all languages?
  • Is each concept (OOP, etc.) all implemented in C?

Am I in right direction?

10 Answers10

220

No.

OCaml, Haskell, Lisp dialects like Scheme, and several other languages are often used in the development of hobby languages.

Many languages are implemented in C because it's a ubiquitous language, and compiler-writing tools like lexer-parser generators (such as yacc and bison) are well-understood and almost as ubiquitous.

But C itself couldn't originally be developed in C when it was first created. It was, in fact, originally developed using the B language. Earlier languages (like Fortran) were usually bootstrapped using a native assembly language or even machine code long before C ever existed.

Unrelatedly, language paradigms like OOP are generally language-agnostic. The functional paradigm, for example, was developed (by Alonzo Church) as a foundation of mathematics long before any programming language ever existed. The procedural and structured programming paradigms came out of the mathematical work of theorists like John von Neumann. Object-orientation was developed by several different and unrelated efforts, some out of the lambda calculus (the functional paradigm) and some out of dynamic programming systems like SmallTalk at Xerox PARC by Alan Kay.

C is merely a tiny part of the story, decades after these ideas came into being.

greyfade
  • 11,133
  • 2
  • 42
  • 43
98

Is each and every language written in C language?

A language is a set of abstract mathematical rules and restrictions ("if I write this, that happens"). It isn't written in anything, really.

It is specified, usually in a mixture of a formalized subset of English, mathematical notation, and maybe some specialized specification language. The syntax is often specified in a variant of EBNF or ABNF.

For example, here is the specification of the for expression from the ISO Ruby Language Specification:

§11.5.2.3.4 The for expression

Syntax

  • for-expression for for-variable [no line-terminator here] in expression do-clause end
  • for-variable left-hand-side | multiple-left-hand-side

Semantics

A for-expression is evaluated as follows:

  1. Evaluate the expression. If the evaluation of the expression is terminated by a break-expression, next-expression, or redo-expression, the behavior is unspecified. Otherwise, let O be the resulting value.
  2. Let E be the primary-method-invocation of the form primary-expression [no line-terminator here].each do | block-parameter-list | block-body end, where the value of the primary-expression is O, the block-parameter-list is the for-variable, the block-body is the compound-statement of the do-clause.

    Evaluate E; however, if a block whose block-body is the compound-statement of the do-clause of the for-expression is called during this evaluation, the steps in §11.3.3 except the Step c) and the Step e) 4) shall be taken for the evaluation of this call.

  3. The value of the for-expression is the resulting value of the invocation.

Here's a different example from the type conformance rules of Scala:

The polymorphic type [a1 >: L1 <: U1 , … , an >: Ln <: Un]T conforms to the polymorphic type [a1 >: L′1 <: U′1 , … , an >: L′n <: U′n]T′ if, assuming L′1 <: a1 <: U′1 , … , L′n <: an <: U′n one has T <: T′ and Li <: L′i and U′i <: Ui for i ∈ { 1 , … , n }.


Is C language mother/father of all languages?

No, it is not. C is pretty young. There are a lot of old languages. Since time travel is physically impossible, it is simply impossible for C to have had any influence whatsoever on those old languages.

  • Plankalkül (1943)
  • Speedcoding (1953)
  • Fortran (1954)
  • IPL (1956)
  • Lisp (1958)
  • Algol (1958)
  • COBOL (1959)
  • JOVIAL (1960)
  • APL (1962)
  • SIMULA (1962)
  • SNOBOL (1962)
  • CPL (1963)
  • BASIC (1964)
  • PL/I (1964)
  • RPG (1964)
  • BCPL (1966)
  • ISWIM (1966)
  • MUMPS (1967)
  • Forth (1968)
  • LOGO (1968)
  • REFAL (1968)
  • B (1969)
  • BLISS (1970)
  • Pascal (1971)
  • KRL (1971)
  • Smalltalk (1972)

All of those existed before C was even invented. And many others have no influence of C in them, even after it existed. The PASCAL-family of languages (ALGOL-58, ALGOL-60, ALGOL-X, ALGOL-W, PASCAL, Modula-2, Oberon, Oberon-2, Active Oberon, Component Pascal) is a completely separate lineage. The whole Lisp family (LISP, Franz Lisp, InterLisp, MacLisp, Scheme, Flavors, LOOPS, CommonLoops, Dylan, CommonLisp, Arc, Clojure, Racket, etc.) is unrelated as well. Functional languages (ISWIM, KRL, Miranda, ML, SML, CAML, OCaml, F#, Haskell, Gofer, Clean) and the whole dependently-typed family (Agda, Coq, GURU, Idris) are about as far from C as possible. The same is true for the Smalltalk family (Smalltalk, Self, Newspeak, Us, Korz), the logic programming family (PLANNER, Prolog, Mercury), SQL, and many others.

Each concept (OOP etc) is all implemented in C language?

The first languages with OO concepts were Simula (1960) and Smalltalk (1972), but object-oriented systems had been built as far back as 1953 (without calling them that). Again, that's long before C existed, so OO cannot possibly have any relation to C.

TehShrike
  • 735
Jörg W Mittag
  • 104,619
51

Most of the core of many important languages is written in C, but things are changing:

  • the reference implementation of Python (CPython) is written in C (but there are other implementations written in other languages, e.g. Jython / Java, PyPy / Python, IronPython / C#...)
  • PHP Zend Engine is written in C
  • very first Java compiler developed by Sun Microsystems was written in C, but now the class libraries are always written in Java (since they are intended to be run using the Java VM itself). Certain libraries using JNI (Java Native Interface) may be partially written in a variety of other languages, as they are intended to be used OUTSIDE the JVM.

    The Sun/Oracle VM is written in C++. The BEA/Weblogic/Oracle VM is written in C. But there are JVM written in Java, Lisp, SmallTalk (IBM)...

  • Perl is implemented as a core interpreter, written in C, together with a large collection of modules, written in Perl and C (but Pugs, a compiler and interpreter for the Perl 6 programming language, is written in Haskell)
  • the official Ruby interpreter, often referred to as the Matz's Ruby Interpreter or MRI, is written in C and uses its own Ruby-specific virtual machine (but there is JRuby, a Java implementation that runs on the Java virtual machine; Rubinius, a C++ bytecode virtual machine that uses LLVM to compile to machine code at runtime...)
  • about 50% of R is written in C
  • and, of course, C is (was) written in C! (but the first C compiler, targeted to the PDP-11, was a mix of B and assembler).

There are many reasons why C was often chosen: performance, portability, experience.

The last probably being the most important: Python was started in 1991, PHP in 1994/1995, Perl in 1988, Ruby in 1995. In those years Java was just released and C++ not yet well standardized.


Somewhat related:

manlio
  • 4,256
11

No, some languages pre-date C. And many are implemented independently of C, e.g. see http://en.wikipedia.org/wiki/Lisp_%28programming_language%29

Ofir
  • 313
  • 1
  • 4
5

I would make this a comment if I could, but I can't so here goes:

One of the reasons C seems so ubiquitous is because it is one of the earliest languages developed, and an enormous amount of modern languages are based off of its structure (Java, Go, PHP, Perl, etc.) - making it seem like it's more places than it is.

Another oft-forgotten reason is that in 1973 Unix was rewritten in C and many of Unix's system calls are also available as C programs/functions, making the two highly interlinked. Since Unix was a powerful part of the development of modern programming as a whole, C was dragged along into infamy with it.

Having said all that, the answer to your question is "No". C is based off of a language called ALGOL, and there were many competitors both with ALGOL (FORTRAN, Lisp, COBOL) and C (none come to mind). Object-oriented programming, arguably the biggest paradigm-shift in programming design, did not originate with C - despite C++ being a very popular OOP language (it showed up first in Lisp or Simula 67, depending on who you ask). By the time OOP came about, C was such a popular language that it didn't need to be first - it was so popular that the C++ "expansion", so to speak, became one of the primary OOP languages too. It remains in modern use mainly because of its powerful memory control features (you can directly allocate and deallocate the memory your structures create), allowing it to create programs on tight memory budgets (think video games) and its highly optimized compiler (obviously depending on the compiler). Admittedly, even these features are losing ground as Java JIT compilation and in-language memory managers become more advanced.

WannabeCoder
  • 2,794
3

Obviously not. How could the first C compiler be written in C if C wasn't exist before? This isn't the chicken and the egg problem.

There are many ways to write the first compiler of a language which are called bootstrapping

Moreover most compilers try to achieve self-hosting, or compile itself it its language, mainly to promote the language and the compiler itself

phuclv
  • 165
3

Programming languages are specifications (not software!) usually written in some English document (with some formalization, e.g. EBNF for most of the syntax; sometimes their semantics is also partly formalized).

For example, C11 is defined by n1570 (which you should read). Some dialect of Scheme is defined by R5RS (which you should also read, it is very well written).

Programming languages may be implemented by some software. Sometimes that software is a compiler written in the programming language itself. Read about bootstrapping compilers.

One can write a compiler in the compiled programming language itself. If that language XX is brand new, you need to go thru a temporary step which involves writing a minimal interpreter or compiler of a subset of that language in some other implementation language (perhaps C), and later your can throw away that temporary compiler or interpreter (which don't need to be "good", just to be enough to compile the other compiler). Once you compiled your XX compiler written in XX you can throw away your temporary compiler.

Often (but not always) the runtime system is partly written in C (in particular the garbage collector).

Notice that bones is a Scheme compiler and runtime entirely written in itself (and you can find many other examples of fully bootstrapped implementations).

BTW it is convenient to use C as the target language of compilers.

Today, a lot of programming languages implementations is free software or open source. Feel free to study (and perhaps contribute to) their source code!

The Programmation Automatique des Formules (literally "automatic formulae programming") programming language was designed and implemented in France (around 1959) by my father, Dimitri Starynkevitch (1919-1993). It is a BASIC like language (whose specification is written in French, on paper). See this web page for more.

Consider reading Queinnec's book Lisp in Small Pieces and Pitrat's book Artificial Beings, the conscience of a conscience machine about bootstrapped programming languages. The RefPerSys open source project aims to become one (but a lot of work remains to generate most of the code of this homoiconic software).

PS. Feel free to send me an email to basile@starynkevitch.net for details you don't want to share on a public forum, but mention the URL of your question in that email.

2

Here is a list of some programming languages that are not written in C, alongside the languages they are implemented in:

  • Haskell - Haskell
  • Idris - Haskell
  • Adga - Haskell
  • Clash - Haskell
  • PureScript - Haskell
  • Elm - Haskell
  • Mercury - Mercury
  • Rust - Rust (initially OCaml)
  • Go - Go
  • Crystal - Crystal
  • OCaml - OCaml
  • Frege - Frege + Java
  • Haxe - OCaml + Haxe
  • Scala - Scala
  • Futhark - Haskell
  • ATS - ATS

The best languages for implementing a compiler are probably going to be pretty far away from C. Functional languages give you things like recursion schemes and monadic parser combinators (provided you have typeclasses), which makes them especially suited for compiler work.

Second, to address your question as to whether C is the "mother/father of all programming languages" - not really. C was a well-designed language at the time it appeared, and it no doubt has influenced language designers who then went on to do very different things. But at the end of the day, Haskell departs from C in essentially every way possible. C is 45 years old and it is not surprising that we have learned to do better in the meantime.

Finally, to answer your third question, it is simply not the case that C implements "all the concepts". In particular, trying to implement some of the advanced concepts from functional programming (such as metamorphisms, or, god forbid, synchromorphisms) in C would be monstrously difficult. I am not particularly familiar with object-oriented programming, but I do know for a fact that some object-oriented languages have sum types.

1

In addition to the answers given so far, I would like to add one of my favourite anecdotes related to programming languages.

There was a Basic Interpreter available on the Atari ST, which was called Omicron Basic.

Later, a compiler for that language was developed: written in Omicron Basic! The compiler compiled itself while being run by the interpreter.

Unfortunately, I don’t know, what the interpreter was originally programmed in. Probably in C, but since interpreters are much easier to implement than compilers it’s not too unlikely it was written in assembler.

0

It is very common to write languages in C or C++ for several reasons, but not ubiquitous:

  1. The C ABI (not the language itself, but a given platform's implementation of the ABI) is basically the lingua franca for calling into dynamic libraries, so anything serious is going to need to support at least that.
  2. On pretty much anything except Linux, the kernel system call interface is API-unstable and making system calls requires calling into a dynamic library which is developed and distributed with the kernel, serves as the stable API, and exposes a C ABI. (libSystem on MacOS, which also contains libc. NTDLL on Windows. etc.)
  3. For a long time, nothing but C and C++ offered a combination of features compelling enough (and it took a while for C++ compilers to get to that point).
  4. Haskell, which is now becoming a popular choice for writing languages, is very different from what a lot of programmers are used to and is decades younger than C.

In fact, there's a perception among some systems programmers that a language isn't serious until it's got a mature self-hosting compiler. (ie. At least one of the mature compilers for the language is written in that same language... thus proving the language's suitability for such tasks and removing its dependence on competitors.)

The Wikipedia "Self-hosting (compilers)" page I linked has a list of languages with self-hosting compilers.

Also, I should note that other factors do come into play.

For example, the official Rust compiler was never written in C or C++ (it started in Ocaml, then was rewritten in Rust to become self-hosting), but it's implemented as a frontend to LLVM for reasons completely unrelated to LLVM being written in C++.

(Namely, that the Rust developers saw how long it took for the LLVM developers to get their optimization passes up into the same ballpart of effectiveness as GCC's and didn't want to needlessly duplicate that effort.)

ssokolow
  • 161