On May 31, 2012, at 8:58 AM, 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
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
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?
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
On Thu, May 31, 2012 at 2:12 PM, James B. Byrne byrn...@harte-lyne.cawrote:
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
On 31 May 2012 14:23, Sam Oliver s...@samoliver.com wrote:
On Thu, May 31, 2012 at 2:12 PM, James B. Byrne byrn...@harte-lyne.cawrote:
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
I'm -1 on a has_* method
If we want to kill ? on non boolean attributes we should encourage standard
@post.url.blank? and @post.url.present? be used instead. The originally
proposed change makes sense to me. The question mark character adds nice
semantics to boolean attributes. I agree it's
+1 to Richard. Keep ? for booleans, get rid of the others and use .blank?
and .present? as needed.
--
Jarrett Meyer
Email: jarrettme...@gmail.com
Web: JarrettMeyer.com http://jarrettmeyer.com
Twitter: @jarrettmeyer http://twitter.com/jarrettmeyer
On Thu, May 31, 2012 at 9:45 AM, Richard
absolutely agree with all points. i just didn't know if methods count
argument is relevant at all. imo it's a nice side-effect of proposed
change.
On Thursday, May 31, 2012 3:45:23 PM UTC+2, richard schneeman wrote:
I'm -1 on a has_* method
If we want to kill ? on non boolean attributes we
I'd guess methods count is relevant based on this pull request:
https://github.com/rails/rails/pull/5763
Em 31-05-2012 10:49, Maksym Melnychok escreveu:
absolutely agree with all points. i just didn't know if methods count
argument is relevant at all. imo it's a nice side-effect of proposed
Not using is_ is idiomatic:
http://devblog.avdi.org/2011/04/07/rspec-is-for-the-literate/ (look
for 'There is a different, but related, effect of using RSpec.')
Every Ruby object is truthy or falsey, and so treating them all as
possibly boolean is 100% okay as far as I'm concerned.
--
You
Actually the query attribute method does more than check if the value is
present. It is very useful for legacy databases where the user persist
boolean values as [0, 1], [t, f], [true, false] and more.
I don't see this being removed from rails or changing your behavior.
Also removing it will not
Em 31-05-2012 11:30, Rafael Mendonça França escreveu:
Actually the query attribute method does more than check if the value
is present. It is very useful for legacy databases where the user
persist boolean values as [0, 1], [t, f], [true, false] and more.
I don't see this being removed from
@ Rafael Mendonça França
legacy databases storage must be concern of corresponding database
adapter, if a field is of boolean type, whatever that means on storage
level of particular database, that field must be treated as boolean in rails
on the model level.
i'm not suggesting to drop such
but if we decide that there doesn't have to be semantical contribution to
your code from using attribute query methods then #{attribute}? is just
a shortcut for !!#{attribute} - so why do we need it in the first place?
saving 1 character is weird goal here.
It's not saving a character. It's
Em 31-05-2012 11:48, Maksym Melnychok escreveu:
@ Rafael Mendonça França
legacy databases storage must be concern of corresponding database
adapter, if a field is of boolean type, whatever that means on storage
level of particular database, that field must be treated as boolean in
rails
on
Em 31-05-2012 11:52, Rodrigo Rosenfeld Rosas escreveu:
Em 31-05-2012 11:48, Maksym Melnychok escreveu:
@ Rafael Mendonça França
legacy databases storage must be concern of corresponding database
adapter, if a field is of boolean type, whatever that means on storage
level of particular
And in these cases you don't know if these fields are boolean or not. If
you are choose to store the visible column as string [yes, no] so you
will not have the query method.
I like this method as it is. For me it is very useful and give me the
possibility to not care about what is the datatype
Another way would add another annotation method to ActiveRecord::Base, like:
boolean_field :incomplete, :disabled, :deleted
This would further document the model mapping and would also allow
better semantics.
Not that I really care about this as I don't even use ActiveRecord ;)
Cheers,
On Thursday, May 31, 2012 4:50:05 PM UTC+2, Steve Klabnik wrote:
It's not saving a character. It's that !! is programmer talk, and ? is
human talk. Ruby prefers human talk.
well your kung-fu beats my kung-fu here
i just don't think post.url? is talking proper human talk to me, i would
Maybe it is just me, but I don't use features that I don't like in rails,
just like I avoid calling private methods. In that sense, there's nothing
that is preventing anyone from using `post.body.present?` instead of
`post.body?`. My argument would be to let rational programmers decide what
is
On Thu, May 31, 2012 09:23, Sam Oliver wrote:
On Thu, May 31, 2012 at 2:12 PM, James B. Byrne
byrn...@harte-lyne.cawrote:
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
22 matches
Mail list logo