-
-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
min/max <?
/ >?
expressions
#20624
Comments
#20626 ...just trying it on! |
Maybe it's because I don't worship at the altar of C++, but I don't see how these messes of random punctuation are more readable than the status quo. |
Suggesting that |
I feel like you didn't read my post, either. |
The question mark because it's short-hand for the
You don't need to repeat |
If we had more Andrei originally also proposed the "elvis operator" |
It's meaningful, it's logical, and I just explained it twice.
It's not C++. This isn't in C++. I already said that too. |
Don't complain to me about your choice to reply to the same post twice with the same content. |
🤨 Now I'm just confused... |
Thanks for posting the suggestion. I want to underscore an important point. Introducing I agree that importing std.algorithm.comparison can be a bit heavyweight. That module imports the usual ghastly panopoly of other modules:
But all is not lost. It turns out that the definition of
I was pleasantly surprised to see that! It's a thing of beauty, ain't it? In fact, it will still work as:
Who wouldn't be proud to take that to the Prom? As a bonus, it only evaluates each argument once. As for debugging issues, if it's inlined there's no further issue with that. The same goes for using Therefore, unless I made an egregious error in this analysis, I suggest just adding that line to your code. |
This bugs me every few weeks for decades... I still want this just as much as the first say it ever came up for me:
It's really annoying to import a module for
min
/max
, it feels so 'heavy' for such a trivial operation. It's also annoying that they're functions; you have to step-in/step-out etc while debugging code, and they are so frequently used in hot-loops, while calling functions in debug/unoptimised code just slows it down needlessly, even more than unoptimised code already it...C++ has a non-standard language extension, and I think it's also present in C# that adds a min/max operator. It is this:
a <? b
anda >? b
, which simply expandsa < b ? a : b
anda > b ? a : b
.I desperately want these in D... they're just so nice and readable, don't require bulky imports, efficient in debug builds, nicer when working in the debugger, etc...
I know these are all minor nuisances, but the practical result is that I very rarely actually import
min
/max
, and almost always just write the expression outa < b ? a : b
, which damages code readability, particularly whena
orb
are long-ish expressions.This could be implemented with trivial lowering. It's lame when other languages have nice QOL features that we don't have in D, especially like this which are just cosmetic and pose no threats.
The text was updated successfully, but these errors were encountered: