-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Rename Expr.valueOr{Error => Throw}
#12022
Conversation
To be consistent with the error reporting API it should be |
@nicolasstucki Sure! So is changing everything to |
@@ -53,7 +53,16 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => | |||
* Emits an error and throws if the expression does not represent a value or possibly contains side effects. | |||
* Otherwise returns the value. | |||
*/ | |||
def valueOrError(using FromExpr[T]): T = | |||
@deprecated("Use valueOrThrow", ">3.0.0-RC2") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If 3.0.0-RC2
gets bumped to 3.0.0
then we should have >3.0.0
. It would probably be 3.1.0
as we this is a binary incompatible change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we keep this PR open until we're 100% sure about the plans for RC3? Then I can update this to either 3.0.0-RC2
or 3.0.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I just set this to 3.0.0
so that it's ready to go if it's correct. (Other PR feedback addressed.)
How about |
I do like |
I think |
xxxOr{Error => Throw}
Expr.valueOr{Error => Throw}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent we still need to have a name that coincides with error reporting. Throwing is only half of what the users need to know about this method. I believe the best option we have to keep everything consistent and clear is to rename as follows
valueOrError -> valueOrErrorAndThrow
report.{throwError -> errorAndThrow}
The advantages of this naming are
- Consistent name suffixes
xxxErrorAndThrow
- Both the error reporting and the throwing are explicitly stated
report.e
will show autocompletion for all variants oferror
anderrorAndThrow
- The longer name of
valueOrErrorAndThrow
will help users to usevalue
instead and handle the error with nicer domain-specific error messages.
-- def valueOrError(using FromExpr[T]): T =
++ def valueOrErrorAndThrow(using FromExpr[T]): T =
val fromExpr = summon[FromExpr[T]]
def reportError =
val msg = s"Expected a known value. \n\nThe value of: ${self.show}\ncould not be extracted using $fromExpr"
-- reflect.report.throwError(msg, self)
++ reflect.report.errorAndThrow(msg, self)
given Quotes = Quotes.this
fromExpr.unapply(self).getOrElse(reportError)
This is a change that should be backported to the release-3.0.0
branch after it is merged.
@@ -53,7 +53,16 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => | |||
* Emits an error and throws if the expression does not represent a value or possibly contains side effects. | |||
* Otherwise returns the value. | |||
*/ | |||
def valueOrError(using FromExpr[T]): T = | |||
@deprecated("Use valueOrThrow", "3.0.0") | |||
def valueOrError(using e: FromExpr[T]): T = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def valueOrError(using e: FromExpr[T]): T = | |
def valueOrError(using FromExpr[T]): T = |
No reasonable person will think that a computation can abort by returning Likewise, The reason why I'm saying "use a different verb than throw" is that within a single API, one is free to use some bespoke terminology. If within that API, "aborting" always means "throw an exception that is intended to be caught by whatever is running quotes", then we get a method that has a succinct name, tells familiar users everything they know, and makes unfamiliar users look at the method docstring and learn something about the API. |
This naming change should not be rushed. We can do it after 3.0. |
@abgruszecki That logic doesn't make sense to me at all. "Throw" is clear because it will throw an exception. There's no other interpretation of that. These ideas that using ambiguous terminology is good because it will encourage people to read the docs is unrealistic and exactly the opposite of what I believe the goal should be. Why not just choose the 100% clear verb? |
@japgolly let me quote myself:
With Also, I'd expect that the vast majority of Scala users can jump to a method's definition with a single click. |
@abgruszecki Ah ok I see what you're saying. So if it's
Woah noooo no no no no I'd put that in the false assumptions bucket if I were you. Metals and to a lesser degree Intellij, very regularly fail to jump to the source of stuff on the classpath for me. Sometimes I waste 20 minutes trying to re-import and restart everything, and clear out what cache directories I can find. I'm a regular counter-example to assuming this works for all people all the time, and I can't imagine I'm the one person in the world who experiences these problems. I've been writing Scala for around 10 years and it's consistently been my experience that inline documentation is completely broken and unfortunately, ultimately useless. What's really great is that Metals keeps getting better and better, and ScalaDoc looks to be getting some proper love for Scala 3, so I'm optimistic about the future! Sadly we're not there yet though, which is why I want to add some caution to your assumption. |
The alternative is to take 30 seconds out of the IDE and just look at the docs online. This is a method of the standard library and it does not depend on the project build anyway. |
We are probably going with |
Tiny change to improve clarity a bit.
Error
is a noun and it's a legitimate interpretation to think "oh, maybe this can return an error". WithThrow
it's clear and unambiguous that an exception will be thrown.