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…
Microfeatures I'd like to see in more languages
111–120 of 539 posts
Re: Microfeatures I'd like to see in more languages
#112Earlier 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.
Re: Microfeatures I'd like to see in more languages
#113Earlier 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.
Re: Microfeatures I'd like to see in more languages
#114I'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
#115Re: Microfeatures I'd like to see in more languages
#116One 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.
Re: Microfeatures I'd like to see in more languages
#117> 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.
const int WAIT_TIME_MICROSECONDS = 42 * 1000 * 1000; // 42 secondsRe: Microfeatures I'd like to see in more languages
#118local 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.
Re: Microfeatures I'd like to see in more languages
#119Earlier 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?
Re: Microfeatures I'd like to see in more languages
#120Earlier 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…