Boolean affectation shortcut

fr 13:
# You can' t because only methods can end with ?

i think he is asking, why not? of course, we know it is not currently possible, but variable names with "?" may enhance readability.

consider,

x? = method_that_determines_some_status

....

if x?
  ....

end

by just looking at the name, we are pretty sure that x? is a boolean (just like is_xx? methods return bools).

wc is better than,

if x
   ...
end

whether x is a variable or method..

it's just an added character where one may happily use or not. But maybe i am missing something deeper..

kind regards -botp

Hi --

···

On Sat, 13 May 2006, Peña, Botp wrote:

fr 13:
# You can' t because only methods can end with ?

i think he is asking, why not? of course, we know it is not
currently possible, but variable names with "?" may enhance
readability.

consider,

x? = method_that_determines_some_status

....

if x?
....

end

by just looking at the name, we are pretty sure that x? is a boolean
(just like is_xx? methods return bools).

wc is better than,

if x
  ...
end

whether x is a variable or method..

it's just an added character where one may happily use or not. But
maybe i am missing something deeper..

To me, this:

   x? = true

reads as:

   set "is x?" to true

... that is, setting the question, rather than the answer.

David

--
David A. Black (dblack@wobblini.net)
* Ruby Power and Light, LLC (http://www.rubypowerandlight.com)
   > Ruby and Rails consultancy and training
* Author of "Ruby for Rails" from Manning Publications!
   > Ruby for Rails