views:

859

answers:

10

Recently, i had to understand the design of a small program written in a language i had no idea about (ABAP, if you must know). I could figure it out without too much difficulty.

I realize that mastering a new language is a completely different ball game, but purely understanding the intent of code (specifically production standard code, which is not necessarily complex) in any language is straight forward, if you already know a couple of languages (preferably one procedural/OO and one functional).

Is this generally true? Are all programming languages made up of similar constructs like loops, conditional statements and message passing between functions? Are there non-esoteric languages that a typical Java/Ruby/Haskell programmer would not be able to make sense of? Do all languages have a common origin?

+2  A: 

I'll direct you to Beating the Averages by Paul Graham. You may or may not want to read the whole thing, but for the relevant part search for the heading "The Blub Paradox". Mr. Graham can't be bothered to put anchors in his wall of text, so I can't directly link to it.

kwatford
I have read 'Hackers and Painters' and i agree about the differences in the power of different languages. My question was more about whether i, without ever having seen the language before, would comprehend the design intent of the code i am reading.
Anirudh
In that case: Lambda calculus. Perhaps not a 'real' language, but it is the mother of all programming languages in a sense. I once had to implement a functional language such that it compiled into lambda expressions (which were then directly interpreted). The results were (to me, at least) unreadable despite preserving all the relevant identifiers. Especially recursive functions using the Y-combinator. The only practical way to figure out what some of the sample expressions did was to hand-evaluate them. Simple things like fibonnaci and merge sort were unreadable.
kwatford
+1  A: 

I would say that a language encodes meaning. If the meaning has any sense in some context then all languages that could express the meaning could be said to be equivalent limited by the meaning and the context.

If you limit that context to a standard von newman (I think) machine then the computational meanings of changing memory and computing in a cpu could be said to be the origin - and possibly the only meaning that all the languages have in common. All other things are abstraction built on these.

Preet Sangha
John von Neumann. And it's NOT pronounced like "newman", more like "noyman".
John Y
Thanks for the correction - I do pronounce is like you said though.
Preet Sangha
When someone suggests a correction, you can just edit your post to reflect it.
Novelocrat
+2  A: 

No, some languages are more powerful than others:

  • More powerful: Smalltalk, Lisp, Haskell, Icon, Perl

  • Less powerful: Simula-67, APL, ML, Snobol, Bourne shell

Mastering the intent of an Icon or Prolog program is nearly impossible until you understand each language's nonstandard model of evaluation.

Norman Ramsey
We're starting to see concepts from Icon in other languages, so maybe it's becoming easier to grasp. I had APL (with Greek keyboards) for my Numerical Methods class as a freshman. I'm not going to argue that it's especially powerful, but it sure is inscrutable to the casual observer. http://upload.wikimedia.org/wikipedia/en/f/ff/LifeInApl.gif
Nosredna
@Nosredna: LOL! APL was my very first language, and I can say with confidence that it is inscrutable even to those who use it daily! Good point!
Norman Ramsey
How on Earth did you manage to learn APL as your first language? :-)
Nosredna
@Nosredna: I took a summer class at my local state university. It was fun, and the machine rooms were air-conditioned!
Norman Ramsey
I'm not certain I would classify languages by how "powerful" they are as that is completely subjective and relative to the problem you are trying to solve. For example, there are certain classes of problems that are most easily solved writing a Bourne shell script than writing a Smalltalk application.
Scott Dorman
@Scott: Partial agreement. It's definitely relevant to application, but not *completely* subjective. And it's a pretty useful shorthand.Read http://www.paulgraham.com/avg.html, especially the part about "Blub".
Norman Ramsey
+3  A: 

