9

At the risk of sounding naive, I ask this question in search of a deeper understanding of the concept of programming languages in general. I write this question for my own edification and the edification of others.

What is a useful definition of a computer programming language and what are its basic and necessary components? What are the key features that differentiate languages (functional, imperative, declarative, object oriented, scripting, etc...)?

One way to think about this question. Imagine you are looking at the hardware of a modern desktop or laptop computer. Assume, that the C language or any of its variants do not exist. How would you describe to others all the things needed to make the computer expressive and functional in terms of what we expect of personal computers today?

Tangentially related, what is it about computer languages that allow other languages to exist? For example take a scripting language like Javascript, Perl, or PHP. I assume part of the definition of these is that there is an interpreter most likely implemented in C or C++ at some level. Is it possible to write an interpreter for Javascript in Javascript? Is this a requirement for a complete language? Same for Perl, PHP, etc?

I would be satisfied with a list of concepts that can be looked up or researched further.

1

11 Answers 11

27

Like any language, programming languages are simply a communication tool for expressing and conveying ideas. In this case, we're translating our ideas of how software should work into a structured and methodical form that computers (as well as other humans who know the language, in most cases) can read and understand.

What is a useful definition of a computer programming language and what are its basic and necessary components?

I would say the defining characteristic of a programming language is as follows: things written in that language are intended to eventually be transformed into something that is executed. Thus, pseudocode, while perhaps having the structure and rigor of a programming language, is not actually a programming language. Likewise, UML can express many powerful ideas in an abstract manner just like a programming language can, but it falls short because people don't generally write UML to be executed.

How would you describe to others all the things needed to make the computer expressive and functional in terms of what we expect of personal computers today?

Even if the word "programming language" wasn't part of the shared vocabulary of the group I was talking to, I think it would be obvious to the others that we'd need a way to communicate with the computer. Just as no one expects a car to drive itself (yet!) without external instructions in the form of interaction with the steering wheel and pedals, no one could expect the hardware to function without being told what to do. As noted above, a programming language is the conduit through which we can make that communication happen.

Tangentially related, what is it about computer languages that allow other languages to exist?

All useful programming languages have a property called Turing completeness. If one language in the Turing-complete set can do something, then any of them can; they are said to be computationally equivalent.

However, just because they're equally "powerful" doesn't mean they're equally nice to work with for humans. This is why many people are willing to sacrifice the unparalleled micromanagement you get from writing assembly code in exchange for the expressiveness and power you get with higher-level languages, like Ruby, Python, or C#.

Is it possible to write an interpreter for Javascript in Javascript? Is this a requirement for a complete language? Same for Perl, PHP, etc?

Since there is a Javascript interpreter written in C, it follows that it must be possible to write a Javascript interpreter in Javascript, since both are Turing-complete. However, again, note that Turing-completeness says nothing about how hard it is to do something in one language versus another -- only whether it is possible to begin with. Your Javascript-interpreter-inside-Javascript might well be horrendously inefficient, consume absurd amounts of memory, require enormous processing power, and be a hideously ugly hack. But Turing-completeness guarantees it can be done!

4
  • 2
    Excellent answer! I would add (to the last point) that not only is it possible, but often languages will be created with another language (C is common) but then compilers or interpreters will be created that can compile the language itself. FORTH, LISP, Scheme, and C++ come immediately to mind - all are in this vein (though some in different ways than others).
    – Mei
    Aug 25, 2009 at 3:03
  • I can make a javascript interpreter with javascript: eval(code); LOLOLOLOLOLOL
    – user216441
    Jan 17, 2010 at 14:35
  • @M28: I'm assuming you're joking here, but eval() is not actually a Javascript interpreter in a true sense. For example, x = 5; is valid Javascript, but you can't pass that to eval(); you have to quote it. But the string "x = 5;" doesn't have the same meaning as x = 5. Thus, eval() falls slightly short. Jan 17, 2010 at 14:42
  • Great explanation, but something in the first paragraph makes me ponder [...] that computers (as well as other humans who [...] - did you ever think about swapping computers and humans? Furthermore, I think computer isn't quite right, you need a compiler to translate "computer languages" into something a computer can understand, or an interpreter which "understands" computer language (by translating statements into subroutine calls). I'm aware that this is a very old answer, but the question is still young :-)
    – Wolf
    Feb 24, 2015 at 11:03
6

While this doesn't directly answer your question, I am reminded of the Revenge of the Nerds essay by Paul Graham about the evolution of programming languages. It's certainly an interesting place to start your investigation.

1
  • Thanks Greg. Looks like an interesting essay. I will be sure to read it. Aug 25, 2009 at 2:13
4

Not a definition, but I think there are essentially two strands of development in programming languages:

  • Those working their way up from what the machine can do to something more expressive and less tied to the machine (Assembly, Fortran, C, C++, Java, ...)

  • Those going down from some mathematical or theoretical computer science concept of computation to something implementable on a real machine (Lisp, Prolog, ML, Haskell, ...)

