Replies: 5 comments 19 replies
Prefix C vs Postfix TypeScript/Python/PHP function RV type declarationsCUsing prefix type name without special characters. return_type function_name( parameter list ) {
body of the function
}int max(int num1, int num2) {
}
// https://www.tutorialspoint.com/cprogramming/c_functions.htmTypeScriptUsing postfix function add(x: number, y: number): number {
return x + y;
}
let myAdd = function (x: number, y: number): number {
return x + y;
};
// https://www.typescriptlang.org/docs/handbook/functions.htmlPythonUsing postfix def add_number(value: int | list, num: int) -> int | list:
...
# https://blog.logrocket.com/understanding-type-annotation-python/PHPUsing postifx function returnIntValue(int $value): int {
return $value;
}
// https://www.tutorialspoint.com/php7/php7_returntype_declarations.htm |
|
once again - checks are NOT types |
|
The prefix doesn't parse well by me, neither as a human nor a computer Also, for parity you would put the check BEFORE the keyword All in all, I think the syntax where return type follows the signature is more natural (maybe just cuz I think rust is cool) |
|
The following is already supported in Perl: my sub blah { ... }The following syntax is proposed as part of this project for adding data checks to variables: my Int $blah = ...;The most consistent way to add a data check to a lexical sub would thus be: my Int sub blah { ... }But what about non-lexical subs? our Int sub blah { ... } |
|
I actually wouldn't mind "our Foo sub {}"; it has a certain consistency to it. And that eliminates the need for the empty parens, right? Brackets that don't bracket anything are a pet peeve of mine. (I'm very fond of the way Perl almost never requires a "()" the way other languages do.) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Why not do:
similar to the existing
my TYPE VARLISTsyntaxie. a syntax similar to C unlike PHP, Python, TypeScript.
method ! VOID get (STR $key) { ... }Or for enhanced readability:
Source:
https://youtu.be/uT0S-jfO1mE
All reactions