You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by "Mike Beckerle (Jira)" <ji...@apache.org> on 2021/08/30 20:59:00 UTC
[jira] [Commented] (DAFFODIL-2542) Change diagnostics to use string
interpolation
[ https://issues.apache.org/jira/browse/DAFFODIL-2542?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17406936#comment-17406936 ]
Mike Beckerle commented on DAFFODIL-2542:
-----------------------------------------
First, we should use the f"..." interpolator not s"...." because f supports type checking also.
The f interpolator provides type checking of numbers vs. strings e.g.,
```
val height = 1.9d
val name = "James"
println(f"$name%s is $height%2.2f meters tall") // James is 1.90 meters tall
```
Second, if we're going to advocate changing SDE/SDW and PE/UE messages to use string interpolation instead of SDE(string, args*) style, then I think we should be using a non-standard string interpolator that at least has the potential to support i18n some day without further code modification.
If we want to stub this by creating our own string interpolator that is exactly equivalent to the built-in f"...." interpolator for now, that would be ok with me.
This would get us both type-safety from the f interpolator and be i18n friendly for the future at the same time.
> Change diagnostics to use string interpolation
> ----------------------------------------------
>
> Key: DAFFODIL-2542
> URL: https://issues.apache.org/jira/browse/DAFFODIL-2542
> Project: Daffodil
> Issue Type: Improvement
> Components: Diagnostics
> Reporter: Steve Lawrence
> Priority: Minor
> Labels: beginner
>
> Our various diagnostics use a format string plus varargs to build a message. For example
> {code:scala}
> this.SDE("Some error message: %s", someArgument)
> {code}
> One downside of this approach is that there is no compile time validation of the format string and arguments. So if the the format strings and args don't match, it can lead to unexpected error messages or runtime errors.
> An alternative approach is to use string interpolation:
> {code:scala}
> this.SDE(s"Some error message: ${someArgument}")
> {code}
> This completely avoids the possibility of format string/var args missmatch.
> We should go through our diagnostic messages and switch to using string interpolation.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)