-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[RFC] Deprecation tool #7655
Comments
It seems a bit odd to have a tool just for deprecations... What would be the chances of naming it e.g. "lint" and adding anything else that might be seen as a warning to it later on? |
Agree with @refi64. The question is: what are the reasons one wouldn't want warnings?
TL;DR: at least enabling the wanings for the main project ( |
@refi64 We actually try to avoid building a linter into the compiler. The compiler is focused on compiling code (and either that works or it fails, no warnings). But it provides a few essential features around that which are considered important enough to have a standard implementation in the compiler. A linter on the other hand is complex and very opinionated. It's probably impossible to get a broad consensus on its rule set. This should be provided by an external tool. |
I forgot to include that a CLI option |
From the PR that the warnings were included, I am more in favor of having this built-in directly in the compiler. But some people prefer warnings free compiler. I care about having some support for smooth migration as early and as easy as possible. |
Here's my opinion: having this as a separate tool is simply hiding it. Who would care about running this tool to see deprecation warnings and then trying to fix them? Or who would remember to do it? And how, a periodical check? It's just not a convenient flow in my opinion. Have it built-in into the compiler and turned on by default: you can immediately see what you can change in your code right now to avoid some pain later when a new release is out. You can't ignore this: it's turned on by default. You can ignore it once you saw it once, but at least you saw it! Then maybe the fix list isn't that long and one can fix those deprecation warnings and move on. If the list is long one can choose to still see it so one doesn't forget about it (it doesn't bother compilation at all, it's just text that's output at the end of compilation). Also, this is yet another tool that comes with the compiler and must be learned. And I was personally more inclined to move these tools outside of the main compiler. Also, linting and deprecation warnings are different things. Deprecation doesn't have to do with code style or recommendation: deprecated method will be removed in the future. |
If it is to be a tool I would call it something more generic than But the deprecation cycle is too important and so much used that I still prefer it bundled it directly in the compiler. Even if it's opt-in for a couple of releases until more feedback is gathered. |
I fully agree with Asterite. A deprecation is a friendly warning that your code will break. I don't understand the idea of running an "additional" tool to get deprecations, which feels like burying these messages :/ |
@asterite I think it was you who first made me realize how compiler warnings affect the UX of the compiler CLI. The But I think an important part of my proposal was missed: in fact I suggested deprecation warnings will always be on in So the workflow becomes this:
I would even suggest replacing If you have just a single invocation of a deprecated method in your project, this way of presenting deprecations produces marginally more work, but for projects with many deprecations, the difference in user experience between the two approaches is stark: possibly 5 pages of text vs 2 lines. You request the 5 pages of text when you need that verbosity, instead of all the time. So what's the difference between this and opt-in compiler warnings? Compiler flags and configuration complexity has been replaced by convention and an additional tool (which could easily be renamed and made more generic to IDEs and editor plugins). |
Did we already see something like that? Or it's just a possible fear? Because 5 pages of text might not be a reality at all. |
@asterite Using a compiler built from the current
|
Deprecating @RX14 then I don't understand why you were against shipping the warning check in 0.28 behind an opt-in, since your proposal includes a less verbose output, but it does include an output.
Within the feedback in this issue, plus your example above and comments in #7652 the best things is to deliver the warning check with opt-in. The output can evolve in the next versions and we can have at least some way to support deprecations. |
@bcardiff yeah I realise after reading the output that it's just the standard library. It also shows a bug with the entire macro expansion showing as context for one deprecated method. I'd rather not show any context though. I think that even ignoring those two mistakes, there's a lot of messy output for a large project with a lot of usages of such methods.
Largely because people will start using the
Agreed. |
Unrelated, bot not that much: for macro expansion code we should probably just show the expanded line that failed, not the entire macro. That could improve the experience a bit. |
But now nobody is saying that it should be removed, the discussion will be about what should be the compilers output when reaching a deprecation method. People that will use
Let's make it |
#7661 created to make it opt-in |
I proposed that it be removed above:
Either way, as long as the default behavior doesn't change in this release I'll begrudgingly approve it. |
Printing the same message many times is verbose, but it shows how many times an issue is present, and where they all are. Running again shows the remaining places to fix. Verbosity can be scary but it's explicit, and less output in subsequent builds is rewarding. Printing a message once shows one issue location, fix it, build again, but fail again with another location, and repeat with no end in sight. It's less scary but can be very frustrating. |
The compiler's responsibility is to compile a program. Obviously, if it fails to do that, it needs to print an error. But deprecated features are not an error. Now the compiler might add some information to inform about the usage of deprecated features. That can be seen as a convenience feature to encourage developers to migrate. But in it's essence, using a deprecated feature is perfectly fine. It's not recommended to do so, but the code compiles and doesn't really pose a situation which requires to focus immediate attention, disregarding all other work. That's not very realistic anyway. Replacing the use of deprecated features is not always as simple as Having a simple list of deprecated features that are used in the code is less obstrusive and encourages users to actually follow it. Changes like a new deprecation coming in from updating some dependency are easy to spot. Once all uses of a deprecated feature have been removed, it will disappear from this list. |
#7639 is a good example why deprecation warnings do not need to be treated as super-important fix-me-or die messages, constantly clogging the compiler output. The deprecation message for |
Except that the Int division isn't deprecated, but behave differently. It should be on a lower priority logging than warning, like information/note. |
Why? It's a deprecation of an API feature. Changing the semantics of a method is similar to removing it. Both may lead to different behaviour and failing builds in the next release. |
I don't supposed the tool will have sort of parsable (json?) output so I can figure out how to feed every deprecated warning to my editor and fix them all at once? |
@didactic-drunk no, it could be added, but after some iteration on the tool, I would say. |
Ref: #7652
The current idea to handle deprecation is to create a separate tool that will check if deprecated definitions are used. This way the compiler can stay warning free and the tool can be used before migrating/updating std/dependencies on demand.
Input from the community is welcome. We want to have a tool that will help shards authors and app developers to provide/have a smooth migration path for breaking changes.
CLI vs integrated with the compiler
Making it a separate tool has on the pro side that:
and on the cons side:
crystal spec
directly grabs./spec/**_spec.cr
.Output
There were some concerns regarding how verbose the output should be (by default). The options discussed where:
The current initial proposal is to:
crystal tool deprecation path/to/main.cr [compiler build options]
If no deprecations are found:
The text was updated successfully, but these errors were encountered: