Style guide is very inconsistent

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Mon Nov 16 09:47:08 PST 2015


On Monday, 16 November 2015 at 16:42:57 UTC, maik klein wrote:
> On Monday, 16 November 2015 at 14:26:41 UTC, Jonathan M Davis 
> wrote:
>> On Monday, 16 November 2015 at 14:09:45 UTC, maik klein wrote:
>>> [...]
>>
>> Per the style guide,
>>
>> =====
>> Eponymous Templates
>>
>> [...]
>
> Okay thanks, but I am still not sure about my example.
>
> I am pretty sure that at least "any" should be camel case 
> because it's a value, but what about "Contains"? It's neither a 
> type nor a eponymous template. My guess is that it should also 
> be camel case?
>
> So it would be contains!C.any!T ?

Okay. Your Any template should clearly be camelCased, because its 
result is a bool. The same goes for ContainsImpl. Contains is a 
weird one though. It's pretty abnormal to use a template that's 
not a type, a function, an eponymous template, or a mixin 
template. Contains doesn't actually evaluate to anything on its 
own. It seems like it's just there so that you can have two sets 
of variadic arguments, which would tend to imply that it should 
be camelCased as part of any. However, the style guide says that 
non-eponymous templates should be PascalCased (though that 
_usually_ only applies to mixin templates), so a strict reading 
of the style guide would indicate that Contains should be 
PascalCased.

Of course, using a verb like contains is also a bit weird when 
it's really just holding a list of types so that they can 
essentially be passed as the first argument to any. So, I'd 
probably be inclined to rename the templates to something that 
was closer to what they're actually doing. e.g.

TypeList!(T, U, V).containsAny!(W, X, Y)

But even that's not all that great, since TypeList is then 
specifically tied to containsAny even though it doesn't really 
look like it is at first glance, and the name TypeList is generic 
enough that it does seem like you might want to reuse it 
elsewhere when it really couldn't be. Maybe

ContainsList!(T, U, V).containsAny(W, X, Y)

would be better? I don't know. Coming up with a name for this is 
hard. What you really want is something like

listsIntersect!((T, U, V), (W, X, Y))

or

ListsIntersect!(AliasSeq!(T, U, V), AliasSeq!(W, X, Y))

but there's no way to express it that like that in D (the 
AliasSeqs auto-expand into a single AliasSeq). The requirement 
for two sets of variadic template arguments just makes this 
awkward.

In any case, a strict reading of the style guide would seem to 
indicate that Contains should be PascalCased, because it's not an 
eponymous template, but given how rare what you're trying to do 
is, I doubt that much of anyone would complain if you used 
camelCase instead. I'd probably go with PascalCase though.

- Jonathan M Davis


More information about the Digitalmars-d mailing list