Yoda-speak as a model for language design

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?