Live data from Hacker News

Microfeatures I'd like to see in more languages

buttondown.email

31–40 of 539 posts

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

#32
post #15

> Instead of writing 10000500, you can write 10_000_500, or 1_00_00_500 if you’re Indian. I hate this so much. It means I can't grep for a constant.

If you have constants repeated throughout the codebase, you can pull them into a constants file, and then you can go to that file, navigate to the definition of interest, and use your IDE of choice to find usages.

You'll also be able to give these constants semantically significant names, and comment next to them providing derivations or citations. And of course, if it's a mistaken or outdated value, you can change it one place and apply it everywhere.

Consider that, if you were debugging a problem with this constant, and the problem was caused by someone having made a typo in one of it's usages (eg having typed 1000500 instead of 10000500, a mistake that's more difficult to make of you have better ways to format numbers [did you have to look back and forth to find the mistake? I did]) - your regex would fail to find it, even if there were no ambiguity about the format it was written in.

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

#33
post #16

Earlier quoted context omitted.

How many languages support kebab case with any Unicode dash that isn't the ASCII one? :)

At the moment, the only one I know for sure is Agda. I suspect java would work as well, not sure about golang unicode var naming.

play.golang wouldn't let me use figure (‒, U+2012), endash (–, U+2013) or emdash (—, U+2014) in a variable name directly.

But then the spec[1] says that only code points characterised as "Letter", an underscore, or characterised as "Number, decimal digit" are valid.

[1] https://go.dev/ref/spec#Identifiers

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

#34

> 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

Year-day-month would be a truly cursed assumption for a format

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

#37
post #17

I really liked the postfix and prefix notation in Mathematica. These three all mean the same: f[x] f@x x // f It matches the flow of thought more naturally when hammering out a couple of one-liners.

How is that third one readable at all? I’d assume it meant integer division.

[deleted]

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

#39

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

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

`unfold`, Rust's `loop`, generators, working tail recursion elimination (the lack of which loop/recur is a workaround for)

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

#40
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 access almost a SQL-like sublanguage.

> Symbols

In Haskell you use hash has a prefix instead of colon.

Haskell sadly does not do automatic lifting, no extended parameter blocks, and no kebab-case.

Post reply on HN