Intention
vs
Implementation(s)

Example: a feature request

In order to review blog posts, admins can see additional information.

Implementation

- if current_user.admin?
  
  // html with details of the blog post

So what?

- it works

- it's clear

... but
 

What was expected?

- admins can see details

- reviewers can see details

- reviewers are admins

What has been coded?

VS

What was expected?

- admins can see details

- reviewers can see details

- reviewers are admins

What has been coded?

!=

Intention

Implementation

Why does it matter?

if                                       is the only criteria for all actions in the code, we can't track the intentions.

 

It's introducing hidden costs in understanding and maintenance.

current_user.admin?

How would you do?

Authorization gems are dedicated to this task.
Or you can create meaningful methods

class User
  def can_review_posts?
    admin?
  end
end
- if current_user.can_review_posts?
  
  // html with details of the blog post

Conclusion

Most of the time, feature requests themselves confuse intention and implementation.

 

Think twice before coding, and make business logic appear in your code.

more presentations here

 

@apneadiving

Made with Slides.com