Live data from Hacker News

Microfeatures I'd like to see in more languages

buttondown.email

511–520 of 539 posts

Re: Microfeatures I'd like to see in more languages

#511

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…

You have things a bit backwards. The try operator was not conceived until after sum types and traits were already stable parts of the language. The addition was simple, didn't really alter the language in a meaningful way and is almost purely syntactic sugar meant as a quality-of-life improvement for users. (ie. it hits pretty every single point in the article's definition of microfeatures)

Re: Microfeatures I'd like to see in more languages

#512

Clojure’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?

Only if you could pass parameters to "continue" (which you can't).

Re: Microfeatures I'd like to see in more languages

#513
post #371

Earlier 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.

I think the argument here is that VB is cursed because Windows is cursed; it inherited the bias toward cursedness. Of course other languages can choose to do better.

Re: Microfeatures I'd like to see in more languages

#515
post #98

Earlier 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.

> The Agda community also heavily uses unicode characters.

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

#516

The "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…

As with almost all "Kotlin features" this is a direct rip off from Scala, where the signature would look almost identical (besides the fun keyword).

Re: Microfeatures I'd like to see in more languages

#517
post #336
post #307

Comments 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

And the result is people writing 10k LOC files.

I'm not sure this is the right approach…

Re: Microfeatures I'd like to see in more languages

#518

Haskell 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…

Same goes for Scala.

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

#519

Comptime. After having discovered Zig, I've been missing that feature in every other language.

Zig would be great if it took security more serous.

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.

Post reply on HN