Live data from Hacker News

Microfeatures I'd like to see in more languages

buttondown.email

11–20 of 539 posts

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

#11

Php supports kebab-case variables: ${"variable-name"}=123; Isnt it beautiful?

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

Probably any language that supports Unicode identifiers.

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

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

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

#13
post #4

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…

There are some cons to using `result`:

https://status-im.github.io/nim-style-guide/language.result....

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

#14
post #8

I have long wondered why Ruby's symbols aren't in every language.

Is it for performant reason ?

Symbols in Ruby are meant to be more performant that strings iirc. If I have symbol :a, then it's allocated once regardless of how many time it appears. As opposed to "a" which is reallocated every time.

I guess it's similar to Python having a single instance of small integers. PlayStation also experimented with caching small floats which gave them some perf improvements too, but I think wasn't as performant in all cases.

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

#16

Php supports kebab-case variables: ${"variable-name"}=123; Isnt it beautiful?

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.

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

#18

I have long wondered why Ruby's symbols aren't in every language.

Because in most languages they're not useful. Symbols are solutions to problems, some of which are:

1. mutable strings (ruby)

2. and / or expensive strings (erlang, also non-global)

If you have immutable "dense" strings and interning, and you automatically intern program symbols (identifiers, string literals, etc...) then symbols give you very little.

And then there's the slightly brain damaged like javascript, where symbols are basically a way to get some level of namespacing to work around the dark years of ubiquitous ad-hoc expansions so you're completely stuck unable to add new program symbols to existing types because you could break any page out there doing something stupid.

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

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

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

#20

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

for x in y: yield x

Job done

Post reply on HN