Live data from Hacker News

Microfeatures I'd like to see in more languages

buttondown.email

111–120 of 539 posts

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

#111
post #68
post #51

Earlier quoted context omitted.

Depends on the size of your codebase and how many people work on it. Once you have 20 years of code written full time by 200 developers in your monolith, finding the constants file out of 400 different subsystem's constant files for a given subsystem that you've never seen before can become a legitimate and challenging pain.

Totally true. I don't know if IDEs commonly have a feature like, "find this value, regardless of how it's expressed" (even better yet, fuzzily, to catch typos), but I think that's the proper general solution. It's a good idea to consider a constants file earlyish, while everything still fits in your head. I'd say in the case of such a sprawling system, make a constants module, and it can have different files for diff…

Then you have a problem with having to update both the constants module and the service that depends on it to change the service, and you need to handle packaging and distributing the module. Maybe if you have a monorepo where those issues are moot...

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

#112

Earlier quoted context omitted.

Chaining without nesting.

If you mean without closing parentheses, I think you can also do that in languages like Haskell with non-parenthetical function calls.

I'm not a Haskell user, but my experience with this in the Nix language is a bit mixed. It definitely works sometimes, but then you get a pileup of parenthesis nesting anyway, because the default is greedy and you have to control which functions get which arguments.

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

#113

Earlier quoted context omitted.

That's for languages that can't define arrays with custom start/stop indexes. But those that have custom indexes they can very easily expand/implement as helper class (for example array.indexFromLast(1) which means array[Length(array)]. This way you can have best of both worlds.

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.

Yes, then I would expect 'First and 'Last with the obvious meaning, and something like 'Range which returns an iterator of all indices.

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

#114
> roughly three classes of language features [...] 3. Quality-of-life features that aren’t too hard to add

I'd regrettably add another class, quality-of-life features which you'd have hoped weren't too hard to add, but because of past choices, now are.

Examples: Adding javascript-like dots a.b.c for Julia Dict's a[:b][:c] would conflict with "wasn't intended to be public but has been" Dict implementation fields, like .count . Adding { a,b | ... } instead of a less concise { |a,b| ...} for Ruby blocks, but for a yacc grammar conflict.

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

#115
post #49

Earlier quoted context omitted.

for x in y: yield x Job done

Also known as (in Python, that is): yield from y

They were providing a partial example, "yield from" does not actually do what the original poster asks about, it merely proxies the inner iterable.

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

#116

One of the best truly micro features I've seen recently (can't remember which langauge unfortunately - it wasn't a mainstream one), is general binary literal syntax of the form: 0x[de ad be ef 00] So much nicer than the usual condensed format. And I think it'd be valid syntax in any language that allows binary integer literal.

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.

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

#117
post #15

> Instead of writing 10000500, you can write 10_000_500, or 1_00_00_500 if you’re Indian. I hate this so much. It means I can't grep for a constant.

You already can't, because someone can write the constant in hex, or even (shudder) octal.

Or like this:

   const int WAIT_TIME_MICROSECONDS = 42 * 1000 * 1000; // 42 seconds

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

#118
post #110

local const variables like JavaScript has them. You can declare variables with „let“ (mutable) or „const“ (immutable). This is really great when reading code, because you never have to check if some code may change the variable at some point. And you usually declare most variables as const. A lot of languages provide immutable variables only for class members or statics, but not for local variables.

I really like Scala’s `val` vs `var`.

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

#119
post #90

Earlier quoted context omitted.

This so hard. A constant that replaces a magic number like 5 that is ungreppable, or a constant for a precise number like the physical constants - sure. A constant that replaces a number like 404 or 500 that you want to be able to easily grep across heterogenous code bases for? Pass.

Is that 500 the HTTP error or 500 the adhoc limit we put on the number of user uploads or a 500, representing half a kilobyte?

I'll take the momentary ambiguity in some cases (usually quickly resolved by line context and file name) over having to manually hunt down 5 different projects' inconsistently named constants to do 5 different greps any day of the week.

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

#120
post #81

Earlier quoted context omitted.

Kotlin is so close on so many things, but then keeps messing up. arrayOf(1, 2, 3) - why not [1,2,3]? emptyArray() - why not []? mapOf("key" to "value") - why not {key => value}? These are all solved problems. Why would they make up some harshly suboptimal syntax?

I am not that familiar with Kotlin, but these seems better than the syntax primitives from a language design perspective (I greatly recommend the “Growing a language” presentation done by Guy Steele), these are ordinary functions that are well-known from other parts of the language, not an added “hack” that has a one-off use. If you were to use a concurrent hashmap implementation you no no longer can use the syntacti…

Interesting, I think the exact opposite :)
Post reply on HN