Is there a programming language with be semantics close to English ?
- by ivo s
Most languages allow to 'tweek' to certain extend parts of the syntax (C++,C#) and/or semantics that you will be using in your code (Katahdin, lua). But I have not heard of a language that can just completely define how your code will look like. So isn't there some language which already exists that has such capabilities to override all syntax & define semantics ?
Example of what I want to do is basically from the C# code below:
foreach(Fruit fruit in Fruits)
{
if(fruit is Apple)
{
fruit.Price = fruit.Price/2;
}
}
I want do be able to to write the above code in my perfect language like this:
Check if any fruits are Macintosh apples and discount the price by 50%.
The advantages that come to my mind looking from a coder's perspective in this "imaginary" language are:
It's very clear what is going on (self descriptive) - it's plain English after all even kid would understand my program
Hides all complexities which I have to write in C#. But why should I care to learn that
if statements, arithmetic operators etc since there are already implemented
The disadvantages that I see for a coder who will maintain this program are:
Maybe you would express this program differently from me so you may not get all the
information that I've expressed in my sentence
Programs can be quite verbose and hard to debug but if possible to even proximate this type of syntax above maybe more people would start programming right? That would be amazing I think. I can go to work and just write an essay to draw a square on a winform like this:
Create a form called MyGreetingForm. Draw a square with in the middle of
MyGreetingFormwith a side of 100 points. In the middle of the square write "Hello! Click here to continue" in Arial font.
In the above code the parser must basically guess that I want to use
the unnamed square from the previous sentence, it'd be hard to write such a smart parser I guess, yet it's so simple what I want to do.
If the user clicks on square in the middle of MyGreetingForm show MyMainForm.
In the above code 'basically' the compiler must: 1)generate an event handler 2) check if there is any square in the middle of the form and if there is - 3) hide the form and show another form
It looks very hard to do but it doesn't look impossible IMO to me at least approximate this (I can personally generate a parser to perform the 3 steps above np & it's basically the same that it has to do any way when you add even in c# a.MyEvent=+handler; so I don't see a problem here) so I'm thinking maybe somebody already did something like this ? Or is there some practical burden of complexity to create such a 'essay style' programming language which I can't see ? I mean what's the worse that can happen if the parser is not that good? - your program will crash so you have to re-word it:)