Skip to content

Instantly share code, notes, and snippets.

@ssylvan
Last active September 7, 2018 17:24
Show Gist options
  • Select an option

  • Save ssylvan/80debcac11605f357e5a45d7aa55058d to your computer and use it in GitHub Desktop.

Select an option

Save ssylvan/80debcac11605f357e5a45d7aa55058d to your computer and use it in GitHub Desktop.

Revisions

  1. ssylvan revised this gist Sep 7, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ ctx.Present(); // This is now available.

    // So basically, shadowing is neat when you have some kind of "protocol" and want to enforce it
    // statically, because the same "object" can be in different states, represented by changing its
    // type throughout the method, which lets the compiler catch mistakes.
    // type over time, which lets the compiler catch mistakes.

    // Without shadowing this gets messier:
    ctx.ClearScreen();
  2. ssylvan created this gist Sep 7, 2018.
    25 changes: 25 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@

    // Example:

    ctx.ClearScreen();
    let ctx = ctx.BeginTriangleStrip(); // Old context is *consumed*, new context has different methods
    // ctx.ClearScreen(); // ERRROR: not supported on this context
    ctx.AddVertex(...);
    ctx.AddVertex(...);
    ctx.AddVertex(...);
    let ctx = ctx.End();
    ctx.Present(); // This is now available.

    // So basically, shadowing is neat when you have some kind of "protocol" and want to enforce it
    // statically, because the same "object" can be in different states, represented by changing its
    // type throughout the method, which lets the compiler catch mistakes.

    // Without shadowing this gets messier:
    ctx.ClearScreen();
    let tri_strip_ctx = ctx.BeginTriangleStrip();
    tri_strip_ctx.AddVertex(...);
    tri_strip_ctx.AddVertex(...);
    tri_strip_ctx.AddVertex(...);
    // What do we call this? It's conceptually the same as the first ctx.. Should we keep incrementing this number?
    let ctx2 = tri_strip.End();
    ctx2.Present();