-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Adds support for optionalcallback and optionalmacrocallback #4037
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
Conversation
The optionalcallback or optionalmacrocallback attribute also defines the Erlang optional_callbacks attribute. If a (macro)callback has been defined as optional(macro)callback and (macro)callback we emit a warning and defines the optional_callbacks attribute. http://www.erlang.org/doc/design_principles/spec_proc.html#id74952
Technically @fishcakez did a lot of the work |
Thank you @stevedomin! I would go with the names Thoughts? /cc @fishcakez |
@josevalim I thought this style was much more in line with elixir than the On Thursday, 3 December 2015, José Valim notifications@github.com wrote:
|
Which style? The |
Sorry the style in the PR is more elixir style. We don't use two attributes On Thursday, 3 December 2015, José Valim notifications@github.com wrote:
|
@fishcakez yes, I know. But optional_macrocallback is too long. :( And we do have a couple things that mimic how optional behaves, for example defoverridable, import and @compile :inline. |
👍 for underscore after |
Hmm. An optional callback is different to those examples because they add Optional_macrocallback is not so nice. On Thursday, 3 December 2015, Aleksei Magusev <notifications@github.com
|
I don't have strong opinions on naming (and not enough context to make the decision) so once you guys have settled on something I'll update my PR. I'll also try to change the behaviour according depending on what you decide. |
optional_macrocallback really is a pain to use both because of its unwieldy length and actually using an optional macro callback. I tried to create some example use cases but I couldn't really come up with anything that was both clean and useful :(. |
Choosing between to underscore |
@lexmag, to be clear I was not suggesting that @optional_macrocallback add(number, number) :: Macro.t, Versus @macrocallback add(number, number) :: Macro.t
@optional_macrocallback add: 2 @stevedomin if you are up for it, would you like to try a separate branch that uses the later pattern? This does indeed fit better with |
Isn't including |
@ericmj this might be only me but I tend to like descriptive name and optional feels a bit too generic in that sense. For a newcomer to the language it might not be obvious what optional means when just reading code whereas optional_callback is fairly explicit. Although you could argue that they wouldn't necessarily know what a callback is in the first place. @fishcakez ok I'll work on this |
@stevedomin to clarify, we don't need both |
I'm sorry guys I have been really busy at work this week, I will hopefully have a go at this over the week-end |
No worries at all @stevedomin. Take your time. :) |
Revamping this because we may need it for GenRouter/GenStage. We have three options:
I would say 3 would be too foreign for Elixir. 1 is too long and uncomfortable. I am 👍 for 2 because it mimics Can we agree on 2? |
@josevalim would we have separate |
@whatyouhide just one attribute I think @stevedomin has some work on this approach already. It uses the same methods to accumulate as @spec/@type and then rewrites the macrocallbacks to the erlang function name/arity. |
Awesome. I'm 👍 for number 2 as well, as it's inline with what Erlang does as well :). |
|
2 seems nice :) |
@stevedomin could you please send a new pull request that adds 2. as discussed above? If not, no problem, let us know so someone else can pick up the issue. Thank you! :) |
Sorry 😔 Having another go at it this week-end |
Thank you Steve! |
@josevalim I think we can close this while @stevedomin is working on the new PR? |
It is up to him. He may still force push to this branch. :) |
Ah, alright! Sorry for the false alarm then :) |
@stevedomin since you are likely busy. Are you ok with someone else tackling this? :) |
Yes, go for it, made some progress but not enough |
Thanks for pinging back @stevedomin! :) |
The optionalcallback or optionalmacrocallback attribute also defines the
Erlang optional_callbacks attribute.
If a (macro)callback has been defined as optional(macro)callback and
(macro)callback we emit a warning and defines the optional_callbacks
attribute.
http://www.erlang.org/doc/design_principles/spec_proc.html#id74952
Fixes #3980