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.

Quick clever idea I saw

Someone at work just pasted in some code that was locking two tables for write, inserting all of one table’s data into another, then making a trigger to keep them in sync in the future after inserts, and then unlocking the tables.

Someone else suggested just making the trigger first, and then replacing all of the data from the first table into the new one. Using replace means that some of the data may be double-copied, but there’s no table-level write locks used — pretty cool.

Also, we’ve been talking about hypergraphs, which are a little confusing. They’re graphs, but instead of each vertex having multiple edges and each edge running between two vertices, each vertex can have multiple edges and each edge can have more than two vertices! I ran into them once before, and still don’t quite understand how that situation even was a hypergraph.

Rigour vs Just Do It

I’m reading The Mythical Man Month, and I also happened to read this post on just getting something started this morning. I’ve got two (conflicting?) messages in my head at the moment:

From the Mythical Man Month, I’m hearing about how much planning used to go into development and testing of software systems. That sort of rigour just doesn’t seem to be present any more, and I am taking a desire away from the book to be a little bit more careful and systematic and thoughtful when approaching a new project. Kind of like that (perhaps apocryphal) Einstein quote about solving a problem in an hour: “If I had an hour to solve a problem I’d spend 55 minutes thinking about the problem and 5 minutes thinking about solutions.” It’s allegedly beneficial to sit down and think before you start doing.

Against that, from the Lean Startup and Fail Fast sort of camp, I have the suggestion to just get something out there. Write anything down, acknowledging that it’s awful, just to get started. Step 2 is easier, and iteration is what drives progress. You won’t know most of the problem until you really dive into solving it. That kind of thing.

These both seem right, but they also seem incompatible. There’s probably a middle road — I wonder whether it’s best to think out how to find it, or to just start trying things and hash something out?

Sickness sucks.

I spent the last week sick with a bad flu. I always imagine that getting sick for a big block of time will be great for reading or watching TV or doing some kind of online course or something, but in that imagination I fail to account for the following issues of the flu:

  • flu-people have no motivation for anything, even peeing or hydrating or breathing
  • flu-people are in constant discomfort and just want to close their eyes
  • flu-people can’t focus on stuff, even if they want to
  • flu-people smell and are sticky and sweaty and ick
  • flu-people think pretty slowly, and mess up some pretty simple logic

So my mighty plans were foiled! But now that I’m getting past it I feel renewed vigour and just feeling ‘normal’ feels comparatively great.

So what do I do now? It’s that perennial problem – I might need a philosophical response to it that just kills the whole question. Being interested in everything to the point that nothing can hold my attention for more than 48 hours is wonderful in its way, but it has made me into a massive dilettante.

I think I found at some earlier point that I find motivation in seeing other people do cool stuff, which only happens when I feed more input into my infohoppers – more commitment to consuming lots of diverse media sounds good. Also, easing barriers to making stuff.

Anyway, I’m glad to be back in the waking world. Next stop: not coughing and sneezing on everything. (there may be some time before we reach that stop)

Thank you, past me

Starting off this morning I had a pretty good idea of what my day would be about, but it hadn’t occurred to me to think about whether or not I had any specific task I was working on when I left.

I typed ‘git co master’, thinking I should probably pull and then merge into my latest work, and I got the following:

error: Your local changes to the following files would be overwritten by checkout:

So I’m thinking “whaaaaat?! why did I leave uncommitted crap hanging around!”

I have git status aliased to ‘s’, and git diff aliased to ‘d’, so ‘s’ showed me that only one file had changes, and I decided to take a peek with ‘d’:

+# get the correct information here to build the correct URL

I left myself a teensy love-note last night before I went off to dinner, and as soon as I saw it, I reloaded a ton of mental context.

So thanks, me.