September 11, 2012
On Tuesday, 11 September 2012 at 16:34:33 UTC, monarch_dodra wrote:
> At the very least, I wish we could write:
> --------
> struct S(T)
> {
>     @property void front(T value)
>         if(isAssignable!(T,T))
>     {
>         ...
>     }
> }
> --------

..Yeah... that wouldn't work would it?

That would just prevent "front" from being matched when the call is attempted, but since it is a non-template, it will still get compiled...

Wish it did work though!

Well... time to move on...
September 11, 2012
On Tuesday, 11 September 2012 at 10:51:35 UTC, monarch_dodra
wrote:
> [SNIP]

One of my gripes was that the static if creates a new block,
which brakes a struct/class's natural flow. The code gets
indented, the DDoc gets placed further away from the function's
name, teh condition gets placed kind of far from the function's
name etc...

However, when written like this:

struct C(T)
{
     private T val;

     // Gets front
     @property T front()
     {val = value;}

     //Writes to front
     static if(isAssignable!(T,T))
     @property void front(T value)
     {val = value;}
}

Then I think it reads alright.

I think I'll come to grips with this.
September 11, 2012
On Tuesday, September 11, 2012 19:37:02 monarch_dodra wrote:
> However, when written like this:
> 
> struct C(T)
> {
>       private T val;
> 
>       // Gets front
>       @property T front()
>       {val = value;}
> 
>       //Writes to front
>       static if(isAssignable!(T,T))
>       @property void front(T value)
>       {val = value;}
> }
> 
> Then I think it reads alright.

Whereas I think that that hards readibility, because it hides the fact that a static if is used. If you're submitting code for Phobos, please do something like

static if(isAssignable!(T, T)) @property void front(T value) {val = value;}

or

static if(isAssignable!(T,T))
    @property void front(T value) { value = value; }

rather than what you have above, otherwise it will harm maintainability.

- Jonathan M Davis
September 11, 2012
On Tuesday, 11 September 2012 at 17:52:44 UTC, Jonathan M Davis wrote:
> On Tuesday, September 11, 2012 19:37:02 monarch_dodra wrote:
>> However, when written like this:
>> 
>> struct C(T)
>> {
>>       private T val;
>> 
>>       // Gets front
>>       @property T front()
>>       {val = value;}
>> 
>>       //Writes to front
>>       static if(isAssignable!(T,T))
>>       @property void front(T value)
>>       {val = value;}
>> }
>> 
>> Then I think it reads alright.
>
> Whereas I think that that hards readibility, because it hides the fact that a
> static if is used. If you're submitting code for Phobos, please do something
> like
>
> static if(isAssignable!(T, T)) @property void front(T value) {val = value;}
>
> or
>
> static if(isAssignable!(T,T))
>     @property void front(T value) { value = value; }
>
> rather than what you have above, otherwise it will harm maintainability.
>
> - Jonathan M Davis

Hum... Yeah, you are kind of right.

I actually am committing something, but the code is a 2 liner. (enforce, then assignment).

Is one of these what you are suggesting?

//One
static if(isAssignable!(T,T)) @property void front(T value)
{
    enforce(someCondition)
    value = value;
}

or

//Two
static if(isAssignable!(T,T))
    @property void front(T value)
{
    enforce(someCondition)
    value = value;
}

or

//Three
static if(isAssignable!(T,T))
@property void front(T value)
{
    enforce(someCondition)
    value = value;
}


(or just plain)

//Four
static if(isAssignable!(T,T))
{
    @property void front(T value)
    {
        enforce(someCondition)
        value = value;
    }
}

Which do YOU think reads best in this case? That the style I'll use in my submit.

I like //Three because it reads like an attribute.

Of course, I have no problem submitting it with the default //Four if you think that is best. I'm just trying to do as best possible.
September 11, 2012
On Tuesday, September 11, 2012 20:39:55 monarch_dodra wrote:
> Is one of these what you are suggesting?
> 
> //One
> static if(isAssignable!(T,T)) @property void front(T value)
> {
>      enforce(someCondition)
>      value = value;
> }
> 
> or
> 
> //Two
> static if(isAssignable!(T,T))
>      @property void front(T value)
> {
>      enforce(someCondition)
>      value = value;
> }
> 
> or
> 
> //Three
> static if(isAssignable!(T,T))
> @property void front(T value)
> {
>      enforce(someCondition)
>      value = value;
> }
> 
> 
> (or just plain)
> 
> //Four
> static if(isAssignable!(T,T))
> {
>      @property void front(T value)
>      {
>          enforce(someCondition)
>          value = value;
>      }
> }
> 
> Which do YOU think reads best in this case? That the style I'll use in my submit.
> 
> I like //Three because it reads like an attribute.
> 
> Of course, I have no problem submitting it with the default //Four if you think that is best. I'm just trying to do as best possible.

I'd use either one or four. I would definitely _not_ use three, precisely because it's using no indentation at all. Either the signature should be one line, or it needs indentation.

- Jonathan M Davis
September 12, 2012
On Tuesday, 11 September 2012 at 21:44:50 UTC, Jonathan M Davis wrote:
>
> I'd use either one or four. I would definitely _not_ use three, precisely
> because it's using no indentation at all. Either the signature should be one
> line, or it needs indentation.
>
> - Jonathan M Davis

I decided to use the basic notation (Four). I don't think there is anything wrong with experimenting, just not in Phobos.

Thankyou.
1 2
Next ›   Last »