Author Topic: How not to write C++  (Read 10283 times)

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
How not to write C++
« on: July 22, 2018, 08:31:22 AM »
There is this older, I guess abandoned roguelike called Avanor. I was reading the source code and thought to remind people about how NOT to write C++ where Avanor is a great example. It's "easy" I guess to criticize an older project, but it's not that people wont make this mistake over again, they do it all the time.

The main problem with Avanor's code is that it's not C++, it's C wrapped in classes in a bad way. It's using none of OOP principles and in particular there are no traces of datatype classes, instead (almost) everything is plain old variables stuffed into large-ish classes. The code itself is old school large if/switch structures (typical in C code). I think Avanor points out perfectly the inability of a programmer to understand OOP (or any specific paradigm). If you just use classes to fill in with procedural code it's not OOP at all. Classes are only used as simple data containers, a lot like structs.

I think we need to make people somehow more aware of this issue, because it has a big impact on source code quality which can make the project fail after it becomes too difficult to maintain.

Alexios

  • Newcomer
  • Posts: 3
  • Karma: +0/-0
  • For god, glory and gold
    • View Profile
    • Email
Re: How not to write C++
« Reply #1 on: October 14, 2022, 10:38:41 PM »
Quote
The main problem with Avanor's code is that it's not C++, it's C wrapped in classes in a bad way. It's using none of OOP principles and in particular there are no traces of datatype classes, instead (almost) everything is plain old variables stuffed into large-ish classes. The code itself is old school large if/switch structures (typical in C code). I think Avanor points out perfectly the inability of a programmer to understand OOP (or any specific paradigm). If you just use classes to fill in with procedural code it's not OOP at all. Classes are only used as simple data containers, a lot like structs.

Sounds like me to a T. I just have a global struct with all my game's state. I'm a noob so what do I know? I'll give the codebase a look
Friends, rogues, countrymen, lend me your ears;
I come to play Rogulikes, and to praise him.