Skip to content
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

[docs] Improve docs for std.conv.to #4900

Closed
wants to merge 5 commits into from
Closed

Conversation

ntrel
Copy link
Contributor

@ntrel ntrel commented Nov 14, 2016

  • Document overloads of to which take a radix - see last commit.

Note: This continues the work done in #4208.

@JackStouffer
Copy link
Member

Have to say that I'm against these changes.

Before I changed the to docs to what they are now, it was a jumbled mess of all of the different overloads of toImpl for every type. The idea with how it's arranged now is that the particulars of each type to type conversion would be under one place. The fact that the radix overloads exist is already listed under the integer conversion examples.

@ntrel
Copy link
Contributor Author

ntrel commented Dec 15, 2016

The radix overload docs are currently buried in the middle of all the other to docs. It seems to me that they are significantly different because they take an extra argument, and should be documented after the usual to overloads. It is also non-standard to document the radix overloads without showing their signature, only their usage.

@wilzbach
Copy link
Member

Have to say that I'm against these changes.
Before I changed the to docs to what they are now, it was a jumbled mess of all of the different overloads of toImpl for every type. The idea with how it's arranged now is that the particulars of each type to type conversion would be under one place. The fact that the radix overloads exist is already listed under the integer conversion examples.

We are currently in the process of removing overloads from Phobos - not adding new ones - as the overloads are an implementation details, that the user of a generic function shouldn't be bothered with..

@ntrel: is there a chance you could maybe improve the text documentation so that it's even clearer?

@ntrel
Copy link
Contributor Author

ntrel commented Mar 3, 2017

@wilzbach:

We are currently in the process of removing overloads from Phobos - not adding new ones - as the overloads are an implementation details, that the user of a generic function shouldn't be bothered with..

The 2 radix overloads are not implementation details, they are important for the user - all the other overloads only take one argument. I have now simplified the constraints (and removed one) so they only show what source type the radix overloads apply to. I have undocumented the static array ref (non-radix) overload as I agree that could be seen as an implementation detail.

@ntrel: is there a chance you could maybe improve the text documentation so that it's even clearer?

Possibly, but it would be fighting against ddoc's purpose of documenting declarations, we shouldn't be explaining what hidden arguments a function takes manually IMO. Documenting the 2 radix overloads normally we get the usual Parameters section etc.

I have also added 3 signatures manually at the top of the docs, partly because the actual signatures from this PR are so far below the pages of docs & examples, but also so the user can quickly grok the function, and the docs now refer to S, the source type from the signatures.

@ntrel
Copy link
Contributor Author

ntrel commented Mar 13, 2017

@wilzbach Removed overloads from docs.

Copy link
Member

@MetaLang MetaLang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ntrel needs a rebase.

std/conv.d Outdated
@@ -1732,7 +1735,7 @@ private T toImpl(T, S)(S value)
/// ditto
private T toImpl(T, S)(S value, uint radix)
if (isInputRange!S && isSomeChar!(ElementEncodingType!S) &&
!isExactSomeString!T && is(typeof(parse!T(value, radix))))
isIntegral!T && is(typeof(parse!T(value, radix))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's with the template constraint change? We can't have that in a doc PR. Please remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to #5647.

@ntrel
Copy link
Contributor Author

ntrel commented Jul 31, 2017

@wilzbach I can't work out why ./circleci.sh style_lint is failing on this. Any ideas?

@wilzbach
Copy link
Member

@wilzbach I can't work out why ./circleci.sh style_lint is failing on this. Any ideas?

Not really, looked pretty strange to me as well. However, rebasing to the latest master commit worked :)

@ntrel
Copy link
Contributor Author

ntrel commented Aug 1, 2017

@wilzbach Thanks!

@quickfur
Copy link
Member

The changes look sensible to me. Improving docs is always welcome. Please rebase and lets get things moving again! ping @wilzbach @ntrel @MetaLang

ntrel and others added 4 commits January 29, 2018 14:02
Document overloads of `to` which take a radix.
Hide the static array ref overload from docs.
Omit constraints involving T (unnecessary for the user).
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @ntrel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.

Some tips to help speed things up:

  • smaller, focused PRs are easier to review than big ones

  • try not to mix up refactoring or style changes with bug fixes or feature enhancements

  • provide helpful commit messages explaining the rationale behind each change

Bear in mind that large or tricky changes may require multiple rounds of review and revision.

