Circle Calculator Help

Steven Schveighoffer schveiguy at yahoo.com
Tue Jun 26 16:53:13 PDT 2012


On Tue, 26 Jun 2012 19:44:34 -0400, Sean Kelly <sean at invisibleduck.org>  
wrote:

> On Jun 26, 2012, at 4:40 PM, Steven Schveighoffer wrote:
>
>> On Tue, 26 Jun 2012 19:10:25 -0400, bearophile  
>> <bearophileHUGS at lycos.com> wrote:
>>
>>> Steven Schveighoffer:
>>>
>>>> I agree with Andrei, there is no outlet for errors in the to!T  
>>>> function, exception is the logical choice.
>>>
>>> Maybe I was not clear enough, so let me explain a bit better.
>>>
>>> What I don't like is to!int("15\n") to be seen as an error in the  
>>> first place.
>>> I'd like it to ignore leading and trailing whitespace, as in Python  
>>> (stripping it automatically):
>>
>> Right, but what if it's an error in your code if whitespace is  
>> present?  Then you have to check for whitespace and throw your own  
>> error.
>
> to!int(trim("5\n"))
>
> no?

That was my original suggestion.  It fixes the problem, but can seem quite  
unintuitive to a developer that they have to do this.

Plus if it actually *is* an error for the string to have whitespace, you  
would want it to throw.  My point to bearophile is, we may want both  
options.

I can easily see someone using just to!int(userInput), and testing without  
ever putting in spaces, and then user does and the application blows up  
(quite needlessly).

-Steve


More information about the Digitalmars-d-learn mailing list