Skip to content

s/string_of_int/Int.to_string/g#2012

Merged
nojb merged 2 commits intoocaml:trunkfrom
dbuenzli:deprecate-string_of_int
Nov 7, 2018
Merged

s/string_of_int/Int.to_string/g#2012
nojb merged 2 commits intoocaml:trunkfrom
dbuenzli:deprecate-string_of_int

Conversation

@dbuenzli
Copy link
Copy Markdown
Contributor

@dbuenzli dbuenzli commented Aug 30, 2018

Following up on #2011 this deprecate substitutes string_of_int in favor of Int.to_string. Note that this basically consists in substituing the latter by the former which has, conveniently, exactly the same number of characters.

There is however one tricky in asmcomp/selectgen.ml since that module defines an Int module internally. For some reason trying to use Stdlib.Int didn't work at that point (the module is unbound, even though the boot interface seems to have stdlib.cmi ?!). Either the Int module can be "saved" to another name before selectgen.ml defines it own Int module or Stdlib__int can be used. I chose the later. If anyones knows a better way please tell. This has been solved.

@dbuenzli dbuenzli force-pushed the deprecate-string_of_int branch from 4f57ab2 to edd2ef8 Compare August 31, 2018 05:51
@ghost
Copy link
Copy Markdown

ghost commented Aug 31, 2018

utils/misc.mli defines a Stdlib module, that might be the issue. I got bitten by this as well recently

@dbuenzli
Copy link
Copy Markdown
Contributor Author

@diml is spot on ! Added a patch that remove the open Misc at the top of the file.

@dbuenzli dbuenzli force-pushed the deprecate-string_of_int branch from 826cf57 to a8273ee Compare August 31, 2018 13:56
@gasche
Copy link
Copy Markdown
Member

gasche commented Sep 2, 2018

I'm a bit uncomfortable with the rash of deprecations that are about to hit the stdlib (already the Pervasives one). Deprecating current practices that are harmful seems reasonable, but I'm not convinced that using string_of_int instead of Int.to_string is harmful, there deprecation seems used more as a "hint towards a modern code writing style".

It's not about this specific issue, I'm not sure what's the best place to discuss the general deprecation practices, and I don't have a clearly better solution to offer to the problem of gradual style evolution. Just airing out a bit, sorry.

@dbuenzli
Copy link
Copy Markdown
Contributor Author

dbuenzli commented Sep 2, 2018

I'm a bit uncomfortable with the rash of deprecations that are about to hit the stdlib (already the Pervasives one).

From an end-user point of view it's actually much better and less time consuming if there's a single rash of deprecations rather than each OCaml version introducing a new one.

Deprecating current practices that are harmful seems reasonable, but I'm not convinced that using string_of_int instead of Int.to_string is harmful, there deprecation seems used more as a "hint towards a modern code writing style".

I find that to be a quite restricted view of deprecation. As far as I'm concerned deprecating some names in favor of others is as important as deprecating harmful practices and I thought people mostly agreed on the idea that these functions were better placed in the module that handles the type rather than in "the initially opened module".

Besides, note that in the particular case of Bool the result is actually a deprecation from a harmful practice (using exceptions for non exceptional errors) and design error (a function raising Invalid_argument in contradiction with the expected semantics of that exception). In that case I would find it a bit odd to deprecate bool_of_string for the corrected functionality in the Bool module but not deprecate string_of_bool because it's not "harmful". And then if you agree with the latter deprecations, then why not do the same with the support for int aswell ?

@dbuenzli
Copy link
Copy Markdown
Contributor Author

dbuenzli commented Sep 2, 2018

I'm a bit uncomfortable with the rash of deprecations that are about to hit the stdlib (already the Pervasives one).

Aside. From a stdlib evolution perspective I think it would actually give a better overall message to end users if the names that are nowadays perceived as being out of place in the "initially opened module" are deprecated at the same time as the historical Pervasives module.

@dbuenzli
Copy link
Copy Markdown
Contributor Author

Even if we don't deprecate the function and assuming #2011 will be merged. Are people interested in these patches which simply uses Int.to_string instead of string_of_int in the code base or should I close this ?

@dbuenzli dbuenzli force-pushed the deprecate-string_of_int branch 2 times, most recently from e815486 to d97822c Compare September 12, 2018 19:28
@dbuenzli dbuenzli changed the title Deprecate string_of_int s/string_of_int/Int.to_string/g Sep 12, 2018
@alainfrisch
Copy link
Copy Markdown
Contributor

Are people interested in these patches which simply uses Int.to_string instead of string_of_int in the code base or should I close this ?

No, let's keep it. It's a good goal to use modern style in the code base. (I would not encourage people to spend time on such PR, but this work is already done in this case.)

Copy link
Copy Markdown
Member

@damiendoligez damiendoligez left a comment

Choose a reason for hiding this comment

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

I have one question that should be answered before merging. Otherwise, looks good.

@dbuenzli
Copy link
Copy Markdown
Contributor Author

It is my intent to rebase this PR and solve the conflicts but it will have to wait next week.

@dbuenzli dbuenzli force-pushed the deprecate-string_of_int branch from d97822c to 0131964 Compare October 31, 2018 15:23
@dbuenzli
Copy link
Copy Markdown
Contributor Author

dbuenzli commented Nov 1, 2018

This has been rebased. The CI failure is due to the lack of changes entry (I don't think one is needed). I tried to find the information in CONTRIBUTING.md on how to disable the test but couldn't find it, the CI tells you:

Some very minor changes (typo fixes for example) may not need
a Changes entry. In this case, you may explicitly disable this test by
adding the code word "No change entry needed" (on a single line) to
a commit message of the PR, or using the "no-change-entry-needed" label
on the github pull request.

would be good to have that in the CONTRIBUTING.md document.

@dbuenzli
Copy link
Copy Markdown
Contributor Author

dbuenzli commented Nov 5, 2018

Ping.

@dbuenzli dbuenzli force-pushed the deprecate-string_of_int branch from 0131964 to a7afd89 Compare November 7, 2018 13:08
@dbuenzli
Copy link
Copy Markdown
Contributor Author

dbuenzli commented Nov 7, 2018

Had to solve conflicts again. Not sure I'll do it once more. Can someone please merge this.

@nojb
Copy link
Copy Markdown
Contributor

nojb commented Nov 7, 2018

I'll merge this as soon as the CI passes. Thanks!

@nojb nojb merged commit 0e5cae8 into ocaml:trunk Nov 7, 2018
@dbuenzli dbuenzli deleted the deprecate-string_of_int branch November 7, 2018 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants