Programming Thoughts

I dislike object oriented code and similar

For work I still have to write tradtional C++ with object orientation, shared pointers, many classes with private data and constructors and destructors, and member functions, and subclasses and move semantics, and accessors etc.

But that’s not at all how I want to write code. I think it encourages bloated, difficult to read code with slow performance.

I am not a fan of object orientation. I am not a fan of shoehorning together your data and the operations you can perform on it. I think it leads to unnecessary complexity and the functions that operate on that code are often much too low level so that other code and manipulate the data.

Using objects with constructors, and destructors, and virtual tables, and move operations means that your data is not just a bunch of bytes representing your data that can be copied around and created where it’s convenient but instead has a life of it’s own. You have to write so much code for hundreds of classes and it makes it very hard to do good memory managment.

What is better?

Just write functions that operate on data structures. Write functions that takes some data or a pointer to a struct or whatever and do something with it.

Write functions that are high level. Don’t create functions that only exist to break up your code into smaller pieces. Create them to implement code that is used in more than one place. If you think you need a function to break up your code, then maybe you just need to put in a comment instead of a named function.

Data should be public always. Your program exists only to manipulate that data. The data is the most important thing. Don’t hide it away in private members. We will build modules and libraries that provide high level opaque interfaces to manipulate data, but the data itself should be public and easy to access.

Don’t have destructors, or constructors or move operations. Just have functions that create data structures and functions that destroy them. If you need to copy data, just write a function that does that. If you need to move data, just write a function that does that. Don’t try to make your data structures do it themselves. It just leads to pain and makes good memory allocation more difficult.