For rust, it is probably the try (?) operator. Fundamentally, it's just syntax sugar for a match statement with an early return in the Error or None cases, but it really improves the ergonomics of dealing with Result and Option types.
Interestingly, there was once a solid effort to add a try operator to Go. While the proposal was quite well received, upon closer inspection it was realized it would be essentially useless in the real world as, given how the rest of the language works, you almost never would want to simply early return with the value received. The data revealed that the vast majority of the code in the wild that the syntax sugar woul…
Microfeatures I'd like to see in more languages
511–520 of 539 posts
Re: Microfeatures I'd like to see in more languages
#512Clojure’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).
Is that like using "continue" in most C-syntax languages?
Re: Microfeatures I'd like to see in more languages
#513Earlier quoted context omitted.
Yeah, but this is Windows we're talking about. Even the SCHTASKS program (kind of like /usr/bin/at) takes a date which is locale sensitive, making it absolutely useless for scripting. Check out this answer to a question about how to use it: https://stackoverflow.com/a/18730884
The language doesn't have to care about $PLATFORM, if the spec says dates in source are ISO 8601 they're ISO 8601 or they're invalid.
Re: Microfeatures I'd like to see in more languages
#514I have long wondered why Ruby's symbols aren't in every language.
Re: Microfeatures I'd like to see in more languages
#515Earlier quoted context omitted.
How many languages support kebab case with any Unicode dash that isn't the ASCII one? :)
Agda does, but it also supports a plain ascii hyphen in identifiers. It allows operator characters inside identifiers and requires spaces around operators otherwise (as proposed in the article). So you can use x-y as an identifier: x-y : ℤ → ℤ → ℤ x-y x y = x - y The Agda community also heavily uses unicode characters. I've even seen a unicode colon used for a custom syntax because the ascii colon was unavailable.
Wise move.
Finally a language from the 21 century.
Still sticking to ASCII is madness. Especially as most people on this planet don't use ASCII as their native char set.
Re: Microfeatures I'd like to see in more languages
#516The "Expanded Parameters blocks" is kind of supported in Kotlin. You can write a function like this: /** * @param arg the string to garble */ fun doThing(@NotEmpty arg: String = "default) In this example, "arg" is mandatory, or else it would have the type "String?", making it nullable. It obviously has a default value. It has an annotation that performs some validation, though admittedly that is a library and not a l…
Re: Microfeatures I'd like to see in more languages
#517Comments Section In Next Generation Shell I've experimented by adding section "arbitrary comment" { code here } and this is staying in the language. It looks good. That's instead of # blah section - start code here # blah section - end Later, since NGS knows about sections, I can potentially add section info to stack traces (also maybe logging and debugging messages). At the moment, it's just an aesthetic comments an…
C# has #region/endregion They are foldable in IDEs
I'm not sure this is the right approach…
Re: Microfeatures I'd like to see in more languages
#518Haskell has almost all of these. > Instead of writing 10000500, you can write 10_000_500, or 1_00_00_500 https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/nume... > Balanced string literals https://hackage.haskell.org/package/raw-strings-qq-1.1/docs/... > Generalized update syntax Use Lens. `fileName %~ max 2` > you can write the sequence 1, 2, … n-1 as 1.. Yup. `[1,2..n-1]` There's far more to it, you have acc…
You could likely build "automatic lifting" this macros.
"Extended parameter blocks" are just normal Scala method signatures.
You can use kebab-case (though with back-ticks).
Re: Microfeatures I'd like to see in more languages
#519Comptime. After having discovered Zig, I've been missing that feature in every other language.
As long as you're ending up with the same problems as in C/C++ it can be as great as it likes it will stay a language of the past.
Re: Microfeatures I'd like to see in more languages
#520I'd like to see the "in" operator from SQL in C-style languages. Something like: if(x in (null, 2, 3.14, foo(123)) { // }
That's a pretty std. feature I guess.