Sign in to follow this  

Thinking of creating a natural looking programming language

This topic is 3650 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was thinking of creating a programming language that looks a lot like English, making it easy to learn. Good or bad idea? Here is an example of the language: Create a variable called password. Output the text "Please enter the password:" and a newline. Accept input from the user and store it in the variable password. While the variable password is not equal to the text "admin123" then do the following: Output the text "Access denied. Please enter the password:" and a newline. Accept input from the user and store it in the variable password. Then end the loop. Output the text "Access granted. Welcome".

Share this post


Link to post
Share on other sites
Ok,
Number 1: The English language is so extensive, that you can say one thing in many ways. You would have to be able to parse the text in your compiler in a manner of ways so that you could cover all possible translations of the text.

Number 2: D you know how long the code would be? You're looking at full essays for simple tasks! Lots of needless text. A waste of time.

Number 3: Who wants programming to be easier? I don't want the market to be flooded (kind of already is) with programmers.

What I'm trying to say is: Yes, it's a cool idea, but not practical. Think about computers that translate one human speaking language to another. They're not perfect, sometimes they completely suck. That's why we still use human translators. In programming, you can't afford to be slightly wrong in translating the code. Would you like to hire translators to change English into a programming code... wait a second, that's what programmers are :D.

Share this post


Link to post
Share on other sites
Quote:
Original post by AdamGL
Ok,
Number 1: The English language is so extensive, that you can say one thing in many ways. You would have to be able to parse the text in your compiler in a manner of ways so that you could cover all possible translations of the text.

Well, people need to stick to a predefined way of doing things, but it still makes everything easier to understand.

Quote:
Original post by AdamGL
Number 2: D you know how long the code would be? You're looking at full essays for simple tasks! Lots of needless text. A waste of time.

See number 1.

Quote:
Original post by AdamGL
Number 3: Who wants programming to be easier? I don't want the market to be flooded (kind of already is) with programmers.

People who want to just create things quickly and easily.

Quote:
Original post by AdamGL
What I'm trying to say is: Yes, it's a cool idea, but not practical. Think about computers that translate one human speaking language to another. They're not perfect, sometimes they completely suck. That's why we still use human translators. In programming, you can't afford to be slightly wrong in translating the code. Would you like to hire translators to change English into a programming code... wait a second, that's what programmers are :D.

Yes, I know. I probably will work on this though, and see where it goes...

Share this post


Link to post
Share on other sites
English is a highly unstructured and ambiguous language, not designed for explicit communication. As a result, teaching a new language to a programmer is much simpler than teaching English to a computer, per se. The state of the art in natural language processing is still highly fallible, and what you would end up with is a subset of English -- which is far more difficult to code in than a new language entirely, because people would expect any sentence that was grammatically correct (or that they THOUGHT was grammatically correct) to compile properly, and it wouldn't, making a debugging into a nightmare...not to mention coding long paragraphs of gobbledygook that ends up looking like a randomly generated spam email

Share this post


Link to post
Share on other sites
Quote:
Original post by SpamBurger
I was thinking of creating a programming language that looks a lot like English, making it easy to learn. Good or bad idea? Here is an example of the language:

I'd argue that programming languages (yes, even C++) are already easier to learn than English.
Of course you need a few other skills as well to be a programmer, but learning the *language* part of C++ is much easier than learning English.

Second, what is it about "natural languages" that are desirable?
That they're vague and ambiguous? That there are two hundred different ways to say even the simplest things, and that there are usually half a dozen different (and all valid) interpretations of what you're saying?

I fail to see how those are at all good things.

Quote:
Create a variable called password.

Or 'please create a varable called password.'.
or 'create <lowercase c> a variable named <instead of called> password.'
or 'make a variable called password'
or 'I'd like a variable called password'
or 'create a variable and call it password'
...

How do I, the programmer know which of the above are legal?
How does the compiler know that what I meant was equivalent to "create a variable called password"?

Natural languages only make things harder to understand, by introducing needless ambiguities and complexities.

In short, it'd be impossibly hard to create a programing language like this, even harder to compile it, harder still to ensure that two separate compilers would interpret the language in the same way (and emit equivalent code).
And for the developer trying to program with this, it'd be just plain impossible.

The hard part when learning programming is not to learn to write "while(true)", it is to get used to *thinking* in terms of variables, if statements, loops, functions, recursion and whatever else.

Your language would still require all of this (create a variable named....), and (while the variable .... is.... then do the following)

All you've achieved is to make the language *much* more verbose, make it *much* harder to verify that my code is correct, *much* harder to debug, *much* harder to parse and overall, just a bad idea.

Yes, programming is hard. But it doesn't become easier by taking the least hard part of it and turning it into something completely impossible.

