Other peoples' code... (in C++)
I am finding what some people consider good code is not as described. I found a class that provides strings. Great it gives me paths and stuff. I incorporated it in a new project.


Hmmm, it must have an init function... It does, but not in the class. It has a friended init function:
friend init_function(). If this function is not created and called external to the class then the class will segfault...


I implement this. I use code from another project that implements this correctly. The friend class allows the private constructor to be called to create the main instance of the class. So its a fucking cryptic ass singleton. I look at this class. It uses a macro to decide what to function call in the class. The class already has function names for each call it needs to make. The class is literally a string lookup table. I vow to redo this shitty code, someday...

I start to wonder what other fragile code I will find. Not long later I keep getting errors on malloc. Like any malloc that is called results in a segfault. The malloc is not at fault though. I run valgrind and find a websocket library is returning an object a different size than the header file describes.


Somebody has left an old ass highly modified definition of the websocket header in a location in that I include headers (partly my fault). I eliminate that from my include path. All is well, everything behaves. I will be making sure this fucking header is not used and it is going to die. Wasted a bunch of time.

Lessons learned: some code is just fucked and don't leave old ass shit you tried laying around.

  • 5
    Don't use old, shitty code full stop
  • 1
    @12bitfloat *this - just extract the strings you need, wrap them in some STL container and live a happy life.

    Manual memory management or stupid API fuck ups like that just tell you, you should not awaken that Zombie code, it will only haunt you.
  • 2

    That reminds me one of php functions i wrote... Oh boi, long time ago, like when I was learning php. It does simple thing, returns allways valid top-level url for given project (subfolder or on webroot, works both).

    To this day i dont even want to know how it works. And somehow I have it pretty much... EVERYWHERE, in every possible project...

    Old shitty thing that just works and I was never bothered to figure out how to rewrite it, as it never failed me lol
  • 1
    @DubbaThony Probably depends on whether you wrote it yourself. I mainly had to deal with old avr C code from my dad, who didn't even write it himself... Oh boy that was a clusterfuck. So glad I rewrote it from scratch for the newest product
  • 1

    Its mixture of stackoverflow, some php tutorials etc.

    Generally it's hacked together.
Add Comment