Yoda-speak as a model for language design

By Kevin Yank

In his blog on MSDN, Microsoft software design engineer Matt Warren has proposed “Yoda-speak” as a useful model for designing more natural programming languages.

Matt has been one of the main drivers behind the evolution of the C# language. Though C# 2.0 is still awaiting its official release in Visual Studio 2005, the design of C# 3.0 is already complete, and Matt is looking to the horizon for what comes next in programming language design.

One of the main features in this upcoming version is Language Integrated Query (LINQ), which aims to provide all the power of database queries in general programming languages. Here’s an example of LINQ in action from Microsoft’s LINQ overview:

string[] names = { "Burke", "Connor", "Frank", 
                   "Everett", "Albert", "George", 
                   "Harris", "David" };

IEnumerable <string> expr = from s in names 
                           where s.Length == 5
                           orderby s
                           select s.ToUpper();

foreach (string item in expr)

The trick, of course, is in assigning expr a value using syntax that resembles an SQL database query. This syntax, however, will be built right into C# 3.0 (among other .NET languages), and fully supported by the next major version of Visual Studio.

One mildly controversial difference between SQL and LINQ syntax is the appearance of ‘from’ ahead of ‘select’. In SQL, you nominate the action you want to perform (e.g. SELECT) before indicating where you want to perform this action (FROM) and how (WHERE). LINQ reverses this in a bid to describe queries in a way that is more natural for human beings.

Matt argues that this transition can (and will) be carried into the rest of the language, and this will be the innovation that characterizes the next wave of programming language redesign. His point gets a little lost, I feel, due to his poor command of Yoda-speak, but some of the examples put forward in the comments to his post hint at the potential.

Of course, Perl has had some of this almost since birth, and has gained a reputation for being needlessly cryptic as a result. From the Perl syntax documentation:

Many of Perl’s syntactic elements are optional. Rather than requiring you to put parentheses around every function call and declare every variable, you can often leave such explicit elements off and Perl will figure out what you meant. This is known as Do What I Mean, abbreviated DWIM. It allows programmers to be lazy and to code in a style with which they are comfortable.

Can current .NET languages like C# and VB.NET make the transition to the ostensibly more natural “Yoda ordering”, or will Microsoft–as Matt suggests–have to create YODA the Programming Language from scratch?

  • Pingback: Lucas Chan :: Weblog()

  • ikarys

    A good LINQ vid is located off the MSDN site.

    I recommend watching the LINQ video. Some of its benefits are astounding. I’m really curious what the Java camp will do to combat this move by MS.

  • Sojan80

    So I’m wondering, if YODA speak proliferates through web programming languages, does that then mean that all web programming languages will be taught by “web jedi masters”?

  • RaS!

    What about the overhead of this?

  • MCsolas

    Hehe .. I am already using this technique in coldfusion coding. You can practically read right through the code because of the variable naming conventions I have applied.

    Also, if your looking for the web jedi master, there can be only one.

    Coldfusions Jedi Master

  • Etnu

    Which is actually “more natural”?

    “Give me all the records from the orders table”
    (SELECT * FROM orders)

    “From the orders table, give me all the records”
    (FROM orders SELECT *)

    The LANGUAGE will never be the barrier in the programming world. It’s always going to come back to the LOGIC of things that makes programming difficult. The ‘casual user’ will never be able to program, no matter how natural you make the language. Sure, they could do queries, run simple commands, etc. (and, as such, natural language programming is quite suitable for small scripts and sql queries), but they’ll still never be able to build an enterprise class web service.

  • mattiasw

    Wow, MS has reinvented embedded SQL :-) which was very common 10-20 years ago.

    Before using LINQ, think about why embedded SQL isn’t used anymore (except maybe some die-hard Oracle fans).

    One of the biggest obstacles is vendor lock-in.

    Example of old-time embedded SQL:

    int thisSID;
    float thisGPA;
    EXEC SQL OPEN CS145Student;
    while (1) {
    EXEC SQL FETCH CS145Student INTO :thisSID, :thisGPA;
    printf("SID %d current GPA %fn", thisSID, thisGPA);
    printf("Enter new GPA: ");
    scanf("%f", &thisGPA);
    EXEC SQL UPDATE Student SET GPA = :thisGPA
    WHERE CURRENT OF CS145Student;
    EXEC SQL CLOSE CS145Student;
  • mattiasw

    Sorry for the missing end-tags in my post. A preview mode would be appreciated.

  • Kevin Yank

    Fixed your comment up for you, mattias. Request for a preview noted.

  • Pingback: Ticklish Ears » Blog Archive » Just Assorted Stuff: End of Semester, Yoda-speak, and FiboNachos()

  • cfarrugia

    Some people have even turned YODA speak into a t-shirt! loool check it out


Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in Front-end, once a week, for free.