View mode: basic / threaded / horizontal-split · Log in · Help
April 05, 2008
Re: pure, safe and generalized attributes
David Wilson wrote:
> On Fri, Apr 4, 2008 at 7:19 AM, Knud Soerensen <4tuu4k002@sneakemail.com> wrote:
>>  With all the talk about pure, safed and transitivity.
>>  I think the time is right for a discussion about
>>  user defined code attributes.
>>
>>  Code attributes is just meta data for the code.
>>  Normally, this meta data is stored in revision systems, databases, in
>>  the code comments or just plain left out.
>>  But there is some advantages by placing them in the code and letting the
>>  compiler take care of them.
>>
>>  Scott Meyers does a good job of introducing the subject in
>>  http://video.google.com/videoplay?docid=-4728145737208991310
>>
>>  ----
>>
>>  The simplest use of code attribute I can imagine
>>  is a attribute which indicate that this piece of code have been review.
>>  It could be defined by.
>>  attribute KilroyWasHere;
> 
> For all that I'd love to see something like .NET attributes in D, if
> it means people starting to mark functions and fields with
> [BugFix(1234)] or [ReviewedBy("me")] then count me out! Source files,
> i.e. the data structures you feed to a compiler,  really isn't the
> place for adding support for ticket tracking or a review process. :)
> 
> For the first case, get a revision control system and use its
> annotation function (this has the benefit of systematically recording
> all changes to every line of code in a file, not just ones some
> programmer arbitrarily decided to tag with an attribute). For the
> latter case, see something like review-board.org or search Google for
> "QA branch". These really aren't good uses of custom attributes at
> all.
> 
Yes, if you only read the part of my post that you have cited
then there is no point of implementing it.

That why I write the you can do that with comment as well.

The real power comes when you utilise the compiler to ensure
the transitivity constraint of the attribute, something most revision
control system can't do and something I think will be very helpful when
dealing with big code bases and/or big teams.
April 05, 2008
Re: pure, safe and generalized attributes
Janice Caron wrote:
> On 05/04/2008, Knud Soerensen <4tuu4k002@sneakemail.com> wrote:
>> You could also ague that it is not necessary because
>>  attributes can only appear in certain places
>>
>>  only in function, class, struct and module declarations.
> 
>     KilroyWasHere:
> 
> Is that an attribute or a label?

"KilroyWasHere" is the label for the attribute
that this place was inspected by Kilroy

Why do you ask ??
April 05, 2008
Re: pure, safe and generalized attributes
On 05/04/2008, Knud Soerensen <4tuu4k002@sneakemail.com> wrote:
> Janice Caron wrote:
>
> > On 05/04/2008, Knud Soerensen <4tuu4k002@sneakemail.com> wrote:
>  >> You could also ague that it is not necessary because
>  >>  attributes can only appear in certain places
>  >>
>  >>  only in function, class, struct and module declarations.
>  >
>
> >     KilroyWasHere:
>  >
>  > Is that an attribute or a label?
>
> "KilroyWasHere" is the label for the attribute
>  that this place was inspected by Kilroy
>
>  Why do you ask ??

I was trying to make the point that D has a context-free grammar, and
that an identifier followed by a colon, where you might expect to find
a statement or a declaration, might be ambiguous.

In hindsight, I might have jumped too fast. It might be possible to
tell the difference because: if you're expecting a statement, it's a
label; if you're expecting a declaration, it's an attribute.

However, the point still stands. Allowing arbitrary identifiers as
attributes is /bound/ to confuse the parser somewhere along the line,
unless we explicitly indicate to the compiler that this identifier is
an attribute.
April 05, 2008
Re: pure, safe and generalized attributes
Janice Caron wrote:
> On 05/04/2008, Knud Soerensen <4tuu4k002@sneakemail.com> wrote:
>> Janice Caron wrote:
>>
>>> On 05/04/2008, Knud Soerensen <4tuu4k002@sneakemail.com> wrote:
>>  >> You could also ague that it is not necessary because
>>  >>  attributes can only appear in certain places
>>  >>
>>  >>  only in function, class, struct and module declarations.
>>  >
>>
>>>     KilroyWasHere:
>>  >
>>  > Is that an attribute or a label?
>>
>> "KilroyWasHere" is the label for the attribute
>>  that this place was inspected by Kilroy
>>
>>  Why do you ask ??
> 
> I was trying to make the point that D has a context-free grammar, and
> that an identifier followed by a colon, where you might expect to find
> a statement or a declaration, might be ambiguous.
> 
> In hindsight, I might have jumped too fast. It might be possible to
> tell the difference because: if you're expecting a statement, it's a
> label; if you're expecting a declaration, it's an attribute.
> 
> However, the point still stands. Allowing arbitrary identifiers as
> attributes is /bound/ to confuse the parser somewhere along the line,
> unless we explicitly indicate to the compiler that this identifier is
> an attribute.

I see that the D manual already have something called attributes
it might have been confusing you.

Maybe if i use the word constrain, for what we talking about is a way to
define code constrains.

We have this now i D
ModuleDeclaration:
module ModuleName ;

ClassDeclaration:
 class Identifier BaseClassList(opt)  ClassBody

FunctionDeclaration: (I didn't find this in the manual)
type Identifier(Parameters) FunctionBody

With constrains we will have this
ModuleDeclaration:
module ModuleName ConstrainList(opt);

ClassDeclaration:
 class Identifier BaseClassList(opt)  ConstrainList(opt) ClassBody

FunctionDeclaration:
type Identifier(Parameters) ConstrainList(opt) FunctionBody

Hope this helps

Knud
April 05, 2008
Re: pure, safe and generalized attributes
On 05/04/2008, Knud Soerensen <4tuu4k002@sneakemail.com> wrote:
> I see that the D manual already have something called attributes
>  it might have been confusing you.

Yes it was. I assumed that "attribute" meant what it means in the D
grammar docs.

This wasn't the first time that confusion was caused by two people
assuming the same word meant two different things. I'm sure it won't
be the last! :-)

That said, you'd probably want your constraints to be attributes
anyway. That is, you'd want to put them anywhere you can currently put
"static", "private", etc.
April 09, 2008
Re: pure, safe and generalized attributes
Janice Caron wrote:
> On 05/04/2008, Knud Soerensen <4tuu4k002@sneakemail.com> wrote:
> 
>>I see that the D manual already have something called attributes
>> it might have been confusing you.
> 
> 
> Yes it was. I assumed that "attribute" meant what it means in the D
> grammar docs.
> 
> This wasn't the first time that confusion was caused by two people
> assuming the same word meant two different things. I'm sure it won't
> be the last! :-)
> 
> That said, you'd probably want your constraints to be attributes
> anyway. That is, you'd want to put them anywhere you can currently put
> "static", "private", etc.

This would be enormously confusing to people reading others' code.
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home