Game Design, Programming and running a one-man games business…

Lessons from 41 years of programming

I don’t blog much about the nuts and bolts of programming, because I know enough to know that others know more than me, but increasingly I’m aware of how other people code, and feel that I probably do have *some* worthwhile advice on the topic. Not many people have been programming for 41 years, especially given how coding seems to skew young, so here we go…

First some background, I started coding in sinclair BASIC on the ZX81 aged 11. I took some time away from code to try and be a musician, and then worked in IT support, but I have worked as a full time programmer for the last 25 or so years. After a while its hard to keep track! I basically code video games in C++. Thats it. I know some php, but not much. I can probably remember some BASIC, but not much. Yes, I’ve been coding 25+ years in a single language.

Lesson #1 Learn a single thing well.

I sometimes do some stuff that would probably be a bit easier in C#, or Rust, or Java, or probably some other language I have not even heard of. I don’t care. I am a massive believer in knowing how to do one thing super well. This is very unusual, because these days, coders are hired as a shopping list of buzzwords. Adverts for coding jobs amuse me no end. They always want someone with experience of 10 different languages. Did the lead programmer have a problem deciding which to use? When you want a coder who knows 10 languages, you get someone who is mediocre in lots of different ways. Thats not ideal.

The ‘familiar with 10 languages’ trope is common because non programmers understand it. A coder with 10 languages must be more skilled than one with just 1 right? To a non coder, its all unintelligible gibberish anyway, they have no way to tell a really GREAT c++ coder from someone who just knows a bit of syntax. Recruitment consultants and idiotic managers without coding experience have created a world where everyone is truly rubbish at 100+ different programming languages.

We do not expect this in other fields.”Doctor wanted. Must be a throat expert / hearing expert / heart specialist / Neurosurgeon”. We also manage to get by in our lives speaking only a single language. Sure, french is more romantic, German more precise, Spanish more passionate, English more subtle, but we don’t change languages constantly in our day to day lives! Tip: If you work for yourself, learn ONE language super well. Only learn others if they are absolutely essential for the task in hand. You can do almost anything in C++.

Also note that being really good at one language does not mean learning every possible feature (see next lesson), but it means using that language so MUCH, in so many different circumstances, that you know the best way to get things done using that language. (by best I mean reliably, efficiently and legibly).

Lesson #2 Language features are optional.

