Archive for the ‘Programming’ Category

Quick and Dirty Browser Cookie Testing

Posted on September 30th, 2008 in Programming, Ruby On Rails, Web Development | 1 Comment »

On a recent Rails project, I was asked to verify if the visiting user’s browser has cookies enabled, and display a message on top of the screen if they don’t. While I don’t want to get into the reasoning why, or get into a flame war whether the site should still be accessible regardless if the user’s browser has cookies, I still needed to implement it.

Since it’s a Rails project, I thought of checking if the session cookie that Rails sets in the Application controller was set. But Rails sets the session after the view is rendered the first time (I have a more detailed explanation somewhere but don’t have it with me, so maybe next time). This means the first time the user visits the site, it will incorrectly display the warning message. Subsequent views will test correctly, but this obviously won’t work.

So I decided to implement a redirect, thanks to ideas given by this blog post. It worked, but it left me with a parameter in my URL the first time the user visited the site. It didn’t seem clean, and the higher-ups didn’t like it either, so off it went.

Then I was given the idea to check it via JavaScript, and with some slight tinkering I think I got what I wanted:


Basically this uses JavaScript to set the cookie when the page is rendering and immediately checks for its availability using a regular expression. If it’s found, then the user has cookies enabled and we can safely delete the test cookie (provided the user has their system clock set after January 1, 2001). If the cookie isn’t set, that means the user doesn’t have cookies enabled in their browser, so we display the ‘cookies_disabled’ element with our message inside.

This function is called in our application layout, between the <head> tags, meaning it’s called for every single page that renders the default layout. I haven’t observed any type of performance issue this might have, but I might have missed something along the way. And there’s probably a better, more efficient way to handle this as well, so if you have any suggestions, feel free to dtop a comment and let me know.

That’s Why There Are Choices, People

Posted on September 18th, 2008 in Opinion, Programming | No Comments »

I was having a quick tech discussion the other day on a non-tech message board I visit on a daily basis. I had mentioned how frustrating it is to have to spend hours developing for good ol’ obsolete Internet Explorer 6.0, and why people are so damn lazy to upgrade. There are countless reasons why people don’t upgrade, which I won’t go into now to avoid a long, long rant on why I think these people should be stripped from their computing privileges. But I was talking about the recent developments in web browsers, in particular how Firefox 3.1 is going to be much faster, or how Internet Explorer 8.0 is promising to play better with web standards, I received this delightful comment from one of the few techies (and one of the few females) in that forum:

He can shove Firefox 3 where the sun doesn’t shine, and if he suggests Internet Explorer 8 in person I will be forced to cram his balls up over his head whilst they are still attached to him.

Just lovely. And I hadn’t even suggested that people upgrade!

The particular reasons she gave me as to why she made this statement are irrelevant to the discussion (“Firefox 3 doesn’t support all my add-ons yet and Internet Explorer lost me a long, long time ago.”), but something slightly ticked me off about this brash statement.

Every single person on this planet has an opinion to express, for whatever reason. People involved in computers aren’t excluded. I’d say we absolutely love expressing our opinions about a myriad of things, leading to sometimes heated (and entertaining) discussions: Windows vs. Linux vs. Mac, Ruby vs. Python, vi vs. emacs… No matter what you say, there will always be someone to express the opposite.

I learned a long time ago to avoid these discussions altogether. Why? It’s not because I’m a poor debater and fear I’m going to lose (which is most likely true). It’s because no one in this world will ever be pleased. That’s why there are choices in this world. To put it as simple as possible, someone wasn’t content with something, so they made another thing. And they’re happy with it.

So if I’m happy with Ruby and Rails, and you’re extremely happy with Python and Django, then I respect your opinion, sir. Just don’t come down on me and run down a zillion reasons why Ruby or Rails suck (which are probably variants of “Rails Can’t Scale“). Be happy with what you have, I’ll be happy with what I have, and we can co-exist nicely in this vast software development universe.

Envy Casts - The New Hotness?

Posted on September 16th, 2008 in Opinion, Programming, Ruby On Rails | 2 Comments »

Last night I was in the mood to just review some of the stuff I already work with on a daily basis. I’ve been reading up on a lot of new stuff that I’m dying to play with, so a quick review of familiar concepts would be a welcome change of pace. Plus, it always seems I’m learning new stuff whenever I go back to an old concept. So I was searching around to see what I could get. I’ve already exhausted most of my Ruby and Rails books, gotten most of what interests me on PeepCode, and seen virtually every single episode of Railscasts, so I wanted to see something different.

That’s when I remembered that the guys from Rails Envy started producing their own screencasts, originally dubbed Envy Casts. As you can see with what I wrote above, and what I’ve written previously, I absolutely love screencasts. And since I’m an avid listener of the Rails Envy Podcast, I thought I would give these guys a try.

So after viewing the screencast on my way to work today, I have to say that Gregg Pollack and Jason Seifer have a good thing in their hands. Their screencasts are totally different from everyone else’s, which is immediately apparent. Instead of just a voiceover of how something is done, they actually have the guys (mostly Gregg) in front of a green screen. While it would virtually be the same if they went the regular screencast route, this adds some sort of personal touch.

Of course, the guys inject their humor as usual (with Jason usually appearing on screen for comedic purposes and nothing else). It even has quick educational breaks, with Gregg posing as a doctor to give us lessons on how our brains work. It has absolutely nothing to do with Ruby, Rails, Active Record, or anything related to software development, but as I mentioned, it provides quick breaks between topics.

So far, they only have one screencast covering Active Record. But I’m definitely looking forward to subsequent screencasts, as long as they’re as good as this first one. Perhaps we have the new hotness of the screencast world in our grasp.

Hoptoad - Rails Exception Catching Made Easy

Posted on August 27th, 2008 in Programming, Ruby On Rails, Services | 1 Comment »

Have you ever installed the Exception Notification plugin in one of your Rails apps, just to get bombarded with E-Mails of the same error over and over again? It’s happened to the best of us.

Thankfully, people in the Rails community have been working on different solutions to handle this. One I discovered recently, which I’m really loving a lot, is Hoptoad, brought to you by the awesome people over at thoughtbot. Really, how can you not be an awesome group when your blog is titled Giant Robots Smashing Into Other Giant Robots?

Anyway, Hoptoad is a service which captures all exceptions that occur in your Rails application, and aggregates them into one place. This way, if you have, for example, a link to AJAX functionality that causes a 500 error, you’ll only get one E-Mail notifying you about the error. The service will actually log the times it’s happened, though. It also provides a full stack trace, session information, parameters that were passed, and just about everything else you need to make a full assessment on why your application failed. Oh, and one more important thing: it’s totally free. Can’t beat the price.

It’s as simple as creating a new account and setting up a project, installing their plugin on your application, putting the assigned API key in an initializer file, and that’s it! It took me about 2 minutes to set everything up the first time. The interface is pretty straight-forward. When you first log in, it will show if any of your projects has any errors (which any developer can mark as ‘Resolved’ so it won’t show again). If there are (and face it, we all get errors at one point or another), then as I mentioned previously, you can view the stack trace to see what happened. Nice, simple and helpful.

I’ve noticed there are some other sites that offer these services (like Exceptional), but none that seem to have the simplicity of Hoptoad. Not that I think the other services are bad, but it’s just not what I want at this moment. In my particular case, I really don’t need to have an app that integrates with other services, let’s me leave comments about an error, or see how many times in the past week the error occurred. I just want to know if my app is getting errors. Hoptoad does just that.

I fully recommend Hoptoad for any Rails app. If you don’t have any sort of exception notifier in your app, you should get something now. If you do, then I hope you never have to constantly use it!

That Was Easy - Upgrading From Rails 1.2 to Rails 2.0

Posted on July 31st, 2008 in Programming, Ruby, Ruby On Rails | 1 Comment »

It’s been an interesting week for me. I got a first-hand taste on upgrading a Rails 1.2.x application to Rails 2.0. To be honest, I was terrified when this task was presented upon me. I had never done this before, since virtually all the Rails 2.0 (and 2.1) apps I’ve worked with have started with that particular version, not an upgrade. Seeing that the application in question had been under development for a long time (hence still using Rails 1.2), I immediately though that an upgrade to Rails 2.0 would cause the app to break so bad, I would be having “NoMethodError” messages in my nightmares for a long time to time.

So with the thought of a long week of fixing trivial changes to make the application work correctly once again, I removed the frozen Rails 1.2 directory from the application and froze Rails 2.0 in its place. I started Mongrel, and… It worked. Like it really worked. Well, not 100%, but most of the application worked as it was before! I definitely couldn’t believe it. That was probably the easiest framework upgrade I’ve done in my entire life. Most of it had to do because of me doing a lot of refactoring for code that I had knew would be removed from the framework soon, but also kudos to the Rails Core team for making this pretty straightforward.

Like I said, it didn’t go 100% smoothly, so I thought I’d share some of the gotchas I encountered during the upgrade.

‘extract_options_from_args!’ method

The extract_options_from_args! method was apparently removed in Rails 2.0. Upon further inspection, there were many plugins using this method, but only one (nested_has_many_though) wasn’t properly handling it. All I had to do was update that particular plugin, and the error disappeared from the entire application. So my recommendation is to upgrade any currently existing plugins you have, although this is more tricky if you have old plugins that aren’t being currently maintained.

‘You are being redirected’ problem

In some places of the application, when an action used ‘redirect_to’ to send me somewhere else, a page would appear, simply saying ‘You are being redirected‘, with a link to where the app should’ve been redirected. The problem: there was a parameter named ’status’ that was used for the redirect. Changing the parameter name to ’state’ solved the problem. I’m guessing it’s because Rails uses the word ’status’ to set the HTTP code for a redirect, so it caused this hiccup.

‘Called id for nil’ error

I was also getting errors for nil variables where they didn’t exist before. The problem here was caused because some ‘form_for’ tags were using variables that weren’t initialized previously in the controller. Taking for example the following code: <% form_for @item, :url =>items_path do |f| %>. The instance variable ‘@item’ wasn’t declared in the controller (or the view, although if someone did that, I would hunt them down), yet in Rails 1.2 it would work properly. It was just a matter of adding @item = Item.new in the controller for the action, and it would work fine again. I guess this was just done to make sure things are coded correctly, which I really don’t mind.

Route Globbing and escaped slashes in URL

This one was an interesting one. Part of the application uses route globbing, where you can set a route to grab everything in a URL and set an array. The application in question was using this in one part of the application, to get a collection of IDs and process them for some other functionality. However, this was being done via a link generated using ‘link_to’, which promptly went to escape the slashes between the IDs (from ‘/’ to ‘%2F’, which the browser read well, but Rails 2.0 apparently doesn’t like), and the route globbing wouldn’t return the array as expected. For example, previously in Rails 1.2, if the URL ended like items/process/101/105/110, the route globbing would return an array of three elements: ["101", "105", "110"], which is what the app expected. In Rails 2.0, since the slashes were escaped thanks to ‘link_to’, it would return an array of one single element: ["101/105/110"]. This problem was already reported and seems like it’ll be fixed in Rails 2.1.1. But in the meantime I did a quick fix: take the element in the array and split it using Ruby’s split method to create the array as it should be before processing.

Besides these errors, the rest went smoothly. The app has been running for two days under moderate testing, and nothing else appears to be broken. So it all went well. Hope this post helps someone get through some problem upgrading their old, creaky Rails app.

Fix my mistakes. Just don’t do it yourself.

Posted on April 3rd, 2008 in Programming | 3 Comments »

When I arrived at my current job, most of the functionality from the Rails application I’m working on was already done by developers before me. There were still some loose ends to tighten, but almost everything was ‘working’. I say ‘working’ in between single quotes, because while the application was certainly working, it really only worked if everything was done in a seemingly exact pattern. Do something different from the pattern, and something will break. Like “Click here and fill in this, in this exact order, and put your cursor there, or the app will give an error.

I understand why this was done this way. I usually code this way too: after deciding what I’m going to do, I whip up a very crude version of what I want to do, then I take care of some loose ends that could be made better. But there are some things I do along the way to avoid having too many loose ends when I finish writing my basic functionality.

Most of us have heard the phrase “premature optimization is the root of all evil” by Donald Knuth. While this is true, I believe that we should think from the beginning about optimization before writing code. Your algorithm or pseudocode should be as optimized as possible from the start to avoid these things. If you think through your problem well enough, too much optimization won’t be needed.

With web development and frameworks such as Ruby On Rails, it’s easy to forget these things. A lot of the times people just sit in front of their computers and code away, hacking up whatever’s on their mind without thinking it through. I admit I’ve been guilty of this behavior before. But with age comes experience, and I’ve learned a lot since then.

Anyway, back to my current code. Apparently the developers working on it before just sat down and wrote a lot of code without thinking about such basic things, like error-handling. It’s not like they didn’t have time to do it. My workplace isn’t a stressful place, my bosses are way nice, and while we do have deadlines, it’s not like we have someone on our backs constantly nagging that we have impending deadlines. Since those original developers don’t work here anymore, I can’t ask them why they coded like this, so I have to just deal with it the best that I can.

I created a document in our company’s Wiki with some coding tips that came off the top of my mind, so that hopefully any new hires can read it and follow them. Even if they know these things, it should serve as a reminder to follow these basic guidelines. By no means it’s a complete document, but these are the most common mistakes I’ve encountered.


Always handle errors gracefully

Try to never show the user an error page. If something went wrong, show a message letting the user know what went wrong, preferibly a `flash[:notice]` or `flash[:error]` message, which will appear at the top of the page, and send them somewhere where they can either try again or get more information.

Bad Example (If the item for some reason doesn’t exist, or a curious user changes the ID in the URL, it will show an not-so-helpful error page):

def offer_for_want
  @have_item = HaveItem.find(params[:id])
end

Good Example:

def offer_for_want
  begin
    @have_item = HaveItem.find(params[:id])
  rescue ActiveRecord::RecordNotFound
    flash[:error] = "Some error"
    redirect_to :somewhere
  end
end

Use descriptive variables

Although using shorter variables keeps the functionality the same as using longer variable names, using descriptive variable names and conventions will help other developers understand how an action or function works more easily. Also, using normal Ruby and Rails variable naming conventions helps others get up to speed on the scope of the variable.

Bad Example (Notice the use of two- and three-letter variables, which are not descriptive to a developer who’s just working on this portion of the code):

def update_relationship(hi, wi, opt, modify_opt = nil)
  _have_want = {}
  _have_want['HaveId'] = hi
  _have_want['WantId'] = wi
  _have_want['Delete_add'] = opt
  [...]
end

Good Example:

def update_relationship(have_item, want_item, update_type, modify_option = nil)
  have_want_hash = {}
  have_want_hash['HaveId'] = have_item
  have_want_hash['WantId'] = want_item
  have_want_hash['Delete_add'] = update_type
  [...]
end

Comment your code!

All controller actions and model functions should be commented before the action or function, giving a brief description on how it works. Also, if the code is not self-explanatory or is done in a non-conventional way, a brief explanation should be included as well to let other developers know why the code was written that way, or how it works. This will also be useful for generating code documentation with RDoc

Bad Example (No comments anywhere):

def rate( _user )
  @current_user = _user

  transaction do
    user_tv = view_for(_user)
    user_tv.next_step = View::CF[:next_step][:nothing]
    user_tv.status_for_user = View::CF[:status_for_user][:nothing]
    user_tv.rated = true
    user_tv.save!
    self.rate!
    self.reload
    return ended?
  end
end

Good Example:

# Action to rate a user after an action has been accepted, completed and shipped.
# Only the people involved in the action are permitted to rate each other.
def rate(_user)
  @current_user = _user
  # Reloading the object attributes from the database, in case something was changed during the rating process.
  self.reload

  transaction do
    user_tv = view_for(_user)
    # Sets the next step of the action to 'nothing' for both users involved,
    # indicating that the entire process is complete.
    user_tv.next_step = View::CF[:next_step][:nothing]
    user_tv.status_for_user = View::CF[:status_for_user][:nothing]
    # Set a flag to mark the user's action as rated, so that multiple feedback can't be given
    user_tv.rated = true
    user_tv.save!
    self.rate!
    self.reload
    return ended?
  end
