Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: How Are Attributes Useful?by talexb (Chancellor) |
on Jan 18, 2005 at 21:55 UTC ( [id://423195]=note: print w/replies, xml ) | Need Help?? |
I'm not an expert, but I can bring some of my C experience to bear. The C language is bound closely to assembler, and as such has certain keywords that act like the attributes that you're talking about. One that comes to mind is volatile, a variable declaration modifier that signals the compiler that whenever that variable was used in an expression, its value had to be read from the memory location assigned to it -- because its value was volatile. Another example is the lock attribute discussed in the Camel (pp. 457-458); it gives the compiler a hint that only the thread that has locked a function is allowed to call it. This is an attempt to prevent a race condition. Finally, there's the oxymoron of the constant variable -- that's just a convenience that allows a constant value to be stored in a read-only variable. Any attempt to update this variable's value will be ignored. So to answer your question -- attributes are used to give hints to the compiler and the run-time about special treatment to be given to certain variables and functions. And sometimes that behaviour isn't fully defined -- it's to leave future perl developers (note the lower case 'p') room to expand, as necessary. Alex / talexb / Toronto "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds
In Section
Seekers of Perl Wisdom
|
|