I believe the 'as' keyword would be more smooth:
def hello(name as String) as String:
var greeting as String
greeting = 'Hello '+name
return greetingI believe the 'as' keyword would be more smooth:
def hello(name as String) as String:
var greeting as String
greeting = 'Hello '+name
return greeting Function hello(ByVal name As String) As String
Dim greeting As String
greeting = "Hello" + name
Return greeting
End Function def hello(String name) as String:
String greeting
greeting = 'Hello '+name
return greeting
which is how a lot of other languages are doing it. On the other hand, maybe I just don't like writing syntax that doesn't add any meaning :p greeting as String
or even greeting :: String
Either is fine, though my preference would then go to the latter option, since it'll be faster when scanning.A good example of this case would be Java (like it or not):
String Hello(String name) {
String greeting;
greeting = "hello " + name;
return greeting;
}
Say of the braces and the semicolons what you will, but the core syntax is unambiguous and doesn't have a single word that doesn't have semantic meaning.Using a keyword to introduce entity definitions (variables, functions, packages, etc.) gives the language more space to grow in syntax without worrying about such ambiguities later. You can construct a grammar without any ambiguities that does not use such keywords - such as with your example of Java - but you're going to have to keep this pitfall in mind anytime you change the grammar.
It's possible to debate the positive side too, but I do agree that constructing a language with a verboser non-semantic grammar is easier.
LISTEN TO ME VERY CAREFULLY hello
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE name
GET TO THE CHOPPER greeting
. . .
ENOUGH TALK
GIVE THESE PEOPLE AIR
I'LL BE BACK greeting
HASTA LA VISTA, BABY
(I have a truly marvelous ArnoldC string library (with string concatenation), which this margin is too narrow to contain.)Of course, the comparison may not be very illuminating given that all ArnoldC variables are Int16s.
You are as brave as the sum of a fat little stuffed misused dusty old rotten codpiece and a beautiful fair warm peaceful sunny summer's day
is pure art. def hello(name : String) -> io String:
[1] http://legacy.python.org/dev/peps/pep-3107/ def hello(name : string) : io String
The only reason they didn't do that is because colon also means block....