Week 109: Refactoring

A necessary week.

After writing the last weekly recap on Tuesday, where I wrote about how I was having a hard time with C++ and missed Lua, a few people came to me saying that integrating Lua was really not that hard and (more or less) that I should totally do it!

So I decided to research the matter, my main concerns being how fast would Lua execute in the compiled program and how easy/quick it would be to integrate it.

The first thing I learned, and it was quite a surprise, is that Lua can actually quite fast, in fact near as fact as C! (at least according to this source which also explains why) Not so much with the official Lua library but more so with Luajit, another standalone library which compiles Lua in more CPU-optimized ways.

So how hard would it be to integrate this Luajit? Well, not apparently not so hard. The most time-costly part would be to write the ‘bridge’ version of the Sugar API to be able to use it in the Lua scripts. The actual Lua setup is just a bunch of functions to call when you want to start using Lua and then when you’re done with Lua. It doesn’t look like a big deal.

And yet. Despite all that info, I was still very hesitant to actually go ahead and integrate Lua. The main reason being that it’s not in the plan I set myself. When I started making Sugar, I had a pretty narrow vision of what it would be, and so far all I did fits in that vision from back then. I did consider Lua scripting back then and decided that maybe I would add it after the engine is functional, it would not be in the first version of Sugar.

What I realized when I wrote the last weekly recap is that I’m on a learning curve with C++. The last time I had used it before Sugar was 2 years back and even then I used it for only a couple of months after it was teached to me. I needed to understand that I am re-learning how to use the language effectively and that I should figure out my own coding practices to answer my needs.

And that’s what I did for the rest of the week! While some progress was done on the ‘Melee’ game, I actually did a lot of refactoring on the little code I had already written for it. My focus has been on developing patterns that look light in code-form and are performant.

One of the things I did is to decompose long functions into smaller functions. When I was in school, a programming teacher had us do a one-week project where no file could be more than 200 lines long, and no one function could have more than two layers of for/while loops into it. Looking back on it, this was an extremely good exercise and there’s definitely some good practices to get from it.

Doing this for a big part of the week meant that I didn’t have anything new to show. That said, I did get some little progress done on the game at the start of the week, adding some very simple (invincible and inoffensive) enemies. (also, collisions)


There should be a lot more new stuff in this game next week, since I’m almost done with the refactoring as I write this.


To conclude, I will not be integrating Lua, or at least not before Sugar 1.0. Instead, I will be learning to harness the power of C++, even if that means going through a learning curve which may slow me down for some time.

And that’s it for this week! Even though there’s not much to show for it, progress sure was made!

Next week I’m finishing up on my refactoring and then I’m actually developing the game again. Hopefully I should start being more comfortable with my new workflow and go a little faster!

Thank you to all my Patreon supporters, because I couldn’t be writing posts like this one without you! Here are the names of all the 3$+ supporters:

Ryan Malm, Joseph White, Austin East, Marcin Majewski, Zachary Cook, Jefff, Riccardo Straccia, HERVAN, Andreas Bretteville, Bitzawolf, Alan Oliver, Paul Nguyen, Dan Lewis, Christian Östman, Dan Rees-Jones, Reza Esmaili, Thomas Wright, Chris McCluskey, Joel Jorgensen, Marty Kovach, Cole Smith, Giles Graham, Tim and Alexandra Swast, Sasha Bilton, berkfrei, Jearl, Dave Hoffman, Finn Ellis, Egor Dorichev, Jakub Wasilewski, amaris, Brent Werness, Anne Le Clech, Jeremy Bouin, Jesse Bergerstock, Jacel the Thing, Pierre B., Sean S. LeBlanc, C Oakreef, Andrew Reist, vaporstack, hushcoil

Have a great week everyone!

Take care!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: