agh c++

I come from the land of python, where the grass is green and the trees are leafy. I’m writing a game in C++ for fun, because I’ve never had to do serious work with C++, and so far… it seems like a nightmare-zone.

First, there’s the crufty syntax, full of useless symbols. That’s a known cost though, visible to any passer-by. Second, there’s type definitions — I have to figure out specific types just to hold outputs of functions, which I’m only going to pass to other functions. But there are advantages and disadvantages to declarative, strongly typed systems, and I knew about this already, so I can’t really complain. Then the final straw: there are no list, tuple, or map types. You think I should use the STL? You’re right — that’s precisely what I ought to do.

Except: the STL requires layer upon layer of confusing boilerplate, and in order to navigate it, you have to really know your C++ shit inside and out. Today, I wanted to remove some unwanted elements from a vector. Several StackOverflow question-reads later, I think the best route is to create a functor (loosely, an object wrapping a function) to use with an iterator to pass into a function to pass into another function. After all that, I have little knowledge of the big-O algorithms underlying these pieces of my code. I’ve also written a dozen lines for what I think of as ‘l.remove(e)’, and I’m wading through complex STL errors to figure out simple syntactical issues.

Worst of all: it doesn’t even work yet. ‘std::remove’ will remove elements equal to a given value, but doesn’t handle functors, while ‘std::remove_if’ can handle a functor, but messes up my iterator somehow so the vector doesn’t truncate.

Imagine a compilable and interpretable dynamically-typed (or at least type-inferred) language with minimal syntax and useful built-in types possessing relevant comprehensions. Now, imagine that it has bindings to popular open source game development libraries. Why can’t that be a thing?

I’m sure that 90%+ of my issues are coming from not having a sufficiently well-developed mental model of the C++ landscape, and if I knew my way around, I wouldn’t be having these problems, but I don’t. I didn’t expect to have to learn how to walk again when I’m already intimately familiar with C, with Python, and with reasonable program design. It’s not a different paradigm, it’s just that everything is harder here.

A different take on the situation is that the things that I’m annoyed by are showing me weaknesses in my own comprehension. Details I ought to be comfortable with are so commonly swept under the rug that I’ve forgotten they were even there, and now that I have to think about them, I’m more prepared to whine than solve the problems. So I’ll just keep on with it, I suppose, but there may yet be more whining.

Leave a Reply

Your email address will not be published.