Jump to page: 1 2
Thread overview
An idea to improve eponymous templates
Apr 12, 2012
Reid Levenick
Apr 12, 2012
H. S. Teoh
Apr 12, 2012
bearophile
Apr 12, 2012
Mehrdad
Apr 12, 2012
Mehrdad
Apr 12, 2012
Nathan M. Swan
Apr 12, 2012
Reid Levenick
Apr 12, 2012
Denis Shelomovskij
Apr 12, 2012
kenji hara
Apr 12, 2012
Daniel Murphy
Apr 12, 2012
Jacob Carlborg
Apr 12, 2012
Daniel Murphy
Apr 12, 2012
H. S. Teoh
Apr 12, 2012
kenji hara
Apr 12, 2012
Don Clugston
Apr 12, 2012
Timon Gehr
Apr 12, 2012
Timon Gehr
Apr 12, 2012
H. S. Teoh
April 12, 2012
Firstly, I had no idea where suggestions should go, and I saw a few others here and thus here I am.

I was writing some code that depended heavily on my own eponymous templates, and decided to change the names of some of them to make them more self-documenting. However, after changing the name, I encountered a long stream of unintelligible errors (to me, I haven't been using D for a long time) about template instances.

So, my idea is that the 'this' keyword could be used in templates as a shortcut for eponymous templates, allowing code like this

template anEponymousTemplate( size_t whatever ) {
  enum this = whatever * 2;
}
template anotherOne( T ) {
  static if( is( T == class ) ) {
    alias long this;
  } else {
    alias int this;
  }
}

Which would reduce cruft and make it easier to read some templates, as well as reducing maintenance.
April 12, 2012
On Thu, Apr 12, 2012 at 04:21:45AM +0200, Reid Levenick wrote:
> Firstly, I had no idea where suggestions should go, and I saw a few others here and thus here I am.

AFAIK this is as good a place as any other.


> I was writing some code that depended heavily on my own eponymous templates, and decided to change the names of some of them to make them more self-documenting. However, after changing the name, I encountered a long stream of unintelligible errors (to me, I haven't been using D for a long time) about template instances.
> 
> So, my idea is that the 'this' keyword could be used in templates as a shortcut for eponymous templates, allowing code like this
> 
> template anEponymousTemplate( size_t whatever ) {
>   enum this = whatever * 2;
> }
[...]

+1. I like this idea. In fact, I've thought about proposing it before. :-) I don't like the idea of having to repeatedly retype the template name. I mean, the compiler already implicitly translates:

	int myfunc(T)(T args) { ... }

to:

	template myfunc(T) {
		int myfunc(T args) { ... }
	}

and nowadays pretty much *nobody* writes it the second way anymore.

Having to repeatedly type the same identifiers is one of the things that puts me off so much about Java. Especially with its proliferation of overly long identifiers (and their respective *Wrappers thereof).


T

-- 
The richest man is not he who has the most, but he who needs the least.
April 12, 2012
Reid Levenick:

> So, my idea is that the 'this' keyword could be used in templates as a shortcut for eponymous templates, allowing code like this
>
> template anEponymousTemplate( size_t whatever ) {
>   enum this = whatever * 2;
> }

Other "This" (with upper case)?

Bye,
bearophile

April 12, 2012
On 4/11/12 9:21 PM, Reid Levenick wrote:
> So, my idea is that the 'this' keyword could be used in templates as a
> shortcut for eponymous templates, allowing code like this
>
> template anEponymousTemplate( size_t whatever ) {
> enum this = whatever * 2;
> }
> template anotherOne( T ) {
> static if( is( T == class ) ) {
> alias long this;
> } else {
> alias int this;
> }
> }

Walter and I discussed this idea a while ago. It's a good one.
To ease into things eponymous templates should work both ways for a while.

We should define a little protocol for ideas that Walter approves but has higher-priority tasks to work on. Like DIPs that he gives the seal of approval to, so people know they can work on them.


Andrei
April 12, 2012
On Thursday, 12 April 2012 at 02:21:46 UTC, Reid Levenick wrote:
> Firstly, I had no idea where suggestions should go, and I saw a few others here and thus here I am.
>
> I was writing some code that depended heavily on my own eponymous templates, and decided to change the names of some of them to make them more self-documenting. However, after changing the name, I encountered a long stream of unintelligible errors (to me, I haven't been using D for a long time) about template instances.
>
> So, my idea is that the 'this' keyword could be used in templates as a shortcut for eponymous templates, allowing code like this
>
> template anEponymousTemplate( size_t whatever ) {
>   enum this = whatever * 2;
> }
> template anotherOne( T ) {
>   static if( is( T == class ) ) {
>     alias long this;
>   } else {
>     alias int this;
>   }
> }
>
> Which would reduce cruft and make it easier to read some templates, as well as reducing maintenance.

I like the idea. To get rid of any confusion with keywords, name-mangling, or classes, I suggest having "this" being syntactic sugar for the name of the template.

NMS

April 12, 2012
On Thursday, 12 April 2012 at 04:28:01 UTC, Nathan M. Swan wrote:
> I like the idea. To get rid of any confusion with keywords, name-mangling, or classes, I suggest having "this" being syntactic sugar for the name of the template.

I expressed it badly at the time, but that is exactly what I meant, yeah.
April 12, 2012
12.04.2012 6:21, Reid Levenick написал:
> Firstly, I had no idea where suggestions should go, and I saw a few
> others here and thus here I am.
>
> I was writing some code that depended heavily on my own eponymous
> templates, and decided to change the names of some of them to make them
> more self-documenting. However, after changing the name, I encountered a
> long stream of unintelligible errors (to me, I haven't been using D for
> a long time) about template instances.
>
> So, my idea is that the 'this' keyword could be used in templates as a
> shortcut for eponymous templates, allowing code like this
>
> template anEponymousTemplate( size_t whatever ) {
> enum this = whatever * 2;
> }
> template anotherOne( T ) {
> static if( is( T == class ) ) {
> alias long this;
> } else {
> alias int this;
> }
> }
>
> Which would reduce cruft and make it easier to read some templates, as
> well as reducing maintenance.

This idea already has it's own issue:
http://d.puremagic.com/issues/show_bug.cgi?id=7364

born from:
http://www.digitalmars.com/d/archives/digitalmars/D/Aliasing_of_template_results_155859.html

-- 
Денис В. Шеломовский
Denis V. Shelomovskij
April 12, 2012
It conflicts with $B!I(Balias this$B!I(B syntax.

template Inherits(T)
{
  T value;
  alias T Inherits;   // (1) Inherits!int == int
  alias T this;   // (2) declares "alias this"!
}
struct S {
  mixin Inherits!int;  // (1) invalid or (2) mixing alias this declaration?
}

Kenji Hara

2012$BG/(B4$B7n(B12$BF|(B11:21 Reid Levenick <reid.whitewater+dlang@gmail.com>:
> Firstly, I had no idea where suggestions should go, and I saw a few others here and thus here I am.
>
> I was writing some code that depended heavily on my own eponymous templates, and decided to change the names of some of them to make them more self-documenting. However, after changing the name, I encountered a long stream of unintelligible errors (to me, I haven't been using D for a long time) about template instances.
>
> So, my idea is that the 'this' keyword could be used in templates as a shortcut for eponymous templates, allowing code like this
>
> template anEponymousTemplate( size_t whatever ) {
>  enum this = whatever * 2;
> }
> template anotherOne( T ) {
>  static if( is( T == class ) ) {
>    alias long this;
>  } else {
>    alias int this;
>  }
> }
>
> Which would reduce cruft and make it easier to read some templates, as well as reducing maintenance.
April 12, 2012
"kenji hara" <k.hara.pg@gmail.com> wrote in message news:mailman.1646.1334209001.4860.digitalmars-d@puremagic.com...
> It conflicts with $B!I(Balias this$B!I(B syntax.
>
> template Inherits(T)
> {
>  T value;
>  alias T Inherits;   // (1) Inherits!int == int
>  alias T this;   // (2) declares "alias this"!
> }
> struct S {
>  mixin Inherits!int;  // (1) invalid or (2) mixing alias this declaration?
> }
>
> Kenji Hara
>

Doesn't it need to be explicitly marked as a 'mixin template' for it to be mixed in?


April 12, 2012
On 2012-04-12 11:21, Daniel Murphy wrote:

> Doesn't it need to be explicitly marked as a 'mixin template' for it to be
> mixed in?
>
>

No, I don't think that is forced.

-- 
/Jacob Carlborg
« First   ‹ Prev
1 2