Archive for the ‘Programming’ Category

Where’s the balance with programming?

Posted on August 17th, 2007 in Programming | Comments

Well, it’s been week two with my nice little VPS, and it’s working like a charm. I’m loving this system. I’ve been playing around with it, tweaking it to squeeze a bit more out of the limited RAM I have, or just to learn new things I haven’t tried before, like setting up DNS (rather easy) or Sendmail (talk about a pain in the ass). It’s certainly been a blast setting up everything, and that’s probably the geekiest thing anyone could say.

In any case, I’ve been wanting to sit down all week and try to finish my Rails project that I have about 75 completed (although I’ve had so many new and cool ideas, I’m considering starting again from scratch), and I just haven’t been able to do it. The time is seriously lacking with my 8-to-5 job, and it’s frustrating. I want to learn so much, but can’t do much, other than read the latest news and that’s it.

I’m still trying to strike a balance between learning and getting some programming, and doing other things. Right now, I’ve been busy having fun with some of my co-workers, as well as some old friends I hadn’t seen in a while. If I wanted to learn programming, that means killing part - or all - of my social life. While I consider myself an introvert, I still enjoy the company of close friends, and I wouldn’t want to neglect them, as I have before in the past.

So right now, if I want to seriously start learning new things, I’m going to have to either cut ties with some friends and stop hanging out with them frequently, risking that they just ditch me whenever they go out, or just sleep less and code more. I know some people who can function well with just two or three hours of sleep. I’m not one of them. I need at least seven hours of sleep, or else I’ll most likely be moody the next day due to a nasty headache that just won’t quit.

I’m also afraid of getting into the habit of drinking highly-caffeinated drinks. I think I drink a lot more Red Bull than the average person, but I don’t do it every day to avoid creating a dependency on them. It happened once with Mountain Dew (where I drank two every morning before 9:00 AM, and once I stopped, the morning headaches started). It’s scary to think about creating an unhealthy habit, like any drug addict would.

So, how do people do it? I’m really curious. I want to create some study habits that will continue no matter what I want to learn, but I don’t want to sacrifice something that I know I will miss in the future (like my friends or my health). Does anyone have any tips on study habits? Does it cut into time you can spend with friends and family? Do you barely sleep? I hope I can get right on track in the upcoming months, and be the coding-maching I know I can be.

How can I compete against a stubborn boss?

Posted on July 15th, 2007 in Programming | Comments

I’m sure most of us have had that ’special’ kind of boss. You know, those who don’t listen to you, who only think their ideas are the correct ones, who under-estimate your knowledge over their “infinite wisdom”. I’m sure we’ve all had these types of bosses around. Overall, it’s just hell for the employee to be subjected to this type of boss on a daily basis.

I think I can say I have this type of boss. To be fair, though, it’s not a full-time thing. My boss can be fair sometimes, and takes the time to listen to some of the things I say need to be done. Other times… Not so lucky. No matter how much I try to explain myself, I fail miserably at getting my point across his brain. Maybe he’s just over-whelmed by a lot of the daily things he has to do. But I don’t buy that as an excuse. If you’re a higher-up, that brings a lot of responsibility to the table. If you can’t handle all the additional responsibility, either allow someone to do part of your work, or just step down. But that’s another topic for another day.

When I first started working at my current job, as any new guy, I kept my mouth shut during meetings. Since I didn’t know the direction the company wanted to go towards, I couldn’t say anything. I just blindly followed along. However, once I had a clearer idea on what the company wanted, I slowly started to question some of the business decisions. Even though I wasn’t successful most of the time, needless to say, at least I gave my piece of my mind, and that alone helped me feel better.

But then there are times when I just know that a particular business decision isn’t right. It’s either because I know from previous experience that something won’t work, there’s a better way to do it, or simply just a good old-fashioned gut feeling. But it’s something that I know the company shouldn’t do. So I let my boss know. If he agrees with me, then fine. If he doesn’t, at least I get to say “I told you so” in the future if I’m right. Of course, if I’m wrong, I’m just screwed.

Still, the main point of this blog entry is that if you disagree with your boss, tell him/her so. As simple as that. I’m not saying that you should scream at your boss, calling them “idiots” or something worse. But as a professional, you should calmly but firmly give your counter-argument. If your boss thinks rationally, you can find a mid-point where both camps are satisfied. But, if your boss is constantly stubborn, it’s time you pack your bags and find a new job. You’ll never get ahead in these circumstances, and you’ll be miserable for the rest of your life there.

This story stems from something a co-worker told me this past week. She had a meeting with our boss about some new changes to the software. After about three hours talking about things that weren’t directly related to the original question, she left the office. She spoke to me later in the day, telling me about how bad things went. So I asked the simple question: “Did you tell him why that won’t work?”. Her answer? “No, I’ll just do what he tells me, even if it won’t work.”

Of course, this will then unleash the following predictable chain of events:

  • The co-worker will do what the boss told her.
  • The changes will take a very long time, and screw with the non-existant schedule the boss has in his mind.
  • Once the changes are made, it will not work, as the co-worker said.
  • The boss will see it didn’t work, and my co-worker’s ass will be promptly chewed out.
  • My co-worker will say that she knew from the beginning it wouldn’t work, to which my boss will ask why she proceeded to do it, knowing it wouldn’t work.
  • After an unsatisfactory answer, my boss with either fire my co-worker, or give her less responsibility.

Instead of just saying something that took 30 minutes in the initial meeting, months of work were lost, confidence was lost in the employee, and it’s just a bad situation all around the office.

So in short, just stand up to your boss. Of course, not in a mean, foul-mouthed way. Just give your points. Counter his arguments. Even if you have to say that he/she is wrong, do it. If your boss can’t respect that from you, then get the hell out of dodge, or relegate yourself to being a “yes-person” from that point on.

Firebug - The best tool any web developer can have

Posted on July 5th, 2007 in Open Source, Programming, Software | Comments

During these past months, as I’ve been learning Rails and getting my feet more and more wet with all the integrated AJAX goodness that’s inside Rails, I’ve found it increasingly frustrating to debug erroneous AJAX code. With regular web development, most of the times you can plainly see if you have an error in your code. Sometimes the results are incorrect, or some aspect of the page is displayed wrong, and other times there’s a big, fat error page letting you know something is seriously wrong. However, with AJAX, whenever erroneous code is executed, most of the times you get nothing. The page stays the same, nothing changes, except that feeling of doom inside the pit of your stomach. Then it’s time to hit the code again, trying to see if something’s wrong.

Luckily for us, there’s a very awesome tool made to debug these types of errors quickly and efficiently. Firebug is simply a godsend for anyone who works with web development of any kind. It can help you debug your web apps so easily, this is certainly one tool that I don’t know how I lived without these past couple of years. It’s a Firefox extension, so you need the Firebox browser installed to use it, no matter if it’s on Windows, Linux or Mac. But I wonder, why the hell wouldn’t you not have Firefox installed in your computer already? That’s a no-brainer.

Firebug helps you debug HTML, CSS and JavaScript. Since it’s a browser extension, it does all the debugging right in the browser, while you’re executing your page. You don’t need to load any other tool, it’s all at the touch of your fingertips. It can be used with any programming language. I’ve used it while developing in PHP, Python with Django and, of course, Ruby on Rails. Not only can you debug the code, you can even make Firebug do some neat things, like edit the HTML, CSS or Javascript code directly in the browser to see the changes immediately, and it even has a profiler that can tell you where your site is slow.

Oh, I forgot to mention the best part of Firebug: It’s 100% free. You just have to love Open Source projects. It’s still difficult to believe that people out there can put out such a quality and life-saving tool for everyone’s use without asking for a single cent in return. That’s the beauty of Open Source. I don’t know if there are any commercial tools that do what Firebug does, but I wouldn’t trade this tool for anything.

If you’re a web developer, and haven’t heard of this awesome tool, I suggest you click the link I set above for Firebug and get it as soon as possible. Unless you like torturing yourself with debugging the old-fashioned way.

Going to the “Dark Side”

Posted on June 17th, 2007 in Open Source, Programming, Software | Comments

It’s been ages since I last updated this blog. I’ve been pretty busy for the past month or so, ut it’s due to something that I didn’t want to do in the first place. Let me tell you a quick story about it.

Earlier this year, I convinced my boss to rewrite our current (and, admittedly, buggy) software from PHP to Ruby on Rails, which would be better suited for the job at hand. Since the boss wants everything to be done fast, good and cheap, obliterating the Project Triangle, then I thought that Rails would do well. I could complete the rewriting task fast (thanks to Rails and its plugins doing almost anything with ease), good (thanks to me starting to love Test-Driven Development) and cheap (less time coding and fixing bugs = more time to implement new features). It seemed like a good fit, and he agreed.

However, a few months later, he hired someone to help me with the programming and database tasks. I desperately needed help, so I agreed to this. The person he hired, a young woman with a Masters Degree in Computer Science who teaches at a local community college, then proceeded to evaluate the current system. After proposing various changes, the boss decided that since so much work needed to be done, he might as well profit out of it, so he wanted to have the program rewritten not only for our internal use, but for commercializing the program as well. His language of choice, due to recommendations from the new employee? Visual Basic.NET. Ugh.

I pleaded with him to reconsider, but his mind was set. He wanted to transfer a PHP web application into a Windows-only desktop app. And his understanding was that since Visual Basic.NET has a nice little form designer, it would be much faster to rewrite the program. I countered these points, but he didn’t want to listen to it. He wanted a Windows application he could sell, and the only programming language the other employee knew enough was Visual Basic.NET (yep, even with a Masters Degree in Computer Science, that was her strong point). I was, simply put, screwed.

I have absolutely nothing against Microsoft tools. In fact, I think they’re great. I even suggested using C# instead, as it would be a more robust platform to do this type of project. It’s simply that I think Visual Basic is something that I used in college to learn the ropes of programming, and nothing more. I ditched Visual Basic the first chance I got, immediately after I graduated from college. I hadn’t used Visual Basic for anything since late 2004. I was surely going to need some time to get up to speed in mid-2007. It’s been a while, but I’ve gotten to a point where I can program once more using this language, even if I don’t want to.

However, from my last conversations with my boss, it seems that he doesn’t want me to program much, since I had told him I was way too rusty with Visual Basic. He seems to want me to manage the entire project. I accepted, as it’s more of a challenge than to sit down and develop an application with a programming language I simply wouldn’t use if it were my project.

So, for the past couple of weeks, I’ve been getting my head into .NET programming. While I still am against choosing Visual Basic.NET as the programming language of a rather large software development project, I’ve been entertained with some things that I hadn’t used in a large-scale project with PHP. I’ve learned a lot about Continuous Integration for the automatic build and testing process. I’ve learned how to use NAnt enough to build and test my projects automatically. I’ve even learned the finer points of creating installers that will work on all systems, no matter the dependencies needed. It’s been a change of pace for me, but I’m making the best of it.

Still, I’m very disappointed in my job and this decision that was taken. My heart is with open-source and web-development projects. Sadly, I need to do that on my own time now, but most of my spare time is used learning these new tools I need for .NET development. I’m still looking for work outside of Puerto Rico (I’m 0 for 2 with companies that have contacted me after sending in my resume), so hopefully this changes soon. In any case, I’m making the best out of this situation, and at least I’m learning new things once again. But one day, I can achieve my dream and be part of a team where I know my heart is.

San Francisco, here I come… Hopefully!

Posted on April 28th, 2007 in Open Source, Programming | Comments

Before starting this post, I want to thank whoever posted my previous post about using the Digg API with Ruby and Rails to dzone. It recently made their front page, and a good amount of traffic headed this way. I hope someone found a good use on that small beginner tutorial.

Anyway, after working a while on this blog and my main site, I would like to tell the story on why this site is here today. I decided to take a look at some Rails hosting, as I wanted to start learning and actively using Ruby on Rails, so I got this small website to just experiment with different things. I had never gotten any type of web hosting before (well, outside my awful Geocities pages back in 1998 while learning HTML with Frontpage, but I hope those remain buried forever), so it was nice to finally have my own little space on the web, with a nice-sounding domain name.

However, after a while, what else was I going to do with this web space? So, I decided to start a blog, and use the main site as a way to post my resumé, my work and what I do for a living. Granted, I still don’t have too much stuff going, but that’s something I hope to change in the coming months. But the real reason of this site’s existance? I want to move to San Francisco and get a job over there.

