Skip to content

Documentation - Change complete_me (inner constructor helper function) to complete_me! #25982

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

Closed
wants to merge 2 commits into from

Conversation

moustachio-belvedere
Copy link

To be consistent with Julia style guidelines change complete_me to complete_me! as it alters at least one of its mutable arguments.

Although the “!” requirement is arguably less stringent on inner constructor completion functions, as they will never be called directly, only indirectly upon creation of a struct instance, the “!” should still be appended to the function name for code reading clarity.

As discussed here:

https://discourse.julialang.org/t/a-question-of-style-should-inner-constructor-completion-functions-end-with/8948

@fredrikekre
Copy link
Member

On second thought -- is this actually mutation?

@moustachio-belvedere
Copy link
Author

moustachio-belvedere commented Feb 13, 2018

On the one hand, it is not traditional mutation as it must also return the struct back rather than just mutate it in place. On the other hand, it is mutating the struct so should be considered a mutating function.

It's my opinion that the "!" appended adds clarity but I'm a fairly inexperienced Julia developer. Others might disagree.

@kshyatt kshyatt added the docs This change adds or pertains to documentation label May 27, 2018
@GregPlowman
Copy link
Contributor

On the one hand, it is not traditional mutation as it must also return the struct back rather than just mutate it in place.

Many mutating functions return the mutated object.

On second thought -- is this actually mutation?

What makes say you that?

Presumably, complete_me! would look like a normal external mutating function, and could be called from anywhere, not just from the inner constructor.

mutable struct Lazy
    xx
    Lazy(v) = complete_me!(new(), v)
end

function complete_me!(lazy::Lazy, v)
    lazy.xx = v
    return lazy
end

In isolation, the complete_me! seems indistinguishable from any other type of mutating function.

@ViralBShah
Copy link
Member

I'm closing this since there doesn't seem to be a clear answer on this. Can always reopen if necessary.

@ViralBShah ViralBShah closed this Apr 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants