The code may look like natural language, but it's really just regular computer code with different keywords. In your example, I want
is probably synonymous with new
. It's not like you can use natural language directly and say make me a window
instead (and if you could, things would get even uglier...).
Lets take a close look at your code and the language implications:
i want window and the window title is Hello World.
i want
means new
, and
denotes beginning of the argument list. the <type_name> <member_name> is
sets instance variable member_name
on the object being created. Note that you have to write the type_name
twice.
i want button and button caption is Close.
and button name is btn1.
.
ends a statement. However, you can 'chain' method calls on an object by starting the next statement with and
. Also, how do you refer to a variable named Close
instead of the string "Close"
? Heck, we even have this problem in regular English: what the difference between 'Say your name' and 'Say "your name"'?
btn1 mouse click. instructions are
you close window
end of instructions
mouse click
is an identifier containing a space, should be mouseClick
. instructions are
defines a lambda (see the is
vs. are
keyword confusion causing trouble yet?). you close window
calls window.close()
. end of instructions
is end of a lambda. All of these are longer than they need to be.
Remember all that? And those are only my guesses at the syntax, which could be completely wrong. Still seem simple? If so, try writing a larger program without breaking any of those rules, AND the additional rules you'll need to define things like conditional logic, loops, classes, generics, inheritance, or whatever else you'll need. All you're doing is changing the symbols in regular programming languages to 'natural language' equivalents that are harder to remember, unnecessarily verbose, and more ambiguous.
Try this translation:
var myWindow = new Window( title="Hello World" );
myWindow.addButton( new Button( caption="Close", name="btn1" ) );
btn1.onMouseClick = function() {
myWindow.close();
}
See how each line maps to its counterpart in the previous example, but states the intent more directly? Natural language may be good for execution by humans, but it is terribly difficult to use for precise specifications.
The more you try to make English communicate these ideas easily and clearly, the more it's going to look like programming languages we already have. In short, programming languages are as close to natural language as we can get without losing clarity and simplicity. :D