8 ms·
I hate the double colon, it's so unpythonic. I believe the 'as' keyword would be more smooth: def hello(name as String) as String: var greeting as
by Thiz 12y ago
I hate the double colon, it's so unpythonic.
I believe the 'as' keyword would be more smooth:
def hello(name as String) as String:
var greeting as String
greeting = 'Hello '+name
return greeting
- jimktrains2 12y agoThis isn't Python. :: is common in many languages, especially functional ones (which aren't just using it as a scope resolution operator).
- pdabbadabba 12y agoNot sure what place "unpythonic" has as a criticism of a language other than Python. (As a matter of personal taste, I too prefer "as." Probably because I do most of my work in Python. But who cares?)
- rilut 12y agoReminds me of Cobra http://cobra-language.com/ http://cobra-language.com/
- peaton 12y agoAnd boo http://boo.codehaus.org http://boo.codehaus.org
- chton 12y agoEven that isn't smooth enough for me. Why is the 'var as' still there? it's superfluous, ofcourse we're declaring a variable, there's nothing else that makes sense at that point. Why not: 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
- mborch 12y agoWhile definitely superfluous, it arguably makes it easier to read and scan.
- chton 12y agoI think that's a matter of habit. I've gotten far more used to the more condensed syntax, so for me that's faster to read and scan. I tend to prefer languages where there is little syntax wasted as a consequence.
- seanmcdirmid 12y agoC style type annotations that put type before name were never as elegant as pascal style annotations that put name before type. They are also more consistent.
- chton 12y agoelegance is debatable, and consistency is a matter of how the rest of the language is built. But you can still eliminate the superfluousness (is that a word?) by using 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.
- scott_s 12y agoHaving a language keyword which means "we are now defining a new variable" makes parsing easier, and you run into less ambiguity. See: http://en.wikipedia.org/wiki/Most_vexing_parse http://en.wikipedia.org/wiki/Most_vexing_parse
- chton 12y agoAmbiguity in the language is a whole problem of its own. Ambiguity in parsing is also ambiguity in writing, so a language should avoid it all cost. It's true that forcing actions to come with extra words is a way to do that, but it's by no means the only one. It's possible to strive for non-ambiguity without extra syntax. 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.
- seanmcdirmid 12y agoI personally use "is" in my own pythonic language (name is string), "as" sounds like coercion rather than being constraining.
- chton 12y agoI believe it the usage of 'as' comes from the idea that whatever value the variable contains, it should be seen AS and present itself AS the type you're supplying. It doesn't need to be a string, it just needs to act 'as' a string.
- munro 12y agoActually, they could of borrowed from Python 3's type annotation syntax! [1] def hello(name : String) -> io String: [1] http://legacy.python.org/dev/peps/pep-3107/ http://legacy.python.org/dev/peps/pep-3107/
- seanmcdirmid 12y agoColon already means block in Python, overloading it for type annotations (ala pascal) would make the parser more complex and less error tolerant. Besides it is inconsistent, you really want def hello(name : string) : io String The only reason they didn't do that is because colon also means block....
- neurobro 12y agoFunction hello(ByVal name As String) As String Dim greeting As String greeting = "Hello" + name Return greeting End Function