[#964] Bastion or SecurityManager for Ruby? — Clemens Hintze <clemens.hintze@...>

Hi,

15 messages 1999/12/10

[#989] a question about to_i — Friedrich Dominicus <Friedrich.Dominicus@...>

Sorry, I'm quite new to ruby. But I encounterd the following problem. If

17 messages 1999/12/19

[ruby-talk:00998] Re: a question about to_i

From: "Conrad Schneiker" <schneiker@...>
Date: 1999-12-19 19:18:30 UTC
List: ruby-talk #998
----- Original Message -----
From: Yukihiro Matsumoto <matz@netlab.co.jp>
To: ruby-talk ML <ruby-talk@netlab.co.jp>
Sent: Sunday, December 19, 1999 10:18 AM
Subject: [ruby-talk:00996] Re: a question about to_i


> Hi,
>
> In message "[ruby-talk:00989] a question about to_i"
>     on 99/12/19, Friedrich Dominicus <Friedrich.Dominicus@inka.de> writes:
>
> |Sorry, I'm quite new to ruby. But I encounterd the following problem. If
> |I have a string "bla" and apply to_i to it I get 0. This seems to be
> |quite strange because it is what it is a string so shouldn't an
> |exeception be rissen or s.th simular.
>
> As Gotoken stated in [ruby-talk:00992], String#to_i (i.e. the to_i
> method of the String class) always return a integer.  This is
> inherited from UNIX's atoi() behavior.

This also appears to be what Perl does implicitly for you:

    $n = 1;
    $a = "xxx";
    $n = 2 + $n + 3;
    print "a = $a, n = $n, \n";

gives:

    a = xxx, n = 6

Perl usually has pretty good reasons (although probably not good enough in
this case!) for its behavior, but I don't know what they are in this case
(all my Perl books are at my other office). It may have something to do
with: (1) UNIX atoi() behavior as well, (2) performance in
conversion-intensive programs, (3) addition to 0 (zero) being the additive
identity, (4) and 0 (zero) meaning "false" in conditional tests.

> I can prepare exception raising version of the conversion method, but
> we have to decide following:
>
>   * the name of the method
>

Unless there are very strong arguments to the contrary, I'd recommend that
the *non-exception-raising* version get the *new* name, and that the current
version should raise an exception for non-numeric data.

This has the twin advantage of following the "principle of least surprise"
and the "principle of greatest default safety/reliability". These are
important considerations for new Ruby users, for the use of Ruby in large
and important projects, and for most easily documenting and teaching Ruby.

>
>   * proper behavior
>
>     on what situation, what kind of exception should be raised?
>     in addition, some may want to retrieve non numeric trailer,
>     the other may want to specify radix.

I don't understand (either/whether the what/why of) "want to retrieve non
numeric trailer.

Again, unless there are very strong arguments to the contrary, for radix,
why not allow exactly the same sorts of specifications that Ruby allows to
be specified in other numeric contexts. I think that this is the behavior
that is the easiest to explain / understand / remember and is also what most
people would regard as most "natural".

> Let's discuss about it.


In This Thread