Counter-Proposal: restrict & tagged functions

foobar foo at bar.com
Sun Sep 2 03:08:22 PDT 2012


On Saturday, 1 September 2012 at 21:50:33 UTC, Dmitry Olshansky 
wrote:
> On 02-Sep-12 01:13, foobar wrote:
> [snip]
> >
> > I skipped the details but I do agree with the general
> sentiment.
> > This long post begs the question - Why a general annotation
> > mechanism isn't enough to justify adding so much complexity to
> > the language?
>
> It's quite short compared to all of the features it replaces 
> and it had to allow for backwards compatibility. And it had to 
> leave place for other @annotations as I felt restricting blocks 
> of code is not the only use case for annotations.
>
> Also sadly it reiterates a lot of trivia around how tagged 
> functions and pointers interact with each another.
>
> About general annotation mechanism. Nobody yet put together a 
> proper proposal (if any at all), all I see is people that keep 
> saying: "it's simple - just add the general annotation 
> mechanism!".
>

This basically reiterates the original post without answering my 
question.
Regarding the general mechanism - Why do we have to re-invent the 
wheel?
There already is a very successful model used by Java, C# and 
even C++11 (with slight variations). My "proper proposal" would 
than to simply look at the C# documentation!

>
> > Me thinks that simply tagging malloc/alloca/GC.allocate/etc..
> > with a _user defined_ annotation should be sufficient without
> the
> > need to introduce all of the above syntax to the language.
>
> Simple tags have no much use on their own - need syntax to use 
> them.
> The compiler can deduce their meaning so you also need a way 
> tell the compiler: this function can only use "yellow" and 
> "green" functions. Then some tags need to be compatible (or 
> convertible with others), then there is a need to bundle tags 
> together and so on.
>
> I agree that simply tagging functions with red/green is 
> attractive and simple concept but to implement things like say 
> @safe you need more then that. You need to tweak what compiler 
> puts in there for you (and forbid/allow as it suits your needs).
>

We already have at least part of the syntax in D.
There is no need to "tweak the compiler", everything can be 
implemented in user code as shown in the link I provided. 
Including a proof of concept implementation in D, thanks to 
Bartosz.

>  In
> > fact, I have a vague memory of reading about green/red
> marking of
> > code via templates in plain old c++. No extra syntax required.
> >
> But xxtra works obviously :)
> The method entails carrying around tag arguments apparently. It 
> could be labeled as creative but a very backward way to do 
> something simple. More specifically it shows that this has to 
> be a language feature so that developers can focus on using it 
> instead of being busy implementing it by hand.
>
> > Here's the link:
> > http://www.artima.com/cppsource/codefeaturesP.html

Again, this is a proof of concept that shows that even current D 
is sufficient to implement this sort of restrictions. Add 
annotations to the mix and you could implement this with a better 
syntax without the need to add extra parameters to functions 
(which is quite an elegant solution imo)
No need for developers to implement this "by hand". Any language 
with a meta-data facility also provides standard annotations in 
its stdlib. If such restrictions are general purpose and useful 
enough they'll end up in Phobos anyway, allowing developers to 
concentrate on using them.



More information about the Digitalmars-d mailing list