Earlier quoted context omitted.
1_?0_?00_?0_?500 yes it sucks
That’s not enough — the underscores can appear anywhere, so you need to cater for 500000_0 and 5_0_0_0_0 etc. basically an optional underscore between each digit.
Microfeatures I'd like to see in more languages
61–70 of 539 posts
Re: Microfeatures I'd like to see in more languages
#62Negative array subscripts. So a[-1] means the last element of an array, a[-2] means the second last, and so on.
Re: Microfeatures I'd like to see in more languages
#63> 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.
Re: Microfeatures I'd like to see in more languages
#64Sounds like a great way to make unreadable code
#define STANDARD_EXP_PARAMS ...
// I hit gotodef on func(...) and got here. What are the arguments?
void func (STANDARD_EXP_PARAMS) {
// ... long function body ...
x = y; // What is the type of x? Is it an argument or a local?
}
I'd really be irritated if someone ever used this feature, optimizing for lines written is shaky territory to begin with. When it's at an interface boundary it's not excusable. NB4 "use an IDE" - requiring an IDE to make code legible is dumb, and I'm an IDE shill!Re: Microfeatures I'd like to see in more languages
#65Earlier quoted context omitted.
Interestingly, I almost prefer Clojure's `recur` semantically. Means you don't have to change the function name twice if you rename it, and it's hard to miss that you're recursing.
If that's your worry then you can probably use the site's namesake. Though simple recursion is generally easy to spot.
Re: Microfeatures I'd like to see in more languages
#66I really liked the postfix and prefix notation in Mathematica. These three all mean the same: f[x] f@x x // f It matches the flow of thought more naturally when hammering out a couple of one-liners.
How is that third one readable at all? I’d assume it meant integer division.
// Column
Useful where the function in question is an "afterthought".
Re: Microfeatures I'd like to see in more languages
#67> If you look at something like numpy functions, so many of them share the exact same parameter definitions. What if you could write def log(standard-exp-params) instead of having to write them out every single time? They're not actually written out every time, the issue is mostly documentary (and it would be nice if Python or Sphinx ever had a good solution). And numpy actually has a bunch of generators for that e.g…
default_args = ('x', 'y', 'z')
default_kwargs = {'p': 'p', 'q': 'q', 'r': 'r'}
def printer(x, y, z, /, *, p, q, r):
print(f'x={x} | y={y} | z={z} | p={p} | q={q} | r={r}')
printer(*default_args, **default_kwargs) # x=x | y=y | z=z | p=p | q=q | r=r
EDIT: Formatting.Re: Microfeatures I'd like to see in more languages
#68Earlier quoted context omitted.
If you have constants repeated throughout the codebase, you can pull them into a constants file, and then you can go to that file, navigate to the definition of interest, and use your IDE of choice to find usages. You'll also be able to give these constants semantically significant names, and comment next to them providing derivations or citations. And of course, if it's a mistaken or outdated value, you can change i…
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.
I'd say in the case of such a sprawling system, make a constants module, and it can have different files for different topics. But keep them all together. Code style is an engineering tool you can use to prevent problems.
But I do understand this is cold comfort for those working on systems where the decision around this were made 15 years ago, and there's no possibility of refactoring the constants. That's quite annoying.
Re: Microfeatures I'd like to see in more languages
#69Negative array subscripts. So a[-1] means the last element of an array, a[-2] means the second last, and so on.
Re: Microfeatures I'd like to see in more languages
#70My 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…
and vice-versa Doesn't the reverse pollute the function namespace? If every obj.fun() can be written as fun(obj), doesn't that cause ambiguity with a previously imported global function fun()?
Right, I'll show myself out...