from Hacker News

OMG: Our Machinery Guidebook

by onekorg on 12/11/19, 9:39 PM with 29 comments

  • by Aardappel on 12/12/19, 3:21 AM

    Generally a wonderful set of minimalistic rules, much could carry over beyond C.

    Except for: "OMG-API-3: Unsigned integers are preferred over signed".. I feel they're on the wrong side of history with this one.

    "Prefer unsigned" only works if you can do 99% of your codebase this way, which, besides LLVM, probably doesn't work for anyone. Having a codebase that is 99% signed is much more feasible. The worst is a codebase with plenty of both, which will be guaranteed endless subtle bugs and/or a ton of casts. That's what they'll end up with.

    Apparently the C++ committee agrees that size_t being unsigned was a huge mistake (reference needed), and I would agree. Related discussion: https://github.com/ericniebler/stl2/issues/182 https://github.com/fish-shell/fish-shell/issues/3493 https://wesmckinney.com/blog/avoid-unsigned-integers/

    Even LLVM has all this comical code dealing with negative values stored in unsigneds.

    The idea that you should use unsigned to indicate that a value can't be negative is also pretty arbitrary. Your integer type doesn't represent the valid range of values in almost all cases, enforcing it is an unrelated concern.

  • by vietjtnguyen on 12/11/19, 11:39 PM

    Quick typo under OMG-CODEORG-2:

        #pragma once
    
        #ifdef __cpluspus // <-- should be __cplusplus
        extern "C" {
        #endif
    
        #include "api_types.h"
    
        // ...
    
        #ifdef __cplusplus
        }
        #endif
    
    
    Can't say I'm a fan of OMG-CODEORG-3, however, it sounds like compilation time is a key metric for them.. I prefer a John Lakos style "physical components" set up which emulates a type-as-module inclusion style. At least OMG-CODEORG-3 clearly states that include order becomes important as a result.
  • by bradknowles on 12/11/19, 11:46 PM

    NB: For those who are not aware, ourmachinery.com is a game engine development company.
  • by mwcremer on 12/11/19, 11:25 PM

    I.e., use a double parameter that specifies seconds, instead of an uint32_t that specifies milliseconds.

    This can have surprising and sometimes unpleasant consequences; see https://0.30000000000000004.com

  • by mistrial9 on 12/11/19, 10:53 PM

    the layout and typesetting on this looks good in Firefox 70!

    view-source:https://ourmachinery.com/files/guidebook.md.html

    <meta charset="utf-8" emacsmode="-- markdown --">

  • by Animats on 12/12/19, 6:35 AM

    Objects as structs with function pointers? 1990 is calling. I'm not a huge C++ fan, but trying to emulate C++ concepts in C is kind of lame at this late date.
  • by rootlocus on 12/11/19, 11:32 PM

    OMG-DESIGN-4: Explicit is better than implicit

    Ahh, straight out of the zen of Python!

        $ python -c "import this"