Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

feat(unit): add InstanceUnit helpers #475

Merged
merged 1 commit into from
May 22, 2014

Conversation

jonboulle
Copy link
Contributor

No description provided.

@jonboulle
Copy link
Contributor Author

Small step towards templated units; going with the "small reviewable chunks" approach instead of the usual megareview.

@bcwaldon
Copy link
Contributor

@jonboulle Assigned #303 to you.

@jonboulle
Copy link
Contributor Author

Oops I thought it already was.


// IsInstanceUnit determines whether the given unit name appears to be an instance
// of a template unit. If so, it returns a *InstanceUnit and true; otherwise, nil and false.
func IsInstanceUnit(name string) (*InstanceUnit, bool) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you could just simplify this down to

func InstanceUnit(name string) *InstanceUnit {
...
}

The non-nilness of the first return value encompasses the truthiness of the second.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dammit, Waldo! I originally had that but then kept thinking back to the exchange we had recently about inferring truthiness, and so eventually ended up here.

Would you object to func MaybeInstanceUnit(name string) *InstanceUnit ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the 'maybe' get you in this situation? You should check for a nil InstanceUnit, even if the code promises to always return a non-nil pointer. I like the usage of 'maybe' when there is no way to tell whether or not a function will *do something, but not for a return value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// MaybeInstanceUnit takes a unit name and possibly returns an InstanceUnit, depending on 
// whether the unit name matches the pattern expected of an instance unit. If not, it returns nil.

Idk, I'm not sold on the conflation between func InstanceUnit and type InstanceUnit

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about FindInstanceUnit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Counter-proposal: UnitNameToInstance? (inspired by systemd once again)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@jonboulle
Copy link
Contributor Author

Renamed, simplified.

}

// UnitNameToInstance determines whether the given unit name appears to be an instance
// of a template unit. If so, it returns an *InstanceUnit; otherwise, nil.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time for nit-pickery: nil is a valid value of *InstanceUnit, so this could be reworded to:

If so, it returns a non-nil *InstanceUnit; otherwise, nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3 come back soon!!

@bcwaldon
Copy link
Contributor

lgtm w/ one nit

jonboulle added a commit that referenced this pull request May 22, 2014
feat(unit): add InstanceUnit helpers
@jonboulle jonboulle merged commit 884d68f into coreos:master May 22, 2014
@jonboulle jonboulle deleted the template_units branch May 22, 2014 21:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants