-
Notifications
You must be signed in to change notification settings - Fork 858
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
Allow multiplication in number values #1036
Comments
The main reason I'd like unit suffixes is to clarify what unit something is. In your examples you still need to clarify that cache-time-s is in seconds with an awkward key name, and cache-size could conceivably be in bytes, K, or M, so that comment is more or less mandatory. So you still need either a somewhat awkward key name ( The biggest issue with suffixes is one of compatibility. I haven't looked at it in depth since so maybe that's resolvable, but if not maybe multiplication is the best we can do. Although I'm not entirely convinced that this:
is strictly better than:
Neither reads particularly naturally, and in both cases you need that "# 1G" comment, although I suppose you could eliminate that by doing:
But meh; it's an ugly key size and I still need to mentally do "bytes → kb → mb → gb" in my head. So I don't think I'd be in favour of this, and I'd prefer to think of a way to solve the compatibility issue. |
Thanks for the suggestion, @J-Vernay. I'm a little concerned about what arbitrary integer multiplication may lead to. It suggests that arbitrary arithmetic of any type will be viable later. We need to avoid that. Unless we can point to several more use cases where different multipliers are involved. And even then, it wouldn't address @arp242's concerns regarding compatibility of units of measure, which is a much more complicated matter. |
I think that this is a good suggestion and summary but I want to argue against having expressions in TOML. When you parse the file the programmer expects to get the result of the expression. Not some expression object. I think we can all agree on that. This means it falls to the parser to evaluate the expressions. You might say a simple multiplication does not hurt, but it does. It means you have to parse the expression and actually execute it recursively until you can't anymore. People will naturally want to expand the expression language once * is added. First with other infix math functions like + and ^ or ** or % and () and then with things like sin and cos and constants like pi or tau. Before you know it every toml parser needs to have a full math expression evaluator inside of it. I believe expressions turn a configuration language into a dsl and toml should be a configuration language and not a dsl. Keep it simple! |
Hello,
I suggest a common solution for both issues #514 (Add a duration/timedelta type) and #912 (Add nicer syntax for file sizes): allow multiplications where integers are expected, output an error if the computation would exceed the 64-bit range.
This design would solve these points:
-ms
,-days
, etc), and the user can use multiplication to express the value in a clearer wayOne open question is whether floats should be allowed in multiplications? What type to use for computation when both integers and floats are present? What about precision regarding float computations? Simpler choice would be to say that only integers can be multiplied.
Have a nice day,
Julien Vernay
The text was updated successfully, but these errors were encountered: