Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Conversation

@humzashah
Copy link
Contributor

Two guard clauses have been combined into one. Previously one clause
was checking for the object's existence, the other was checking for
its attributes. Now the same guard clause chains the conditions
together thereby reducing a code line.

Two guard clauses have been combined into one. Previously one clause
was checking for the object's existence, the other was checking for
its attributes. Now the same guard clause chains the conditions
together thereby reducing a code line.
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be shorter via, return unless value?.lng and value?.lat

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nmccready, nice! isn't as readable though. plus it checks for the existence of value twice. to clarify:

original code:
return if value is undefined
return if value doesn't have a lng or it doesn't have a ltd

my code:
return unless there is a value defined with lng and ltd

your code:
return unless value is defined and has a lng and value is defined and has a lat

what do u say?

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't say it is less readable, if your used to coffee this is a goto staple for me know. It eliminates tons of redundant code.

Also unless I normally use only if there is one variable to check for truthyness but your case works cause your using a bunch of ands. Basically unless has unexpected behavior at times where it really means if !(value and value.lng and value.lat).

Anyway this one liner is not worth arguing about.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually this would have been best return unless value?.lng and value.lat then one check for existence and it satisfies me and u.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, @nmccready ! :)

nmccready added a commit that referenced this pull request Dec 11, 2015
@nmccready nmccready merged commit 1f8259d into angular-ui:master Dec 11, 2015
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