[BUG] String>>asInteger

Doug Way dway at mailcan.com
Wed Jan 21 18:36:54 UTC 2004


I agree that the naming here is bad enough to be considered a bug.  The 
solution would appear to be to rename String>>asInteger to 
String>>asUnsignedInteger, and rename String>>asSignedInteger to 
String>>asInteger.  (Or possibly keep asSignedInteger, but that seems 
like a bad idea.)

It looks like there are no senders of asUnsignedInteger in the alpha 
image.  There are lots of senders of asInteger, but many of those are 
converting from other Number types.  I'd guess that probably none of the 
senders rely on the signed behavior, but we'd just have to wait and see 
if any bugs showed up.

Another possible improvement would be to reimplement these methods to 
use Integer>>readFrom:.

- Doug


Martin Wirblat wrote:

>I would clearly rate this a bug, because there are negative Integers 
>in class Integer, and the semantics of #asXyz is that Xyz is a class. 
>Even in the rest of the computing world Integers mostly if not always 
>include negatives. 
>
>Integer readFrom: ( ReadStream on: '-1' ) answers -1, and that is 
>the expected implementation. 
>
>Furthermore the compiler converts '-1' to Integer -1, and so should do 
>this method. Everything else is totally unexpected.
>
>regards
>Martin
>
>Michael Roberts <mike at mjr104.co.uk> wrote on 21.01.2004 12:52:57:
>  
>
>>I was wondering if someone might help me out with the intent behind 
>>String>>asInteger and String>>asSignedInteger. 
>>
>>I was puzzled for a while why '-1' asInteger returned '1'.  I was 
>>about to ask about this when I stumbled across the second method - 
>>aha! 
>>
>>The code for the two methods is largely identical with 
>>asSignedInteger appearing two years later. 
>>
>>I was wondering why one would not want the signed behaviour most of 
>>the time.  Do people always expect this to be unsigned?  I'm sorry if 
>>that's a stupid question! 
>>
>>I was wondering about the consistency:
>>-3 asInteger -> -3
>>'-3' asInteger -> 3
>>-1 asString asInteger -> 1
>>
>>So I was wondering what the usage would be like if the functionality 
>>was reversed and the later called String>>asUnsignedInteger.  
>>
>>what a lot of wonderng....
>>
>>Cheers
>>
>>Mike
>>    
>>
>
>
>
>  
>





More information about the Squeak-dev mailing list