Live data from Hacker News

Microfeatures I'd like to see in more languages

buttondown.email

251–260 of 539 posts

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

#251

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

Nestable comment syntax is also nice. At least some MLs (eg SML) has it, that I know of. Indentation-sensitivity can also solve similar problems. (Indentation does not have to exclude requiring graphic termination. A formal language can require both. Or just a helpful tool.) (Also agree with 'kebab-case', although the name is new to me and a bit weird.)

What makes C-style comments unnestable?

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

#252
> Frink has special syntax for date values. You can write # 2001-08-12 # to mean the date 2001-08-12

Frink? Frink?

This Visual Basic erasure can not stand. The #-delimited date literal syntax has been found all over the VB family: Visual Basic, VBA, VBScript, and it persists to this day in Visual Basic .NET.

Of course, being a VB syntax, it's completely cursed. You can put

    # 01/05/2023 # 
in a VB file, and what date it represents will depend on what locale it's.. compiled? executed? evaluated? in? Maybe? Depending on which VB dialect you're in? Good luck. Some of those languages would also accept

   # 01/05/23 #
And they might even agree about what century it's in.

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

#253

Earlier quoted context omitted.

I don't understand the link with parent, nor why + would be bad, besides a) because language is naive about concatenation / allocation, and b) if the language allows / doesn't differentiate between a char 'x' and an integer, bc that would result in an integer addition instead of a concatenation.

If you manipulate strings in code using "+" (string concatenation symbol) from a user input you'd be in a world of hurt where you either do a lot of regex (which is ugly and unmaintainable) or you limit the user input to known characters only (which would be a bad user experience and later on your manager would ask you to lift such constraint anyway because they want to support a new feature from now on). Therefore y…

Not OP, but I'm still confused. Is this assuming that the language is naive in its implementation of string concatenation so it screws up Unicode?

I'm just not sure what the syntax has to do with the semantics of string concatenation.

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

#254

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…

That's actually a great point. Perl has so many syntactic sugars that it is a poster child for too much variety in ways you can write things. Making it much harder to read someone else's code.

Yeah, it's a trade-off that's not discussed enough, IMO. Most general programming advice is directed at "programming in the large", involving many people, over a longer period of time, and the maintainability issues that go with that.

But you give up something to get benefits in those areas. Making use of the expressive power of something like Perl is a wonderful sensation. The barriers between thought and making it happen are lower, and so you can be remarkably productive. It is also just more fun, I find, which has subtle and under-valued long-term benefits.

But yeah, agreed that comprehending someone else's Perl-fueled vision quest can be ... rough (:

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

#255

Earlier quoted context omitted.

That's actually a great point. Perl has so many syntactic sugars that it is a poster child for too much variety in ways you can write things. Making it much harder to read someone else's code.

Perl has so much syntactic sugar it's the poster child for syntactic diabetes, really.

"Syntactic sugar causes cancer of the semicolon." ― Alan J. Perlis

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

#256

Earlier quoted context omitted.

Ruby happily allows this and I can't recall it ever being an issue. It's no more prone to errors than `x` being greater than the number of elements. > arr = ["a", "b", "c", "d", "e"] > x = -2 > arr[x] => "d"

If you intended to calculate an index and you accidentally get len(arr), you get a runtime error. But if you accidentally get -1 you silently get the last element instead. Similar to the argument about signed/unsigned indices in low level languages.

If you calculated wrong you can land on positive-but-existing value just fine...

> Similar to the argument about signed/unsigned indices in low level languages.

Think that one has to do more with convenience where most of stuff uses int by default

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

#257
post #163

Earlier quoted context omitted.

If you have two functions abracadabra(foo) and foo.abracadabra() which do different things , you should rename one of those functions tbh.

The problem is when you have the functions: Square.computeArea() Circle.computeArea() Clearly these should do different things. I suppose "computeArea(shape)" does dynamic dispatch based on the type of shape? But you're still putting every function defined on every type in your entire codebase in a global namespace. It's not obviously awful but I'd definitely be a bit nervous about it.

I dunno, I kinda like that, add sum types and you can pass anything to computeArea.

The problem really starts when you have

typeA.func()

typeB.func(x)

typeC.func(x=default_value)

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

#258

Earlier quoted context omitted.

Both Lisp and Erlang have them, so they're much older than Ruby.

Presumably Erlang inherited them from Prolog, too.

I don't remember Prolog much, but since Erlang inherited very much, you're probably right.

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

#259
post #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.

you can do

    func sum(nums []int) (result int) {
        for _, n := range nums {
            result += n
        }
        return
    }
and it will work same as if you would do

    return result
As for omitting return entirely I hated it in every language where I saw it. It just feels wrong to not have return in functions that return stuff

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

#260

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

Personally, I found Ruby's symbols to be a source of bugs because they can easily get mixed up with strings. The article gives the example of dict[:employee_id]. But what happens if you serialize "dict" as JSON, then parse it again? The symbol :employee_id will be silently converted to "employee_id", which is treated as a different dict key from :employee_id. I found it was easy to lose track of whether a given dictionary is using the "keys are symbols" or the "keys are strings" convention, especially in larger codebases.
Post reply on HN