Live data from Hacker News

Microfeatures I'd like to see in more languages

buttondown.email

151–160 of 539 posts

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

#151
Some from Raku (formerly Perl 6) that I really like:

* sub MAIN:

sub MAIN(Int $x, :$verbose) { }

generates a command line parser that expects an Integer plus an optional named switch --verbose

* It has named params (as seen above), and there are abbreviations: instead of thing => $thing you can write :$thing to avoid duplicating the name (:thing also exists, though it create a pair "thing" => True, so ruby lovers need to be careful :D )

* junctions for quick conditionals/validation: 0 * this is a probably debatable, but: if you use a * as a term, it will create a lambda for you, so *+2 is similar to sub ($x) { $x + 2 }

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

#152
post #100

Earlier quoted context omitted.

Out of interest, how often do you do this, and what are the semantics of the numbers you're grepping for? I literally can't remember a time I've ever tried to grep for a number.

I've done it for error codes but that was awfully cursed

But you need to search for both hex and dec codes for that

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

#153
post #116

Earlier quoted context omitted.

A lot of languages allow underscores in numeric literals. Something like 10_000. You can put them anywhere and they get ignored. I don’t know if they also allow it for hex numbers.

> I don’t know if they also allow it for hex numbers. They do e.g. Python >>> 0x_ab_cd_01_23 2882339107 or >>> 0b_0010_0100 36

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

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

#154
post #138
post #121

Earlier quoted context omitted.

Nowadays even Java will do that, var list = yourFunctionReturningThatSet();

Also on a function? var getDate() { return „no date“; }

That is often considered undesirable because it makes code less clear and compilation errors inscrutable.

For instance the rust developers consciously decided to remove that from the language, named functions must be fully typed.

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

#155

Earlier quoted context omitted.

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

I find Mathematica code unreadable full stop. Its convenient when writing though.

I see Mathematica as a shell for math. You can write long programs or modules in it, sure, but very often you're simply typing up a couple of lines to check some computation or visualize an expression which you won't even save, in which case readability is secondary.

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

#156
post #131

> [In Chapel] there’s the config keyword. If you write config var n=1, the compiler will automatically add a --n flag to the binary. As someone who 1) loves having configurable program, and 2) hates wrangling CLI libraries, a quick-and-dirty way to add single-variable flags seems like an obvious win. Letting people define configurable variables at their call site is incredibly valuable, even if you don't have compile…

> The first time it's seen in any environment, it thread-safely inserts-if-not-present the default value into a key-value storage That seems like a great way to get amazingly hard to replicate bugs or odd behaviours if different subsystems use different values for the default.

You'd just need to have a mutex lock on the values. That could be slow, but you probably don't want to have a config flag in a hot loop anyways. :)

In Nim you can do compile flags which let you set constants so you avoid the problem:

    const myLibraryVersion {.intdefine.} = 3

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

#158

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

if it works on literals only, so a[x] doesnt work if x is negative, then ok.

otherwise seems like an errors that are hard to spot.

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

#159

Elixir’s testing library uses meta programming to show the code that fails and what the values were at both sides of a comparison. IE a = 1; b = 2 assert a == b Will fail with error like: Assertion failed, a == b Left is 1 Right is 2 So you don’t have a bunch of assert-functions; you just assert anything and it will spit out a decent error.

Yes! That feature is great. I got used to it in Elixir and Nim provides it as well. It's one of those little things that makes programming nicer.

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

#160
What I'd like to have brought back is basically the extended version of the numbers/kebap-case: Ignore white space in constants and identifiers if possible, like Algol-68 did.

That means you can write your number as "1 000 000" and put it in the variable "one million", and then feed that to your function called "withdraw money".

Yes, sure, makes it harder to grep. Here's a nickel, get a better grep tool (or wrapper thereof).

Post reply on HN