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

Static lifecycle annotation #110

Closed
hadley opened this issue Mar 23, 2021 · 8 comments
Closed

Static lifecycle annotation #110

hadley opened this issue Mar 23, 2021 · 8 comments

Comments

@hadley
Copy link
Member

hadley commented Mar 23, 2021

Maybe something like:

lifecycle(fun) <- "deprecated"

This would make future static analysis easier, and would also display a message when you printed the function.

The downside is that I think this would have to be duplicative with the lifecycle deprecation calls + documentation badge, since I don't see how to automatically generate one from any of the others.

@lionel-
Copy link
Member

lionel- commented Mar 24, 2021

It might be better for static annotations to be internal to the function rather than external, this way they can also be inspected dynamically. Taking inspiration from Emacs Lisp static declarations:

fn <- function() {
  declare(
    lifecycle = "deprecated"
  )
}

I guess lifecycle<- could also add attributes. However that requires some conventions about attributes. I think a declare() function that ignores its arguments and is only meant to be parsed would be flexible and simple.

@hadley
Copy link
Member Author

hadley commented Mar 24, 2021

An internal declaration wouldn't help with printing and doesn't seem easier to parse than deprecate_warn()?

@lionel-
Copy link
Member

lionel- commented Mar 24, 2021

It's not about being easier to parse than deprecate_warn() but about creating a flexible and easy to follow convention for static declarations.

@lionel-
Copy link
Member

lionel- commented Mar 24, 2021

Actually it's easier to parse because deprecate_warn() may be nested in other code and declare() would never be.

@hadley
Copy link
Member Author

hadley commented Mar 24, 2021

deprecate_warn() is only nested when the deprecation is conditional, so I don't think that affects the overall ease of parsing.

@lionel-
Copy link
Member

lionel- commented Mar 24, 2021

With declare() we wouldn't parse ourrself we'd use a dedicated extractor. Probably that makes it easier. Implementors don't have to worry about things like namespace-qualified calls. Also parsing actual function calls like deprecate_warn() prevents them from being wrapped in other functions and declare() doesn't have this limitation.

@hadley
Copy link
Member Author

hadley commented Oct 20, 2022

I think we should start with a tool that does static analysis of existing code; it won't be perfect but the lifecycle functions have been designed to be self-contained, and just extracting all deprecate_* calls at the top level of a function would be a good start. We can then save that in a yaml file and (e.g.) the IDE could use for autocomplete and syntax highlighting.

@hadley
Copy link
Member Author

hadley commented Nov 2, 2023

Closing this since I think we'll consider more broadly in the context of static declarations about functions.

@hadley hadley closed this as completed Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants