1. Automate ALL the things!!!

      written by Ray Benefield
      Twas a good weekend. There is no update to the game this week, but what I did this weekend will MORE than make up for that. I love the world of software engineering. Most of the things we do regularly can be automated in one way or another. Be it through machines in the physical realm, or through scripting in the virtual realm. Automation is amazing...



      That Realization



      So I was always aware of automation, but it didn't quite click with me until I got my first job. When you have a regular thing you do often, it just makes sense to automate it. But most people are afraid that the initial investment is not worth it. The amount of time you have to spend learning an automation system, then figuring out the best way to automate your task can be daunting. Enough so that people continue working in their normal routines to not have to invest that extra time. If you require delivering things in a timely manner, that is understandble. However, if you can ever afford it, as soon as you recognize that automation can be a solution I HIGHLY recommend doing that. Because otherwise we keep going and realize that a lot of time could have been saved if we were to just automate it that much sooner.



      It is time...



      In my scenario, I'm switching to a much more structured way of organizing the code that I write for games in general. The 'S' in SOLID principles is Single Responsibility. This equates to a LOT of files... seriously, a lot. Where in the past I would have a monolithic class that does a lot, now that one file would be split into several dozen classes... and then with these same principles I also need an interface or more for each of those classes. That is a lot of extra busy work essentially, just to get setup. The benefit is that our code is well organized and that each piece acts as a small lego, as opposed to a complex pre-built block as I discussed in last week's post.

      I'm not sure where the term came from, but I believe the term is boiler plate code... essentially a lot of code that you have to write over and over again. Essentially the same code. A new class declaration, your constructor, your using statements, etc. Lots of the same... what do we do with lots of the same? If you said "Automate the process" then you are correct. I use VIM as a text editor, which has a built in macro system. Which is nice, but with the amount of file manipulation involved VIM was not appropriate for the situation. I needed a generic macro system that hits the keyboard in a very particular sequence, preferably with the ability to setup functions (little bits of code) that can be reused for similar situations. Enter AutoHotKey.



      Enter AutoHotKey



      For those who do a lot of things on the computer, where you feel like what you do is very repetitive I highly suggest you look into learning the language tied to AutoHotKey... it is a powerful tool that is going to save me a LOT of time. It could take me anywhere from 15-30 minutes setting up boiler plate code for a new Controller, Service, View, or Model. And it was almost the same every time. This past week I invested 11 sessions into learning AutoHotKey and writing out code to write code for me. ;) It is some crazy shit, but it is awesome. Seriously... it takes like less than a minute or two depending on the scripts that need to be generated to create all of the boiler plate code I need. And it has the ability to jump to the write folders, find the right files, and with VIM it can find the text the needs to be changed and change it efficiently. The keyboard shortcut world is amazing folks. ;)



      Demonstration



      So instead of just talking about it, I also learned how to do screencasts as gifs. I wanted to showcase what exactly is going on behind the scenes. In the world of MVC architecture, a Controller is a manager that tells things to happen and directs them to various places. Every time a decision point is made it goes through a Controller. Every time I needed to create a Controller I needed to do the following:

      • Create the Interface. Building in SOLID requires that we create contracts for classes to work with so we can substituate different code that just meets the contract.
      • Format the interface by adding a basic function, adding using, adding an implemented by tag, and various other tasks
      • Create the class. This is the actual work that gets done by the controller
      • Format the class by extending Command from the strange framework, implementing the interface, adding a constructor, and tying in an "I'm complete" signal for other Controllers to react to
      • Create the new complete signal in the signals file
      • Create a binding for the signal so I can use it with Strange... (this part isn't implemented yet)
      • Go through and add comment documentation to each major part
      • I even go through and add "Task List" TODO comments so I can use that feature of Visual Studio to make sure I double check stuff later


      So here is the creation of a Controller... I hit the "Windows Key" and the letter 'C', type in a name for the new controller and I sit back and watch. Rather than taking me 10-20 minutes setting all of this up and making sure I don't miss a step... it takes less than a minute or two to build up the files and code. AND IT DOES THE SAME THING EVERY TIME!!! Amazing. While watching the GIF, notice that in the bottom left it finds the folder that it needs to be in and creates the file in the right place, and in the bottom center the "TODO" comments populate the task list for me to go back to later:


      Click the GIF to make it larger (1280 x 720 to be exact)


      Next Steps



      So now I have a lot of the major stuff ready with AutoHotKey. I can create a Controller and a Service. I'm currently working on Views/Mediators, and after that I have to create Repositories (Creators, Readers, Updaters, and Deleters... the CRUD operations), Signals, Providers, and Models. Signals won't take long, Repositories and Providers should be pretty standard. Models on the other hand, those may take a little bit more effort. We'll see how things work out. So I think one more week of automation and then back to working on the game. ;) See you next week, when I will hopefully have the rest of the automation done. I squeezed all of this out in 11 sessions of 50-minutes. ;)

      Release Date: May 27, 2014
      50-Minute Session Count (June 4, 2014): 28

      5 comments:

      Gnappy said...

      That is incredibly useful man. And here I was using AHK to idle in cookie clicker...

      GodlyPerfection said...

      Yes it is. And to make it clear how useful it is, there are currently about 10 controllers in the current build. If we say consider each controller takes about 15 minutes to setup properly with an interface, comments, signals, etc. then it would have taken 2 1/2 hours for all of those controllers. Now i can do that in about 10-15 minutes. Worth the 9ish hour commitment. Only one more weekend to do the other parts.

      Doc1777 said...

      My gawd. That is awesome. Now I wonder if I can use AutoHotkey with setting up computers automatically at the school. Specifically to build an image by installing all the programs needed that Ninite doesn't have. Though when the image is created there is not much else I need to do; however, when you create a brand new install of fog it can be a little annoying to setup programs for the image even with sysprep.

      GodlyPerfection said...

      It is entirely possible. I use a lot of sleep commands to give parts of visual studio the chance to load. I haven't quite learned the best way to respond to events yet with autohotkey, but I'm sure they exist.

      Doc1777 said...

      This is one heck of a useful program. Thanks for sharing this :P