My favorite is uniform function call syntax. In several languages (Nim, Koka, D, …), you can always write bar.foo(baz) instead of foo(bar, baz) and vice-versa. Another one from Nim is the implicit result variable. Instead of having to do this: func sum(nums: seq[int]): int = var result = 0 for num in nums: result += num return result you just do this: func sum(nums: seq[int]): int = for num in nums: result += num It…
I think you can also do the second in Go with named returns, e.g. func sum(nums []int) (result int) { for _, n := range nums { result += n } } No clue if it's an idiomatic usage, and named returns always felt a little too magic for me.
Microfeatures I'd like to see in more languages
101–110 of 539 posts
Re: Microfeatures I'd like to see in more languages
#102Php supports kebab-case variables: ${"variable-name"}=123; Isnt it beautiful?
You can also put a newline in a variable name if you really want. Or a 0 byte.
Here's a demo. I've used the debugger because its "X" command can print the true name of the variable:
$ perl -d -e 1
Loading DB routines from perl5db.pl version 1.60
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
main::(-e:1): 1
DB ${"variable-name"} = 123;
DB ${"variable\nname"} = 456;
DB ${"variable\0name"} = 789;
DB X ~variable
$variable^@name = 789
$variable^Jname = 456
$variable-name = 123Re: Microfeatures I'd like to see in more languages
#103My favorite is uniform function call syntax. In several languages (Nim, Koka, D, …), you can always write bar.foo(baz) instead of foo(bar, baz) and vice-versa. Another one from Nim is the implicit result variable. Instead of having to do this: func sum(nums: seq[int]): int = var result = 0 for num in nums: result += num return result you just do this: func sum(nums: seq[int]): int = for num in nums: result += num It…
and vice-versa Doesn't the reverse pollute the function namespace? If every obj.fun() can be written as fun(obj), doesn't that cause ambiguity with a previously imported global function fun()?
Re: Microfeatures I'd like to see in more languages
#104> You can write # 2001-08-12 # to mean the date 2001-08-12, instead of writing something annoying like Date(2001, 8, 12) I like this article but oh man dates just trigger me. Such a missed opportunity to use an unambiguous date example like 2001-08-13
It would have been unambiguous in a world where we all agreed that both months and days start at 0 :)
Re: Microfeatures I'd like to see in more languages
#105My favorite is uniform function call syntax. In several languages (Nim, Koka, D, …), you can always write bar.foo(baz) instead of foo(bar, baz) and vice-versa. Another one from Nim is the implicit result variable. Instead of having to do this: func sum(nums: seq[int]): int = var result = 0 for num in nums: result += num return result you just do this: func sum(nums: seq[int]): int = for num in nums: result += num It…
and vice-versa Doesn't the reverse pollute the function namespace? If every obj.fun() can be written as fun(obj), doesn't that cause ambiguity with a previously imported global function fun()?
Re: Microfeatures I'd like to see in more languages
#106My favorite is uniform function call syntax. In several languages (Nim, Koka, D, …), you can always write bar.foo(baz) instead of foo(bar, baz) and vice-versa. Another one from Nim is the implicit result variable. Instead of having to do this: func sum(nums: seq[int]): int = var result = 0 for num in nums: result += num return result you just do this: func sum(nums: seq[int]): int = for num in nums: result += num It…
and vice-versa Doesn't the reverse pollute the function namespace? If every obj.fun() can be written as fun(obj), doesn't that cause ambiguity with a previously imported global function fun()?
Yes, although overloading can mitigate the issue.
Re: Microfeatures I'd like to see in more languages
#107Clojure’s loop expression hits this spot for me. It sets a recursion point to which you can jump using any logic inside the body you want, as long as it is from tail position. It’s like a while loop turned into an expression. I haven’t encountered any other way to write iterative expressions whose number of iterations isn’t known at the top (like map and reduce).
Re: Microfeatures I'd like to see in more languages
#108Php supports kebab-case variables: ${"variable-name"}=123; Isnt it beautiful?
locals()["kebab-case"]=123Re: Microfeatures I'd like to see in more languages
#109Earlier quoted context omitted.
and vice-versa Doesn't the reverse pollute the function namespace? If every obj.fun() can be written as fun(obj), doesn't that cause ambiguity with a previously imported global function fun()?
In Rust, it's still qualified by the type you're calling it on, which I assume is also the case in other languages.
Nope. Rust has an extremely restrictive form of UFCS. In fact officially it's not called UFCS, but "Fully Qualified Path syntax".
Re: Microfeatures I'd like to see in more languages
#110A lot of languages provide immutable variables only for class members or statics, but not for local variables.