bloc referral

If you are interested in learning to code with a mentor, try bloc and get $100 off.

Friday, July 11, 2014

Tell Don't Ask concept

So I finally attended the Orlando Ruby User's Group for the first time since October and blown away from how much I learned from two topics I was already familiar with. One was on creating an MVP and the other was on authentication with the devise gem.

The first was given by Code School's Carlos Souza and he gave us a sneak peak into a video series coming out shortly called, Feature Focus. The repo is available on Github for the Base Camp clone if you are looking to read some code, which is a great way to see what an MVP is. There are no slide available but the course will go over the details of building the Base Camp app.

Something I am looking forward is the interview with DHH and his critque on the code and his recommendations for Carlos. For example there was a method offered called "Tell Don't Ask." The idea is basically to stop writing if statements and begging the language for info, but getting what you need.

For example this is from the Code Schoolrepo. The | | is literally checking the if the result is this or that, this an alternative to writing out an entire if/else statement.

Translation to if/else:

def find_by_target

  if result = User.name
     then this
  elsif result = Product.title
    then that
  else
    nil

end



Let me know if this makes sense or can be better clarified, this a subject I will be doing some research on, for sure posting on more. Really happy I discover this. I am sure there are also better examples of this, please share those too.

1 comment:

  1. I love "Tell Don't Ask". It avoids many headaches and is less error prone.

    ReplyDelete