C++ lets you override operators. It also supports templates and the stringizing thingy (## i think?). I don’t use any of them. I use maybe a quarter of C++. Most of the newer stuff seems like solutions looking for a problem. Its FINE to just stick with the feature set you find to be most usable for you. Nobody is going to point at you at parties and mock you in front of the opposite sex because you don’t use the whole range of C++ features in every program.

There are multiple ways to handle files in C++. fopen, iostream, CreateFile() etc. I use the old fashioned fopen() stuff. I know the syntax super well. I can type it as fast as I can speak. This is fine. I’ve never had someone leave me at the altar for not using iostream.

I am constantly told by people I am reducing my productivity by sticking with old, outdated and cumbersome systems when new-fangled ones have apparently done the same but better. Without exception I am more productive than everyone who tells me this.

Lesson #3 Legibility is the goal.

Coders start off as n00bs with no confidence or idea how to do things. They then go through a ‘gunslinger’ phase, filled with the coders equivalent of testosterone, where they write ‘impressive’ code, that uses cool obscure language features or fancy techniques to do whizz-bang stuff that impresses other coders at parties. This phase lasts about a decade, or maybe longer if you are in a big company with bosses that need impressing.

The ultimate stage for a coder is to realize that ‘impressive code’ phase is just so much adolescent bullshit. The goal of code is to be reliable, efficient and legible. That last one really matters. If there is a way to perform a task that is simple, clear, and a way that I have used 100x in the past, then thats the way I do it. There may be a ‘cool’ way to do that task that involves callbacks and threading and whatever the heck microservices are… but why over-complicate things when you can just write simple code that you will understand instantly on reading it in 10 years time. 99.99% of the impact of your code is on the users, not the other coders who might glance at it. My code probably looks simplistic, very literal, very accessible for even non coders to read. I’m happy about that.

Lesson #4 Consistent Formatting

No 2 coders ever agree on how to format code. I have my own opinions which I shall not bore you with, but here are two thoughts: Firstly, be aware that a lot of ‘standard’ ways to format code were dreamed up before we had intellisense and visual assist. If you are still relying on a naming convention that shows you what is a function, what is an enum and what is a variable… then its kind of pointless. We have syntax-coloring now. You don’t need to do that, and can get back some much needed legibility. No more LpSZ_mem_Name.

Secondly…and this is even more important, the goal of code formatting is to minimize the cognitive load on the person reading it. Most programs do complex things, and to debug or add features, you need to maintain a HUGE network of complex stuff in your head as you work. If you are having to mentally translate a lot of different variable-naming conventions and code layouts in your head as you read then you will be amazed at how much

HARDER

to

_read

This

cAn

then

BE.

Our brains seem very good and building up mental translation systems. if you have text in ALL CAPITALS then we adjust to it ok. Pretty much *any* coding standard is fine… as long as you have only one. This is another reason why I hate middleware, because obviously its all formatted differently. Having to chop and change mentally between different ways of doing the same thing adds huge mental overload.

If I ran a studio, the question ‘will you agree to 100% without question always follow the code style guide of the company or face immediate dismissal’ would be the first interview question for new hires.

Lesson #5 Be aware of the overhead.

Almost all modern code is absolute trash, total garbage, an embarrassingly badly constructed towering pile of crud that should bring deep shame on everybody who wrote it. People with a lot of coding experience tend to agree on this topic. I think its inevitable, given that the demand for coders vastly outstripped that number of people with experience. Maybe over time it will be redressed, but I worry that these days coders are just used to code being crap and do not understand its even a problem. You don’t need 20 years experience to post a useless reply on stackoverflow. Sadly.

Its REALLY instructive for you to step through every single line of code in the execution of the stuff you do. If you are an app developer relying on middleware that is closed source… i pity you. A simple step through one instruction of yours probably means running 5,000 lines of bullshit layers of code that you will never see. This is why we all have incredible supercomputers, and yet we stare at progress bars…

If you are lucky enough to have full source access, or have written it all yourself (yay!), then do the ‘step-through-everything’ test regularly. It will AMAZE you how much code seems to be run without actually being needed. The inefficiency of most code is mind-boggling, and its because hardware has outrun software so much that we can write code that runs at 1% efficiency and hardly anyone complains.

Learn how to use a profiler, and go through your code looking at where all the time is spent. Its actually REALLY interesting, and kinda fun. I enjoy spending time in stuff like aqtime, or vtune. If you have not profiled your code, then you have not finished it. You are not a software engineer if you have not done the post-coding analysis of what the code actually *does*.

Lesson #6: Avoid massive functions, and massive source files.

There are technical reasons for this, in terms of compile times etc, but it really comes down to the overall structure of code. If you have a function that is 100 lines long or more… then you have probably fucked up. If a single source file for a class is 1,500 lines long…then you have probably fucked up. (yes, I know about function call overhead. Are you working on spacecraft control systems that have to run at 5,000 fps with minimal power? I am guessing no, so don’t worry about that trivial overhead here)

The most common mistake that leads to buggy, hard-to-work-with C++ code is that classes are too big, and functions too long. A function does one thing. The clue is in the name. What tends to happen is people start off with a perfectly reasonable class and functions, then they add functionality (ha!) and the class sprawls, and the functions sprawl. What was once a perfectly reasonable Update(), becomes 100 lines long. What was once a reasonable Entity class suddenly becomes a behemoth.

This is normal. You now need to work out the cleanest, most sensible way to break that class into multiple objects or derived classes, and change the layout so that the code is done in more single-focused functions. This is not some bothersome task that wastes time… this is literally software engineering. This is the difference between a coder and a software engineer. This vastly increases the legibility and debugability of your code.

Getting code to work is just the easy bit. The hard bit is knowing exactly how to layout the relationships between objects and functions so that everything seems sensible, and organised. Knowing how to do this takes a lot of experience, and is normally the outcome of many bleary-eyed 3AM debugging nightmares where you stare at the big giga-function when you are nested 16 deep into curly brackets wondering what the fuck its supposed to do.

Call stacks are your friend! Call stacks are amazing. I have the call stack always open at the bottom of my screen. I offload my mental model of ‘how we got to be here’ into the callstack window. I find this incredibly helpful. Making sense of the flow of code through the callstack window is 100x easier than keeping mental callstacks in mind as you navigate giant functions.

Conclusion

These are my broad thoughts on stuff I wish I knew earlier. I’m sure lots of people disagree, and thats fine, I’m not starting a political movement here, just sharing my experience. Sadly, the awful state of modern coding is largely outside coder’s control, due to incompetent managers, feature-centric marketing and tech-ignorant recruitment practices. I hope its of some interest to solo coders or lead coders with complete control of how a codebase is made.

The late 2021 case for buying and holding TSLA (yes…still)

I blogged about how you should buy shares in Tesla many years ago, then I revised it. The first revision was able to happily mention that the stock had tripled since I first blogged about it. Well… its quintupled since then. (There was a 5:1 share split, so it looks like its about flat but is anything but…). Given that a stock is now worth 15 times what it was when I first suggested buying the stock, how can I possibly not be selling? How does this make sense? This is just a meme stock right?

No.

Lets update some figures since I last blogged on the topic. Here are numbers a year on from the last blog post:

  • In 2020 Tesla produced 499,950 vehicles. (vs 367k)
  • The market cap of the company is currently $1.06 Trillion. (vs 180bn)
  • The automotive gross margin is approximately 30.5% (vs 25%)
  • YoY revenue growth is 28% (vs 38%)

Those are all VERY good numbers, but given a 5x increase in the stock, you would expect absolutely insane numbers, so on the face of it, this is pretty underwhelming. The number of vehicles produced is still only half a million in 2020, and revenue growth was great but not incredible. However, there is massive, massive context.

Vehicle Production

Firstly, the year 2020 is now so far in the rear view mirror its almost laughable to try and assess the correct stock price with 2020 figures. It makes more sense to look at quarterly figures to see the real picture. Here are the last 4 quarters

  • Q4 20 180k vehicles
  • Q1 21 184k vehicles
  • Q2 21 201k vehicles
  • Q3 21 241k vehicles

If you extrapolate from Q3, we are looking than an annual run rate of 964,000 vehicles. Thats pretty good when we compare it to 499k, but probably does not justify a 5x stock growth. The two points to be aware of here are:

Firstly… we have just had the twin pains of a global supply crunch caused by covid19 combined with a chip shortage that has effectively paralyzed the car industry

Secondly, Tesla are imminently (ie: likely December) opening TWO new factories. One in Berlin, One in Texas. Both are HUGE. Both of these will easily match the shanghai factory. Meanwhile, the Fremont factory (where Tesla started) is basically the runt of the litter. A badly designed, un-optimized mess built originally to make ICE vehicles.

Analysts have given Tesla a lot of credit for weathering supply chain and ship shortage woes far better than any other car company. Take a look at global car sales from the big brands and you would see almost everyone is heavily DOWN year on year, except Tesla and some super niche luxury brands.

Why? 2 reasons: Tesla is very vertically integrated, so it can handle a lot of supply chain issues internally, and secondly, its very software centric. Tesla managed to adapt to chip shortages by rewriting its own firmware to use different chips. Volkswagen just do not have this expertise, and nor does Toyota, GM or Ford.

So…vehicle deliveries are pretty good considering the market, and set to explode pretty heavily next year as Texas and Berlin start producing cars. Thats great… but again we are talking a 5x stock growth so… we need to be dazzled more.

Profitability

Did you notice that the automotive gross margin actually went UP? (you would expect it to fall as the company moved from luxury sports cars to more affordable models like the 3 and the Y) TBH it was already exceptionally good, but it looks like the profit margins on Tesla cars are actually rising, quite considerably. Best of all, the model Y is likely the same cost to produce as the 3, yet sells for way more. The introduction of new casting methods to hugely simplify assembly is likely to make the Y even cheaper to produce, and a shift to 4680 batteries and a structural battery pack will push costs lower still. Meanwhile, Tesla keeps increasing the price of the model Y. Having a Texas and Berlin factory will reduce the shipping cost to the customer as well, and stop Tesla paying EU import tariffs.

Much was made recently of Hertz ordering 100,000 model 3 cars from Tesla. They even ran an ad campaign about it. This is a car company that spends $0 on advertising, and yet its business partners actually do the ads for you. This is nuts. Plus it means Tesla don’t need to give a damn about arranging test drives. You want to try one out? go to hertz. If not… there is no shortage of demand.

Hertz ordered 100,000 cars (to start with) and got 0 discount. To the great masses of opinionated ‘analysts’ on twitter, that sounds like it cannot be true, but if you follow Teslas order backlog and wait times, you know its true. If hertz didn’t want to pay full price, they can go elsewhere, the model 3 backlog is huge already. The model Y is also massively in demand. I ordered one recently, and am told to expect it in April/May maybe. If I’m lucky. Paid full price, obviously. There are zero discounts on teslas cars…

In the US… it looks like people are going to get a $7,500 tax rebate when they buy an EV, with no upper limit on how many cars this applies to. Conveniently Tesla have raised the model Y price about $8,000 this year. That means all someone in the US ordering now, will get the car for the same price in January, but Tesla make ANOTHER $8k profit on top of the already high gross margin. The 2022 profit margin for Tesla is going to be embarrassingly high.

Competition

What competition? Much is made of a long sad history of cars that were considered to be ‘Tesla Killers’. One by one they have come and gone. Arguably the Porsche taycan is a good car, if you don’t want a supercharger network, autonomy or over-the-air software updates, AND want to pay an extra $50k for the privilege… but the audi-e-tron? who cares? its just a rounding error in terms of EV sales next to Teslas mass-market cars. Illustrative chart below:

Does it really look like the VW ID.3 or ID.4 are any competition? It sure does not look that way, especially as VW seems top be in crisi meeting after crisis meeting trying to persuade its own workforce that making EVs at some point in the future might be a good idea maybe? Meanwhile any German engineers actually interested in working in EVs have likely left to join Teslas Berlin factory.

The Future

There are so many catalysts to push Tesla’s profitability and net income higher its almost ridiculous, but lets go through a few of the big ones.

Firstly, they have over a million pre-orders for the cybertruck. Yes really, yes, the one you think looks weird. Yes, its really going to be built, and yes, its going to be incredibly popular. The plan is that they start building them next year. These vehicles look so unusual they all act like billboards for the company.

Secondly, they are switching to a structural battery pack and 4680 format batteries linked to front and end cast metal design. All three of these changes are about a single metric: efficiency. When efficiency is better, you car is both cheaper to make, and gets better range and performance. The comparison of Tesla efficiency versus other EV’s is telling, and thats current models:

  • Model 3 240 wh/mile
  • Nissan Leaf 260 wh/mile
  • VW ID.3 265wh/mile
  • Audi e-tron 290 wh/mile
  • Ford Mach-e 315 wh/mile

In other words, rivals are charging more, for less. And thats also without a supercharger network or over-the-air updates or autonomy. (oh I forgot to mention Tesla is starting to earn revenue from selling use of its supercharger network to owners of non tesla EVs. A hilariously good marketing channel to known EV-buyers, that will cost Tesla nothing, in fact people will pay them money to sit and stare at a big red tesla symbol as they charge…)

Thirdly, the long awaited improvements to autopilot are rolling out, meaning a LOT of ‘deferred revenue’ for selling ‘full self driving’ can be recognized as profit over the next few years.

Fourthly, the semi-truck is coming, which will be a BIG part of the business.

Fifthly, there will be eventual revenue from cloud computing of neural network training thanks to teslas’ in-house designed chip that forms a scalable supercomputer. (yes really).

Sixthly: slowly but surely Tesla are rolling out their own insurance product. Eventually they will sell you the car (direct, at 0 advertising and 0 discount and 0 dealership fee), the fuel (via supercharger network), the insurance, and software/entertainment services in the car, through payments for premium connectivity, and an autopilot subscription.

Seventhly: Battery storage and solar roofs. This is a business that has floundered a bit for the last 5 or so years, but Tesla are also in the energy storage and generation market. This gives them an advantage over every other provider of such services, as they can leverage the brand built on the car business to cross sell solar panels and home battery storage. They are obtaining licenses to even sell you power, starting in Texas.

So yup, I’m holding Tesla stock, at least until three or four of the above things become common knowledge. Until then, most analysts, and almost all retail investors have absolutely zero clue as to the future profit potential of this company.

Lots of credit should go to Rob Maurers excellent, hyperbole-free youtube channel in which all this stuff is plainly spelled out for everyone to investigate for themselves.

In defense of ‘gatekeeping’.

One of my pet hates is the huge avalanche of really bad advice and ‘hot takes’ that spread rapidly over the interwebs that have zero experience or data behind them. The problem has been made infinitely worse by the shift over time from asynchronous communication to real time communication as the preferred system. This is really, really bad.

Go back 100+ years and the primary means of communication between geographically separate individuals was probably a letter. Letters have some downsides, mostly the delay in receiving a reply, but actually that delay can be a feature. Not only is it harder to send an embarrassing emotional drunken ‘hot take’ by letter, you also have a much slower expectation of reply times. You can almost certainly ‘sleep on it’, do some research, discuss the topic with friends and family, read the news, let the contents of the letter sink in… and then, once you have marshaled your thoughts, and mentally composed an intelligent, thoughtful, and reasoned reply, you can put pen to paper.

Email worsened the situation, because now you do not need to walk to a post box. You can email drunk, or angry, or without checking your facts. However, you do not HAVE to respond right now. The sender isn’t sure if you get the email in a minute or an hour. A next day reply is fine.

Social media makes everything worse in 4 different vectors:

  • Delivery is instant, so there is pressure to reply without thinking or researching
  • Replying is gamified, with notifications, so there is a push to respond, even if you have no insight
  • Replies are global. Anybody can reply, and everyone can see the reply.
  • Your replies (ie: your personal work/content) is now monetized by a 3rd party, and you are paid $0 for this.

One of the huge downsides of connecting everyone to everyone else over the entire planet is that we no longer have any idea who has experience, or data, and who is just a talkative idiot who wades into every conversation they can find. We also have no time, or incentive to give a damn who anybody is. On the internet, all opinions have become equally weighted, whether they are the considered conclusions from a multi-year phd research project, or a drunken reality tv-star’s vodka-fueled hot take. (FWIW I don’t care what actor Idris Elba said about climate change at COP26…)

Many thousands of years ago, I was one of many people who hung out on an internet forum for indie game developers. It basically WAS the indie game community, probably a decade before ‘indie game:the movie’, and long before steam. The entire indie community, globally, would chat there about programming, design, and business…

…and as the community grew, people who had been making games for a long time noticed a tendency for newcomers (without any shipped games) to get increasingly vocal about every topic, in terms of offering their advice to other newcomers. The advice was often bad, coming from neither experience or data. People started to complain that they had no idea who to listen to. The idea was mooted that forum posters with actual, shipped, commercial games would get a forum badge by their name, to give context to the replies and posts from people with experience and data.

Begun, the indie wars had…

By modern twitter standards it probably would not seem too bad, but oh my god, it was bad. People who were extremely frequent posters who had not shipped a game were FURIOUS to put it mildly. How DARE people say that their opinions were worthless? how dare the forum become so elitist? These days, on twitter, such a move is described as gatekeeping, and is apparently a really bad thing.

There is a difference between arbitrary gatekeeping (ie: not letting people join your club for no good reason), and giving context to information. I will even add to that to say that some times, a little gatekeeping makes a lot of sense. If you want a forum where long established game developers want to talk about running a studio, dealing with staff, negotiating contracts etc… then only allowing people in the forum who have some experience of such stuff makes a lot of sense. And there are quite a few private indie forums in 2021 full of such people. I’m a member of 3 of them, and used to be in a forth.

People seem to have a blindspot when it comes to the creative industries, where there is an oft-repeated mantra that ‘if you are working on a game, you are already a game developer’, and the same for acting, writing, music and so on. Perhaps controversially, I think this is total bollocks.

People used to mock Sarah Palin for saying she has foreign affairs expertise because she lived in Alaska and could see Russia. My favorite joke was to say if you can see the moon, you are an astronaut. When I worked in a boatyard, there was a VERY FIRM rule, that you could not describe yourself as a boatbuilder unless you had built a boat… from scratch. So you did the keel, the ribs, the planking, everything. I worked on boats for 8 years, banged in tens of thousands of nails, did a lot of ribs, and floor joints and a huge amount of planking, but never the keel. People were very firm: I was not a boatbuilder…

And thats fine. Because frankly, I wasn’t. I can tell you a few tricks about banging in nails accurately, and how to drill holes in thin wood without splitting the timber, but my experience is limited, and my hot takes on how to build a boat should not be public. Be aware that I have 8 years experience in that industry, but I still know I am not vaguely qualified to give general advice on it.

Back in Sarah Palin’s era, she was rightly mocked for pretending to have worthy experience when she had none, but these days, having absolutely fuck-all experience and data regarding a topic is becoming a badge of honor. In the US, President Trump literally claimed to ‘love the poorly educated’. He knew absolutely nothing about what covid was, or why climate change was a threat, and much, much more worryingly, he expressed zero interest in learning from experts on either topic. Despite this he expressed insane ideas on national TV about solutions, with actual experts stood to the side looking on in horror.

This should not be a political issue. Whether you are left wing or right wing, liberal or conservative, science is science, data is data, experience is experience. I have absolutely NO IDEA how the global climate works, but the overwhelming majority of people who have phds and nobel prizes in this stuff tell me about climate change, and I believe them. I have no idea how covid spreads, but medical experts tell me to wear a mask, so I do so. I do this because the alternative is a frightening one, which is trusting my own hunch and gut feeling on topics, instead of experts.

Here are some of the things my gut instinct tells me, if I ignored the opinions of ‘so-called-experts’. Planes cannot fly, because they are metal, and its heavy. The earth cannot be round because Australians would fall off. Quantum physics sounds confusing, so clearly its just made up. Advertising doesn’t affect me, because I am smart.

All the time, every day, we encounter stuff that our immediate ‘hot-take’ on is wrong, because we are not experts. The problem is, we are so encouraged to share our dumb hot takes on social media, that we are now all overloading each other with ignorance. When everyone is constantly offering their shallow analysis on everything, all the time, how on earth are people ever going to be sensibly informed? When our analysis is a popularity contest on twitter, the electorate become literally stupider every day, the chances of us electing decent politicians, or allowing them to make the right choices are slim to none. The best facts should be the correct ones, not the ones with most upvotes from people who have no idea. e=mc2 is not the result of a twitter poll

We need to fight back against the urge to offer up our opinions when we have zero experience and zero data. The urge is strong, and psychology experts working at social media companies are working hard to force us to vomit up hot-takes 24/7, but its highly destructive. I’m probably as guilty as the next person, so to help out anybody unlucky enough to know me, or follow me on twitter, or read this blog, here is a list of all of the topics I actually have a decent, serious amount of experience and data on, after 52 years on this planet. Anything else I offer an opinion on is likely bullshit:

  • The electric car market, and the plans and existing business of Tesla.
  • Marketing and selling a PC-focused indie strategy game, especially advertising.
  • Heavy metal guitar playing techniques, up to a certain level.
  • C++, with some stl, but excluding any modern additions in the last 15 years.
  • Solar panel economics, and challenges associated with solar farm construction in the UK.
  • Classical Economic theory, but only to degree level.

Everything else I offer an opinion on is basically garbage, and not worthy of you listening to. There are more experienced experts on all of those topics BTW (although I *might* make a play for being a decent expert for the second one).

So to conclude, having experience MATTERS. having data MATTERS. Lets stop being ashamed to admit that we disregard some peoples opinions on some topics. Expertise has real value. To make a point, I’ll close comments for this post :D.