[Semi OT] Language for Game Development talk

bearophile via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 28 11:21:20 PDT 2014


Walter Bright:

> Inlining is not a random thing. If there's a case that doesn't 
> inline, ask about it.

Even when you use annotations like "forced_inline" and the like 
you can't be certain the compiler is doing what you ask for. I 
have seen several critical template functions not inlined even by 
ldc2 (dmd is usually worse). And if your function is in a 
pre-compiled object where the source code is not available, 
inlining doesn't happen.


> @outer implies purity with a list of exceptions.

Right, an empty "@outer()" equals to the D "weakly pure". But if 
I put those exceptions then I am essentially stating that a 
function is not pure. So you usually don't put @outer() on pure 
functions.


> Again, template functions do that rather nicely, and no type is 
> required.

I think templates are blunt tools for this purpose. But I will 
try to use them for this purpose, to see how they fare. I think I 
have not seen people use templates for this purpose, so I think 
it's not very natural.


>> void foo() {
>>   int x;
>>   @outer(in x) void bar() {
>>     writeln(x);
>>   }
>>   bar();
>> }
>
> This I find to be a bit more lame, because the declarations 
> used will be right there.

Yes, and a module-level variable can be defined the line before 
the function definition. Or it can be far from it (it can even be 
from an imported module). The same is true for the variables 
defined in the outer function. That's why I have named it @outer 
instead of @globals. Even a large function is usually smaller 
than a whole module (and modern coding practices suggest to avoid 
very large functions), so the variable definition should be 
closer (and in D it must be lexically before the definition of 
the inner function), so the problems with module-level variables 
is bigger, but it's similar.


> But if you really wanted to do it,
>
>  void foo() {
>     int x;
>     static void bar(int x) {
>       writeln(x);
>     }
>     bar(x);
>  }

As you said, the same is possible with global variables, you can 
often pass them as arguments, by value or by reference. I agree 
that the case of using @outer() for inner functions is weaker.

Bye,
bearophile


More information about the Digitalmars-d mailing list