-
-
Notifications
You must be signed in to change notification settings - Fork 746
Sort imports in Phobos #5478
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
Sort imports in Phobos #5478
Conversation
| @safe pure unittest | ||
| { | ||
| import std.utf : byChar, byWchar, byDchar; | ||
| import std.utf : byChar, byDchar, byWchar; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andralex if we want to enforce sortedness for all imports, we have to look over a few minor exceptions where the order makes a bit of sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too worried about the few hand-optimizations that could be done. I'd say sorted is the simple and effective way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎
| @safe unittest | ||
| { | ||
| import core.time : msecs, usecs, hnsecs, nsecs; | ||
| import core.time : hnsecs, msecs, nsecs, usecs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the other example I found where order made sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎
|
Sure, it makes sense to be sorting imports alphabetically in general, but does it really make sense to effectively make it an error when they're not sorted that way? That seems like it's getting really picky about something that doesn't really matter much, especially if most imports are local, and we have fewer, large blocks of import statements. And of course, forcing sorting causes problems in the cases where another order arguably makes more sense. |
|
It would be odd to have the compiler enforce it, but in phobos it's reasonable. The problem with other orders is that everybody may have their own notion of the best order. |
|
Thanks. Should I override jenkins? |
|
Apparently I can... we really should get jenkins going. |
|
I'm really not sure about this one (for the reasons @jmdavis mentioned). |
|
I think this should be reverted.
This is a slippery slope towards having one single "normalized" form of the code, and deviating from it is punishable by a 10-minute edit/amend/push/wait-for-CI cycle, and if we continue moving in this direction, I can see it happening a lot. Having code follow a consistent style is good, but this is going beyond style - many of the changes make the code uglier simply for the sake of normalization. If we are to enforce that imports are sorted, then why not also enforce that local variables are also sorted? Why should it be allowed to write |
FWIW You can run dscanner locally - it's one of the most popular D projects & some IDEs/editors even have native support.
I only found two examples where order actually made sense. |
This is going to be completely irrelevant to most submitters unless they are told how to do it during the submission process. Links hidden among walls of text don't count. Even then, it lessens the frustration only to some degree. |
This is getting OT a bit, but FWIW we do plan to show a hello word message to new contributors. Also will this message contain detailed instructions based on the errors, see e.g. dlang/dlang-bot#57 |
This causes no harm regardless of how we move forward, so please leave it in. Thanks.
Yah, if we go for the tooling approach we should make it trivial for people to make the check locally - perhaps even automatically as part of the make process. A variety of successful projects have very strict rules for formatting. I know from a GNU tools maintainer that their "good diff" tool (I forgot the name) was a lifesaver. |
|
Btw @CyberShadow we have had sortedness of imports as part of the DStyle for Phobos since some time now.
... and we don't swear at people using the wrong comment style: |
CyberShadow
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only found two examples where order actually made sense.
Please count again, I think you're off by one or two ... orders of magnitude.
| @safe pure unittest | ||
| { | ||
| import std.utf : byChar, byWchar, byDchar; | ||
| import std.utf : byChar, byDchar, byWchar; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎
| if (op == "^^" && is(C R == Complex!R)) | ||
| { | ||
| import std.math : exp, log, cos, sin; | ||
| import std.math : cos, exp, log, sin; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎
| if (op == "^^" && isNumeric!R) | ||
| { | ||
| import std.math : cos, exp, log, sin, PI; | ||
| import std.math : cos, exp, log, PI, sin; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎
| @safe pure nothrow @nogc | ||
| { | ||
| import std.math : sin, cos; | ||
| import std.math : cos, sin; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎
| if (!is(Unqual!T == bool)) | ||
| { | ||
| import core.stdc.stdlib : malloc, realloc, free; | ||
| import core.stdc.stdlib : free, malloc, realloc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎
| private void setCLOEXEC(int fd, bool on) nothrow @nogc | ||
| { | ||
| import core.sys.posix.fcntl : fcntl, F_GETFD, FD_CLOEXEC, F_SETFD; | ||
| import core.sys.posix.fcntl : fcntl, FD_CLOEXEC, F_GETFD, F_SETFD; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| import std.conv : to; | ||
| import std.traits : EnumMembers; | ||
| import std.utf : byCodeUnit, byChar, byWchar; | ||
| import std.utf : byChar, byCodeUnit, byWchar; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎
| } | ||
|
|
||
| version(unittest) import std.string : startsWith, endsWith; | ||
| version(unittest) import std.string : endsWith, startsWith; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎
| public import std.algorithm.comparison : cmp; | ||
| public import std.algorithm.searching : startsWith, endsWith, count; | ||
| public import std.array : join, replace, replaceInPlace, split, empty; | ||
| public import std.algorithm.searching : count, endsWith, startsWith; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎
| import std.algorithm.searching : endsWith, startsWith; | ||
| import std.exception; | ||
| import std.string; | ||
| import std.algorithm.searching : startsWith, endsWith; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎
Not true, this is a regression in code readability. Many, many small regressions, but a step backwards nevertheless.
Formatting is one thing; normalization at the cost of readability is another. Which is it?
The style guide is ambiguous on whether the rule applies to selective imports as well. |
It happens to me almost every time I create a pull request. From my perspective, the CI stuff has largely made life far more annoying for minimal benefit.
That would improve things in some ways and make them worse in others. I didn't even know that the 'style' target existed until Seb pointed out it to me at dconf, but even knowing about it, I can't use it on my Ubuntu system, because it doesn't work with It seems to me that all of this extra stuff is making it harder to contribute, not easier. |
Most definitely a smooth operation is essential for the success of tooling. Style checks should simply be part of the unittest build. cc @wilzbach can you please make that happen for all makefiles?
There's a lot of value in having automated tools instead of reviewers point out simple things like brace placement, punctuations, indentation etc. It's much more effective for both contributors and reviewers. |
Oh, it can definitely help, but simply not being picky about something makes it even easier. Some level of pickiness on style makes sense so that the code is reasonably consistent, but it really feels to me like it's gone too far. Even with proper tooling that points out problems locally before creating a PR, complaining about something like the fact that Regardless, as it stands, the end result is that many of us create PRs only to have the Circle CI scream at us over some nitpicky thing, and then we have to go through several cycles to make it happy. |
|
@jmdavis most certainly the hodge-podge of styles present in Phobos right now does not make it easier for anyone involved. @wilzbach how about we start with only sorting imports alphabetically, not symbols within imports. The original problem was that people missed the presence of an import and would add it again. |
This is a preparation of the upcoming Dscanner enforcement for sorted imports in Phobos.
Of course, this wasn't done by hand.
There are still a couple of false negative to filter out at the Dscanner plugin (e.g. dlang-community/D-Scanner#444), but this import sorting script was laying on my disk now for a couple of months and we need to sort the imports anyways before we can move ahead with enforcing sortedness.
CC @andralex @CyberShadow
As this is quite a big chunk, I would appreciate if I don't need to rebase this that often ;-)