Share this post


Link to post
Share on other sites
You might want to take a look at AppleScript, as a case-in-point for natural language not working well for computers. It *still* takes me 3 tries to get a working loop in AppleScript, something you will never have with simple 'for' loop syntax.

Share this post


Link to post
Share on other sites
A really impressive example of an English-based language is Inform 7. It's a language for creating text adventures. Here's the full "source code" to a simple game:


"Hello World" by "I.F. Author"

The story headline is "An Interactive Example".

The Living Room is a room. "A comfortably furnished living room." The
Kitchen is north of the Living Room. The Front Door is south of the Living
Room. The Front Door is a closed locked door.

The insurance salesman is a man in the Living Room. The description is "An
insurance salesman in a tacky polyester suit. He seems eager to speak to you."
Understand "man" as the insurance salesman.

A briefcase is carried by the insurance salesman. The description is "A
slightly worn, black briefcase." Understand "case" as the briefcase.

The insurance paperwork is in the briefcase. The description is "Page after
page of small legalese." Understand "papers" or "documents" or "forms" as the
paperwork.

Instead of listening to the insurance salesman:
say "The salesman bores you with a discussion of life insurance
policies. From his briefcase he pulls some paperwork which he hands to you.";
now the player carries the insurance paperwork.




Which, to me, is pretty good. That code is not that much longer than it would be to write the same thing in a typical programming language.

I don't think English-based languages are great for *every* kind of programming, but it sure seems to work great for Inform's domain.

Share this post


Link to post
Share on other sites
Quote:
Original post by SpamBurger
I was thinking of creating a programming language that looks a lot like English, making it easy to learn.


I think you've confused "easy to learn" with "easy to read for non-programmers".

Quote:

Create a variable called password.
Output the text "Please enter the password:" and a newline.
Accept input from the user and store it in the variable password.


Your example makes me think the syntax would be very hard to learn ("do I need a preposition here or don't I?", or "is this dangling participle going to cause a compiler error?") unless your language had many legal forms for the same thing. As others have pointed out, ambiguities would be difficult to avoid (what does "it" refer to in line 3?)

Notice that I said that your example may be easy to read for non-programmers. Identical code in C would be much faster and easier to read for programmers due to the verbosity and ambiguity of your example.

In short, I agree with others that this is a bad idea, even if it were feasible technically.

Cheers,
Matt




Share this post


Link to post
Share on other sites
The main thing you would need to do is make a special kind of parser...

It reads the paragraphs/sentences provided by the "coder" and parses them to a more basic, common format. It then, using some algorithm, finds what each statement is trying to tell it. If it cannot find it, it let's the user know. After that, you create a list of "intentions," or concepts that the user wants. Make a C++ equivalent of it, and compile it. Or, just make your own compiling system for all of the intentions in the paragraph.

This would require that the user be fairly specific about what he wants, and a bit less ambiguous, but if you develop it enough, you might get something...

You could make an AI that you feed what you want to, and just have him code it all. ;)

Share this post


Link to post
Share on other sites
Shakespeare is fun but useless :). Since it's esoteric it isn't very good example thought. It just gives you idea of how code could look. You would see a big pile of text and it would take a long time and effort to find something. In C for example you can tell where's a loop were are calcualtions or declarations in a second. In your language we would have to read the whole "code" first. Waste of time if you ask me.

Share this post


Link to post
Share on other sites
The problem with construction of natural languages isn't verbosity or friendliness.

It's context dependence and ambiguity. Human languages have both, and rely on them. Computer languages cannot have either.

Programming is not about syntax. There's too many guru and pro programmers which have learned all C++ in 2 weeks.

Share this post


Link to post
Share on other sites
Quote:

Create a variable called password.
Output the text "Please enter the password:" and a newline.
Accept input from the user and store it in the variable password.

While the variable password is not equal to the text "admin123" then do the following:
Output the text "Access denied. Please enter the password:" and a newline.
Accept input from the user and store it in the variable password.
Then end the loop.

Output the text "Access granted. Welcome".


That's just too low level. You're using whole sentences to create something as trivial as a variable, or set values to it. Who would want that? What's the use of something like that? It's just as low-level as any other programming language, except it uses more words. Now, if you could do something like...

Password is "admin123"
Get the password from the user, and output "Acess denied" if failed, otherwise proceed and output "Access granted".

That would be of some use. But I don't know if it's feasible.

Share this post


Link to post
Share on other sites
It might be more practical to build an interface that accepts more abstract, syntactical criteria and outputs text that a non-programmer will find easier to understand.

