#to_b - why isn't this one already in there?

Phlip wrote:

Michael T. Richter wrote:

> > if foo == "false"
> >
> > can see the usefulness of this.
>
> In which locales?

sorry? I don't know what you mean.

I think he was trying to gently point out that "false" is English, so it's
likely to be the kind of problem only an English speaker would have. (Not
that I can say I've ever had this problem of confusing false with "false"
in *ANY* language.

Si.

This seems a bit silly to me. The language of Ruby is far more English
than any other language. Would this be of any use:

"false" == false.to_s

···

--
Posted via http://www.ruby-forum.com/\.

The thing I like about the approach I took is that it doesn't
generalize to any other context. It only does one thing. I'm using it
in a constructor which takes a hash. Sometimes the hash is built by
code, and sometimes it's a params hash in Rails - in other words, a
set of Strings - with a few additional values merged in. It's pretty
common in Ruby to use a hash as a substitute for keyword arguments to
methods, and that's what's happening here. The code gets kind of
wiggy, and it makes it really nice when the params specified in a URL
or a form post line up exactly with the "keyword arguments" so that
there's no unnecessary synonyms clouding the semantic space. you
basically get semantic URLs this way internally to your application.
but if you want to use a boolean in this context, you have to convert
it, and circumvent that whole

if "false" # => true

gotcha.

this isn't actually related to human language **at all**. if you're
attempting to use URL parameters as keyword arguments, you want the
URLs to look just like Ruby, but of course the values in a URL or in
form parameters can actually only move out to the Web or come back
from it as strings. false doesn't come in as the string "false"
because I speak English. it comes in as the string "false" because
**Ruby** speaks English. if Ruby used the word "falso" or for that
matter "nothos," transliterating Ruby literals into strings would mean
using "nothos" or "falso" also. it's got nothing to do with locales.
it's got to do with being able to seamlessly transliterate your code
into URLs for the Web and get it back in executable form.

ok, apologies if that's somewhat defensive. I'm just saying, a lot of
the critiques sound dead on, but in this case I totally stand by my
design. in the broader case, I'm used to this from Perl, where the
scalar "false" also evaluates to true. but one of the huge strengths
of Ruby is that it keeps a lot of Perl's power and flexibility, but
throws away the weird, nearly demented idiosyncrasies. I can't be the
first person who ever coded a solution like this, and I know that
.to_i exists because your code can get numbers in as Strings or Floats
or what have you and need to convert it before doing anything real
with it.

(probably I should just STFU and package this up as a microgem or what
have you.)

anyway I think this is probably the answer:

I am thinking that, with people saying that they want to
have a wide assortment of what constitutes true, that they should
make a list (array) of things which would evaluate to true and
anything else would be false. But that is so individual that
making it part of the language seems counter productive.

I think the reason it's not part of the language is that you
**should** alter the language for specific things. I kind of
overloaded on Perl and went to Java and Python, and I actually found
the stability of those languages a nice change. so when I got into
Ruby, the idea of changing fundamental types for specific programs
seemed notorious and reckless, what the Pythonistas used to snort
derisively about and call "Perlish," but I'm thinking it's actually a
very sensible approach. you shouldn't view Ruby the language as
fundamental - you should view it as a **template** for the language
you're actually going to use once you fully define the problem space
and your corresponding solution. like the Paul Graham idea about Lisp,
that you build the program down to the language and build the language
up to the program, except a lot more of the work is already done for
you when you start.

···

--
Giles Bowkett

Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com/

Lloyd Linklater wrote:

This seems a bit silly to me. The language of Ruby is far more English
than any other language. Would this be of any use:

"false" == false.to_s

Quoting Joel Spolsky, "There's no such thing as raw text".

···

--
Phlip

Phlip wrote:

Michael T. Richter wrote:

if foo == "false"

can see the usefulness of this.

In which locales?

sorry? I don't know what you mean.
I think he was trying to gently point out that "false" is English, so it's likely to be the kind of problem only an English speaker would have. (Not that I can say I've ever had this problem of confusing false with "false" in *ANY* language.

Si.

This seems a bit silly to me. The language of Ruby is far more English than any other language.

I am not sure: Ruby originated in Japan and has a strong Japanese community AFAIK. You may not have notice because Matz, Nobu and all the others are kind enough to use English when they post here. :slight_smile:

Would this be of any use:
"false" == false.to_s

I'm not sure what you try to point out. If you are referring to the fact that false returns "false" when invoking #to_s (which is locale unaware) then I'd say this is a different story: one string representation *has* to be chosen and what would be more natural than using the same wording?

Conversion of values obtained from user input or something similar is a completely different story because these will usually be in a particular language which often depends on the user. Note that, if I'm not mistaken, browsers can send anything for marked checkboxes and radiobuttons in forms so the proper distinction might rather be present and not present. (Dunno how Rails handles this though).

Another note: I am increasingly reluctant to modify core classes to achieve specialized behavior like this. A simple method called on the result of the Hash lookup would have served the same purpose. An even more efficient solution would use a Hash for conversion:

# one variant
BOOL = Hash.new {|h,k| k}.merge("false" => false)

Kind regards

  robert

···

On 08.09.2007 16:42, Lloyd Linklater wrote:

I think the reason it's not part of the language is that you
**should** alter the language for specific things. I kind of
overloaded on Perl and went to Java and Python, and I actually found
the stability of those languages a nice change. so when I got into
Ruby, the idea of changing fundamental types for specific programs
seemed notorious and reckless, what the Pythonistas used to snort
derisively about and call "Perlish," but I'm thinking it's actually a
very sensible approach. you shouldn't view Ruby the language as
fundamental - you should view it as a **template** for the language
you're actually going to use once you fully define the problem space
and your corresponding solution. like the Paul Graham idea about Lisp,
that you build the program down to the language and build the language
up to the program, except a lot more of the work is already done for
you when you start.

Chiming in here to say that this paragraph is an awesome way of
describing the way things seem.

Cheers,
  Arlen.

> I think the reason it's not part of the language is that you
> **should** alter the language for specific things. I kind of
> overloaded on Perl and went to Java and Python, and I actually found
> the stability of those languages a nice change. so when I got into
> Ruby, the idea of changing fundamental types for specific programs
> seemed notorious and reckless, what the Pythonistas used to snort
> derisively about and call "Perlish," but I'm thinking it's actually a
> very sensible approach. you shouldn't view Ruby the language as
> fundamental - you should view it as a **template** for the language
> you're actually going to use once you fully define the problem space
> and your corresponding solution. like the Paul Graham idea about Lisp,
> that you build the program down to the language and build the language
> up to the program, except a lot more of the work is already done for
> you when you start.
>

Chiming in here to say that this paragraph is an awesome way of
describing the way things seem.

hey, thanks.

···

--
Giles Bowkett

Blog: http://gilesbowkett.blogspot.com
Portfolio: http://www.gilesgoatboy.org
Tumblelog: http://giles.tumblr.com/