Don’t get me wrong. I love Puerto Rico, and all of my family and friends are here, who I’ll certainly miss a lot if I leave. However, I find my chances of career advancement very limited here. The entire programming landscape, like most everywhere, is dominated by Microsoft products. And at this moment in time, I have no interest in learning .NET, C# or any other Microsoft-based language. I’m not anti-Microsoft at all, but I think my time will be better spent with what really interests me at this time, which is virtually all about open-source.

That’s the biggest difference between Puerto Rico and the United States, particularly San Francisco. There’s just many, many more opportunities for me to work with Linux, Ruby, Rails and any other open-source software available. Every time I search for job openings here in Puerto Rico, it’s pretty much all the same: System Administrators need people with MSCE certifications to work with Windows 2000/2003, or web developers who need to know ASP.NET. I’ve never seen an opening that needs someone who knows how to work with Red Hat Enterprise Linux servers, or web developers who know Rails, Django or any other open-source programming language.

Searching in different websites and job boards, it seems that California has many jobs that fit my interests. And while I’m still a relative ‘newbie’ in many programming languages, I know that if I find work in something that I would totally do for free if given the chance, I would give the proverbial 110% to that job, instead of viewing it as simply a paycheck. While I’m currently a bit happier at work due to what I’m doing now, I’ve been down that road at my current job, and it’s not really a good feeling to just go to work simply to pay the bills. I want to accomplish something. I know I won’t do that here, at least at the moment. I want to go somewhere and be part of a team that does something great.

I’ve been planning most of this year on what I need to do. I really don’t need to worry about family, as they’re all very supportive of me, and with no girlfriend or spouse, nothing is really tying me down here. I’m just saving money to be able to go later this year, hopefully before my 27th birthday this November. If all goes well, I’ll be a San Francisco resident by the time in 2008.

I’ve done a lot of research about the city and the Bay Area in particular. I’ve seen a lot of job openings, and I imagine it’s very competitive to land a good job there. But the thing that’s really holding me back now is that it’s expensive. I mean, at my current apartment, I’m paying a mere $200 per month; The cheapest one-room apartments over there are at least $750. So that’s a pretty scary thought, going over there without a job will be tough. I guess I’ll have to get used to Ramen noodles. I hope they’re as cheap as they are here!

So, any recommendations? I really hope someone from the Bay Area gets to read this and can leave a comment to set the record straight as to how life is over there, especially as far as job openings and the cost of life is. And if by any small chance you’re an employer (or are close to one), feel free to browse my resumé. I’m completely available to move to the Bay Area is needed. Hopefully this blog leads to the change I need for my career.

Digg API with Ruby (and Rails too!)

Posted on April 25th, 2007 in Programming, Ruby, Ruby On Rails, Software, Web Development | Comments

Note: This site has changed a lot over the last year. I’m not using Rails anymore on the site, so there’s no place where I’m currently using the Digg API. However, I’ll leave this post intact, as it might help others with something similar.

If any of you readers have come in through my main site lately, you should notice that I added a little something on the sidebar. One of my favorite time-wasting activities of the day is browsing Digg. I tell you, there should be some sort of “Diggers Anonymous” for us simple-minded folk who can’t stop from visiting the site for stories many times a day!

Anyway, they recently announced the release of the Digg API, to allow any user to access the stories on the site in any way, shape or form we desire. Now, I must say that I have no real use for this. Of course, being the geek I am, I just wanted to try it out and see how I could use a simple API using Ruby, for use on my Rails site (this one). This is also made in case anyone else wants to do the same. One note, however: I’m only a Ruby / Rails beginner. I’m sure there are much better and efficient ways to do this. Since I haven’t dabbled in this too much, and “it works on my machine“, I’ll leave it as it is for now.

Just for the record, the testing and development for this code was made on my computer running Ubuntu 7.04, along with Ruby 1.8.6 (compiled by myself, not downloaded from the Ubuntu repos), RubyGems 0.9.2 and Rails 1.2.3. It should work correctly with any fairly recent version of the software mentioned above.

The Digg API is rather simplistic right now. All you need is a simple request using a URL like this:

