News for hackers. Stuff that matters.
Re:10 Most Common Rails Mistakes by rubiquity on Tuesday June 03, 2014 @12:33PM (#7841189)
nil is annoying and should be avoided when possible. nil gives no useful feedback when blowing up and communicates nothing about the intent of the code. Using a Guest object is a great use of polymorphism and duck typing, which are great features of Ruby (and object orientation). Having nils all over the place and having to do `if some_obj` all of the time is messy.

Your example is pretty simple, so my solution will sound like overkill, but I would use some other type of object such as a Presenter to handle the rendering logic.

Re:10 Most Common Rails Mistakes by 3pt14159 on Tuesday June 03, 2014 @01:43PM (#7841650)
Naw, you're complicating things. Nil should not be avoided, it should be accepted. If there isn't a current user then don't pretend that there is. Anywhere you are doing `if some_obj` in view code you'll probably be doing `if some_obj.is_a? Guest` or `if some_obj.guest?` anyway.

I've worked on very large and well used applications (billions of loads, multiple data centers, hundreds of thousands of lines of code), not that that should really matter to the argument (logical fallacy and all that), but the thing that I've found messes up Rails applications is large model objects ("god objects"), poorly thought out data relationships, and inconsistent assumptions across systems that lead to hacks. Not nils.

Re:10 Most Common Rails Mistakes by rubiquity on Wednesday June 04, 2014 @12:28PM (#7846519)
> Anywhere you are doing `if some_obj` in view code you'll probably be doing `if some_obj.is_a? Guest` or `if some_obj.guest?` anyway.

Sorry, you're completely wrong. Polymorphism and duck typing exist specifically so that you don't have to do `is_a?` checks.

> but the thing that I've found messes up Rails applications is large model objects ("god objects"),

How do you think god object models get created in the first place? By not extracting out logic. When you have models that have very different state, you actually have very different objects. Those differences should be extracted into different classes.

Re:10 Most Common Rails Mistakes by Finbarr on Tuesday June 03, 2014 @02:01PM (#7841763)
Agree that `if some_obj` all the time is annoying. Instead, better to introduce semantic helper methods like `if signed_in?` (which incidentally is included with gems like Devise).
Re:10 Most Common Rails Mistakes by matdes on Tuesday June 03, 2014 @07:00PM (#7843207)
helpers are awful

embrace OO