Please see CONTRIBUTING.md for more information.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@quickfur
Copy link
Member

My impatience got the better of me, so I took it upon myself to rebase this. Let's see if it passes; if so, I'm going to pull the trigger.

@quickfur
Copy link
Member

quickfur commented Jan 29, 2018

ping @JackStouffer
Is this PR OK, or are you still against this?

Copy link
Member

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My impatience got the better of me, so I took it upon myself to rebase this. Let's see if it passes; if so, I'm going to pull the trigger.

I really really like your enthusiasm and the way you most PRs in the Phobos queue ahead, but in this case I would be careful here as AFAICT we haven't had a precedent of specifying "pseudo-overloads" in the plain-text documentation.

@@ -176,8 +176,9 @@ class ConvOverflowException : ConvException
}

/**
The `to` template converts a value from one type _to another.
The source type is deduced and the target type must be specified, for example the
$(D_CODE T $(DDOC_PSYMBOL _to)$(DDOC_TEMPLATE_PARAM_LIST (S))(S value);)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

There's any precedent for this, is there?

*
* _To work around this, you can specify a radix for conversions involving numbers.
* To work around this, you can specify a radix for conversions involving numbers:
* $(D_CODE T $(DDOC_PSYMBOL _to)$(DDOC_TEMPLATE_PARAM_LIST (S))(S value, uint radix);)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks a bit weird on the docs:

image

and again no precedent of manually specifying the overload in the plain-text docs.

* $(D_PARAM radix) must be a value from 2 _to 36.
* $(D_PARAM value) is treated as a signed value only if $(D_PARAM radix) is 10.
* The characters A through Z are used _to represent values 10 through 36.
* $(D_PARAM letterCase) is the case _to use for non-decimal output characters.)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before:

image

After:

image

@quickfur
Copy link
Member

@wilzbach
Hmph, you're right. I just saw that this PR was approved by another reviewer but was rotting in the queue pending a rebase, so I just rebased it myself; didn't look too closely at the actual change.

There was a case (not sure if there still is now) where the ddoc header contained a "pseudo" declaration, I don't remember exactly now, it may have been reduce or one of those doubly-templated functions, i.e., template reduce(Seeds...) { auto reduce(R)(R range, ...) ... } where ddoc produces rather ugly declarations, even though the function is intended to be used just like a regular template function. In any case, it's very ugly to introduce this kind of pseudo declaration instead of fixing ddoc or refactoring the code so that it will be formatted better automatically.

But yeah, it's probably a bad idea to merge this without a good reason.

Perhaps the solution here might be to document the 2-argument to overloads separately, then link to this from the 1-argument to docs in the section that talks about conversions to integers with a radix argument.

@JackStouffer
Copy link
Member

Perhaps the solution here might be to document the 2-argument to overloads separately, then link to this from the 1-argument to docs in the section that talks about conversions to integers with a radix argument.

I'm still against splitting the to docs for the reasons listed above.

An easy solution is to add a Params: section to the template ddoc which is currently absent.

@quickfur
Copy link
Member

@JackStouffer Now that I look at at again, not only the current docs is missing a Params:, the only thing that's documented is the outer template itself, not any of its inner functions. And a Params: without any documented function declarations is pretty useless.

Worse yet, there's no indication whatever about what possible combination of arguments are possible. I see that since the last time I looked, the number of possible arguments has been generalized to 1 possible radix to now an additional LetterCase, and the to template itself is now variadic, forwarding an arbitrary number of arguments to toImpl. There's probably a very good reason for this, but this is IMO currently very poorly-documented. I mean, I didn't even know LetterCase got added until I read the code just now. Maybe this PR isn't the right answer, but the documentation for to seriously needs some work here.

@quickfur
Copy link
Member

P.S. I would say, from a doc reader's POV, the bare minimum for the docs would be:

  1. A brief summary of all possible ways to call to, e.g.:
to!T(); // convert to T
to!T(radix); // convert to integral type T with specified radix
to!T(radix, LetterCase.upper); // convert to integral type T with specified radix and letter casing
  1. Brief synopsis of what kind of conversions are possible (this information is already there but interspersed with numerous code example blocks, making a high-level understanding impossible)

  2. How to integrate a user type with to so that it can support custom conversions.

@RazvanN7
Copy link
Collaborator

Most of the changes in this PR have already been addressed.

@RazvanN7 RazvanN7 closed this Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants