Tuesday, August 30, 2011

Bizz Buzz Woof

If you don't know what Bizz Buzz is then you are, quite frankly, as ignorant as I was until 5 minutes ago.  Until recently, I didn't know that the game Bizz Buzz and several variations of it had existed.  Wikipedia to the rescue: http://en.wikipedia.org/wiki/Bizz_buzz.

The Bizz Buzz game, commonly known as the Fizz Buzz game is a game where the goal is to count numbers starting from 1.  However, whenever the counter encounters a number which is divisible by 3 he says the word "fizz" in place of the number.  Likewise, when the number is divisible by 5 it is replaced by the word "buzz" and when the number is divisible by both 3 and 5 the word "fizzbuzz" is said in place of the number.

By now, you're probably already 4 drinks in after finding out about this wonderfully simple game and can no longer make it past 6 without having to take yet another sip.  Alas, this is a software engineering blog after all so why even mention a silly game here?  Adapted for computer science, we can convert the game into a programming exercise: Print whole numbers from 1 to 100 but print "Fizz" in place of numbers divisible by 3, print "Buzz" in place of numbers divisible by 5 and print "FizzBuzz" in place of numbers divisible by both.  It's easy to see how this seems like a trivial matter when solved by a computer program, but according to an article written in 2007, "the majority of comp sci graduates can't [write the fizzbuzz program]."

Here is my solution which, by the way, took me 4 minutes and 56 seconds to implement from the time I opened by editor to the time that I was satisfied it was correct.  Obviously, I didn't do a lot of testing but I am still reasonably confident that the code satisfies the fizzbuzz requirements.


This program was by no means difficult to implement.  In fact, I was quite shocked to hear that most computer science graduates struggled writing something to simple.  Just to touch on the code briefly, I should explain the logic behind it just a bit.  Often, when converting a word problem into logic, it is easier to implement the algorithm behind solving the problem by thinking backwards.  The most specific case in this problem seems to be printing FizzBuzz when a number is divisible by both 3 and 5.  Simple arithmetic tells us that a number being divisible by both 3 and 5 means the same thing as a number being divisible by 15, saving us from doing two comparisons instead of one.  Next, it is important to realize that even though a number being divisible by 15 appears to be the most specific scenario, it is actually the most broad because it covers numbers divisible by 15, 5 and 3.  Thus, in order to make sure that, when a number is divisible by 15, we ignore the fact that it is also divisible by 5 and 3, we perform this check first.  The next two checks for divisibility by 5 or 3 can be interchanged and finally, if all checks fail, we know the number must not be divisible by any of the aforementioned numbers.

Personally, this logic struck me immediately, but I too can't claim that I am an expert programmer by a long shot.  When first posed with this questions, I came to the realization that I had quickly forgot how to start off a Java program.  It's almost embarrassing to admit but a couple simple lines of code to start a Java class and the main method in the class had slipped my mind because I had grown somewhat reliant on Eclipse filling in the "trivial" parts for me.  The other mistake that I originally made in my mind was to put everything into one method without considering the need for effective testing, which is now more achievable through JUnit in its current two method form.  Ultimately, the more complex logical parts of any program ought be split off from the main method so that each module can be tested individually.  Fortunately, because the program was so fresh in my mind from having walked through it in my computer science class, I ended up writing this code without running into any issues beyond quick syntax errors.  Unfortunately, for the exact same reason, my variables ended up being named the exact same way both times that I rewrote the program for my own edification and for that display of genuine lack of creativity, I had to frown upon myself.

Friday, August 26, 2011

aTunes - Welcome to the open source music revolution


Sorry iTunes, I borrowed your slogan from 2004, reworded it cleverly to describe a different piece of software and now harbor no intentions on giving it back to you.  On the other hand, an apology might need to be issued to aTunes - recent benefactor of the aforementioned cleverly reworded slogan - as well because I am about to pass judgment on whether you have met the three Prime Directives of open source software engineering.

