So I have a function that I’ve depreciated, what I’d like is for the compiler to issue a warning or error, but only if that function is being used in the current project. It’s in a shared object, that’s used in almost all my projects.
Is this possible?
#pragma error "This function is depreciated, please use ""window.makeVibrant"" instead."
displays even when the function isn’t being used, I only want to see the error if the function is actually used in that project.
Set an attribute on the function “deprecated” (not “depreciated” ), and fill in the value with the replacement call. The compiler will do the rest.
Thanks Kem, it only shows up when checking the project. I’d like it to show up when debugging or building the project (but only if it’s actually used in the project).
I’ve had this conversation with others, yet I can’t help myself in spelling in that way.
depreciate - diminish in value over a period of time
deprecate - express disapproval of
So are we removing the functions or disliking them
I don’t think you can do that. You can raise an exception, of course, but you’d better find those before building. Maybe something like this?
dim err as new RuntimeException
err.Message = "Deprecated!"
Or you could use
#pragma error "Deprecated", but that will keep you from building even if you don’t use the function anywhere.
You can also skip the value if there is no replacement.
[quote=227310:@Sam Rowlands]Thanks Kem, it only shows up when checking the project. I’d like it to show up when debugging or building the project (but only if it’s actually used in the project).
Deprecation is a pleasant means to say “Hey you should update your code”
If you want it to fail when you compile just rename the method or remove it
That forces the issue
Hi Greg, in this case, there is a replacement.
[quote=227382:@Norman Palardy]If you want it to fail when you compile just rename the method or remove it
That forces the issue[/quote]
I was just hoping of a way to remind me (and anyone else who uses my code) of what the replacement mechanism is.
More thought required…
Deprecation would be that means but until you actually remove it its not a required update to code.
Same as on our front where we deprecate a feature and a lot of people never notice until we outright remove it
Maybe I should file a feature request, I personally think it would be better to be pro-active and alert the user when they build, rather than relying on them using the verification function to see what should be updated.
Couple different things I can think you might ask for
- a attribute “ErrorOnDeprecation” or something like it that causes an error about the deprecation
That’d be very “in your face” about it
- a “deprecations are errors” compiler setting kind of like some compilers have a means to treat all warnings as errors
The first would be a means for a library author to “force” people to update their code
I suspect you’d get complaints about such a thing
The second would be user settable so under their control - much like it is today
Able to ignore it until they felt it was time to do something about it - like when the method is removed from an updated version
I think what I’m looking for is option 1), as I have a replacement function, so it would notify them which function to use instead.
Just to make it clear, I only want it to show if they’re using this function, if not then don’t worry. Does that make sense?
the deprecated attribute is like that now - if you dont use the function analyze wont show you anything
I think Sam may want a warning on running in the IDE and maybe build instead of just on analyze.
Why doesn’t the “needs attention” dialog when loading a project present deprecation warnings like it does for EditField -> TextField?
I liked Thom’s suggestion, although, frankly, I Analyze a project so often, I wouldn’t need it and would want to turn that off.
It doesn’t compile the code which is what would be required to know if you’ve used a method marked as deprecated.
Examining a controls parentage is a simple walk up a list of supers seeing if any has a deprecated attribute.
[quote=227526:@Norman Palardy]It doesn’t compile the code which is what would be required to know if you’ve used a method marked as deprecated.
Examining a controls parentage is a simple walk up a list of supers seeing if any has a deprecated attribute.[/quote]
That makes sense.