@property - take it behind the woodshed and shoot it?

Simen Kjaeraas simen.kjaras at gmail.com
Fri Jan 25 08:48:02 PST 2013


On 2013-37-25 17:01, eles <eles at eles.com> wrote:

> On Thursday, 24 January 2013 at 08:35:01 UTC, Walter Bright wrote:
>
> One more thing (see also this:
> http://www.25hoursaday.com/CsharpVsJava.html#properties)
>
> In order to avoid properties throwing exceptions, maybe is wise
> to impose getters and setters to be nothrow.
>
> Why? Because code like this (C#) seems a bit unnatural:
>
> try{
>
> myClock.Hours   = 28;  /* setter throws exception because 28 is
> an invalid hour value */
> myClock.Minutes = 15;
> myClock.Seconds = 39;
>
> }catch(InvalidTimeValueException itve){
>
> /* figure out which field was invalid and report error */
>
> }

But setting the hours field to 28 is natural? While I want all
properties to be safe nothrow pure, it is unlikely to be a good
idea to force this upon people.

I'm all for putting it in the style guide, though.

-- 
Simen


More information about the Digitalmars-d mailing list