Polishing A Turd

I pride myself with not spending longer than is necessary on a project.

That being said I present the final version of crappy higher or lower, a day late. At least I’m semi happy with it, right?

As before, it’s playable here.

Final features

I decided I’d add a score timeline to the history section. It felt like a good idea and made the history portion a non sensical mess. Goal achieved. Some styling would help but I’m not spending any more time on this. Time to kill it.

I added a function to toggle the behaviour of button presses too. This prevents weird behaviour where a user could press a control more than once at a time, triggering several rolls. This thing is more robust than some of the code in my day job.

I didn’t do local storage game saves because well, there’s no point. If anyone plays this final version more than once and gets upset that their high score isn’t saved then I’ll buy them a drink to make up for it.

Refactoring

I don’t know why I refactored it. The fact is the code was a bit messy and not my best. I reckon I could get it down to less than 100 lines if I tried but it’s current state is that it works and is readable, in my opinion. In my head I didn’t want to put messy code online but half way through me refactoring I realised that I already had in the previous two versions and that I’m currently anonymous too.

I also realised that I just don’t care anymore. I used to be afraid of showing others code that I’d written. These days I’m seeing it as a learning opportunity. If someone can show me a better way of doing something then great, I’m all ears.

Lessons learnt

  • Just finish the damn thing.
    I’m writing this blog post at quarter to midnight, a day after the deadline I set myself. Partly because this is when I work anyway but also because I’m lazy. I could have finished this by last weekend if I’d bothered but also, why not play overwatch? It wasn’t a particularly long project. If I don’t include the blog writing, I’d estimate about 3-4 hours spent on this in total. Realistically I could have done that in a single evening but I allowed other things to get in the way. Stop wasting time and just code for god sake.

  • Write code quickly.
    This is something I sort of subscribed to already. My point is that instead of trying to write the neatest code immediately just get something working. The options for more clever logic or simplified functions will appear and jump out at you. Obviously, take this with a pinch of salt. Should you begin writing a long term project in this way without regular, thorough refactoring? Absolutely not, the creator of in depth planning sleeps soundly in their grave. But I’m a firm believer of trying out a new concept or idea quickly to get some feedback from your own usage. Especially important with UI.

  • Practise pure javascript more.
    Some of the stuff I had to look up for this was just dumb. Partly because I always get some things confused with php syntax but also because I’ve only ever learnt to do some things in jQuery or in JS frameworks. I feel like I need to go back to my roots a little and rely less on frameworks. Yes they make my life easier but also, they’re just not needed for small stuff like this.