http://services.digg.com/stories?appkey=http%3A%2F%2Fdennmart.com&type=xml&count=5

In the example above, the API is called to the ‘http://services.digg.com’ server. The parameters afterwards (in this case, ‘/stories‘) is the request. You can add more parameters for a finer-grained search.

Once the request URL is complete, you need some additional actions to add as well. The ‘appkey‘ is required, but can be anything for now. Digg isn’t generating application keys (a la eBay or other external API’s), but an appkey is required for ’statistical purposes’, according to the documentation. The ‘type‘ is how the data is going to be returned to the app, and it can be either XML, Javascript, JSON or PHP. I use good ol’ XML for now, until I can actually play around further with the other response types. Finally, the ‘count’ action is to limit how many stories are returned. I’m only going over these options quickly, as the API documentation has much more information.

Once you figure out which request you want to make (using Mozilla Firefox can help greatly, as the XML response is nicely formatted), it’s a matter of getting that data into your Ruby or Rails app. Going back to the ol’ trusty Pickaxe book, I found a nice little module integrated in Ruby called open-uri. This module allows the Ruby application to open a URL (either http, https or ftp) and get the returned contents. To use this module, a simple line of code is needed:

require 'open-uri'

That should load your module correctly. Now it’s just a matter of having Ruby open the API connection and store its XML response in a variable:

response = open('http://services.digg.com/stories/popular?appkey=http%3A%2F%2Fdennmart.com&type=xml&count=5').read

The ‘open‘ function, well, opens the connection to the API, while the ‘read‘ method gets the data that’s returned from the URL. Like I said, rather simple.

However, I was getting timeout errors when calling the ‘open’ function. Strangely enough, the function worked fine when using any other URL. Upon further reading of the API documentation, I found this little tidbit:

“All API requests must include a User-Agent HTTP Header. A request without this header will receive no response.”

So, after that small mistake, I edited the request like so:

response = open('http://services.digg.com/stories/popular?appkey=http%3A%2F%2Fdennmart.com&type=xml&count=5', 'User-Agent' => 'Ruby/1.8.6').read

The ‘User-Agent‘ parameter can be anything. I just decided to use the Ruby version I have. Once I added that, I had my nice XML with the five most recent Digg stories that have been promoted to the front page.

After that, I needed to parse that XML. I searched around the Internet, and found a great little module called ‘XmlSimple‘. This module reads and writes XML, and formats it according to whatever’s needed. In my case, I needed to read the XML response. Just like the ‘open-url’ module previously, you need to load the ‘XmlSimple’ module as well, once installed (”gem install xml-simple“):

require 'xmlsimple'

I did run into some minor problems when loading this module. The Ruby interpreter cried out loud, saying it couldn’t load the module. How come? I verified that the gem was installed correctly, and it was. Then I realized that since this is a gem, I need to have ‘RubyGems‘ loaded before loading ‘xmlsimple’:

require 'rubygems'

I believe that Rails already loads the module for you. But if you’re testing this out on Ruby and not on Rails, you’ll need it.

Okay, once I did that, I was able to load the ‘xmlsimple’ module. Now I need it to parse the XML response that I stored in the aptly-named ‘response‘ variable. A simple line of code can convert the XML into a hash:

XmlSimple.xml_in(response)

That takes the entire XML string and puts it into a neatly organized hash. I really don’t need everything in the hash, just the story title, link and how many diggs the story has. So I just access those particular keys:

digg_hash = XmlSimple.xml_in(response)
story_title = digg_hash['story'][0]['title']
story_link = digg_hash['story'][0]['link']
story_diggs = digg_hash['story'][0]['diggs']

In the example above, the ‘story_title‘ variable has the most recent story title, the ‘story_link‘ is the link that takes you directly to the story, and the ‘story_diggs‘ has the current amount of diggs that story has. The number zero used in the array is the story number. If you want to get more than one, you’ll need to loop through the array and get the other stories.

The code I’m using on the main site right now is the following:

<%
  require 'open-uri'
  require 'rubygems'
  require 'xmlsimple'

  response = open('http://services.digg.com/stories/popular?appkey=http%3A%2F%2Fdennmart.com&type=xml&count=5', 'User-Agent' => 'Ruby/1.8.6').read
  articles = 0
  while articles < 5
