Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fallacies of Doom - JavaZone 18

Fallacies of Doom - JavaZone 18

Mahmoud Abdelghany

September 12, 2018
Tweet

More Decks by Mahmoud Abdelghany

Other Decks in Programming

Transcript

  1. Fallacies of Doom
    Lessons learned from porting
    Doom 3 to Java

    View full-size slide

  2. @blackbeard0x14e
    @blackbeard0x14e
    Boring intro: history
    • id Software: Unusual company creating ‘innovative’ games(Rover, Dave, Keen,
    Wolf3D, Doom, Quake)
    • Self taught era, efficient coding style(s)
    ○ Nerd rage anecdote
    • Djoom3==fun
    • So why the boring awesome intro?

    View full-size slide

  3. @blackbeard0x14e

    View full-size slide

  4. @blackbeard0x14e
    wishlist

    C++ protects against
    accident, not against fraud.

    Bjarne Stroustrup

    View full-size slide

  5. @blackbeard0x14e

    View full-size slide

  6. @blackbeard0x14e
    @blackbeard0x14e
    Operator overloading
    cout << ”Total price: “ << price*quantity << endl;
    c->J1 * c->body1->acceleration + c->J2 * c->body2->acceleration + invStep *
    (c->c1 + c->c2);
    c.J1.oMultiply(c.body1.acceleration).oPlus(c.J2.oMultiply(c.body2.acceleration)
    ).oPlus((c.c1.oPlus(c.c2)).oMultiply(invStep));
    [2] https://www.cs.virginia.edu/~evans/cs655/readings/steele.pdf

    View full-size slide

  7. @blackbeard0x14e
    @blackbeard0x14e
    Operator overloading
    idMat3 a, b, c, z;
    z = a + b * c;
    z = a.oPlus(b).oMultiply(c);
    z = b.oMultiply(c).oPlus(a);//technically correct
    z = a.oPlus(b.oMultiply(c));//compiler correct

    View full-size slide

  8. @blackbeard0x14e

    View full-size slide

  9. @blackbeard0x14e
    >>>

    View full-size slide

  10. @blackbeard0x14e
    @blackbeard0x14e
    Unsigned primitives
    Runtime or compile-time error??

    View full-size slide

  11. @blackbeard0x14e
    @blackbeard0x14e
    Unsigned primitives

    View full-size slide

  12. @blackbeard0x14e
    @blackbeard0x14e
    Unsigned primitives
    Microbenchmark alert:

    View full-size slide

  13. @blackbeard0x14e

    View full-size slide

  14. @blackbeard0x14e
    @blackbeard0x14e
    Immutability; const vs final

    View full-size slide

  15. @blackbeard0x14e
    @blackbeard0x14e
    Immutability; const vs final
    • final for variables sucks
    • final for functions sucks less
    • final for classes rocks
    [1] ftp://ftp.idsoftware.com/idstuff/doom3/source/CodeStyleConventions.doc

    View full-size slide

  16. @blackbeard0x14e
    @blackbeard0x14e
    sizeof( )

    View full-size slide

  17. @blackbeard0x14e
    @blackbeard0x14e
    sizeof( )

    View full-size slide

  18. @blackbeard0x14e
    @blackbeard0x14e
    Enum

    View full-size slide

  19. @blackbeard0x14e
    @blackbeard0x14e
    Enum

    View full-size slide

  20. @blackbeard0x14e
    @blackbeard0x14e
    Enum

    View full-size slide

  21. @blackbeard0x14e
    @blackbeard0x14e
    Grandfather inheritance
    • Super.super.function
    • Why are equals/hashcode inherited?!

    View full-size slide

  22. @blackbeard0x14e

    View full-size slide

  23. @blackbeard0x14e
    @blackbeard0x14e
    Pointers

    View full-size slide

  24. @blackbeard0x14e
    @blackbeard0x14e
    Pointers

    View full-size slide

  25. @blackbeard0x14e
    @blackbeard0x14e
    Pointers

    View full-size slide

  26. @blackbeard0x14e
    @blackbeard0x14e
    Pointers

    View full-size slide

  27. @blackbeard0x14e
    (thank God we don’t have
    this…)-list
    System.out.println(
    (byte)~(char)-(int)+(long)-1
    );

    View full-size slide

  28. @blackbeard0x14e
    @blackbeard0x14e
    Death by Macros
    [3] https://blogs.msdn.microsoft.com/oldnewthing/20050106-00/?p=36783
    [4] https://youtu.be/4cCeUfzH-No?t=23m

    View full-size slide

  29. @blackbeard0x14e

    View full-size slide

  30. @blackbeard0x14e
    @blackbeard0x14e
    Death by Macros

    View full-size slide

  31. @blackbeard0x14e
    @blackbeard0x14e
    Death by Macros

    View full-size slide

  32. @blackbeard0x14e
    @blackbeard0x14e
    Death by Macros

    View full-size slide

  33. @blackbeard0x14e

    View full-size slide

  34. @blackbeard0x14e
    @blackbeard0x14e
    Hungarian Camels
    [5]https://www.joelonsoftware.com/2005/05/11/making-wrong-code-look-wrong/
    [6] https://steve-yegge.blogspot.nl/2006/03/execution-in-kingdom-of-nouns.html

    View full-size slide

  35. @blackbeard0x14e
    Hungarian Camels

    View full-size slide

  36. @blackbeard0x14e
    @blackbeard0x14e
    Unholy union

    View full-size slide

  37. @blackbeard0x14e
    @blackbeard0x14e
    Unholy union: SDL_events.h

    View full-size slide

  38. @blackbeard0x14e
    Unholy union

    View full-size slide

  39. @blackbeard0x14e
    @blackbeard0x14e
    Unholy union

    View full-size slide

  40. @blackbeard0x14e
    nice to have -list

    Object-oriented design is the
    roman numerals of
    Computing.

    Rob Pike

    View full-size slide

  41. @blackbeard0x14e

    View full-size slide

  42. @blackbeard0x14e
    @blackbeard0x14e
    Destructor
    • Deconstructors
    • Finalize(@deprecated)
    • Autocloseable++

    View full-size slide

  43. @blackbeard0x14e
    Default arguments

    View full-size slide

  44. @blackbeard0x14e
    @blackbeard0x14e
    string::insert, string::swap

    View full-size slide

  45. @blackbeard0x14e
    @blackbeard0x14e
    Inlining

    View full-size slide

  46. @blackbeard0x14e
    weird(tips...tricks...pitfalls)
    -list
    Integer a = 42;
    Integer b = 42;
    System.out.println(a == b);
    Integer c = 666;
    Integer d = 666;
    System.out.println(c == d);
    String e = “666”;
    String f = “666”;
    String g = new String(“666”);
    System.out.println(e == f);
    System.out.println(f == g);

    View full-size slide

  47. @blackbeard0x14e
    @blackbeard0x14e
    The memory watcher

    View full-size slide

  48. @blackbeard0x14e
    @blackbeard0x14e
    5.1.2. Widening Primitive Conversion

    View full-size slide

  49. @blackbeard0x14e
    @blackbeard0x14e
    Pop goes the callstack

    View full-size slide

  50. @blackbeard0x14e
    @blackbeard0x14e
    Floating point operator precedence

    View full-size slide

  51. @blackbeard0x14e
    @blackbeard0x14e
    Floating point operator precedence

    View full-size slide

  52. @blackbeard0x14e

    View full-size slide

  53. @blackbeard0x14e
    @blackbeard0x14e
    Floating point operator precedence

    View full-size slide

  54. @blackbeard0x14e
    @blackbeard0x14e
    Floating point operator precedence

    View full-size slide

  55. @blackbeard0x14e
    @blackbeard0x14e
    Conditional breakpoints

    View full-size slide

  56. @blackbeard0x14e
    @blackbeard0x14e
    Conditional breakpoints
    •Sloooow(interpretive)
    Microbenchmark alert:

    View full-size slide

  57. @blackbeard0x14e
    @blackbeard0x14e
    A backwards compatible story?

    View full-size slide

  58. @blackbeard0x14e
    @blackbeard0x14e
    A backwards compatible story?
    •Why is backwards compatibility the default mode of operation?
    •Why not make it optional with compile/runtime warnings/errors?

    View full-size slide

  59. @blackbeard0x14e
    @blackbeard0x14e
    Sometimes the bug isn’t in your code...T_T

    View full-size slide

  60. @blackbeard0x14e
    @blackbeard0x14e

    View full-size slide

  61. @blackbeard0x14e
    Questions...while the Demo loads?
    https://github.com/blackbeard334/djoom3

    View full-size slide