end

Properly substitute variables from MySQL queries for security purposes

Any query to the database where the user can enter the parameters (for example, a user enters terms in a search field) can potentially allow a malicious user to run a harmful query against the database, like dropping tables. These user-entered parameters need to be protected from these types of problems.

Bad Example (In this example, a user can enter something like ; DROP TABLE users as their search parameters, deleting the users table):

@item = HaveItem.find(:all, :conditions => "title = #{params[:search]}")

Good Examples (All of these samples do the same thing, except Rails sanitizes the parameters to make sure no arbitrary SQL code is run):

@item = HaveItem.find_by_title(params[:search])
@item = HaveItem.find(:all, :conditions => [:title => params[:search]])
@item = HaveItem.find(:all, :conditions => ["title = ?", params[:search]])

Sanitize any user input before rendering it in the view

Anything the user enters should be treated as potentially hazardous. Any unsanitized output can be vulnerable to Cross-Site Scripting. Any fields in the view that show information entered by a user should be sanitized. It’s as simple as adding the h function before the string.

Bad Example (Anything the user enters in the database, when shown later in a view, can execute arbitrary code):

<%= @item.description %>

Good Example:

<%= h @item.description %>

Keep presentation and business logic separate

Thanks to the MVC paradigm, Rails makes it easy for any new developer to get find presentation code or business logic, but only if they’re stored in the correct places. Any business logic (such as declaring variables, conditionals, etc.) should be kept in the controller or model and not inside the views. Likewise, all presentation code (such as rendering page updates via AJAX) should be done in either regular view files or RJS templates, not in the controller.

Bad Example (Variables being declared inside the view):

<% result ||= match_result %>
<% size ||= :small %>
<% match = HaveItem.find(result.incoming_item) %>
[...]

Good Examples (In both cases, this leaves the view with just HTML and some Ruby/Rails code inside):

Declare the variables in the controller action instead of the view

def action
  @result = Engine.results
  @match = HaveItem.find(@result.incoming_item)
  [...]
end

In case the view is a partial, declare the variables when calling the partial

<%= render :partial "match_results", :locals { :result => @result, :match => @match } %>

Of course, I’m not an expert on these things. Most of them are probably common sense to most people, but you’d be surprised how often these mistakes are actually made. I’m sure you all have seen these, or probably worse. Does anyone have any other tips that can be added? Feel free to leave a comment.

It’s As Easy As Working Your Ass Off

Posted on March 27th, 2008 in Opinion, Programming | No Comments »

In the past couple of weeks, I’ve gotten incredibly addicted to Twitter, the micro-blogging, social-networking, chatting, or whatever you want to call it tool that’s been a huge hit in the past year or so. I had my account for a while, but never did anything with it. Recently I’ve just started following people and it’s just plain fun to see what these people are doing most of the time. I’m connected all the time now, so feel free to follow me! If you still don’t know what Twitter is, see a pretty cool video called Twitter in Plain English.

