[Semi OT] Language for Game Development talk

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 28 10:19:36 PDT 2014


On 9/28/2014 2:16 AM, bearophile wrote:
> Walter Bright:
>> If the function is small enough that parameter setup time is significant, it
>> is likely to be inlined anyway which will erase the penalty.
> This is the theory :-) Sometimes I have seen this not to be true.

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


>> Then you really aren't encapsulating the globals the function uses, anyway,
>> and the feature is useless.
>
> The point of having an @outer() is to enforce what module-level names a function
> is using and how it is using them (in/out/inout), so it's useful for _impure_
> functions. If your functions can be annotated with "pure" you don't need @outer
> much.

@outer implies purity with a list of exceptions.


>>> - @outer is more DRY, because you don't need to specify the type of the global
>>> variable received by ref, you just need to know its name.
>>
>> That's why gawd invented templates.
>
> Templates are a blunt tool to solve the problems faced by @outer(). @outer()
> allows you to specify for each variable if it's going to just be read, written,
> or read-written.

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


> And @outer() is not named @globals() because it works for inner
> functions too, it allows to control and specify the access of names from the
> outer scopes, so an inner impure nonstatic function can use @outer() to specify
> what names it can use from the scope of the outer function:
>
> 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. But if you really wanted to do it,

  void foo() {
     int x;
     static void bar(int x) {
       writeln(x);
     }
     bar(x);
  }




More information about the Digitalmars-d mailing list