From: Ryan Davis Date: 2011-03-26T05:06:53+09:00 Subject: Re: shortcut for add unless nil ? On Mar 24, 2011, at 22:33 , Iain Barnett wrote: > > On 24 Mar 2011, at 22:45, Ryan Davis wrote: > >> The most idiomatic (and performant) shortcut is to not have the situation arise in the first place. Nil checks everywhere is generally a design smell. Push things up to whereever the defaults should be figured out... in railsy parlance: >> >> thingies = params[:thingies] || [] >> >> then later you never have to worry about it. >> > > I agree to an extent, but even when you're defining defaults it would be nice: > > thingies = params[:thingies] || [] > wotsits = params[: wotsits] || [] > stuff = thingies + wotsits > > isn't as nice as > > stuff = params[:thingies] +? params[:wotsits] > > where +? is my new infix operator of choice for "add unless nil" :) Sometimes I don't want the extra typing or to use extra locals that will only be used for that one line. Yeah. Well... I disagree. We really don't need extra magical syntax. I can almost guarantee you that this proposal would get rejected by ruby-core@, but you're free to ask.