3 ms·
if `str` is too short, surely `int` is, too: function fibunacci(integer index) { if (index <= 1) { return 1; } else {
by Derbasti 13y ago
if `str` is too short, surely `int` is, too:
function fibunacci(integer index) {
if (index <= 1) {
return 1;
} else {
return fibunacci(index-1) + fibunacci(index-2);
}
}
compared to:
fn fib(int n) {
if (n <= 1) {
return 1;
} else {
return fib(n-1) + fib(n-2);
}
}
Personally, I prefer `fn`, `int`, and `str`. I actually think that the short names are a nice way of distinguishing between built-in keywords (abbreviated, like `str`), and user-defined names (typically whole words). Also, short names are useful since they can be used as pre/post-fixes to function names like `strsplit`.
- gmjosack 13y agoyour comparison isn't fair. you're making an argument against fn/int vs function/integer but the largest difference in the code is between index and n. I prefer the version with a longer variable name despite the length. also shouldn't the returns be unnecessary here since the conditional is an expression?
- oscargrouch 13y agoi think 'fn' is too much minimalism.. better 'fun' or even 'func' .. but maybe they wanted to distinguish the sintax from Go's 'func' int -> int (ok) str -> string but anyway.. nothing that can prevent someone to enjoy the language.. but the 'fn' for me is the most odd.. getting used to it