This concept reminds me of "pre-compiled" scripting languages that have a fixed number of statements, and you select which statement you from a list, generally in the form of buttons. I could click the "Create Variable" button and specify a name: "var", and the output would look like, "Create a variable named var." So I wouldn't be responsible for writing the actual code, nor would your software be responsible for parsing its own English (or Spanish, or whatever other languages you want to support). Code would be stored as statement indices and identifier names, but to the end-user it would look like structured phrases.

Of course, you could build a front-end to do this for just about any existing language, though it would of course limit the user's flexibility with using the language, but that seems to be your intent: to make programming easier, not more powerful. And I don't disagree. There are plenty of tools to make software engineering easier; this is simply another approach.

Share this post


Link to post
Share on other sites
I applaud the effort in thinking about how to make things better as I believe that is the most noble motivation that a programmer could have. However, you are likely spending your efforts in the wrong direction here.

Perhaps it would be good for you to explore more of the languages that are available. Which ones have you already tried? How long have you worked with them?

Share this post


Link to post
Share on other sites
Well, I created a basic version of MICE. A few things don't work and this is pretty buggy (such as you can't use keywords even in a string). However, you can do things such as looping, conditionals, output text, etc. The source is only like 35 lines, all I did was convert the MICE code into Perl and eval() it. I just learned Perl today so give me a break :p

http://helnet.org/mice/MICE.zip - MICE .zip
Usage: mice.pl src.ext

You must have Perl to use this obviously. Here is an example that will work in the interpreter:


Output the text "Please enter the password: " and a newline.
Accept input from the user and store it in the variable password.

While the variable password is not equal to the text "admin123", then do the following:
Output the text "Password incorrect, try again: " and a newline.
Accept input from the user and store it in the variable password.
Then end the block.

Output the text "\n\nAccess granted, welcome!".


There is a documentation file in the zip, but note that not everything in it works yet.

[Edited by - SpamBurger on December 1, 2007 6:52:31 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by SpamBurger
I was thinking of creating a programming language that looks a lot like English, making it easy to learn. Good or bad idea?


The last time someone had this idea, and was given encouragement and the means to act on it and popularize the result, that result was COBOL.

[EDIT: Thanks for the other examples, guys. Actually, COBOL was probably the first time this happened, if anything :)]

... I'll let you decide for yourself.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
The last time someone had this idea, and was given encouragement and the means to act on it and popularize the result, that result was COBOL.

[EDIT: Thanks for the other examples, guys. Actually, COBOL was probably the first time this happened, if anything :)]


The last time this happened that comes to mind was with Speedo's En.

Well, okay, I guess we didn't really encourage him.

In fact he kind of got banned not just from Wikipedia for sockpuppetry (IIRC), but from the gamedev IRC channel as well for repeatedly spamming his half baked language implementation on everyone, including utter novices who wouldn't be in a position to know any better than to avoid starting on a language that's mostly the efforts of one ranting loon. After being asked by the operators to stop such behavior. Repeatedly.

He also seemed to be immune from the suggestion that his language could have any flaws whatsoever.

As for natural looking languages, well, there's a time and place for them, but as a simple counterexample, I'd simply put forth the question: Which is easier to answer:

Solve for y:
4x - 3y + 5 = 2(3x2 + y)

Or:

Solve for y: The equation, 4x minus 3y plus 5 equals 2 times the sum of 3 times x squared and y.

Mathematical notation is an example of creating a non-English language for the express purpose of more easily manipulating and dealing with a specific concept. It follows, then, that programming, especially given it's ties to mathematics, could also easily benefit from such specialization, both for clarity and expressiveness.

Share this post


Link to post
Share on other sites
I've written a concise program in your language, please compile it and let me know how it runs:

"Make cool game like Crysis only better and with bigger more realistic explosions and graphics. Start game."

Share this post


Link to post
Share on other sites
A natural language is too much efort for all the above reasons, at this time. However another related idea would be to produce an IDR for an existing language that actualy helps to debug your code rather than just telling you the contents of variables and which line broke in execution. How you do this might take a lot of thought and experimentation as well as discussion.
One point on the natural language. I would forget parsing ALL the words and just pick salient ones from a sentence, if you don't already and word order of cause. this will expand the number of ways to write the same sentence.
Make a = 21
Make a varable equivilent to 21
Assign 21 to a variable called a

Also a vay to go is to use a tree constructto find what is being wanted in a sentence again with the salient words that brance and brance till an action is arrived at.
Syntax and gammer checking will be very important so a word out of context can be caught early in the sentance construction. I like the method used in Test automation stratagies with a high degree of abstraction, a keyword is selected from a list and this then populates a new list of possible 'next' words based on the growing context etc etc.

Good luck.
You might try Python as it has a clean grammer compared to Perl.

Share this post


Link to post
Share on other sites

This topic is 3650 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this