Search Unity

Question About advanced programming on Unity and game architecture

Discussion in 'Scripting' started by mwss1996, Nov 26, 2022.

  1. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    For me this is the second objective, also known as kiss or Occam's razor.

    My first objective is always to reuse code and reduce the number of lines of code. This sometimes conflicts with the simplicity principle, but tries to make sure that any adjustment only needs to be made in one place.

    Example, I've used SharpPDF before to generate PDF's from Unity. It contains a lot of redundant code, which in my opinion is bad design. Small example from that package:
    Code (csharp):
    1.  
    2. /// <summary>
    3. /// Class's constructor
    4. /// </summary>
    5. /// <param name="author">Author of the document</param>
    6. /// <param name="title">Title of the document</param>
    7. public pdfDocument(string title, string author)
    8. {      
    9.    _title = title;
    10.    _author = author;
    11.    _openBookmark = false;
    12.    _outlines = new pdfOutlines();
    13.    _pages = new ArrayList();
    14.    _persistentPage = new pdfPersistentPage(this);
    15. }
    16.  
    17. /// <summary>
    18. /// Class's constructor
    19. /// </summary>
    20. /// <param name="author">Author of the document</param>
    21. /// <param name="title">Title of the document</param>
    22. /// <param name="openBookmark">Allow to show directly bookmarks near the document</param>
    23. public pdfDocument(string title, string author, bool openBookmark)
    24. {      
    25.    _title = title;
    26.    _author = author;
    27.    _openBookmark = openBookmark;
    28.    _outlines = new pdfOutlines();
    29.    _pages = new ArrayList();
    30.    _persistentPage = new pdfPersistentPage(this);
    31. }
    32.  
    Which, to make quicker edits later, can be reduced to:
    Code (csharp):
    1.  
    2. /// <summary>
    3. /// Class's constructor
    4. /// </summary>
    5. /// <param name="author">Author of the document</param>
    6. /// <param name="title">Title of the document</param>
    7. public pdfDocument(string title, string author) : this(title, author, false) {}
    8.  
    9. /// <summary>
    10. /// Class's constructor
    11. /// </summary>
    12. /// <param name="author">Author of the document</param>
    13. /// <param name="title">Title of the document</param>
    14. /// <param name="openBookmark">Allow to show directly bookmarks near the document</param>
    15. public pdfDocument(string title, string author, bool openBookmark)
    16. {      
    17.    _title = title;
    18.    _author = author;
    19.    _openBookmark = openBookmark;
    20.    _outlines = new pdfOutlines();
    21.    _pages = new ArrayList();
    22.    _persistentPage = new pdfPersistentPage(this);
    23. }
    24.  
    It was quite possible to reduce the number of lines in this package to less than 50% while keeping the exact same functionality, which in my opinion is an absolute gain.
     
    Last edited: Dec 1, 2022
  2. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,998
    This is one seriously hijacked thread. A drive-through "Unity sucks" post grew into what I can't even call a tangent -- just a 100% hijack.

    I was curious about how a database background mattered, too. Here we get lots of Q's from complete beginners (asking how to learn Unity). But a database background. Hmmm -- you don't need to know coding to run a DB, but in most places where you'd learn them, they teach basics of coding first. Being decent at databases makes it so you know functions and compound functions; variables, types and the idea of temp or convenience vars; syntax and the idea of debugging; lists and list searching -- in general you'd have an amount of programming sophistication. But you're still just writing queries without having to worry about big control flow issues. Hmmm.

    I'm not sure how an "Intro to Unity for database professionals" would look and I was a little curious.
     
  3. mwss1996

    mwss1996

    Joined:
    May 27, 2018
    Posts:
    5
    I just used databases as a example of technologies i had studied, it could be anything else.
     
  4. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,113
    Hey I was very explicit with exactly the functions you're quoting. I've even listed all of them already having 32-bit implementations in Math. So no, I haven't talked about the performance of Ceiling, Abs, or Sign.

    I also did not claim that Mono in itself is inferior (just that the Unity's Mono is inferior to IL2CPP for the most part; and this is the official sentiment, not my own), and I never talked about JIT emission.

    This is just to remedy the misquotings, because I was absent.