Just as little experiment, as a part of a larger journey to try to understand how computers work, I started to learn the programming language C on my free time. I have only ever studied Japanese, linguistics and didactics… For a few months now, I have been able to make a program that prints various stuff on the screen using the commonly known function printf. This, of course, didn’t satisfy me at all, since this doesn’t tell me how the displaying of characters on my screen is actually happening. To make a somewhat forced comparison, I’m using a toaster to toast a slice of bread, but I have no idea how the heating strings inside the toaster become hot. In order to understand “the toaster”, I tried to dig up a piece of the source code responsible for making “my bread crispy and delicious”. Well…

Can something be DISHEARTENING and fun at the same time?

  • pelya@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    2 months ago

    Standard C library is not the place to learn from or an example of good programming. This particular piece would not only fail every code review, but would make your colleagues point fingers at you and laugh:

    #define ... (repeated 10 times)
    #include ...
    #undef ... (repeated another 10 times)
    

    In every sane codebase this piece of code would be replaced with some Python script that generates C source file that, while not pretty, does not make you want to commit an arson in your office room.

    No. Standard C library is a pile of legacy code from 1980 that still includes pieces to support obscure OSes with the last version released in 1990, using a massive unreadable mess of #ifdef. It’s only purpose is to work exactly as described in the documentation, pass unit tests, and maybe follow POSIX standard when it has the mood.