Hardware description languages are programming languages, but they are conceptually very different. Try VHDL or Verilog on for size. They are common for programming FPGAs. (Ok, so they're not processors, but they are general purpose computing devices. And such should be considered valid hardware for computer science topics.) You have to explicitely make things occur serially. It's a completely different model. You have think of things occuring in parallel as the rule not the exception. For loops in verilog expand into parallel hardware. So the "expected" behavior might not be what you expect.

NoMoreZealots
That's a good point. I will look look up Verilog/VHDL.
Anirudh
+39  A: 

The basics of most procedural languages are pretty much the same.

They offer:

  • Scalar data types: usually boolean, integers, floats and characters
  • Compound data types: arrays (strings are special case) and structures
  • Basic code constructs: arithmetic over scalars, array/structure access, assignments
  • Simple control structures: if-then, if-then-else, while, for loops
  • Packages of code blocks: functions, procedures with parameters
  • Scopes: areas in which identifiers have specific meanings

If you understand this, you have a good grasp of 90% of the languages on the planet. What makes these languages slightly more difficult to understand is the incredible variety of odd syntax that people use to say the same basic things. Some use terse notation involving odd punctuation (APL being an extreme). Some use lots of keywords (COBOL being an excellent representative). That doesn't change much.

More interesting procedural languages offer

  • Nested or lexical scopes, namespaces
  • Pointers allowing one entity to refer to another, with dynamic storage allocation
  • Packaging of related code: packages, objects with methods, traits
  • More sophisticated control: recursion, continuations, closures
  • Specialized operators: string and array operations, math functions

The languages which are harder to understand are the non-procedural ones:

  • Purely functional languages, with no assignments or side effects
  • Logic languages, such as Prolog, in which symbolic computation and unification occur
  • Pattern matching languages, in which you specify shapes that are matched to the problem, and often actions are triggered by a match
  • Constraint languages, which let you specify relations and automatically solve equations
  • Hardware description languages, in which everything executes in parallel
  • Domain-specific languages, such as SQL, Colored Petri Nets, etc.

There are two major representational styles for languages:

  • Text based, in which identifiers name entities and information flows are encoded implicitly in formulas that uses the identifiers to name the entities (Java, APL, ...)
  • Graphical, in which entities are drawn as nodes, and relations between entities are drawn as explicit arcs between those nodes (UML, Simulink, LabView)

The graphical languages often allow textual sublanguages as annotations in nodes and on arcs. Odder graphical languages recursively graphs (with text :) in nodes and on arcs. Really odd graphical languages allow annotation graphs to point to graphs being annotated.

Most of these languages are based on a very small number of models of computation:

  • The lambda calculus (basis for Lisp and all functional languages)
  • Post systems (or string/tree/graph rewriting techniques)
  • Turing machines (state modification and selection of new memory cells)

Given the focus by most of industry on procedural languages and complex control structures, you are well served if you learn one of the more interesting languages in this category well.

I highly recommend learning Scheme, in particular from a really wonderful book: Structure and Interpretation of Computer Programs. This describes all these basic concepts. If you know this stuff, other languages will seem pretty straightforward except for goofy syntax.

Ira Baxter
Great Answer!As a follow-up (is there a way to ask a follow-up question in SO?), is there one language i could master and claim to understand all concepts in programming software? Would it be Lisp (or a dialect such as Scheme)?
Anirudh
@Anirudh: There's no formal follow-up mechanism, but you could open a new question. If it contains a rationale and a link to this question, it might not even be closed. ;) To answer your follow-up, I wholeheartedly believe there isn't just one language, since the paradigms are too different.
John Y
@Anirudh: Agreed with John Y, there isn't just one. But if you are relatively new to the field, you should spend considerable energy to master the procedural paradigm (I consider OO just a specialization). It wouldn't hurt to look other paradigms (logic, constraint, dataflow) to get a sense of how they work, but for most day to day industrial work, procedural languages are pretty much king.
Ira Baxter
A: 

It all depends. If you define the language as just syntax, then they are fairly similar. (Excluding the Brainf*** language)

But people do favour languages over another because of slight differences such as how verbose a language is, what frameworks the language supports, whether the language is extensible, whether there is a big community behind it, etc. These small differences tend to make a big when you use the same constructs over and over again in your code.

Also, if there is a common origin, it would probably be C.

Mike
C isn't the common origin of all languages.
Emil H
C isn't even the common origin of all imperative languages, let alone all languages.
John Y
"If there is a common origin". But there isn't so the next bit doesn't matter. "If there is a common origin, it'll rain cats".
WW
@WW: The statement "if there is a common origin..." is false. The first part does not matter. "If snow is red, then Stack Overflow exists". Snow is white, however, Stack Overflow still exists. If SO would not exist, then snow would not be red, because if it would be red, SO would exist.
fishlips
+2  A: 

Depends on what you mean by "basically." All languages of any flexibility are Turing-complete. In that sense: yes, they are all basically the same.

On a low level, they all perform similar sequences of operations and all Windows, Linux, and (recent) OS X stuff all runs on Intel-compatible processors using the same instruction sets. In that way they are also basically the same.

I realize that you sorta defined "basically" in your question, but to really answer it, that definition will have to be much more refined. In many ways they are all alike. In many ways they are distinct. It's all too easy to say "it depends." If you take either extreme, the question will likely not answer what you intend it to so where that line is drawn is crucial to answering your question as you intend it.

Dinah
A: 

Mature languages generally have a few goals, and they make tradeoffs where they sacrifice one thing for another. A general-purpose language can be used for anything, but no language can ever excel in every area. A few examples:

C attempts to be an ideal systems programming language. To this end it sacrifices readability and safety for low-level control and speed.

Python aims to be an ideal scripting language. To this end it sacrifices speed and verifiability for productivity and portability.

Haskell attempts to be a safe, mathematically pure language. To this end it sacrifices learnability and convention for verifiability and reliability.

These sacrifices and benefits make a huge difference in the language. Yes, most programming languages can be used for anything that can be done by a computer, but none of those same languages should be used for everything. All of the languages above are ones I would choose for certain tasks but not for others. If I were programming an operating system I would choose C. If I were writing a backend for a website, I would use Python. And if I were writing a financial system I would use Haskell.

In the end, your choice as a programmer is what the right tool for the job is.

Imagist
A: 

Piet is pretty different. :)

Jack Leow
A: 

I would not consider things like Lisp and Prolog to be anything like ordinary languages.

Loren Pechtel