Cocoa’s Nil Behavior to Ruby

As you may or may not know, when you send a message to nil in Cocoa, it doesn’t do anything and certainly doesn’t raise any exception. You may or may not agree with the design, but we’ve all programmed just fine with this fact.

Having said that, what if you wanted the same behavior in Ruby?

NilClass.class_eval { define_method(:method_missing) {|*args| self} }

Is this a good idea?

* this is a code joke, please don’t take it too seriously

Management

If you’re a manager or is about to become one, try these lessons I’ve learned starting from business school (I have a degree in Finance) and all throughout my career at this point. I realized that I’ve forgotten some of these and this is a great reminder.

The best managers do not “manage”, instead, they inspire and create a working environment for others to flourish. They also hire the right people for the job with the personality that fits the team, no matter how talented someone is. The same goes for getting rid of anyone that throws off the team balance.

Here’s my list of “things”:

  1. Always eat together. I made it mandatory for everyone to eat lunch together. I never compromised on this and you shouldn’t either.
  2. Don’t interfere with productive creativity. In other words, stay out of the way and let people soar.
  3. Learn to sell your ideas. The sales skill I learned (yes, it’s learned, not born with as some people would say) still applies to all aspects of my life.
  4. Always put yourself in their shoes.
  5. Entertain. People should look forward to talking to you, not dread it
  6. Protect your people. Never throw anyone under the bus, even if they deserve it.
  7. Listen!
  8. Don’t try to change things that will never change. It’s okay to accept the fact that cows can’t talk no matter how hard you try to teach it.

Rehashing Old Contents

I’ve realized that when I switched over to selfthis.com, I abandoned lots of personal notes from RubyHead blog. In any case, now that I’m going through digital spring cleaning, I’m going to transfer them here.

Passing in Arguments to Rake – My Way

** This is an update from RubyHead post ***

I’ve seen many interesting ways to pass arguments to rake tasks. The fact of matter is, I really don’t like messing around with any constant or global variable. Here’s how I like to do it.

rake mytask:do_something 1 2 3

Arguments 1, 2, and 3 will be available in the task. Therefore, if you look at the arguments($*), you’ll see [“mytask:do_something”, “1”, “2”, “3”]. Just reject the first in the Array and you got yourself arguments

Here’s another example of passing in “Hash”. This is with quotes because there’s a bit of manipulation needed.

rake mytask:do_something setting:WHATEVER user:me

Using the argument facility built into Ruby, just create a hash inside of my task. I can even create a method to do this for all tasks. Below is my implementation.

desc "my task do something"
task :do_something => :environment do
  options = {}
  $*.each {|arg| options[arg.split(":")[0]] = arg.split(":")[1]}
  options.reject! {|k,v| v == "" || v.nil? }
  # I now have {"setting" => "WHATEVER", "user" => "me"}
  # for whatever I want to do.
  # ...

  exit
end


Make sure you have exit or it will try to run arguments as a series of tasks.

I think it’s cleaner and easier way to do it, but that’s just my opinion. By the way, $* has an alias, ARGV.

Cocoa/Objective-C Book Recommendations

*** Disclaimer ***
I didn’t get to completely read some of the books on this list. In fact, I went through the books to see the quality of the material and the style of the writing.
***

Cocoa and Objective-C: Up and Running – This may be considered outdated by some, but think it lays a solid foundation for beginning developers. He wrote ton of tutorials on Cocoa before it became cool with iOS and real contributor to Cocoa community.
Learning Objective-C 2.0: A Hands-on Guide to Objective-C for Mac and iOS Developers
Effective Objective-C 2.0: 52 Specific Ways to Improve Your iOS and OS X Programs (Effective Software Development Series
Advanced Mac OS X Programming: The Big Nerd Ranch Guide

Xcode Snippets Backup

I recently had the misfortune of losing my code snippets in Xcode that was built over the years. I was able to recover some, but can’t believe that I forgot to backup properly. Yeah, talk about monumental screw up.

The snippets are located at ~Library/Developer/Xcode/UserData/CodeSnippets and that should be backed up daily. That’s what I’m now doing.

In case you’re not using snippets, then I highly recommend that you do since they’ll greatly increase your productivity. I know, duh.

Ruby 2.1.1 Released!

Here’s the link

Ruby 2.1 has many improvements including speedup without severe incompatibilities. You can use this on Rails and some applications, and get more comfortable experience.

R.I.P. Jim

I was sad and shocked to wake up to the news that Jim Weirich passed away. He contributed so much to Ruby community and was one of the nice Rubyist.

Not only he created Rake, but he also created Flexmock. One of those component that I loved so much.

I’ll always remember Jim whenever I issue a rake command.

I’d like to thank Jim for everything and will always remember his gifts to us while he was with us.