views:

1217

answers:

23

What would your own (I assume perfect) programming language look like? Give a small example and explain your novel ideas!

I'm really interested in the syntax.

+7  A: 

I have no concept of a "perfect" programming language because there isn't just one task to be performed.

Different tasks suit different languages and paradigms.

Jon Skeet
So we should only strive to create tailored languages for specific tasks? I can agree that there might need to be a seperation between low level languages (like c and asm) where you can predict the effects of your code and high-level languages.
Daniel W
We should (and do!) create languages which suit *categories* of tasks. Some tasks naturally suit functional languages. Some naturally suit scripting languages (and subdivisions within them). Others naturally fit OO better. Try to be perfect and you'll be a jack of all trades, master of none.
Jon Skeet
But there are no rules that states that a functional language cannot also have OO aspects. See Scala, Boo (opt. duck-t) and C#. They are definitely a jack of all trades and it seems to work perfectly for them. I would go so far as to say that the longer a language evolves the more features it gets.
Daniel W
But as it gains more features, it becomes more complicated - which is a problem, making the language non-perfect. I agree that C# et al are aimed at being general-purpose languages, but they're still not the most appropriate tools for *all* tasks.
Jon Skeet
I did write the I assume perfect sentence tongue in cheek. As I see it programming languages are about controlling the dataflow, which could be done in any language and task. I also think we have a long way to go to find a sweet spot between features and complexity.
Daniel W
@Jon, from what I've seen, the complexity seems to be mainly from languages that must build in all features directly. Compare this to a simple approach that lets features emerge. So yea, if you add features the "C# way" it's going to get complicated. But that doesn't need to hold true in general.
MichaelGG
Well, I'll remain skeptical until I see this mythical language which is better than all other languages at all other tasks...
Jon Skeet
It's not that it has to be better than _all_ languages at _all_ tasks, just that "best tool for the job" seems like an overused excuse for poor design.
MichaelGG
Sorry, but this is a really corny answer. OP obviously asked for hypothetical language that is most likely of everything you love about all of your languages.
LiraNuna
@LiraNuna: But that's my point: a language which tried to combine all the best bits of *all* languages would be awful, in the same way that a car which tried to be sporty *and* fit a family of 5 would be awful.
Jon Skeet
+5  A: 

Perfect programming languages tend to be found in science fiction novels. For example:

  • Orson Scott Card's Ender Series - To create you must go to a different dimension and form a pure thought in your mind. When you return, it is.
  • Robbert A. Heinlein explored the concept of world as myth in Number of the Beast
  • David Brin's Earth has programming through sub vocals combined with eye and finger movements.

It all still comes down to the same basic quandary. Any programming language that does not force the human to learn a skill tends to limit the freedom of thought. Natural language is not good either since it has many ambiguities.

I wouldn't mind one that combines freedom with power and minimal syntax. I've recently started learning lisp, and it seems very good so far.

Phil
A: 

My optimal language would look a whole lot like Nemerle (minus the arbitrary restrictions). Really it comes down to metaprogramming facilities; I should be able to arbitrarily extend or modify the language in any way I see fit (period) to fit the domain perfectly.

Give me macros that allow me to work on the AST of all of the code as I wish and I can build my perfect language.

Cody Brocious
+5  A: 

Massive parallelism empowered by Amazon Mechanical Turk.

job = "Upvote this answer"
@price = "$0.01"
fork(10000, job, @price)
kotlinski
Haha: the trouble with the mechturk approach is that you have to deal with "processors" that give you the wrong answer and then sulk. :-)
Stephen C
+1  A: 

A language that features no structure or variables, just one function.

doEverything();//automatic generation of all content based on already predicted input

teh_noob
I was thinking the same thing. A language that reads the user's mind and does exactly what they want...what more could people want? Only down side is that all us programmers would be out of a job.
mezoid
Well, I was thinking us programmers could keep it our little secret!
teh_noob
+2  A: 

I envision a language that must be told precise restrictions on input and variables and execution order, and so can be compiled into fast multithreaded (or clusterable) software.