Well, I’m not here to talk about Twitter, although I’ve gone on and talked a fair bit about it. This post does have something to do with Twitter. I’ve been following a lot of people from the Rails community on Twitter (Geoffrey Grosenbach, Obie Fernandez, Dave Thomas, Jamis Buck and Rick Olson, among others). Some of the things they say are funny as hell (such as Obie’s “Po-po made me pour out my beer :( “), but for the most part they’re interesting stuff from these people. Most recently what I noticed is all the stuff these people actually do. They travel a whole lot, they meet a lot of interesting people and work on a ton of cool stuff.

My first thought when reading these comments are “Damn, these people are lucky to be doing all this stuff.” But in reality, I think they didn’t get lucky all of a sudden. Well, probably they had a little luck, but nonetheless it’s not pure luck. It seems like these people actually worked hard to get where they are now, and are probably still working hard to keep it going.

I always wondered why I couldn’t be the one working on awesome stuff, traveling to cool conferences and all that jazz. But making an honest assessment of myself, I definitely don’t work hard enough to earn these things. And it’s disappointing, because I know that if I put more effort into what I currently do now, I can achieve these things as well. Instead of picking up my Nintendo DS and playing The Legend Of Zelda: Phantom Hourglass for one or two hours straight, I could be starting formulating plans for some interesting ideas and projects I have in my mind. Instead of being on IM and chatting about non-significant things with people I don’t know in real life, I could be reading a book that will expand my knowledge. Instead of checking my RSS feeds every 20-30 minutes (like I obsessively do sometimes for no apparent reason), I could be helping with an open source project.

These are just a few of the things I can tweak to make more time for these things. I’m seriously going to try to change these things, even if it means less sleep and less playing Zelda - although I can’t promise anything when I get my Playstation 2 and Guitar Hero games sent from Puerto Rico, those games are more addicting than heroin. Anyway, I really want to start putting an honest effort to get myself more known out there, to do lots of things that other people will use, and to just help in any way possible those things I enjoy the most.

If you think like I thought before, it’s time to take a good look at yourself and see if the problem is that you’re truly unlucky, or if the problem lies simply in yourself.

“Women in Development”? How about just “People in Development”?

Posted on March 19th, 2008 in Computer Science, Opinion, Programming | 5 Comments »

For some reason, I wasn’t too much into podcasts until recently, when long trips in the subway made me find something constructive to do while traveling to work. So I’ve been downloading a ton of podcasts that have been out there for a while now. My favorite has to be Ask A Ninja - it’s just hilarious. But as far as tech podcasts go, the Ruby On Rails Podcast is one I’ve been going way back to download and listen as many as I can.

One particular podcast (or rather, two podcasts which were from the same interview, just split in two) that caught my attention was a roundtable discussion about women in development (Part 1 / Part 2).

I found this discussion interesting, as I have to admit I haven’t encountered that many female developers myself. During my university days, I probably saw less than 10 different females taking Computer Science courses during my nearly five years there. Half of those were in the introductory programming courses, from which they rapidly switched their major when they realized they didn’t like it. The other half stuck around, but most of them didn’t seem to enjoy it much. It could probably be due to the fact that they were female.

No, I’m not saying that because they’re women, they immediately shun all types of advanced technology or science courses. I say this because in one course, I was paired with a female student for a class project. At the end of the project, while at the library finishing up on some details, she said she was surprised during this project with me, When I asked why, she said that in every Computer Science class, in every single project she’s been teamed up with boys, the guys either dumbed down what was given to her to work on, or she would be constantly be getting hit on. This was the first time someone from the opposite sex seemingly treated her as an equal, which I did.

This is a sad truth in those academic fields where men outnumber women greatly. They’re either perceived to be dumb, or simply viewed as a potential mate. And I honestly never viewed one of these girls who took classes with me like this. Okay, maybe once I took a liking to one girl, but I still would’ve liked her no matter which major she was, so I feel like I’m clear of all charges against me. I’m not sure if this has to do with the extremely-low number of Computer Science students who are female, but I’m suspecting this has something to do with it.

Trying to put myself in their shoes, I’m sure it’s difficult to deal with these things when all you want to do is just learn and be a software developer like any other. Still, I find it somewhat odd that the women need to start off groups like DevChix and PHPWomen. It’s cool to see enough females get together and form these groups and get recognized for it. But I think these groups just label them as a different breed of developer, instead of just trying to get themselves being viewed as equals. Or maybe these groups are really necessary to combat all the obstacles I mentioned that women in this field encounter. It doesn’t seem like there’s an easy way for this behavior to end.

In any case, I’m all for the females getting their voices heard, showing the world what I have known all along: women are awesome developers. Their genetics don’t have a damn thing to do with their abilities, so stop viewing them as “that programmer chick”.

Don’t be proficient in just one programming language

Posted on March 13th, 2008 in Opinion, Programming | 3 Comments »

I just read a post by Joan Planas Illas titled “Be proficient in one programming language“. In this post, Joan gives some advice that developers should stick to one programming language, get really good at it, and make a career out of it. He does offer some good points, such as software development not being just about learning programming languages, and how employers actually prefer if a prospective employee is well-versed in the programming language they’re looking for.

But for me, those who follow the advice of just mastering one programming language are usually day-coders: those who only think about software development from 9 to 5, nothing else. Don’t get me wrong, I’m sure there are a lot of day-coders who are awesome at what they do. But usually these people don’t have much passion for what they do. They’re happy being in their own groove, not expanding their knowledge, and just do their job because it pays well and nothing more. These are probably the worst types of software developers any company can hire. No passion almost always leads to a sloppy job.

But the best software developers I’ve seen show an insatiable amount of curiosity to learn every single thing out there. Of course, it’s not possible. While I don’t have any sort of scientific proof to back me up on this claim, I’m fairly sure there’s a direct correlation between how effective a programmer is with what they’ve learned. A person who reads and stays up to date with different programming languages will have a broader vision on how to get things done. A person who only knows one thing will most likely know only how to solve problems the way their language does. Sadly, a lot of programming languages have their own conventions on doing things their way, which sometimes isn’t the right way to do. These bad habits are then embedded to the developers, who are unfortunately ignorant to recognize there are better ways of solving a problem.

I have yet to meet or read about a kick-ass or famous software developer (well, at least famous in my mind and geeks around the world) who is an expert with just one programming language. Martin Fowler didn’t just stick with C. Yukihiro Matsumoto didn’t stay with C++. Zed Shaw definitely didn’t ‘get married’ with Ruby. These are just a few examples. But just think of any well-known software developer, and one common trait they’ll have is that they at least have experimented with many programming languages, and I’m sure that helped them be as knowledgeable as they have been.

So if you have the time, get to know a programming language of your choosing, preferably one that interests you and not one that all the ‘cool kids’ are using so you need to learn it too. Once you get a firm grasp of that language - not master the language, there’s a huge difference - take the time to learn a new one. For example, if you know Ruby pretty well, get into Python. They both are similar, yet have different ways of doing things. Just don’t choose Ruby and stick with that for the rest of your life. You’ll earn no real benefit at all, and when the next big thing comes along, you’ll be get left behind. Unless you’re happy with that, day-coder.

Original developers and non-workaholics beware

Posted on March 8th, 2008 in Opinion, Programming | 2 Comments »

Here in New York, I’m working at a start-up company that is a few months away from their initial launch. This is a refreshing change of pace from where I used to work. In my previous job, I was the sole programmer, but not for a company whose main purpose was build software. Now, I’m part of a group of people, where we’re all working together to complete a software project. It’s an interesting experience for now, and I know it’s going to be an awesome experience for me.

As many of you should know, working at a start-up that hasn’t launched yet is hard. Really hard. Trying to build something that hasn’t been done yet will definitely have its setbacks, and there’s a high risk involved in the whole deal. Just a look at TechCrunch’s so-called DeadPool, start-up companies who had to shut down for one reason or another - usually because they didn’t have enough money to finish. Also, since these companies aren’t actually generating any revenue while building their product, most of the times there’s not a whole lot of people working at any given time. That means a ton of work for those involved.

Of course, I’m not saying start-up life is bad. On the contrary, it’s been fun and exciting for me. I’m doing what I want to do for a company that has a great idea that, if all goes smoothly with no major bumps on the road, will enjoy massive amounts of success. And being one of the main persons to actually have constructed part of that success, it means there will definitely be rewards down the road. With this being said, lately I noticed a couple of articles with some people saying some… Well, I’m tempted to say ’stupid things’, but I’m not one to pass judgement, especially to those I don’t know personally.

The first one comes from Mike Mason, a software consultant, who advises start-ups to fire their original development team when the company has a successful launch. Of course, now that I’m part of a dev team who’s with a start-up that hasn’t launched yet, I definitely wouldn’t want to be fired. But this article offers absolutely no valid points whatsoever as to why firing the original people who helped get the company to the “Promised Land” is a good idea. His main gripe is apparently this:

The problem I’ve found when working at startups-turned-enterprises is that the guys who built v1 of that web site are now running the IT department.

Yeah, this is a problem, definitely. But guess what? Who put the developers in charge of running IT? It’s not the developers themselves - it’s management. Why on Earth would a manager put a software developer in an IT role - a main position, at that - if they’re not actually qualified to do the job? In this case, the developer who built the first version of the site should stick around, possibly as the lead developer for newer hires, while they’re making their product better. For IT, hire someone who’s actually qualified for what you want. That way, you have someone who know about your codebase actually working with code, while someone who knows about IT tasks can focus on that. Like the ol’ lightning rod him, Zed Shaw, said in his blog about this post:

If you want to fire someone, it’s management. Fire the assholes who focused on making everyone cram for some shitty demo to moron VCs instead of focusing on the quality of the mother fucking code in the first place.

You just gotta love Zed, even if you don’t agree with him most of the times. If you read Mason’s blog post, he also has some more ‘advice’, like “Hire an expensive consulting company to help you build your systems better, and allow Chief Architect dude to ignore their recommendations” and “The minute you’re successful, plan to rewrite your software from scratch“. I admit I haven’t had years of experience in the software development world, but honestly, it seems like this is just a plain bad idea mentioned by Mike here, and just reeks of being counter-productive to the entire company.

Another article I read that left me wondering what the hell the author of the article was thinking was written by Jason Calacanis, CEO of Mahalo, some human-powered search engine, who wrote some tips on how to save some cash when running a start-up. Most of the ideas sound really good, and I agree with most of them. But there was one item that caused a lot of debate around some other sites. Here’s the original quote, as apparently the author noticed he put his foot in his mouth and edited it to sound “less harsh”:

Fire people who are not workaholics…. come on folks, this is startup life, it’s not a game. go work at the post office or stabucks if you want balance in your life. For realz

Whoa, so if I work for you, you’re going to fire me if I don’t work 12 hours a day, at least six days a week? For realz? Sorry, but I definitely wouldn’t want to EVER work for you, even if you pay me ten times as much as I’m earning now. This idea of being a workaholic is just plain idiotic. Overworking leads to so many problems, it’s not even worth it to mention all of them. Stress, bad productivity, bad decision-making, all of these are caused by people working more than they should.

It’s sad to see that in this day and age, there are still people who view borderline slavery (i.e. making them work way too much) as the only way to be successful. People like these shouldn’t be running companies at all. It’s not about how much you work, it’s how smart you work. David Heinemeier Hansson over at 37Signals’ Signal Vs. Noise blog gives his take on this, and brings up some great points to do, what he says, “Fire the people who are workaholics!

Of course, after a backlash around the Internet, especially in TechCrunch’s aptly-titled post Calacanis Fires People Who Have A Life, Calacanis back-peddled and wrote a follow-up post where he said didn’t actually mean it that way, and that he meant that the TechCrunch headline should be “Calacanis fires folks who don’t love their work”. This, I can agree with a bit more, but still, the post was just plain back-peddling, even if he doesn’t want to admit it.

Calacanis goes on to ask two questions: “Can you have a life and work at a startup?” and “How do you manage stress?” The first one is easy: Yes, I can. I’m currently working in a start-up, and still have more than enough time to explore New York City, keep in touch with my friends and family, work on personal projects, and even write long, interesting blog posts. The second question, about managing stress, it’s also easy: Don’t be a workaholic. If you work all the time, if work is your life, of course you’re going be stressed. Take some time away from work. Go do whatever relaxes you (please don’t say work relaxes you, you liar). Take one day off, it won’t be the end of the world or your start-up. Come back feeling refreshed and hopefully stress-free.

Working and/or managing a start-up is definitely no easy task. But don’t think that working all the time or firing your original people because they’ll run the rest of the operation to the ground will help. Work smart, keep your good people around and treat them well, and you’ll see that your start-up will be successful. As long as your idea is good and you have the funding, of course!