The Prime Directive, as we all know, is that there can be no interference with the internal affairs, natural development or progression of alien cultures.  Fortunately, I am not a Starfleet Officer and my jurisdiction extends only as far as the three Prime Directives of open source software engineering.  Naturally, in order to determine if aTunes does indeed meet these directives, we must know what the directives are.  Furthermore, to appreciate the existence of any law or rule, it is always a good idea to first gain an insight into why they exist in the first place.

Software exists to aid its users in accomplishing certain tasks with relative ease.  Typically, a software company will have programmers who write software with their code kept hidden deep within their walls.  In other words, a lot of software written is proprietary and the underlying blueprints for how they do what they do are sealed off to the public.  Open source development, however, views software development from a different perspective and embraces the concept of "two heads are better than one" on a much grander scale.  Open source projects allow developers from all walks of life to contribute and often allow collaboration between any numbers of people across long distances, perhaps from around the world.  But ultimately, the projects become software - usually available to the public - and, as with all software, ought to aid its users in accomplishing certain tasks with relative ease.  Additionally, since it is open source after all, it should allow for relatively efficient collaboration between developers as well.  Thus, we have the three Prime Directives of open source software engineering.

Prime Directive #1 - The system successfully accomplishes a useful task.

aTunes performs admirably when accomplishing its primary functions.  As a music player, it does pretty much everything you would expect out of a music player, including the ability to pause, skip tracks, adjust volume, and skip to specific times in the track and even an equalizer is available to appeal to your inner audiophile.  Not only does aTunes provide your average everyday music player’s arsenal of tools, however, it also provides surprisingly useful features as well.  Upon launching the program for the first time, navigating to my music library and playing my first song, I was awestruck when the lyrics to the song I had played instantly came up in the lyrics window of the program.  Although aTunes was merely extracting the lyrics from an online lyrics source and displaying it to me, I nevertheless found myself wondering why I hadn’t seen any other music player do this before now.

There's Lady Gaga on there, but you can't tell

Prime Directive #2: An external user can successfully install and use the system.

aTunes boasts a cross-platform compatibility, and being both a Windows and Mac OSX user myself, it was pleasant surprise to find that it would be possible to test the program on both platforms.  Unfortunately, although the Windows installer was pain-free and straightforward for any Windows user who’s ever downloaded and installed a program on their own before, the same could not be said for Mac OSX.  Although executing both installers was a simple matter of double clicking the .exe file on Windows or the .jar file in OSX, the results were vastly different in my experience.  After the installer finished its automated routines, the Windows installer asked my preference for how I wished to launch the program whereas the OSX installer just closed itself and sneered at me, so to speak.  As it turns out, the OSX installation required further steps that weren’t made known to me until I visited the aTunes Wiki and a brief FAQ section about installation led me to learn that aTunes required an additional download to run and if I was running OSX 10.7, I would be unable to run aTunes completely.  Had I been a Windows user, I would have been inclined to say that Prime Directive number two was fulfilled.  However, because aTunes is designed to be a user friendly client, the installation for the Mac OSX left much to be desired, especially considering the Mac user demographic is largely used to installation being as simple as dragging an icon into their Applications folder.

Prime Directive #3: An external developer can successfully understand and enhance the system.

In order to officially develop for aTunes, a proposal with desired changes or additional features must be submitted for approval.  The aTunes Wiki also has coding guidelines for prospective developers to adhere to, which is not only appropriate but helpful in helping developers be on the same page regarding coding practices.  As for the code itself, almost every method in the code I reviewed appeared to be commented, although not necessarily very thoroughly.  However, the formatting seemed clear and inline comments were injected into the code to help supplement a developer’s understanding of the original coder’s intent.  While there is definitely room for improvement, a savvy developer would probably not have too much trouble understanding the code.

aTunes project page:

aTunes official page:

aTunes Wiki:

Wednesday, August 24, 2011

Blog number 27 and counting (not really)

In regards to the social craze that is blogging I am, so to speak, a seasoned veteran in creating them and promptly abandoning them.  With any luck, being forced by a professor to create and maintain a blog will be precisely the motivation that I needed to keep a blog running for more than a few measly posts.

Raise your glasses, fellow ICS314 patrons, in toasting the birth of yet another blog by yours truly.