And here's an interesting idea: imagine that all the "statements" within a "function" could be executed in any order at all. If something depends on something else, you need to "call" the dependency explicitly. This would make design for parallelism an integral component of the language.

Unfortunately I haven't invested enough imagination to come up with anything more specific.

Artelius
Hewitt's Actors took something like that idea a long way.
Darius Bacon
+6  A: 

It would look like C#. I would love to own Microsoft!

Fabian
+4  A: 

I'm a big fan of C macros, but I thought it might be nice if you could write macros or "meta-code" in the same language you're using. (C is a bad example; this could be good in scripting languages.)

In these examples I'm using braces to identify the meta-code. You would be able to run the source through a "preprocessor" to expand the meta-code out. Otherwise it would just be expanded once at runtime.

print "Your product ID is: ", { print '"', generateGUID(), '"' }

or

lookupTable[] = {
                  /* insert code to generate table here
                   *
                   * This lets you modify the algorithm easily
                   * but speeds up the final program.
                   * 
                   * This would be especially appropriate in
                   * cases where you would otherwise type out
                   * the table as a literal (yuck)
                   */
                }

Now and then we have to write several lines of very repetitive code; can't think of a good example right now but this kind of think would also be very helpful in such situations.

Artelius
This is what metaprogramming is all about. There are many languages with native support (Lisp-family, Nemerle, etc) and some with it hacked on (my own MetaPy project). Being able to run code at 'compiletime' (whatever that is) is incredibly valuable.
Cody Brocious
Take a look at D
BCS
Other variants of this idea include Lisp (defmacro, syntax-rules), Forth, Prolog (term_expansion), MetaOcaml, and Template Haskell.
Darius Bacon
Bear in mind that this is more difficult than it looks, even in a language set up for it (like Lisp); Lisp macros are harder to get right than Lisp functions.
David Thornley
How about trying ruby?
epochwolf
SO is So Awesome... my, what you can learn...
Artelius
A: 

My ideal programming language, the code would be smart, it would tell me if it had a problem with another piece of code, we would sit down and talk and it would tell me what its problem was so we could work it out... I call it "EmotionPeople++"

Kyle G
+3  A: 

I would imagine mine would be somewhere between Brainf*ck and LOLCODE except with A LOT more parentheses.

Lolindrath
+4  A: 

My perfect language would allow me to ratchet up the functionality as I need it. If I need to write a small straight forward utility program without classes I could. If I needed to use classes I could do that also, and if I wanted to write a completely object oriented solution I would be able to do that too. The linker would be smart enough to let me create small fast command line utilities (with no runtime dependencies) or the largest bloated OOP GUI app I could imagine.

The problem is that what I like has opposing goals and thus I've always been forced into using completely different languages. I currently use in no particular order PowerShell, VBScript, PowerBasic, Java, and C# (and sometimes VB .NET, VB 6, C++, Python, and Perl).

Now if I could do it all with one C# like language that had global functions with no runtime dependencies when creating those small apps, but let me make full use of the power of the .NET Framework and Java SDK when I needed to, I'd be happy.

bruceatk
+1  A: 

Clojure is getting pretty close...

Technical Bard
+3  A: 

Multi-media.

I want to be able to scribble some graphical symbols, quickly sketch connections and then flip to other modes such as typing where precision is needed.

I also think programmming languages should support people who don't think in English (yes, even Americans ..... joking!). I've studied enough Japanese and tried to pick up some Indonesian - I would like to see a language support people with different grammatical constructs and orders.

I raised a question at a recent forum I attended on the future of the web, asking a visiting Chinese professor if he thought Chinese written language would be more likely to enable a workable semantic web than English. He was intrigued by the notion.

A lot of SF I read talks about future UI's for computer interaction:

  • data wands in David Drake's Lt Leary series (some of which are available free from Baen)
  • multi-modal favourite sets of gestures and vocalisations in some other book I can't remember
Andy Dent
+25  A: 
Rik
Lego Mindstorms?
Richard Ev
Programing already has a lot in common in with Lego (when compared with, say, sheet metal fabrication). It's usually 1x1 flat legos, but the similarity is there.
Scott Wisniewski
You, sir, are my hero.
annakata
Couldn't agree more!
Frank
I would upvote you, but it turns out I already did.
Chris Lutz
In order ot make anything decent, one needs at least 1X2 flat legos. Anything less and all you can make are small towers.
RCIX
+1  A: 

