4 ms·
What more agreeable syntax could you possibly ask for?
by gipp 11y ago
What more agreeable syntax could you possibly ask for?
- frik 11y agodef (str) greeting((str) name): Edit: it was just an idea, it would be a bit more C-style syntax; of course backwards compatibility wouldn't be possible. Instead of downvoting would you care to explain?
- rootlocus 11y agoI didn't downvote, but I don't like the syntax for a couple of reasons: 1. Instead of being more like C-style function declarations, they look a lot more like C-style type conversions. 2. However closer it may be to C (type before identifier I guess?) it's pretty far from any other mainstream language. For instance, C++ has support for -> syntax for function types (http://stackoverflow.com/questions/22514855/arrow-operator-in-function-heading http://stackoverflow.com/questions/22514855/arrow-operator-i...) and some other languages (I can think of Scala) use name: Type declarations. As a personal preference, I find the python type hinting more familiar than your example, despite (myself) being most familiar with C-like syntax.
- vive-la-liberte 11y agoPython is not C so why should it suddenly "pretend to be" when doing type hinting? Also, I personally find that the type declaration format of C is one of my least favorite things about C.
- ghshephard 11y agoDefinitely not downvoting - but, all the extra parentheses are a kind of lispy in having to grok (and balance). Also, having the (str) at the beginning makes me think that it's an input, whereas having -> makes it clear (to me at least) that it's an output return type.
- coldtea 11y agoTons of extra needless parenthesis for what exactly? To look more like C? It's not like (foo:x) is not also a common type of type annotation. Besides they look more like casts than type declarations to a C programmer.
- dtech 11y agoYou're too familiar with C-style languages. When I initially picked up Scala the : type syntax felt a bit strange, but I really came to like it and am happy when it's in other languages. Putting the type after the name feels more natural, and the : also translated nicely into 'of type' (or if you prefer for functions 'returns type').
- rbehrends 11y agoI didn't downvote, but it being C-style syntax is not a recommendation in this context. For familiarity, while the C family of languages favors "type name" declarations, the Pascal and ML family of languages use "name: type" instead. So, familiarity is entirely a function of what language you used before. Second, C-style declarations have their problems, which is why they aren't used much outside of languages that derive from C. Generally, you look up declarations by searching for the name of the variable to determine the type; this generally has less cognitive overhead if the variable is at the start of the clause, not the end, ideally separated by punctuation (note how the "name: type" syntax mirrors Python dictionary "key: value" syntax) [1]. [1] Also, in C/C++ the "type name" syntax complicates the parser, as the parser has to be able to distinguish between type names and other identifiers; while this wouldn't be an issue for Python, there is still no reason to perpetuate this syntax choice.
- daveguy 11y agoSomething that doesn't require a -> and something with type prefix rather than postfix. Still sticking with 2.7, thanks.