From: Robert Klemme Date: 2008-10-03T05:38:53+09:00 Subject: Re: Is Assignment in a Conditional an Idiom? On 02.10.2008 20:35, worthee@gmail.com wrote: > I was just reading the following blog post > http://www.elctech.com/blog/clarity-over-cleverness-but-what-is-clever, > and like the author, it is the first time I have seen code as he > describes. From the comments it would seem that some think it is an > idiom to be used, and perhaps others do not. > > Just curious as to how common this use it? I do tend to side with > view that it is not clear at first glance. I believe this is a bad idiom. First, the test for "comments" is not needed because "String === comments" will be false if "comments" is nil. The statement would have been written much clearer as comments = @attributes['comments']) if comments.is_a? String @attributes['comments'] = comments.split(" ") end or comments = @attributes['comments']) @attributes['comments'] = comments.split(" ") if comments.is_a? String or comments = @attributes['comments']) @attributes['comments'] = comments.split(" ") if String === comments There is only one situation where assignment in a conditional actually makes code clearer and that is with loops, e.g. while line = io.gets puts line end My 0.02EUR Kind regards robert