I am not sure what my dream language would look like, but I have a little improvement for C-style languages. How many times have I written something like this:

Node foundNode = null;  // need stupid null value here to keep track if it was not found
foreach (Node testNode in nodes) {
  if (testNode.YesItsMe) {
    foundNode = testNode;
    break;
  }
}
if (foundNode == null) {
  // create new instance
  foundNode = new Node(blabla);
}

I know there are more elegant functional ways for this, but sometimes you still end up with code like this. A simple "guard" statement would help here:

Node foundNode;  // no need to initialize anymore
foreach (Node testNode in nodes) {
  if (testNode.YesItsMe) {
    foundNode = testNode;
    break;
  }
} guard {  // we get here if break was never called
  // create new instance
  foundNode = new Node(blabla);
}
Lemmy
as for me: s/guard/else/
BCS
Python has this: for x in y: ... else: foundNode = Node(blabla)
Darius Bacon
(let ((found-node (or (find-if #'test nodes) (make-node data)))) do-something-with-found-node)
Svante
One year later I know but why don't you write: http://pastebin.com/eDcVCw6m if node is found, the value is replaced, if node is not found it was already set by the initalization part
OscarRyz
+1  A: 

I would like a programming language that makes tools really easy to write correctly. Extract method, colorization, autocomplete, compilation, etc.

I want this to happen while still being easy to write and easy to read.

Jay Bazuzi
A: 

It would be machine readable/writeable, and it would be written by intelligent software that takes instructions by voice.

Ali A
+13  A: 

Jon is right in saying that “[d]ifferent tasks suit different languages and paradigms.” However, there are a few considerations that are largely independent of the domain. These mostly concern syntax but since code is read more often than written, I actually think that syntax matters.

For one thing, and something that many languages do wrong, it's completely arbitrary to base the syntax off C. C actually has an exceptionally bad syntax. I'll just pick two examples.

The first is quite uncontroversial: semicolons are unnecessary. Take the following code; the grammar is completely unambiguous and easy to parse for a compiler. Neither semicolons nor explicit line continuations are necessary.

answer = 42
fraction = answer * 2 /
           (answer + 1)
Console.WriteLine(
    "Some funny number: {0}",
    fraction
)

This is actually quite similar to Python but even more permissive: the definition of fraction spans multiple lines. This is logical since the first line isn't yet complete.

Another bone I've got to pick with C-like syntaxes are their largely implicit variable declarations. Instead of announcing clearly “I'm declaring a variable of type Foo,” all they whisper shyly is “Foo var”. Since Foo isn't even a reserved word in most cases, the programmer isn't offered a single visual hint here. I prefer VB's explicit Dim var As Foo, even thought he keyword used here is, well, quite dim.

(C++ actually makes matters much, much worse by introducing a lot of nearly identical and often ambiguous syntaxes that mean completely different things, from variable initializations to function declarations).

Another thing my language would have to have is static typing. It's true that dynamic typing has its uses but they are surprisingly rare. Even most “scripting languages” wouldn't really need them. I think that this is often confused with implicit typing which has rather more uses. Take (again) the example of Python. Why doesn't it offer static typing? It's already strongly typed, statical type checking would only be consequent, and would cut down on debugging quite a bit. The same goes for explicit variable declaration. I fail to see what advantages implied variable declaration offers.

So there we've already got an outline for a language:

  • Clean syntax, avoid historical clutter. In particular:
    • No semicolons
    • No explicit line continuations à la VB
  • Explicit variable declarations
  • Static typing

Furthermore, I'm a huge fan of certain C++ concepts, such as general-purpose templates, RAII (i.e. avoiding garbage rather than collecting it), immutability and the concept of value ranges defined via iterators. I've stated elsewhere that I believe iterators to be one of the most fundamental innovations ever. Give'em a little lipstick and you won't even recognize the ugly beast that is C++:

for i in MyVector:
    print(i)

rather than

for (typename vector<T>::const_iterator i = MyVector.begin();
     i != MyVector.end();
     ++i)
    cout << *i << endl;

Of course I'm aware that the above syntax is offered by many languages. But they all only offer watered-down versions of C++' powerful iterator concept (to use C++ terminology, the only kind of iterators that most languages know are input iterators, which are basically the least powerful iterators).

At this point I should probably say that the sole copyright for all these ideas is mine, patents pending (in particular for the MayOrMayNotBe operator that doesn't really compare object references).

Konrad Rudolph
Static typing is almost always premature optimization. How much experience do you have with dynamic typing?
David Thornley
This has absolutely nothing to do with optimization (although that's a nice bonus). It simply makes you more productive (IMHO) because it strengthens the compiler's ability to provide meaningful diagnostics. My claim is that dynamic typing is credited with a lot of advantages it doesn't really have.
Konrad Rudolph
For the record, I've got extensive experience with dynamic typing. I've done web development in Ruby on Rails and PHP, I use Python and Perl extensively for all kinds of tasks and I've developed in VB6 for years.
Konrad Rudolph
+3  A: 

Python is pretty close to ideal for me... I would just get rid of some annoyances like having the self keyword... but with a good editor, Python can do amazing things very quickly...

jle
+1  A: 

It would look exactly like Scheme. Only it would compile to both IL and Java bytecode, and assembly so I could use all those libraries.

mannicken
+3  A: 

It wouldn't be very different from taking the best ideas of Eiffel and C# (because, plainly, I don't have the knowledge to come up with anything better - I haven't studied CS in the first place).

However, my main practical concern would be go to one step beyond the classical "source code text" approach. I know this is (or sounds like) an IDE thing, but why can't I have a configurable code view with columns such as preconditions/body/postconditions instead of a "linear" form (i):

  function f
  // f's preconditions
  // f's body
  // f's postconditions
  end

  function g
  // g's preconditions
  // g's body
  // g's postconditions
  end

Why not (ii) - imagine this is a table (with borders):

f      f's parameters    f's prec      f's body      f's postc    f's comments
g      g's parameters    g's prec      g's body      g's postc    g's comments

And also, why can't I choose how functions "begin" and "end" (braces, keywords...) in style (i)? Why can't I instantly show or hide private or protected members? Why can't I instantly see the "flat version" with all the inherited functions inside? etc.

The point would not be to have one holy code file where you edit and then multiple "cool views", but to be able to edit and add code in both (i), (ii) and whatever form is most useful to you.

In a way, talking about "IDE" may seem off-topic here. But OTOH I think this is going to change the way we write and read code, sooner or later. And this will ultimately influence the way languages evolve. The future goals would be to enhance not only readability but also "understandability" and interactivity.

Daniel Daranas
You make many good points!
RCIX
+2  A: 

One designs languages to meet specific goals. Syntax and semantics should follow desired function.

In my case, I wanted a language with fine-grain parallelism, that is, very low overhead per grain to allow small chunks of code to be parallelized.

I've designed and implemented it on x86 SMP systems, and it has been in use for about 10 years as the foundation for a large-scale software analysis tools.

The main point was to allow me (us) to specify parallelism easily:

(|| A B)

does A and B in parallel, and let the compiler generate all the crud that makes this possible. We didn't care about whether the syntax was infix or not, so we went LISP style to avoid arguments.

A paper describing the language and a number of parallel applications can be found at http://www.semanticdesigns.com/Company/Publications/parallelism-in-symbolic-computation.pdf

The paper briefly discusses how we didn't succeed in avoiding arguments over syntax in spite of our decision.

Ira Baxter
A: 

Hmm. this is a tough one. My tastes run towards the easily human understandable, and light scripting-style languages (though i do believe this could work for larger apps). See code snippet:

function Foo takes x as string, y as boolean //can add returns [return type] if one wishes to be explicit
    //explicit variable declaration
    z as number
    //explicit cast from boolean to number
    z is y as number
    //implicit variable declaration
    bar is 3 * 5
    //function call
    print x
    return z / bar //since we casted z to a number, it returns a number
RCIX