%>

(Dugg <%= XmlSimple.xml_in(response)['story'][articles]['diggs'] %> times)
<% articles += 1 end %>

In all, this was rather simple, and I’m sure there will be a much more creative use for the Digg API soon. But for those who want to learn how to use it, or those who need a very simple approach, this works just fine. I’m interested in listening on how other people have put this to use. Hope this helps someone!

Rails Screencasts = The best learning tool on the Internet

Posted on April 16th, 2007 in Programming, Ruby On Rails | Comments

Well, it’s been a while since I last posted. Maybe it was due to the fact that I received so many damn spam comments that Akismet seemingly didn’t block. I’ll look into that when I have some free time to check it out. For now, I’ll just give a quick post on what’s on my mind.

Even though I haven’t been posting on this blog, it doesn’t mean I haven’t been occupied with my Rails learnings. I just discovered the wonderful new world of screencasts as a learning tool. If you don’t know what a screencast is, it’s basically a video tutorial. Instead of reading something off the Internet, where the instructions aren’t always crystal clear, a screencast shows you what to do, and how it’s supposed to work. I’ve found them to be an invaluable tool in my quest for Rails wisdom.

There are a couple of sites that offer Rails screencasts exclusively. The first site is Railscasts. This site is frequently updated with short screencasts about various Rails topics. I’ve noticed these videos are truly great for beginners, as most of the topics covered so far seem geared more towards people without much Rails experience. Even though the videos are normally short (about five minutes in length, maybe less, as an average), they’re packed with useful information that’ll help any beginner get a better grasp at certain Rails topics.

The other site I’ve visited is Peepcode. These people make high-quality and full-length screencasts (over an hour long!) for the low price of $9.00 for each video. Many may think “But why pay for screencasts that can be freely accessible from the other site?” There’s a very large distinction between the screencasts from both sites. While length is obviously the main factor, the material shown on Peepcode screencasts is much more extensive and covers absolutely all the bases. Many of the screencasts that are currently available for purchase on Peepcode are geared to more advanced users, though. But in all honesty, $9.00 is a very small price to pay, given what you learn.

So if you’re trying to learn Rails like myself, I’d suggest you head over to one of these site pronto. You’ll be amazed at the great work that’s put out on the Internet for the sake of teaching others. That’s the beauty of the Internet.

Unfuddle Your Project!

Posted on March 11th, 2007 in Programming | Comments

I set up a small server using some spare parts at my apartment, which I leave up and running 24/7. I connect to that server via the small router I have (only opening the ports I want to have open, obviously) whenever I’m not home, using a dynamic IP service. This server is mainly used as my Subversion repository, with all the projects I’m working on. Unfortunately, this isn’t working too well, as blackouts, Internet outages and even system lock-ups (hey, I said the server was made using spare parts) at my apartment render it useless. It happened to me this weekend, when I was away from my apartment, so I couldn’t work with anything I had planned.

So I searched around, and found the most excellent service that I needed, called Unfuddle. Unfuddle is a site that offers source control services, along with bug tracking, for free for simple, private projects (or a minimal fee for larger projects). I created an account yesterday, and I just arrived at my apartment, so I immediately transferred my source code to the Unfuddle servers. I played around with the service for a while, and I have to say, this is really a great solution for those in need of source control in a remote server.

The simplicity of the service is really the nicest touch, in my opinion. It’s really easy to navigate around the system and work with your project. Looking through your source code in the repository (using Subversion) is a breeze, and adding issues to the bug tracker, or any other message is just as easy. Seriously, it’s a great tool for all those software developers out there who need a place to have their code handy, ready to work with, anywhere you are.

The higher fees are for largers groups with different projects and many users, along with added security features. If I were working with a group, I would totally pay up for one of these services. If it works great for a lone individual like me, this has to be excellent for groups of two or more. So you should take a look at this service, as it’s a good one. I have nothing bad to say about Unfuddle for the time being. Hopefully it’ll help you too.

Yet another FizzBuzz post

Posted on March 10th, 2007 in Programming | Comments

A couple of weeks ago, CodingHorror (an awesome and wildly popular blog) wrote about the fact that programmers can’t program. Like I mentioned in my previous post, this can’t be any more true. But in reality, I think this is more of an issue with people over-analyzing the problem at hand.

In today’s world, things tend to get really complicated. Programming is no different. In my current project, I’m already reached a point where I would like to tell my boss “No more code - Fix this junk and forget about the users until it’s fixed.” Admittedly, most of that junk has been done by me. But I’ve been campaigning to stop development for a while and fix the current problems without adding any new features.

But this isn’t the story I wanted to give today. As far as the “FizzBuzz” phenomena goes, I think most of those people who couldn’t solve that problem were most likely over-analyzing the problem. Of course, there had to be people who honestly didn’t have any earthly idea on how to code the solution. But for the rest, maybe thinking of a solution that was too flashy could’ve been the problem.

Like many others, as specified in a follow-up post, I immediately fired up the text editor, and coded the solution in Ruby (which I was studying at the time I read the original post) in about 10 lines of code, thinking “Wow, that was easy.” And seriously, it is, if you take the KISS route (that’s “Keep It Simple, Stupid”, for those who don’t know) as I did. Just a simple if-else condition, along with the trusty mod operator, it was easy.

I can only imagine many thinking about putting the FizzBuzz code in a separate class, complete with iterators, inside neat and well-designed blocks of code, ready for Object-Oriented goodness. Why? This is simply overkill. Unfortunately, many developers think that way. It’s possibly our nature, just as it was in our nature to try to solve the FizzBuzz problem.

Sometimes, keeping things simple is just what we need in a crazy world like this.

Learn to write code for my sanity

Posted on March 5th, 2007 in Computer Science, Programming | Comments

I’m currently at work, and I seriously needed a break, which is why I’m here, writing something for my blog. Why? It’s a long story, but I’ll keep it short.

My boss decided to start using part of our program that hasn’t been modified since 2004, and last used in early 2005. Of course, with all the changes we’ve done, lots of bugs started cropping up, so he put that on my lap. The problem is, I didn’t make this part of the program. Someone else who worked here until early 2005 worked completely on that module. Now that person is long gone, and I’m stuck with his code.

“No biggie”, I thought. “This shouldn’t be too difficult to modify for what the boss wants now.” Then I opened the file… It was a total mess.

I mean, I had seen messy code, a lot from myself. But this was messy. And if I have to bold and italicize a word, it’s because I really mean it. This was the worst code I have ever seen written by any developer ever. I know that PHP has a reputation for producing some awful code, but this really took the cake.

We start off with lots of Dreamweaver generated code at the beginning (some Javascript code that apparently doesn’t do anything in the application). Then we head off towards the land of unknown variables: $dbQuery1, $dbQuery2, $dbQuery3, and my personal fave, $c. Also, there was virtually no indentation all around, and the indentation that did exist was very poorly done (some if-else blocks were completely on the left margin of the code). Add up that there were exactly two comments consisting of only one word throughout the 600 lines of code, and you have a developer with a huge headache, trying to figure out what the damn thing does. And while it kinda works, now I’m faced with the dilemma of trying to add new functionality to the module while not breaking anything.

The worst part of it all is that I showed the code to one of the technicians here who actually studied in the same web-development class as the previous developer, and he told me “That’s how he’s always programmed.” So I asked what the teacher did with that code, and he told me “The teacher probably writes worse code than that.” What? A college professor writing worse code than that?

I can’t believe that Computer Science professors aren’t enforcing their students to learn how to write clean and maintainable code. And I don’t think this is an isolated incident, because at my university, the professors didn’t enforce this either. And while we were taught to use indentation correctly, informative variable names and all that, they never said anything if we didn’t follow those simple steps.

If I were a college professor giving a programming class, I would enforce those rules, probably almost harshly. If I see generic variable names (like the ones I mentioned above), I’ll dock one or two points from the final grade. If indentation isn’t used correctly, another one or two points disappear. And if the code is as unreadable as the code I’m working on now, I’ll probably fail the student, or at least give him one more day to fix that code before giving it back to me.

I’m curious to know if anyone else has seen this at college, or if it’s just another Puerto Rican incident.