my point is about semantics, not truthiness/falseness of values post.visible? - is asking post object if it is visible because it has a flag(boolean attribute) named 'visible'
post.url? - is checking if attribute named 'url' is present or not, and that is exactly what i find confusing because even though syntactically it is identical to flag check, semantically this line looks like we're asking post object if it is a url which makes no sense. Regards, Max On Thursday, May 31, 2012 3:12:21 PM UTC+2, byrnejb wrote: > > > On Thu, May 31, 2012 08:58, Maksym Melnychok wrote: > > Does anyone else finds attribute query methods semantically confusing? > > > > Hi, > > > > Consider this code: > > > > post = Post.new(:visible => true, :url => "http://com") > > > > if post.visible? > > puts "ima visible!" > > end > > > > if post.url? > > puts "ima url! (wait wat? o_0)" > > end > > > > Does this feel right to you? In case with post.url? i read it as "Hey > > post object, are you an url?" which is apparently not what the code > > will do. > > > > So it seems like semantically perfect flag checks go together with > > totally confusing(for a reader) way of checking whether an attribute > > is present or not. > > > > I would generate attribute query methods only for boolean attributes. > > I am not sure that I understand your point, but in Ruby anything that > is neither nil nor false is true. Thus returning the url string, if > not nil, is the same as saying that it is true but also allows access > to the actual data without having to send another message. > > -- > *** E-Mail is NOT a SECURE channel *** > James B. Byrne mailto:byrn...@harte-lyne.ca > Harte & Lyne Limited http://www.harte-lyne.ca > 9 Brockley Drive vox: +1 905 561 1241 > Hamilton, Ontario fax: +1 905 561 0757 > Canada L8E 3C3 > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/0YtbyF6g470J. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.