Sunday, November 27, 2011

Get Organized: Spaghetti Code

An interesting part of my brain is that I am spectacular at organization - I just have trouble forcing myself to start the process. Once I begin, then, it becomes almost impossible to finish the job.

Being a programmer and developer, I have countless files in numerous locations on my hard drive that are in an inconvenient location or are simply no longer needed. The problem with many of these files is that I am a lazy coder - the code requires that the files be in their current location, and in order to change that dependency, I have to go back and edit the path in the source code and recompile, or combine the files into a single program, a process which takes even longer than the "quick fix."

As a result of this lack of resolve, I've put off any serious organization of my code files since I stopped using Visual Studio, which organizes the user's file for them. My preferred editor, Vim, goes for a minimalist approach and does no organization for the user. I began using Vim about a year and a half ago.

Programmers have a term that they use to describe code that is messy and unorganized: spaghetti code. I guess you could say my computer was full of spaghetti files. I had gotten lazy, and it was initially easy to work around the small inconveniences, but as the files piled up, it became impossible. There were source files in bin, tmp, usr, home, and countless other directories that the user isn't even supposed to touch.

I didn't realize before I began the project how much harder it was to bridge my coding from one part of the computer to another. Every time I had to switch terminals to grab a file it made me lose concentration (as I realized all too well in the Ludum Dare speedcoding competition, which I did not complete). As I organized, I got a feel for where everything was and exactly what would need to be changed.

When I finished, I felt moderately satisfied, but it wasn't until I got back to coding that I realized what a difference it had made. First of all, it had convinced me to use more efficient methods in my code, requiring less external dependency and decreasing compile time. It also allowed the programs to run significantly faster and with less system resources.

The process of code writing itself was also much easier and far less stressful - no longer did I need four file managers open at the same time to search for files, and many of the memory-hogging search scripts that had previously been necessary could be disabled. The process came quite a bit more naturally, as well - more time could be spent on content as opposed to organization and my code became quite a bit more concise and efficient.

No comments:

Post a Comment