Welcome to travisbontrager.com

Software Engineering vs. Hacking Code

June 11, 2017

This week I set out to code my first JavaScript browser game. I made two decisions before I began coding. I decided to code my own version of the classic snake game. And, I decided to hack it together as quickly as possible.

There are many versions of the snake game with different rules and objectives. These include the Tron version and the version that came with the old Nokia cell phones. I made the decision to build a snake game clone partly because I had never programmed one before, so it was a new challenge (albeit not an imposing challenge). And partly because these types of small, simple games were a staple of the programming projects I took on in my teen years when I was first learning to program (using BASIC, Pascal, and C). So, constructing a small game program like this was a totally nostalgic exercise for me.

The main purpose of this project, however, was to practice my coding skills and become more familiar with JavaScript. In their book, The C Programming Language, Dennis Ritchie and Brian Kernigan (1978) state, “The only way to master a new language is by writing programs in it.” JavaScript being one of the two languages (with the other being C#) that I want to spend my time trying to master, I need to write programs in it. Any programs. Mastering either language will undoubtedly take years, but it all begins with a single program and continued progress is made only through continued programming.

How does a master brick layer become a master of brick laying? One brick at a time and a whole lot of sweat of course. And to extend the metaphor, a master brick layer has made more brick-laying related mistakes than an apprentice brick layer has laid bricks. This is important to remember when learning any new skill. Mistakes will be made. That’s inevitable. It’s unavoidable. What’s important is how mistakes are handled – should one treat them as failures, or as opportunities to learn what not to do? The latter approach makes more sense to me and should lend to an examination of why a given mistake was made. I had to make such an examination of myself and my choices over the course of this project.

I made a mistake.

Early on in the implementation phase of this project, I made a decision about how to code the animation of my snake. I made a poor choice. Why? Mainly because it seemed like the easiest thing to do at the time and I wanted to finish the project as fast as possible. After fifteen years as a carpet installer, this is not at all how I approach any installation – I’m a craftsman, not a hack – but, it’s exactly how I approached most installations when I was first starting out as an installer. This is an important lesson I should be able to learn from myself.

I feel the main take away here should be to take the time to design the algorithm on paper before jumping into the coding. Taking the time to actually design a project before beginning the coding phase. Trying to anticipate any later issues that will arise from implementation decisions made early in the process so the best decision can be made before implementation has begun. Being a craftsman, not a hack. Doing real engineering, rather than trying to MacGyver together a solution that probably won’t be robust or scalable enough to be permanent.

This saves times in the long run, even though it may not seem like it at first. To continue drawing the parallel to my career as a carpet installer, nowadays I spend, on average, a half an hour to an hour on a jobsite before actually starting the installation (not including the time it takes to carry in my tools and the product). This time is spent measuring, laying the seams out in my head, checking the subfloor and room perimeter for any issues, asking the customer questions, and on rare occasions consulting with the manager of the carpet shop. This is time spent making decisions about implementation before implementation begins. This is something I never did in my early years of installation. And yet, nowadays I’ll spend from four to six hours on a job that would have taken me seven or eight hours when I was first starting out. Why do you think that is?

Don’t get me wrong, I know it’s partly just because I’m better at my job as a result of my years of experience. But it’s also because I spend less time cleaning up messes that could have easily been avoided with a little discernment and preparation. It’s been argued to me in the past that the best way to approach any project is to just jump right in because a type of paralysis can be caused by over analyzing the situation. I agree that over analysis is bad, but no analysis is worse. Learning the difference between analysis and over analysis takes time as well, but the effort spent doing so pays back in dividends. In the end, the question is, “Do I want to be a hack, or do I want to be a real engineer?” It seems like an obvious choice to me.

[technical details]

The problem I dealt with here was a memory issue.

Another reason I chose to implement a snake game clone is because of the snake-like animation on my website. I originally choose that design for my website simply because I wanted some sort of animation and I liked the aesthetics of what I chose – I had no original intentions of later implementing a snake game clone. However, I later made the decision that because I had implemented that animation on my website I could build on it to make a snake game clone, which is what I tried to do.

The problem with this approach is that the website animation uses a set of sixteen small div tags that move around the screen in unison. This is not a problem for the website animation. It works fine with sixteen div tags. However, when you add a new div tag every time the snake moves ten pixels, you soon have thousands of div tags, tens of thousands if the player is good. That quickly sucks up memory which in turns slows program execution. In simpler terms, as the snake got longer, it moved slower and slower. This is not something I had considered during the initial stages of coding the game, and in fact I had the game almost finished when I discovered the issue.

I chose to refactor the code using the canvas tag. Ironically, I would have chosen to use the canvas tag from the start had I taken the time to even consider the best way to implement this game rather than just doing what I thought would be the easiest. The time spent considering that decision would have easily been less than the time I spent refactoring the code. That is especially true given that using a canvas tag cut the quantity of lines of code in half by greatly simplifying the game control logic.
Live and learn, right?

The martianCube - My New Computer

June 4, 2017

Upon graduation from my Bachelor’s program, I decided to reward myself with a new computer. I wanted something more powerful and impressive than I have been using. At first, I was looking at a new laptop, but they’re so much more expensive than desktops and I already have one. Once I started considering desktop computers, I thought why not build it. I built my first computer back when I was in high school and was able to save a bundle. While computer parts aren’t as inexpensive as they were back then, it was still a rewarding process to build my own computer.

The Asus laptop I’ve been using to this point has a 15” screen, an Intel Core i3 processor running at 2.4 GHz, 8 GB of RAM (that I upgraded from the 4 GB with which it originally came), a 750GB hard drive, and a spacebar that only works approximately fifty percent of the time.

For my new build, which I have code named the martianCube, I started with an Intel Core i7 processor running at 3.8MHz, 16 GB of ram, and a one terabyte hard drive, and a 24x DVD/CD read/write drive. I added a 128 GB solid state drive as the boot drive which allows an unparalleled boot time. I decided on a Super Micro motherboard with all the bells and whistles, including built in high definition sound and two graphics processors. It’s all powered by a 650 watt Seasonic power supply and contained in an Apevia X-QBER computer case. The case is super cool – it has clear Plexiglass panels on both sides to allow all of the internal components to be viewed and three fans with built-in green neon lights. I also added an extra video card to allow for a third display and a battery backup system to prevent data loss in the event of a power outage.

I am extremely happy with my new creation.

[ back to the top ]

My First C# Program

May 28, 2017

All my core programming classes at Regis University were taught using C++. That made me quite happy at the time because it had been my programming language of choice since I began learning it in high school. While I had little experience with object-oriented programming before beginning my degree program, I knew C++ well enough that my first two programming courses were completely review. I understood all the fundamental concepts of imperative programming. In addition to C++, I learned many other programming languages while earning my Bachelor’s degree.

In my Web Programming course, we covered HTML, CSS, JavaScript, PHP, SQL, and XML. More advanced courses introduced me to Assembly, Java, Ruby, Haskell, Prolog, UML, and UNIX scripting. However, there was one extremely popular language completely missing - C#. Not only was C# not included in the core curriculum, but there wasn’t even a C# elective available. During my job search I have noticed considerably more opportunities for C# developers in my area than for either C++ or Java developers. I’ve also previously read that it’s an easy language to learn for anyone already familiar with C++ or Java since the fundamental syntax is practically identical. Therefore, I have recently decided that C# will be my next course of self-study. This week’s blog entry is about the first step of that epic quest.

Technically my first program in C# was a hello world program. For anyone reading this who isn’t a programmer, that’s just a program that displays the words “hello world” to the computer screen. It’s traditionally the first program a programmer writes in a new language. The origins of that tradition go back to the early 70s, a programmer named Brian Kernighan, and an extinct programming language named B, which is the direct ancestor of C, C++, Java, and C#. In addition to hello world, I began by writing several small programs focused on specific tasks and techniques. While coding those small programs, I was just trying to get a feel for the basic techniques used in any program. Most of them were composed of only a few lines of code and didn’t even instantiate any objects. However, once I felt I had covered the basics, as laid out in my core programming classes at Regis, I began to code my first real C# program.

My first C# program was a very simple mock payroll application which ran in the console. It accepts some input from the user, reads in some data from a file, does some math, and writes the resulting data out to several files. It makes use of most, if not all, of the very basic fundamental concepts necessary in most useful computer programs. These include control structures, data structures, inheritance, polymorphism, method overriding, enums, a list, try/catch blocks, and a LINQ statement. The program is very small, consisting of just seven classes including the Program class which contains only the main method.

The Staff class is a base class. It contains two fields and four properties which are used to store basic employee data including name, hourly rate, hours worked, basic pay, and total pay. It also has three methods including a Staff constructor, a method named CalculatePay(), and an override of the ToString() method which is used to write the values of all fields and properties to the console. Both the Hourly and Manager classes are derived from the Staff class. The main difference between these two classes is how pay is calculated when more than forty hours a week are worked. As such both classes override the Staff class’s CalculatePay() method and provide their own versions of the ToString() method.

The FileReader class consists of just one method named ReadFile() which returns a list of Staff objects. When called, the ReadFile() method first opens a text file containing employee records, after first checking that it does indeed exist of course. Next, it reads the entries in the file one at a time, copies the employee data into either a Manager or an Hourly object, and adds each object to the list. Finally, it closes the file and returns the list. Only one FileReader object is instantiated, in the Main() method.

The UserInput class, which is implemented as a static class, consists of three methods. The first two methods, GetMonth() and GetYear() are used to get the current month and year for which the payroll reports are being generated. These user interactions take place using console IO. They make use of the Parse() method of the Int32 class and try/catch blocks for exception handling. The third method, GetEmployeeHours(), receives the list of Staff objects as a parameter. It loops though the list requesting the user to input the amount of hours worked for the month and calling the CalculatePay() method for each object. All three methods are called from the Main() method.

The last class is the PaySlip class. This class consists of an enum for the names of the months, three private fields (one of which is a constant), and four methods including a constructor and an override of the ToString() method. Both the GeneratePaySlip() and GenerateSummary() methods receive the list of Staff objects as a parameter. The first of the two methods generates a simple pay slip for each employee which is then copied into its own separate file. The second method generates a single report, copied to another file, of all the employees who worked less than a given number of hours for the month, in this case ten hours. This is accomplished using an LINQ statement to query the list of Staff objects. The results of the query are copied into a variable of type var which is then looped through using a foreach loop to generate the report.

Although this is a very small program, offering nothing in the way of an elegant user interface or positive user experience, I feel like it was a very beneficial first project for me. I think it helped me to learn the very basics of C# quite well. I also feel that the syntax and concepts were further cemented into my brain by writing this blog entry which required me to explain what I did in English. At this point, I am very excited to continue my journey down this rabbit hole. I plan to write several more small programs using this language – perhaps I will revisit some of the assignments I did in my core programming courses at Regis – as well as studying Microsoft’s online C# Programming Guide. All this will be preparation for taking Microsoft’s C# certification exam 70-483. I feel that earning that certification will certainly open up my employment possibilities one day. And, to quote the Mad Hatter, “When that day comes I shall futterwacken... vigorously.”

[ back to the top ]

I Finished My Bachelor's Degree

May 21, 2017

I finished my degree. I graduated Magna Cum Laude and am now the proud bearer of a Bachelor’s of Science in Computer Science. It’s something I will always have for the rest of my life and no one can ever take it away from me. It’s a good feeling. I don’t really feel any different. I don’t really feel any smarter. But, What I do feel in more accomplished. This is a huge accomplishment for me. It’s something to which I had to dedicate four years of my life and of which I am extremely proud.

Now that’s it’s over and finished, those four years seem like a drop in a bucket, but at the onset they seemed like an eternity. It wasn’t an easy thing to accomplish as a non-traditional student. It was absolutely a character-building exercise. And upon completion of this exercise, I’m convinced that most people in modern-day America could certainly use more character. That being said, I am unequivocally thrilled with the personal growth I experienced as a result of higher education and critical thinking.

Going in, I was really excited about the programming and math courses, but was a little apprehensive concerning the general education requirements. Looking back, however, those turned out to be some of my favorite subjects – Philosophy, Logic and Reasoning, Psychology, World Religions, and Anthropology. There were also a few I didn’t enjoy – Composition, Speech, and Civics. My favorite core CS class was Advanced Programming and my favorite advanced level CS course was a tie between Computation theory and Computer Architecture. My favorite math class was easily Linear Algebra.

If I had to pick a favorite over-all course, I would have to go with my Senior Capstone course. There are several reasons for this, but the main one is that it, more than any other course, was a confidence builder. We were required to define our own capstone project and requirements for success (both of which had to fit within certain predefined parameters), and find a stakeholder with which to work. We were required to define and follow a tight development schedule including weekly progress reports and iterative product releases. And, we were required to learn a new concept or technique, with which we were previously completely unfamiliar, through research and self-study.

I was terrified of that course before I took it. I was uneasy about it for the first few weeks. A little over halfway through, I questioned whether I would meet my deadline. But in the end, when I did meet my deadline and the website turned out better than I had expected, I felt a confidence in my programming skills and ability to learn new concepts that was previously unimaginable. It felt good. After that course, I knew I would be able to tackle any programming problem set in front of me and provide a solution even more elegant than that which I could conceive at the onset of the software development life cycle. So, what does it feel like to finally have my degree? It feels wicked groovy awesome!!!

[ back to the top ]

Hello World

May 18, 2017

This is a test of the maskedMartian's emergency broadcast system. This is only a test. If this were an actual emergency, this broadcast would be accompanied by instructions for how to avoid having your brain sucked out of your head during the impending alien invasion from the planet Gilderaan. If this test is successful, it will be followed by further blog posts. This blog section of the website was included mainly to allow me further practice back-end development and database usage. However, using it to document milestones in my continued self-education seems like a great idea.

[ back to the top ]

Developed by Travis Bontrager

     © copyright 2017