
Ask HH: Universal programming language? - KhalilK
Is there a chance for such a language to exist? A programming language that supports many paradigms and can be used everywhere instead of the myriad of languages&#x2F;tools we have today.
======
malisper
The closest thing I can think of would be Lisp (any dialect) because of the
ability to add embedded languages/DSLs to the language. Pure Common Lisp (no
macros), does not have any iteration constructs (besides goto). On top of
these basic primitives you could build something much more complicated such as
the 'loop' macro, a DSL for describing iteration. Here is the second problem
on project euler (sum of even Fibonacci numbers up to 4,000,000) solved using
loop.

    
    
      (loop for n   = 1 then (+ n n-1)
            and n-1 = 0 then n
    
            while (<= n 4000000)
    
            if (evenp n) ; predicates in CL end in 'p'
              sum n)
    

You can add almost any (AFAIK any) paradigm you want. Initially Lisp did not
have any object system. When OOP became a thing it was added to Lisp. Today it
exists in the form of CLOS, a very powerful object system which at its core is
two macros, defclass[0] and defmethod[1]. Logic programming can also be added
through the use of macros[2]. Here is an example of append written using logic
programming in Lisp (compare it to the Prolog version).

    
    
      (<- (append nil ?xs ?xs))
      (<- (append (?x . ?xs) ?ys (?x . ?zs))
          (append ?xs ?ys ?zs)
    

The thing is you can make Lisp any language you want it to be. Want a (better)
language to write HTML, you can do that[3]. Want a language which can parse
ATNs (augmented transition networks), you can do that[2]. You can add to Lisp
almost any feature you can think of. This is what makes it appear (at least to
me) as the "universal language".

[0] [http://www.gigamonkeys.com/book/object-reorientation-
classes...](http://www.gigamonkeys.com/book/object-reorientation-classes.html)

[1] [http://www.gigamonkeys.com/book/object-reorientation-
generic...](http://www.gigamonkeys.com/book/object-reorientation-generic-
functions.html)

[2]
[http://ep.yimg.com/ty/cdn/paulgraham/onlisp.pdf](http://ep.yimg.com/ty/cdn/paulgraham/onlisp.pdf)

[3] [http://allegroserve.sourceforge.net/aserve-
dist/doc/htmlgen....](http://allegroserve.sourceforge.net/aserve-
dist/doc/htmlgen.html)

------
tinco
Well since people are going to answer with languages they think are universal
enough anyway, I'll say what I think comes closest to a universal language at
the moment. Keep in mind, I do my daily programming in Ruby and Javascript,
and my hobby/personal projects in Haskell so I'm not a mindless Microsoftie.

The language that I know comes closest to a universal language is C#.

C# has a rich static typesystem with generics, is typesafe, has a garbage
collector, can be precompiled and has runtimes for most operating systems.

C# also has a dynamic type system, that can be enabled with a keyword.

C# has an embedded functional language, has function references and lambda
expressions.

C# has extensive libraries for Server applications, CLI applications and GUI
applications, including asynchronous and syncronous I/O, events and
accelerated graphics.

C# supports reflection and code generation at runtime.

Over the years Microsoft has managed to cram almost every programming paradigm
that's out there into C#, yet has carefully avoided it becoming a multi-headed
unusable monster like C++ is (I'm not saying you can't write beautiful code in
C++, just saying there's a lot in there that you shouldn't do).

About the only thing that's not in C# as far as I am aware is predictable/high
performance, like C and C++ have. You can not disable the garbage collector
and can't embed machine language.

So why, if I think C# is such a cool language, don't I use it? Well.. I just
really like Ruby's type system and syntax. And I just really like Haskell's
typesystem and syntax. There's really no need to have all features in one
language when you can do just as well with multiple programming languages that
might have specific advantages.

~~~
runT1ME
C# is missing good type inference, implicit conversions, implicit parameters,
higher kinded types (huge loss), lightweight method syntax, currying, pattern
matching...

~~~
noblethrasher
C# has implicit conversions. It doesn't have pattern matching, but it does
have proper sum types.

------
jeremyjh
It is not exactly what you are asking, but the answers are about the same as
if you asked "Why can't everyone just use X?"

Beyond the language and deployment factors, languages are optimized for
different human factors. Some languages give up a lot of expressive power and
flexibility in order to optimize the performance of large teams of developers
with relatively poor code discipline. But for me personally on my side
projects I prefer to have features like stronger static guarantees, less
boilerplate and more expressive power. It seems hard to reconcile these
different approaches in a single language.

------
actsasbuffoon
Many new paradigms can be defined not by what they add, but what they take
away.

The most obvious example is GOTO. It's a very powerful tool. A GOTO can do
anything you can accomplish with an IF, WHILE, FOR, etc. yet we got rid of it
because that incredible flexibility made it hard to reason about. The result
was structured programming.

Object orientation can also be looked at as the removal of shared global
state. There are multiple definitions of OO, but I like Alan Kay's definition
best. He said the two primary principles are encapsulation and message
passing. Encapsulation is obviously the one I'm touching on here. Some people
include class hierarchies and open recursion in their definition of OO, and
those certainly do constitute new functionality, but as I said, I prefer Alan
Kay's definition.

Functional programming can be looked at as the removal of mutation. Where once
we could create side-effects whenever we pleased, FP tells us that we probably
shouldn't. Removing mutation makes it easier to reason about our programs,
just like removing GOTO.

Haskell goes even further and removes implicit ordering of execution. Because
the language is lazy it probably won't execute your code in the sequence you
were expecting. Due to immutability and referential transparency everything
works out just fine anyway. This makes certain kinds of algorithm much more
performant (Huett zippers come to mind).

Instead of asking what new features we can add to languages, perhaps we should
ask what else can be taken away.

------
fabriceleal
Well, if you are asking for the most versatile programming language, I would
point to Oz:

[http://mozart.github.io/](http://mozart.github.io/)

"The Mozart Programming System combines ongoing research in programming
language design and implementation, constraint logic programming, distributed
computing, and human-computer interfaces. Mozart implements the Oz language
and provides both expressive power and advanced functionality."

------
avmich
Programming problems are diverse, and so are languages. It's similar to what
we have in human languages - if you're talking deep specifics of medicine,
it's quite different than if the matter discussed is car performance, even if
both languages are based on English.

I'd hesitate to point to Lisp, with its ability to be "programmable
programming language". The modus operandi, explained by e.g. PG, is to create
a domain-specific language and then solve the problem using that DSL. This way
you can have a great variety of problems which are relatively accessible by
such a language... Would like to know more alternatives to the topic.

------
yokuze
This is a lot like asking: "Could there be one tool that supports every
function and task in the field of carpentry?"

Maybe? But who would want to use something like that? Good programming
languages, like most useful tools, are specialized. They support modes of
thinking that allow effective problem solving, each within its own domain.
(Think Haskell vs Java).

In other words, programming languages are tools, and tools are useful because
they are limited.

~~~
moron4hire
Well, there are CNC routers, which come pretty close.

Joking aside, I think it is still to the point you are trying to make. A CNC
router, despite looking like a general purpose tool, is actually a very
specialized tool, meant for rapid prototyping at precision scale. You won't
very often find a CNC router in the common garage workshop, primarily because
they are so freaking expensive, but also because they are a might-bit
dangerous.

------
lucozade
Put another way: can a programming language be specified without any
compromises to hardware, environment, programmer or use case? I'm going to go
with the same answer that I have for the existence of god* or alien*. I don't
know, but current evidence would suggest that the most probable answer is zero
such languages can or will exist but with an approximately infinite error bar
on that answer.

------
dnesteruk
In theory, I don't see why not. For instance, you could have a language that
is adapted for both the JVM, CLR and native and also cross-compiles to
JavaScript.

------
moron4hire
There are several already.

Answer intentionally as vague as question.

------
wingi
Should every turing complete language fit?

------
byefruit
[http://paulgraham.com/hundred.html](http://paulgraham.com/hundred.html)

------
rlmw
Write once, run anywhere: Java.

~~~
eigenrick
Except when you need to have a guarantee of consistent response times.
Response rates where the 99th percentile is guaranteed to be under, say 50ms
is important in many real world applications, trading systems, sensor
networks, controls networks etc.

The Java GC, no matter which way you tune it, fails at this in my experience.

------
BenDaglish
Perl :)

------
dz0ny
OMG Assembly

------
kayra
Pseudo code

------
informatimago
Lisp.

