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.htm TypeScriptUsing 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.html PythonUsing 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 |
Beta Was this translation helpful? Give feedback.
-
once again - checks are NOT types |
Beta Was this translation helpful? Give feedback.
-
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) |
Beta Was this translation helpful? Give feedback.
-
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 { ... } |
Beta Was this translation helpful? Give feedback.
-
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.) |
Beta Was this translation helpful? Give feedback.
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 VARLIST
syntaxie. a syntax similar to C unlike PHP, Python, TypeScript.
method ! VOID get (STR $key) { ... }
Or for enhanced readability:
Source:
https://youtu.be/uT0S-jfO1mE
Beta Was this translation helpful? Give feedback.
All reactions