Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: to_i
Austin Ziegler
11/17/2003 4:23:00 AM
On Mon, 17 Nov 2003 10:24:58 +0900, Artur Merke wrote:
>> IMHO this is a struggle between convenience and cleanness. I guess
>> Matz decided for convenience in this case, maybe because in most cases
>> using 0 is ok. If you want to do correct input checking you do /^[+-
>> ]?\d+$/ =~ foo anyway.
>>
> IMO, it has to do with the principle of least surprise, and it is a BIG
> surprise to get "hello".to_i -> 0
http://www.cplusplus.com/ref/cstdlib...
It is common for integer conversion techniques to use only what is known
(e.g., "123hello" => 123; "hello" => 0). Delphi's StrToInt method, however,
will throw an error (in some silly cases, IMO).
-austin
--
austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.11.16
* 23.21.40
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: to_i
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password