Live data from Hacker News

Microfeatures I'd like to see in more languages

buttondown.email

51–60 of 539 posts

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

#51
post #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 i…

Depends on the size of your codebase and how many people work on it. Once you have 20 years of code written full time by 200 developers in your monolith, finding the constants file out of 400 different subsystem's constant files for a given subsystem that you've never seen before can become a legitimate and challenging pain.

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

#52

I love all the sugar of Kotlin, but there is one thing I miss, and it is the indexing of arrays of Python when pulling out part of an array.

Kotlin is so close on so many things, but then keeps messing up.

arrayOf(1, 2, 3) - why not [1,2,3]?

emptyArray() - why not []?

mapOf("key" to "value") - why not {key => value}?

These are all solved problems. Why would they make up some harshly suboptimal syntax?

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

#53
post #28

Earlier quoted context omitted.

Tail call optimization can get you that, too. If you've written Scheme and/or gone through SICP you might be familiar with this: you write a recursive function, with the recursive function call as the last thing the function does ('tail-recursion'), and the compiler/runtime is able to optimize those recursive calls out rather than consuming one stack frame of space per call ('tail call optimization'). Clojure has loo…

Interestingly, I almost prefer Clojure's `recur` semantically. Means you don't have to change the function name twice if you rename it, and it's hard to miss that you're recursing.

If that's your worry then you can probably use the site's namesake. Though simple recursion is generally easy to spot.

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

#55
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.

Mathematica uses a lot of syntactic sugar. You will find all Mathematica code unreadable until you've learned to read it; `//` is no exception.

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

#56
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.

1_?0_?00_?0_?500 yes it sucks

That’s not enough — the underscores can appear anywhere, so you need to cater for 500000_0 and 5_0_0_0_0 etc. basically an optional underscore between each digit.

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

#59

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

And error unions with corresponding semantics. And explicit casting requirements. And @TypeInfo. And no hidden allocations. And probably like 4 or 5 other things I'm not thinking of right now.

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

#60
Agree with kebab-case.

> Most languages have multiline literals, but what makes the Lua version great is that the beginning and ending marks are different characters. This solves the infuriating “unnestable quotes” problem string literals have, and you don’t have to escape all your literal \s.

That paragraph also uses “nestable marks”.

Post reply on HN