Live data from Hacker News

Microfeatures I'd like to see in more languages

buttondown.email

1–10 of 539 posts

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

#2
With regard to strings, they give a good example in Lua, but oh boy wait until this person hears about Perl (:

There's a whole section in the manual [1] for string quoting operators (qq, qw, qx, ...)

In general, I feel like Perl is one of those languages that has a high amount of these "quality of life" syntactic features, and helps make it enjoyable to write, once you get over the learning curve.

[1] https://perldoc.perl.org/perlop#Quote-Like-Operators

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

#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 saves so much time and I'm disappointed that more languages don't have it.

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

#6
I wrote a small DSL for easy compilation to SQL that included some similar features. It included datetime literals, but they were specified as just a string prefixed with "d".

    d'2020-02-20'
I also tried to make it so that every comparison had both english and symbol representations, a range syntax, and an approximation/match comparison (e.g. "=~", "!~") which could work with both floating point numbers and strings properly.

I found this useful, and wish it was in more languages.

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

#9
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…

I think you can also do the second in Go with named returns, e.g.

    func sum(nums []int) (result int) {
        for _, n := range nums {
            result += n
        }
    }
No clue if it's an idiomatic usage, and named returns always felt a little too magic for me.
Post reply on HN