Why I Always End Up Going Back to C

(deplet.ing)

26 points | by indy 8 hours ago ago

6 comments

  • pjmlp an hour ago

    > The language shows you the machine, a machine which is not forgiving to mistakes.

    Assembly does that, C not really, it is a myth that it does.

  • theamk 7 hours ago

    C sounds nice if your task is simple enough, or at least if you can decompose this to a series of loosely-connected simple-enough tasks.

    But sometimes, there is an inherent complexity in what you are trying to implement, then C becomes way, way complex than C++. You build stuff, and there is so many manual steps, and none of them must be missing, or things will subtly break.

    A good example is "gstreamer", the multimedia streaming framework. It is implemented in pure C. It needs to use basic data structures, so it uses GLib. It also need to support runtime-defined connection graph, so it is built on top of GObject.

    Yes, build times are amazingly fast. But you pay for it - look at something simple, like display_name property[0]. There is display_name member, and PROP_DISPLAY_NAME enum, and switch case in setter (don't forget to free previous value!) , and switch case in getter, and it's manually installed in class_init, and you need to manually free it in dispose (except they forgot this).

    So many places just for a single property, something that would have been 1 or 2 lines in a well-structured C++ app. And unlike C++, you cannot make simple rules like "never use char* except for 3rd party libs" - it's all those multi-point checklists which are not even written down. A

    [0] https://github.com/GStreamer/gst-plugins-good/blob/master/sy...

    • flohofwoe an hour ago

      > It needs to use basic data structures, so it uses GLib. It also need to support runtime-defined connection graph, so it is built on top of GObject.

      That's running into the age old trap of trying to shoehorn an OOP system into C, just don't do that ;) E.g. don't design your systems around the OOP paradigm in the first place.

    • acuozzo 2 hours ago

      > You build stuff, and there is so many manual steps

      "The real goal isn’t to write C once for a one-off project. It’s to write it for decades. To build up a personal ecosystem of practices, libraries, conventions, and tooling that compound over time."

  • kianN 3 hours ago

    > Code gets simpler because it has to, and architecture becomes explicit.

    > The real goal isn’t to write C once for a one-off project. It’s to write it for decades. To build up a personal ecosystem of practices, libraries, conventions, and tooling that compound over time. Each project gets easier not because I've memorized more tricks, but because you’ve invested in myself and my tools.

    I deeply appreciate this in the C code bases I work in (scientific computing, small team)

  • jezze 3 hours ago

    First off, I want to congratulate you on reaching this milestone. I think this is the state where the most seasoned programmers end up. They know how to write code that works and they don't need a language to "help" or "guide" them.

    Enjoy!