Live data from Hacker News

Microfeatures I'd like to see in more languages

buttondown.email

381–390 of 539 posts

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

#381

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

FWIW, Raku and XPath support kebap-case. If you really mean subtraction, you have to add whitespace.

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

#382

Earlier quoted context omitted.

When your code-base reaches a certain size, you cease using the IDE to find code and instead start using specialized tools, such as Lucene indexes so that grepping through code takes seconds rather than minutes. One of the bads of this is that using regex over an index is O(n) in comparison to the O(log(n)) of a normal index lookup.

Perhaps this special tooling can normalize numbers and other source code ambiguity.

It certainly seems possible to use a parser when building your index. It's a lot of work though.

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

#383
post #353

Earlier quoted context omitted.

In c# -1 % 2 == -1. Doesn't help.

It's a little verbose and can probably be reduced, but "((x % m) + m) % m" always works. Although it's probably not better than a check if x I do think it's quite odd and frustrating that modulo can return negative numbers and I don't really get the reasoning there, but there's probably a good reason I don't know about.

The only reason is that C does it that way. And C does it that way because machine code does it that way.

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

#384
post #92

Earlier quoted context omitted.

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

Coptic Small Letter Dialect-P Ni should work, looks like a hyphen. Go Playground: https://go.dev/play/p/kxgOcEWsznz https://www.compart.com/en/unicode/U+2CBB

Oh, neat catch!

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

#385

Earlier quoted context omitted.

C# has a very nice approach to this: indices aren't simple numbers, but values of type Index [1], which store both the offset and the direction, and can be implicitly created for plain ints. When you do want to index from the end, you use the unary ^ operator to create a reverse index. Thus, you can write things like a[^1] or a[0..^1]. But, more importantly, it means that any custom collection type can define an inde…

That's a lot of machinery which I feel is going to benefit relatively few people and cases. I suppose I should learn it just in case but my suspicion is that MS is adding extra stuff which they hope people will use which will act as a lock-in to C#. Ergo the benefit of this is to MS not to the end user ISTM.

Nim, which is not controlled by a corporation, does it the exact same way. The unary ^ operator applied to an integer creates a value of type BackwardIndex.

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

#386

Negative array subscripts. So a[-1] means the last element of an array, a[-2] means the second last, and so on.

Yes please, there was nothing on the article's list that particularly resonated with me but I really wish this was standard in every language.

The problem is that it adds runtime overhead and can cause silent bugs.

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

#388

Keyword and optional arguments (seen in e.g. Python, Bash with --flags, and OCaml) are my favorite language superpower. They make code more self-documenting and let you add add optional behaviors to functions. This makes it really easy to make concise, highly usable APIs.

Toit makes a lot of use of this, and uses the bash syntax.

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

#389
post #153

Earlier quoted context omitted.

Even C these days, although they chose ' instead of _ :-(

My guess is that they did that because there are real human languages where ' is used as a thousands separator.

There are also real human languages where a space is used as a thousands separator, and an underscore is kind of the programming equivalent of a space.

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

#390

Earlier quoted context omitted.

Surely if your language has custom indexes / ranges `Length(array)` is completely broken and the language provides something like "Index`Last" you can hook on? Because an array with indexes [3, 7) has length 4, but 4 is not the index of the last element.

That's what Ada does, yes. You'd let the array (or whatever collection) do the work for you: for I in A'Range loop A(I) = A(I) + A(I); end loop; Whatever the range is, this will work. If you really need the first and last elements or want to be explicit: Start := A'First; End := A'Last; And if the type of the range (since any discrete type can be used) doesn't support simple incrementing with +1 or similar, you can u…

And with its array slice mechanisms, Ada is one of the most easy/productive language to handle arrays.

Being able to give subarrays to a procedure and preventing buffer overruns everywhere, reducing screw-up scope everywhere is a superpower I didn't know I needed before starting writing proved parsers.

Post reply on HN