21 ms·
Thirteen Years of Bad Game Code
- partycoder 10y agoFor booleans prefer prefixes such as: has, can, is. e.g: hasEnemies.
- deleted 10y ago[deleted]
- janwillemb 10y ago> I was thirteen No need to be harsh on yourself if you created games like this on that age!
- danbolt 10y agoAgreed! While a lot of these games might not have been the most pretty to look at or play, I'm sure the author learned a lot making each.
- ianlevesque 10y agoMade me wish I had more of my old code to cringe at, but honestly I cringe after just a few weeks removed from a project.
- hinkley 10y agoI tell all the junior Devs: if you aren't horrified by something you wrote a year ago, you aren't learning fast enough. 20 years in and I still find things I wrote 8 months ago that I would not do again.
- zelos 10y agoI learned that about 4 years ago. I wish someone had told me when I was first starting out as a developer.
- sillysaurus3 10y agoBut it also means that what you're writing right now isn't that bad. If you accept that your best is your best, then your best is good enough. The effort is what matters.
- wingerlang 10y ago> your best is good enough. The effort is what matters. Not necessarily true, if you're (trying to be) a professional then it might not be enough.
- zero_iq 10y agoJudging by some of the 'professional' code I've read over the years, I'd say that's not a particularly high bar...! At least if you're horrified by code you wrote, it shows you care, and that shows some promise :)
- TeMPOraL 10y agoI concur. Especially if you define "professional" as "stuff people do at work, for money", the kind of code I saw in my career... well, it wasn't that much different from the code I was writing when I was 13.
- philbarr 10y agoBest one liner I've ever seen in "professional" code: String myBoolean = "yes"
- 10y ago
- kpil 10y agoI think I overused every single pattern, method, or framework I happened to learn until maybe after 15 years of coding. Probably still do to some extent. Nice read, and something to reflect upon for all young "fundamentalist". It takes some experience to learn when to bend the rules...
- stinos 10y agoI think I overused exactly. But, imo, you should do that in one point. Only then you can learn from mistakes, and learning from mistakes is the best learning. At least for me. Same in real life. Many examples, here's one: I'm confident and careful with ultrasharp cutting tools. But only because I cut myself bad a couple of times: before that I was more reckless even though I thought I was doing ok. Also others telling me to be careful had no effect whatsoever.
- retox 10y agoIf you think of patterns and frameworks as tools, when you're a beginner the only way to master and ultimately discover the limitations of those tools is to use them everyday.
- AstralStorm 10y agoHowever you shouldn't release a training prototype. Artists do not release sketches. Architects do not sell concept drawings.
- z3t4 10y agoI might be biased as I agree 100% on the takeaway, but this is amazing! Not only did he use best practice, but most importantly he made his own conclusions, and learned new things, instead of just accepting things how they where. When I started coding, I though you could only have one letter variables, like a, b, c, x, y, z. I did not question this, but one day I ran out of variables ... Edit: I looked at some of his other posts and saw an altitude bed on an old photo, witch concludes he probably is/was an athlete. I think it's common among athletes to have the mindset that they want to keep improving their skill level. This can be a good trait as a developer, but they are hard to manage, as such persons will quickly outperform their colleges and get bored. They work best with other people like themselves, or with old experienced developers. Make sure you protect him so that he do not burn out himself or his team. While these "10X" developers can work very hard, they are just humans.
- danielsamuels 10y ago> When I started coding, I though you could only have one letter variables, like a, b, c, x, y, z. I did not question this, but one day I ran out of variables ... At least the minifier wouldn't have to do much work. :)
- cableshaft 10y agoI started development on Texas Instrument calculators. On most of those, you could only have one letter variables in its TI-BASIC programming. I lucked out and convinced my parents to spring a little extra for the TI-85, and it had a lot of extra goodies, including named variables. I credit a lot of my initial understanding of how programming works to making various text-based games on those calculators while only half paying attention to class in high school.
- kkoomi 10y agoThe TI-85/6 is a magical device. A widespread built-in text editor, compiler and GUI library in one. I was very sad when I realized the BASIC performance was like an order of magnitude worse than ASM performance.
- geokon 10y agoHe basically admits that several of the "improvements" boils down to ripping out patterns that decouple code instead of finding alternate solutions. They're kinda quick and dirty, not agile, and could make refactoring a nightmare. I mean, he's not necessarily wrong, but hindsight is 20/20 and once you're done you can look back and cherry-pick and say "ahh, well obviously these things would always need to be coupled! I shouldn't have done the gymnastics to decouple them!" .. but that's a dangerous mindset to start solving the problem with. The whole topic of global state is very interesting and one I approach cautiously. I'd love to hear what more experienced programmers have to saw. When I go with global state I usually rely on someone else's judgement and use a framework. Like OpenGL and the graphics pipeline has global state.. and I'm okay with that. I use Cinder/Arduino, those things have some global states and for good reasons as well. But you really try your best to find a stateless solution - and here is feels like he isn't really trying
- girvo 10y ago> stateless Game development is kind of different, in that it's rendering the state of a simulation; so aiming for completely stateless solutions ends up making code quite convoluted -- you're hiding state rather than getting rid of it, in my experience. Now, stateless functions are still well worth it, at least up until it's time to get it optimised for performance ;) Game development is a fascinating world where a lot of the things I would normally reach for don't apply quite as well. It's quite likely you know all of this already, but I found learning this myself absolutely fascinating, and one of the reasons I still like to tinker with game development in my spare time :)
- TeMPOraL 10y agoSince a lot of my programming experience is writing hobby engines and games (and reading up a lot of engine code and gamedev resources), I sometimes wonder how negatively does this impact my regular career (previously web, now desktop applications). EDIT: to clarify, I mean the code I write, not my career prospects.
- deleted 10y ago
- DropbearRob 10y agoI really enjoyed this read. I still look at code I write every year and cringe. Everything becomes influenced by the flavour of the week. Don't be so hard on yourself, We all suck in hindsight, but its all about recognising it an constant improvement.
- eigenbom 10y agoA good retrospective. I'm always inspired by Evan's passion and ability.
- deleted 10y ago[deleted]
- jlebrech 10y agoI want to start writing something that would have been on the original atari to begin with, just have to look like that style. and keep moving up a generation in terms of gameplay.
- 97s 10y agoPico-8 is a good place to start.
- OskarS 10y ago> There are many, many more embarrassing mistakes to discuss. I discovered another "creative" method to avoid globals. For some time I was obsessed with closures. I designed an "entity" "component" "system" that was anything but. I tried to multithread a voxel engine by sprinkling locks everywhere. Dear God, I feel like I'm having my game dev life read back to me...
- hopfog 10y agoI've been running a browser-based MMORPG for a couple of years and when I started out I was a total novice in Node.js. I didn't even know how modules worked so the back end was just one big file. Needless to say, the code is a complete mess and the refactoring has made it even worse since I've started to implement some patterns just to regret it. I'm thinking of making the whole game open source but I'm so ashamed of the codebase that I don't want anyone to see it. It's a dilemma since I think the game has potential as an open source project. It's inspired by Ultima Online, Minecraft and Reign of Kings but with a lot of constraints making it easy to implement new features. It also has quite a few dedicated players.
- doppel 10y agoI say go for it - everybody learns something about good and bad code design when more code becomes available, and despite what you may think of it, there's still stuff to learn, especially form larger code bases.
- ithinkso 10y agoDon't let us hanging, what's the game? I've been looking for something web-based and casual to log few times a day and click some stuff:)
- hopfog 10y agoIt's actually almost unplayable right now since a bug I haven't managed to pinpoint is messing up all the mines (ugly codebase doesn't help). They're completely strip-mined and the economy is broken with a few players sitting on all the resources. I wouldn't recommend starting until I've managed to fix it in and restart the world. I'm currently in the process of rewriting the front-end from the old jQuery mess to React. It's like 95% feature complete but as soon as that is done I will start investigating what's going on with the mines. Anyway, here it is: http://canvaslegacy.com/ http://canvaslegacy.com/ Again, I strongly advise against starting right now since you won't experience the game like it's supposed to be. It's hard mode even for seasoned players. :)
- 10y ago
- Sir_Cmpwn 10y agoOne mistake you're still making: cross platform. I'd love to try out Lemma on Linux :)
- kuerbel 10y agoAs a 2nd semester cs student, that was pretty helpful. I have to design a battleship game in Java and have no idea what I'm doing actually. I'm just staring at the cursor and don't even know where to start, and it's comforting to know that other people struggled as well
- TeMPOraL 10y agoBattleships? Like that? http://static.kidspot.com.au/cm_assets/32032/battleship-game-main-jpg-20151022131744.jpg~q75,dx720y-u0r1g0,c--.jpg http://static.kidspot.com.au/cm_assets/32032/battleship-game... I.e. turn-based and probably doable with an UI toolkit (as opposed to drawing stuff directly with DirectX / OpenGL)? Anyway, shoot me an e-mail (address in my profile), I'll give you a few quick hints to get you started.
- Jach 10y agoI remember having to do something similar in college. I think the first time we had to do it in C, the second time we had to do it in C++ and make it OOPy. No GUI was required but with such a simple game it was possible (I think some students did it for extra credit?) to strap a GUI on top once the text based version was done. That might give you an idea of how to proceed. I was fortunate to have been programming before college but I was always amazed at how lots of those who made it to their junior year and beyond were basically as productive as me for school assignments despite only really starting to program in college. I still remember struggling with the syntax of the for() loop in PHP. My struggles are different now (and mostly related to modifying code that already exists rather than creating fresh new code) but struggle is a good sign that you're learning something. Just be careful it doesn't turn into never-ending masochism!
- falsedan 10y ago> Unregistered HyperCam 2 This is legit af
- falsedan 10y ago> www.fraps.com yesssss
- falsedan 10y agoReal comment: this advice is excellent, don't fall into the trap of perfecting your tools before starting. The article presents the code quality issues as constantly there and always getting more regrettable over time, but the finished products get better and better! I say, write bad code if it will get you closer to your goal (here, making a game people will pay money to play). Learn from your mistakes, and make new mistakes next time.
- TeMPOraL 10y agoI have a very similar history (though a lot worse games). I still have the backups of my first OpenGL programs and game code from ~16 years ago, I might put up a similar article at some point. The difference is that the author's game seem to improve visually over the years; mine actually regressed from 3D to 2D world (since the latter is easier to manage) ;). Some random comments follow. > Still, I loved data binding so much that I built the entire game on top of it. I broke down objects into components and bound their properties together. Things quickly got out of hand. Boy, you have to see JavaFX. And I inherited a codebase at work written by a cow-orker who was absolutely in love with bindings at that moment... Also the big blob of code reminded me why good macros in a language (not C-like macros) are a blessing ;). > Separate behavior and state. Yeah, learned that same lesson too. I prefer to think in systems operating on data as opposed to a web of objects calling each other. One of the reason is that the web of objects is very implicit; you soon have no idea who actually refers to who anymore. > If I start typing self. in an IDE, these functions will not show up next to each other in the autocomplete menu. That's a good and practical point, though I feel dirty about renaming functions for solely that reason. I wonder if this isn't time to experiment with some "first-class editor semantics". Here, ability to explicitly mark functions as grouped together solely for the purpose of IDE displaying them like that in autocomplete and outline view. In my evening Lisping, I'd love to have more control over indentation for macros I write. > global variables are Bad™ Yeah, that's almost like "goto considered harmful", and about as much correct as a soundbite (i.e. not very). Unfortunately, everyone keeps writing how global variables are evil, and what I'd love to read is some treatment on how to use global variables correctly. For the situations where - like often in games - you absolutely, positively need a lot of globally accessible data. > Group interdependent code together into cohesive systems to minimize these invisible dependencies. A good way to enforce this is to throw everything related to a system onto its own thread, and force the rest of the code to communicate with it via messaging. That's a... very self-conscious approach. Odysseus-tied-to-a-mast style.
- and0 10y agoAgreed on globals. I learned to code making a huge Java + OpenGL game engine some years back, right when scripted web frameworks were really blowing up and people were becoming test-obsessed. Every new article said that global variables and static anything were a deadly sin, so I did some really ugly things to avoid using them. Now I think global state is significantly simpler for certain systems, better than trying to pass that state around when it'll never be instanced.
- mirekrusin 10y agoI wish people would blog more like this. Majority of blogging is focused on how to use something or describe some final idea/conclusion. They are not bad per se but reading about failed ideas, dead ends etc. - the journey itself that lead to the final shape/conclusion is very valuable.
- DEFINE1727 10y agoNO MUNE GLITCHES HIW WAS THAT OR ASDUMPTION WERD IMPORTEINT THEN OS AS FINDING THESSASILIONS CONTINGEING
- Jimmy 10y agoMeh. If your code works, then it's good. Of course I don't literally mean that; you can write code in a way that makes it easier to debug, extend, etc. But too many developers get wrapped up in engineering the perfect system and forget that they're supposed to be, you know, writing a program. I think this is why a lot of hobbyist projects run out of steam.
- h3ctic 10y ago> I think this is why a lot of hobbyist projects run out of steam. Thank you! I asked that for myself and tried to create (really) good code. Result: Hobby project felt more like work, than actual work did. Now I realized why.
- snarf21 10y agoExactly. Perfect is the enemy of good enough. Granted, you still do have to cross the good enough threshold. I think this is the harder question to answer: Is this code a good balance of correctness and maintainability without being perfect? At the end of the day, you are either adding value for the company and team or you are not.
- vkjv 10y agoOne of the quotes from a senior engineer that has stuck with me over the years: > "Working is the lowest bar of quality."
- cestith 10y agoIf you replace "bar" with "rung" I think you may evaluate that a bit differently. According to Kent Beck, "Make it work, make it right, make it fast." Something that's reached for the most proper implementation, the fastest execution, and the most compatibility with something else is still useless if it produces the wrong results quickly and prettily.
- and0 10y agoGoing through this with my side project (a game of sorts, C++ and DirectX) but it's more of the opposite issue. I needed to implement a very simple GUI and didn't want to dig into any libraries, so I created a sort of minimalist mouse event flow with GUI objects. It was designed just well enough that it wouldn't be full of bugs. But as I've been adding all the features I originally intended I'm finding it's a bit of a slog. Every new feature I add is pretty well compartmentalized but it all still smells a little + sometimes requires some refactoring to fix unintended side effects. I'm only working on it a few hours a week (as opposed to 16+ last month), partially because it's just not fun writing code that I'm not proud of, but also because new code requires more and more caution as the system grows.
- JCDenton2052 10y agoI think we have all been guilty of negatively-named booleans at some point or other.
- davidbiehl 10y agoi would love to read a follow up that dove into the PHP dark ages. i was doing PHP around that time as well.
- mirages 10y agoWell one day I didn't foudn anything better to solve my sync issue with queries to the server than putting a Thread.Sleep(int) the variable name for it was private int DO_NOT_TOUCH_THIS_IF_YOU_DONT_KNOW_WHAT_YOU_ARE_DOING_Timeout = 7000; The code actually made it and is still in production
- pnathan 10y agoHaha, this is great! Memories. All those terrible lines of code I wrote when younger led up to less terrible later. I too got on some of the cargo cults until the harsh reality of the projects showed me why not. :) This year marks 20 years since opening up QBasic as a 13 y/o.
- prance 10y ago> Unfortunately, Sun decided that almost all Java errors must be recoverable, which results in lazy error handling like the above. Not quite: Java insists that all (checked) Exceptions be handled or passed up explicitly. One can argue that this design decision is bad, as has been done extensively elsewhere. However, in the particular example given, I'd argue that it would have made much more sense to display a user-understandable error message to the user (e.g. "Required gun resource file is missing, please re-download the game here: (...)"), and then just System.exit() if it's non-recoverable. Maybe print a stacktrace if the game was started in debug mode.
- kelvin0 10y agoThe only way to not make any mistakes, is to do nothing. As Nike says: Just Do It!
- yblu 10y agoThis `for` loop looks particularly curious to me: for (int i = this.bindings.Count - 1; i >= 0; i = Math.Min(this.bindings.Count - 1, i - 1)) Why isn't the last expression a normal i--?