Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
macro_rules! assume {
($r:tt) => {
$r.unwrap_or_else(|e| eprintln!("{e:?}"));
}
}
In case anyone missed this antipattern from Rust -
I have entirely too many macros. I have one for mapping shared enum values, specifically for use in a match statement. I have a macro that's just Option::unwrap_or but with support for control flow commands such as continue or return in the null path.
-
@Lensflare it is ok in this context. Rust uses single letter when there is only one error also
-
@darksideofyay I don‘t know about JS but it‘s still considered bad practice in the languages that I know.
And I agree: Doesn‘t matter if it‘s common and known by most devs, it‘s still bad imo. Just use "error". It‘s not that long. -
@Lensflare sure, I'm just saying it's still readable, so I'm not that offended by it. to me e for error is like i for iteration, it's very commonplace
-
@Lensflare Even if we say that "e" is a bad name, why would "error" be any better? This is an argument to a catch block, so the fact that it is an error is already evident. Just putting more characters in the name isn't going to improve readability. If we wanted to give it a better name, it should refer to what the error indicates and most likely take the form of a past perfect verb such as "buzzed" or "eBuzzed" (because JS is a dynamically typed language so JS devs often rely on variants of hungarian notation to couple type information to variables somehow).
-
@lbfalvy you got a point there. But in the case that the error is really generic, "error" is fine.
-
@Lensflare I think that if error is fine then so is e, all readers who know how to code even just a little bit associate e to error instantly.
-
@lbfalvy I disagree. I’ve seen e also being used for "event".
It may be true for JS, though. -
@Lensflare "ev" is more common for events, but the ambiguity exists nonetheless so you convinced me that "e" should not be used.
-
@Lensflare especially in a Result<Event, Error> this will confuse the hell out of you, if suddenly both matches provide e.
And especially in a language like rust, you should be clear about intent.
horror story in two lines
```
} catch (e) {
console.log(e)
}
```
rant