8000 Add invalid float examples by marzer · Pull Request #760 · toml-lang/toml · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add invalid float examples #760

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

Merged
merged 1 commit into from
Jul 8, 2020
Merged

Add invalid float examples #760

merged 1 commit into from
Jul 8, 2020

Conversation

marzer
Copy link
Contributor
@marzer marzer commented Jul 3, 2020

Clarifies 'floats' section to explicitly demonstrate that omission of integer or fractional+exponent parts isn't legal (closes #759).

@marzer
Copy link
Contributor Author
marzer commented Jul 3, 2020

I'm not married to the wording here. Being both clear and concise about this particular point leaves a lot of room for bike-shedding.

@ChristianSi
Copy link
Contributor

Complementing my comments above I just noticed that the invalid floats example should be moved after the paragraphs explaining how fractional part and exponent part look like, that is in front of the sentence "Similar to integers, you may use...".

@ChristianSi
Copy link
Contributor

I still consider the first sentence added by the PR as redundant. If I say: "X consists of A followed by B and/or C", then, in my mind, this clearly means that, when talking about X, A will always be there, and at least one of B or C will too. What's unclear about that?

Admittedly saying the same thing twice is not so bad and teachers do it quite often – it may help with learning. So I'm not strictly opposed to adding the new sentence – but still feel that, since the first sentence of the same paragraph already says as much and since the new example (added by this PR) makes everything crystal-clear, it would be better to leave it out for the sake of brevity.

The rest of the PR is now fine; however, I would still propose to insert the new text ("Note that the decimal point..." and the following example) above the sentence "Similar to integers, you may use..." (leading to the flt8 example) rather than below it. Since the text before that explicitly speaks about the fractional and exponent parts it feels more logical to have the new text there; the underscores issue is something else again, hence it would prefer to see it afterwards.

@marzer
Copy link
Contributor Author
marzer commented Jul 5, 2020

I still consider the first sentence added by the PR as redundant. If I say: "X consists of A followed by B and/or C", then, in my mind, this clearly means that, when talking about X, A will always be there, and at least one of B or C will too. What's unclear about that?

It's not a hypothetical problem; I'll remind you again that I made this PR as a result of a real experience I had personally. I've spent a lot of time reading this spec and still the nuance of that point was a surprise to me since I came in with a programming-oriented preconception of what a 'float' is and how it may be represented. My natural feeling was one of "oh I know this!" and I missed a small but significant detail because of it. This sort of mental hop-scotch phenomenon is not unique to me or this situation, mind you; you would have fallen victim to it countless times in your own life, as has everyone. If being a touch more explicit than you feel is necessary helps solve this problem in this particular case going forward, then it's not redundant at all (insofar as redundancy implies waste).

I would still propose to insert the new text ("Note that the decimal point..." and the following example) above the sentence "Similar to integers, you may use..."

Sure, why not.

@eksortso
Copy link
Contributor
eksortso commented Jul 6, 2020

The redundancy doesn't bother me, except it's not technically correct. Leaving off both the fractional part and the exponent part is actually not invalid, but only because doing so makes the value an integer, not a float. Integers are valid TOML, but the consumer of the value could complain if it was expecting a float. So I'm not sure how to best rewrite that latter phrase.

@marzer
Copy link
Contributor Author
marzer commented Jul 6, 2020

@eksortso 1. is an example of leaving both off while not being an integer.

Strictly speaking you could argue that the presence of a decimal point implies a fractional part (which it does in TOML's grammar), and omitting the digits of the fractional part just means it's ill-formed, though given it's valid in other languages that consider the decimal point it's own entity in the grammar etc there's still ambiguity when coming from those contexts.

@eksortso
Copy link
Contributor
eksortso commented Jul 7, 2020

@eksortso 1. is an example of leaving both off while not being an integer.

I've been using toml.abnf for the definition of floats, and it explicitly includes the decimal point with the fractional part. Here's the section of that document that's currently relevant:

float = float-int-part ( exp / frac [ exp ] )
float =/ special-float

float-int-part = dec-int
frac = decimal-point zero-prefixable-int
decimal-point = %x2E ; .
zero-prefixable-int = DIGIT *( DIGIT / underscore DIGIT )

Though I was aware that many languages allow literals with hanging decimal points for float values, I did consider it better form to require that a decimal point always include at least one digit, for the sake of readability and unobscured identification. That's why I went along with the conversation and didn't say much until now.

The ABNF has been moving towards being fully in line with the spec. I'm not sure where its official status stands at this point, but I think we're close to done, so that anything valid per toml.md is necessarily well-formed per toml.abnf.

@marzer
Copy link
Contributor Author
marzer commented Jul 7, 2020

@eksortso Yup, I get all that. I'm trying to clearly, explicitly disambiguate the difference in what TOML considers a float versus what many other languages do. When I think "float" I think "a floating-point number as per a thousand different programming languages", not "a floating-point number as TOML would have it", and I'll not be the first to make the mistake of conflating the two. The whole point of this PR is basically to make the point you just did in fewer words.

@marzer
Copy link
8000
Contributor Author
marzer commented Jul 7, 2020

@pradyunsg I've moved the first sentence to down with the example, as well as adjusting the wording to essentially combine the two and make it read as less formal in the process. Hopefully closer to what you were driving at.

Incidentally, in working on this I've noticed that the repository lacks a .gitattributes and .editorconfig, mainly because my git client and text editor on my windows machine were both initally trying to convert everything to CRLF. I'm happy to add those too if that would be welcome.

@eksortso
Copy link
Contributor
eksortso commented Jul 7, 2020

@marzer Please address the issue that I brought up. If both the fractional part (including the decimal point) and the exponent part are excluded, then what remains is the integer part, not invalid syntax. Could you please revise that part of your proposal?

@marzer
Copy link
Contributor Author
marzer commented Jul 7, 2020

@eksortso Huh? Haven't I? The sentence you took issue with isn't in the PR any more.

Also, I answered that directly anyway with a rationale to explain why I disagree (insofar as the decimal point implying a fractional is TOML-specific). Neither here nor there now, though.

@eksortso
Copy link
Contributor
eksortso commented Jul 7, 2020

My apologies, @marzer. I couldn't tell. I'm still getting used to the app, which is no excuse. Didn't mean to devalue your work, and I'm sorry.

@pradyunsg pradyunsg changed the title Adding invalid float examples Add invalid float examples Jul 8, 2020
@pradyunsg pradyunsg merged commit 6c72d6f into toml-lang:master Jul 8, 2020
@pradyunsg
Copy link
Member

Thanks @marzer for the PR, and thanks all for an interesting discussion. :)

@marzer marzer deleted the omit-float-part-example branch July 20, 2020 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should floats allow omission of integer or fractional/exponent?
4 participants
0