Of course, in reality the picture is not as neat, and both strands influence each other by borrowing the best ideas.

4

Slightly long rant ahead.

A computer language is actually not all that different from a human language. Both are used to express ideas and concepts in commonly understood terms. Among different human languages there are syntactic differences, but you can express the same thing in every language (does that make human languages Turing complete? :)). Some languages are better suited for expressing certain things than others.

For example, although technically not completely correct, the Inuit language seems quite suited to describe various kinds of snow. Japanese in my experience is very suitable for expressing ones feelings and state of mind thanks to a large, concise vocabulary in that area. German is pretty good for being very precise thanks to largely unambiguous grammar.

Different programming languages have different specialities as well, but they mostly differ in the level of detail required to express things. The big difference between human and programming languages is mostly that programming languages lack a lot of vocabulary and have very few "grammatical" rules. With libraries you can extend the vocabulary of a language though.

For example:

Make me coffee.

Very easy to understand for a human, but only because we know what each of the words mean.

coffee : a drink made from the roasted and ground beanlike seeds of a tropical shrub
drink : a liquid that can be swallowed
swallow : cause or allow to pass down the throat
... and so on and so on

We know all these definitions by heart, but we had to learn them at some point.

In the same way, a computer can be "taught" to "understand" words as well.

Coffee::make()->giveTo($me);

This could be a perfectly valid expression in a computer language. If the computer "knows" what Coffee, make() and giveTo() means and if $me is defined. It expresses the same idea as the English sentence, just with a different, more rigorous syntax.

In a different environment you'd have to say slightly different things to get the same outcome. In Japanese for example you'd probably say something like:

コーヒーを作ってもらっても良いですか?
Kōhī o tsukuttemoratte mo ii desu ka?

Which would roughly translate to:

if ($Person->isAgreeable('Coffee::make()')) {
    return $Person->return(Coffee::make());
}

Same idea, same outcome, but the $me is implied and if you don't check for isAgreeable first you may get a runtime error. In computer terms that would be somewhat analogous to Ruby's implied behaviour of returning the result of the last expression ("grammatical feature") and checking for available memory first (environmental necessity).

If you're talking to a really slow person with little vocabulary, you probably have to explain things in a lot more detail:

Go to the kitchen.
Take a pot.
Fill the pot with water.
...

Just like Assembler. :o)

Anyway, the point being, a programming language is actually a language just like a human language. Their syntax is different and specialized for the problem domain (logic/math) and the "listener" (computers), but they're just ways to transport ideas and concepts.

EDIT:
Another point about "optimization for the listener" is that programming languages try to eliminate ambiguity. The "make me coffee" example could, technically, be understood as "turn me into coffee". A human can tell what's meant intuitively, a computer can't. Hence in programming languages everything usually has one and one meaning only. Where it doesn't you can run into problems, the "+" operator in Javascript being a common example.

1 + 1     -> 2
'1' + '1' -> '11'
1
  • Nice answer. I like your analogy to the assembler and the need for more detail. Aug 25, 2009 at 5:35
3

See "Programming Considered as a Human Activity." EWD 117. http://www.cs.utexas.edu/~EWD/transcriptions/EWD01xx/EWD117.html

Also See http://www.csee.umbc.edu/331/current/notes/01/01introduction.pdf

1
  • Sadly, your second link is dead, I'm curious what it has been after looking at the first. BTW: adding page titles to links seem to be superfluous at first, but often it becomes essential some later...
    – Wolf
    Feb 24, 2015 at 10:48
2

Human expression which:

  • describes mathematical functions
  • makes the computer turn switches on and off
2

This question is very broad. My favorite definition is that a programming language is a means of expressing computations

  • Precisely
  • At a high level
  • In ways we can reason about them

By computation I mean what Turing and Church meant: the Turing machine and the lambda calculus have equivalent expressive power (which is a theorem), and the Church-Turing hypothesis (which is a conjecture) says roughly that there's no more powerful notion of computation out there. In other words, the kinds of computations that can be expressed in any programming languages are at best the kinds that can be expressed using Turing machines or lambda-calculus programs—and some languages will be able to express only a subset of those calculations.

This definition of computation also encompasses your friendly neighborhood hardware, which is pretty easy to simulate using a Turing machine and even easier to simulate using the lambda calculus.

Expressing computations precisely means the computer can't wiggle out of its obligations: if we have a particular computation in mind, we can use a programming language to force the computer to perform that computation. (Languages with "implementation defined" or "undefined" constructs make this task more difficult. Programmers using these languages are often willing to settle for—or may be unknowingly settling for—some computation that is only closely related to the computation they had in mind.)

Expressing computation at a high level is what programming langauges are all about. An important reason that there are so many different programming languages out there is that there are so many different high-level ways of thinking about problems. Often, if you have an important new class of problems to solve, you may be best off creating a new programming language. For example, Larry Wall's writing suggests that solving a class of problems called "systems administration" was a motivation for him to create Perl.

(Another reason there are so many different programming languages out there is that creating a new language is a lot of fun, and anyone can learn to do it.)

Finally, many programmers want languages that make it easy to reason about programs. For example, today a student of mine implemented a new algorithm that made his program run over six times faster. He had to reason very carefully about the contents of C arrays to make sure that the new algorithm would do the same job the old one did. Luckily C has decent tools for reasoning about programs, for example:

  • A change in a[i] cannot affect the value of a[i-1].

My student also applied a reasoning principle that isn't valid in C:

  • The sum of of a sequence unsigned integers will be at least as large as any integer in the sequence.

This isn't true in C because the sum might overflow. One reason some programmers prefer languages like Standard ML is that in SML, this reasoning principle is always valid. Of languages in wide use, probably Haskell has the strongest reasoning principles Richard Bird has developed equational reasoning about programs to a high art.


I will not attempt to address all the tangential details that follow your opening question. But I hope you will get something out of an answer that aims to give a deeper understanding, as you asked, of a fundamental question about programming languages.

1
  • Thanks for the Turing Complete explanation. I had heard of the idea but didn't quite grasp it. Your answer provided a nice clarification. Aug 25, 2009 at 8:20
2

One thing a lot of "IT" types forget is that there are 2 types of computer programming languages:

  1. Software programming languages: C, Java, Perl, COBAL, etc.

  2. Hardware programming languages: VHDL, Verilog, System Verilog, etc.

2

Interesting.

I'd say the defining feature of a programming language is the ability to make decisions based on input. Effectively, if and goto. Everything else is lots and lots of syntactic sugar. This is the idea that spawned Brainfuck, which is actually remarkably fun to (try to) use.

There are places where the line blurs; for example, I doubt people would consider XSLT to really be a programming language, but it's Turing-complete. I've even solved a Project Euler problem with it. (Very, very slowly.)

Three main properties of languages come to mind:

  1. How is it run? Is it compiled to bare metal (C), compiled to mostly bare metal with some runtime lookup (C++), run on a JIT virtual machine (Java, .NET), bytecode-interpreted (Perl), or purely interpreted (uhh..)? This doesn't comment much on the language itself, but speaks to how portable the code may be, what sort of speed I might expect (and thus what broad classes of tasks would work well), and sometimes how flexible the language is.
  2. What paradigms does it support? Procedural? Functional? Is the standard library built with classes or functions? Is there reflection? Is there, ideally, support for pretty much whatever I want to do?
  3. How can I represent my data? Are there arrays, and are they fixed-size or not? How easy is it to use strings? Are there structs or hashes built in? What's the type system like? Are there objects? Are they class-based or prototype-based? Is everything an object, or are there primitives? Can I inherit from built-in objects?

I realize the last one is a very large collection of potential questions, but it's all related in my mind.

I imagine rebuilding the programming language landscape entirely from scratch would work pretty much how it did the first time: iteratively. Start with assembly, the list of direct commands the processor understands, and wrap it with something a bit easier to use. Repeat until you're happy.

Yes, you can write a Javascript interpreter in Javascript, or a Python interpreter in Python (see: PyPy), or a Python interpreter in Javascript. Such languages are called self-hosting. Have a look at Perl 6; this has been a goal for its main implementation from the start.

Ultimately, everything just has to translate to machine code, not necessarily C. You can write D or Fortran or Haskell or Lisp if you want. C just happens to be an old standard. And if you write a compiler for language Foo that can ultimately spit out machine code, by whatever means, then you can rewrite that compiler in Foo and skip the middleman. Of course, if your language is purely interpreted, this will probably result in a stack overflow...

2
  • The term you are looking for is Turing complete. In simple terms such a language can write any program while something that is not TC can only do a limited set of task. eg SQL is not Turing complete while Basic is. Aug 25, 2009 at 2:51
  • Whoops. That's a bad typo; my mistake.
    – Eevee
    Aug 25, 2009 at 7:02
2

As a friend taught me about computer languages, a language is a world. A world of communication with that machine. It is world for implementing ideas, algorithms, functionality, as Alonzo and Alan described. It is the technical equivalent of the mathematical structures that the aforementioned scientists built. It is a language with epxressions and also limits. However, as Ludwig Wittgenstein said "The limits of my language mean the limits of my world", there are always limitations and that's how one chooses it's language that fits better his needs.

It is a generic answer... some thoughts actually and less an answer.

1
  • I like the Wittgenstein reference. Wittgenstein also said "The world is the totality of facts, not of things." Perhaps we could take this to be analogous to the way binary information works. A program is therefor a totality of "binary" facts as expressed by the programming language once compiled. Jan 24, 2010 at 10:55
0

There are many definitions to this but what I prefer is:

Computer programming is programming that helps to solve a particular technical task/problem.

There are 3 key phrases to look out for:

You: Computer will do what you (Programmer) told it to do.

Instruct: Instruction is given to the computer in a language that it can understand. We will discuss that below.

Problem: At the end of the day computers are tools (Complex). They are there to make out life simpler.

The answer can be lengthy but you can find more about computer programming

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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