Start Projects Faster with Scaf
Table of Contents
- Intro
- Background: Problem Identification
- Existing Solutions
- Existing Solutions are Bad
- Spring 2023 Code Jam
- Whats scaf
- Challenges
- A Video
- Future Improvements
- More Info
- Update
Intro
This post is about my submission to the 2023 PennWest Code Jam, scaf, a universal project initialization tool.
Background: Problem Identification
At some point last year, I was focused on learning how to make web servers with Node and Express. I learn best by doing so, as I read documentation, I made projects. Over and over again, I created some node-test-55
folder, copied a package.json
, rewrote the boilerplate code for starting an express server, and after 10 minutes of copying, I was ready to actually work on the latest iteration. I went through the same boilerplatey process learning a variety of other languages and libraries.
I really noticed it on a web-based MUD game I was working on (future project), which I scrapped and restarted several times. Each time I had to figure out boilerplate again. Sometimes this is useful, and you figure out better ways to layout your project, but after a couple of iterations it’s just a waste of time.
Existing Solutions
I know I’m not the only coder who dislikes this boilerplate time sink. There are countless templates on GitHub, such as this nuxt/ts one, this go microservice one, or this c++ gui one. Clearly there is a basic project structure creation process that shouldn’t be repeated for every project; it should be abstracted away.
The solution is scaffolding. Wikipedia defines scaffolding as a “project generation technique supported by various tools.” So what are those tools? Here are a few:
- Spring Roo : Provide rapid application development of Java-based enterprise software.
- Catalyst : Written in Perl, closely supports a Model-View-Controller pattern.
- Yeoman an open-source client-side scaffolding tool for web applications.
And many others.
Existing Solutions are Bad
There are many scaffolding tools, but they’re all bad. They’re all a complicated new technology and configuration system to learn. They’re all geared towards specific languages. Even if they support a variety of languages, they’re designed to do really clever and complicated things to build your scaffold for you, and that means you have to learn the clever and complicated ways they work.
Let’s pretend my project is a shed I’m trying to build. I don’t want to build some bespoke, exactly-measured scaffolding for it. I want to go to my garage, pick a scaffold on wheels that’s the right height, and roll it out. It doesn’t need to be more complicated than that.
Spring 2023 Code Jam
I entered the 2023 PennWest Spring Code Jam in the category “Automate Life”. The prompt was as follows:
There are many things in our daily lives that are annoying to handle, even only in virtual, such as digging through to find important emails, double checking what appointments were left, checking to see if any missed calls were actually useful. Identify an area of annoyance in your virtual life that could be automated to be made significantly easier and less of a pain to deal with and create a solution for it.
Starting projects is definitely an area of my life that is a pain to deal with and I already had the solution in mind. Scaf!
Whats scaf
Scaf is general purpose, command line, project initialization tool.
Scaf is purpose-agnostic and can be used to start-up (“scaffold”) any type of project that has a directory structure.
Scaf works by maintaining directories of templates that the user supplies. When the user wants to scaffold a new project, they may use scaf to copy the contents from one of these directories into their current directory.
I coded it in C++ over this last weekend.
It simple; when you scaf add
a folder, the folder’s contents are copied to your templates directory, excluding a .git
folder.
When you scaff load <template>
a folder, the contents of the template are loaded into your target folder.
That’s it!
The great thing about this design is that you can create new scaffolds from any existing project very quickly.
Challenges
There were only a few allowed languages for the Code Jam, so I decided to upskill C++. I ran into challenges configuring the Makefile in a sensible way, and wasted some time trying to fool around with callbacks, a pattern C++ doesn’t accomodate very well. I scrapped that idea in favor of patterns C++ plays more nicely with.
Another challenge was saving and reading a configuration file. I didn’t want to come up with a clever new format, I wanted to use JSON. Fortunately there is a fantastic 3rd party library nlohmann/json that is a masterfully elegant implementation of json handling in C++.
I also had to regulate my scope. I thought about adding colored printing and a gui, but with only 48 hours to code, I wanted to make sure I had something DONE at the end.
A Video
I made a video for the project submission and put it in YouTube.
From 09:09 on is a video in 1000x speed of my day 2 coding of scaf (starting at about 4 in the morning). The real draw isn’t watching an exhausted me make silly mistakes super fast, but listening to seren1tyy - Classical House, an epic track by my brother.
Future Improvements
- Refactor: split out Parse and Execute functions.
- Simple GUI
- Colored terminal printing
- More saved config settings?
- More info about templates with
scaf info
like what languages they are
More Info
You can find scaf here: github.com/klm127/scaf
Generated code documentation is here
Update
I rewrote the project in Go, because my binary was missing .dlls on some systems. Go is my preferred language in general and is very reliable for cross platform compilation.