Archive for February, 2010

5 Things That ASP.NET Developers Would Love about Ruby on Rails

Feb 23 2010 Published by under Programming

NetToRails

I’m a longtime ASP.NET developer, and indeed that’s how I’ve made my professional living for many years now, but I have to say there is a lot to love about Ruby on Rails.
There’s a simplicity and common sense approach that I really like.

I think other ASP.NET developers would enjoy certain aspects of Rails as well, so I put together a list of my 5 favorite things (in no particular order):

1) Migrations

If you’re like me, you really don’t like writing database change scripts in SQL. Wouldn’t it be nice if you could write the scripts in your favorite programming language rather than resorting to T-SQL? Well, with rails migrations you can!

You write your schema changes as a ruby class (or even generate them) and run it at the database to modify your schema. For example, to create a posts table, on the command line just type:

$ script/generate model Post name:string content:text

This will automatically generate the required class for you which looks like this:

class CreatePosts < ActiveRecord::Migration
  def self.up
    create_table :posts do |t|
      t.string :name
      t.string :title
      t.text :content

      t.timestamps
    end
  end

  def self.down
    drop_table :posts
  end
end

Then you just run “rake db:migrate” at the command line and your table is created. The framework even keeps track of which migrations have been run and versions them all so you can roll back to previous DB versions at any time.

2) Active Record

I love how active record does not force you to model out all your fields as properties. You simply build your table with migrations and then create a class of the same name that derives from ActiveRecord and Rails figures out the rest. No config files to set up or angle brackets to mess with.

It adds all the properties based on the table columns and a bunch of helper methods for finding records and working with the dataset, but your code is as simple as this:

class Post < ActiveRecord::Base
end

3) Opinionated

With Rails a lot of decisions are made for you and that’s a good thing! Instead of endlessly debating which of the 10 ORMs to use for your data layer, you just use Active Record because that’s what’s built-in out of the box and works for 90% of the cases.

Rails has a specific way of doing things, and if you buy into it, you can let the framework take care of a lot of the little details for you.

4) Lightweight

There’s something wonderful about not having to fire up a huge IDE to do development. Just launch your favorite text editor and start writing code. My personal preference for writing Rails code on windows is the E-TextEditor (which is modeled after TextMate), but I could just as easily use notepad++. 

This simply would not be possible with ASP.NET as there are just too many frameworks and libraries to deal with as well as just a lot of code to write that you almost need the IDE’s help to sort them all out. Not to mention, you need the IDE to compile your code (or the cmd line with hundreds of switches) which is not necessary in the the interpreted world of Ruby. The code and run cycle is almost instantaneous.

5) Less Code

After porting an ASP.NET MVC app to rails I was amazed with how little code it took in rails. The rails version was only about 25% of the code that was required for the ASP.NET MVC version.So, how is that possible?

Much of this is due to Active Record and the fact that I didn’t have to write any DB connector code, but also Ruby’s terse syntax and lack of strong typing just means that the amount of code you write is much less.

For example, a typical controller method in Rails looks like this:

  def show 
     @post = Post.find(params[:post_id])
  end

And then @post is automatically visible in the corresponding view. Nice and elegant – the way coding should be.

View Comments

Can Programming be Art?

Feb 14 2010 Published by under Programming

image

Lately I’ve been reading Seth Godin’s Linchpin. It’s an excellent book and the key point is that your work should be a platform for art:

Art [in this context] is a personal act of courage, something one human does that creates change in another. … I think it’s art when a great customer service person uses a conversation to convert an angry person into a raving fan. And it’s art when Craig Newmark invents a new business model that uses the Internet to revolutionize classifieds." …

Godin really expands the traditional definition of “art”; It doesn’t have to just be a painting that you hang on a wall, but it’s something that you create which directly impacts another in a dramatic and positive way.

Given that I’m a programmer, It makes me wonder in what ways programming and it’s output can be considered art– Is twitter art? What about facebook?

According to Godin, both of those sites would be art. They are unique and they have profoundly impacted people (as opposed to most software).

So a software product can be art, but what about an individual piece of code. Can that be art?

Obviously, O’Reilly thinks so given that they’ve published a book on the topic of beautiful code. I have to agree that some code and frameworks (eg – jQuery and Rails).are so elegant and  well-written that they are a true joy to work with.

It seems odd at first to be to lump programmers in with artists. Aren’t they two totally different types of people – one left-brained and the other right-brained? Yet, in many ways, they’re closer than you think.

Hackers and Painters

Paul Graham nailed this strange dichotomy in his classic essay entitled Hackers and Painters:

Hacking and painting have a lot in common. In fact, of all the different types of people I’ve known, hackers and painters are among the most alike.

What hackers and painters have in common is that they’re both makers. Along with composers, architects, and writers, what hackers and painters are trying to do is make good things. They’re not doing research per se, though if in the course of trying to make good things they discover some new technique, so much the better.

At the end of the day, both are craftsman.

I can appreciate this more than most because I actually studied art and computer science in school. Both held great appeal for me and most likely for similar reasons:They both allow you to perform solitary acts of creation.

Software Craftsmanship

In fact, there’s a powerful new movement in software focusing on craftsmanship – they even have their own manifesto:

As aspiring Software Craftsmen we are raising the bar of professional software development by practicing it and helping others learn the craft. Through this work we have come to value:


Not only working software, but also well-crafted software
Not only responding to change, but also steadily adding value
Not only individuals and interactions, but also a community of professionals
Not only customer collaboration, but also productive partnerships

This movement is largely a reaction to offshoring and businesses trying to treat software developers as replaceable cogs. The movement focuses more on individuals and their specific skills. These software craftsmen strive to create not just software that meets spec, but hand-crafted pieces of art.

Seth Godin would be proud.

View Comments

Is it Time to Join the NoSQL Movement?

Feb 08 2010 Published by under Programming

no-sql-tea-party Photo Credits: James Fee

The Battle Cry

There’s a new revolution brewing in the software industry, and it goes something like this…

For too long software developers have been oppressed by the tyranny of relational database! Are they really the right tool for every job? Should we really have to map our OO code to a relational DB?

Now the time has come to throw off those shackles and enter the free world of NoSQL! Who’s with me?…<sound of crickets chirping>

Ok. So maybe people aren’t quite ready to join the revolution yet, but let’s dig into this new movement and understand what it it.

What is it?

According to Wikipedia, NoSQL is:

an umbrella term for a loosely defined class of non-relational data stores that break with a long history of relational databases and ACID guarantees. Data stores that fall under this term may not require fixed table schemas, and usually avoid join operations. The term was first popularised in early 2009.

In other words, it’s not: SQL Server, mySQL or Oracle — the leading relational database engines in the market.

By contrast, NoSql databases usually involve persisting objects to the database through key-value pairs, XML and/or JSON. They are often called document databases or object-oriented databases.

The benefits are primarily two-fold:

  • Developer Efficiency: Because you don’t need to map your objects to database tables, the classic object-relational impedance mismatch is gone. This allows developers to simply focus on building their objects persisting them to the database as is.
  • Database Performance: When you have a database that is nothing but key-value pair lookups it becomes lightning fast which is why NoSQL databases are used by the largest websites out there like: Facebook (Cassandra), Amazon (Dynamo) & Google (BigTable)

So if you’re convinced that NoSQL is the wave of the future, here’s how you get started.

How Do I Get Started?

The first choice you have to make is which NoSQL DB you’d like to use. From what I’ve read, here are the most common options:

  • MongoDB: From the MongoDB site:”MongoDB (from "humongous") is a scalable, high-performance, open source, schema-free, document-oriented database. Written in C++”. MongoDB seems to be a good choice if you are working in rails because of a MongoMapper which makes it easy to plug rails code into a MongoDB. There are also a series of Tekpub screencasts for using MongoDB with Rails
  • CouchDB: From the CouchDB site: “CouchDB is a document-oriented database…[that] provides a RESTful JSON API than can be accessed from any environment that allows HTTP requests.” It does seem like CouchDB is not ready for production yet and most people are just experimenting with it at this point.
  • DB40: From the DB40 site: “db4o is the open source object-oriented database that enables Java and .NET developers to store and retrieve any application object with only one line of code, eliminating the need to predefine or maintain a separate, rigid data model.” DB40 does seem to be production ready (it even supports LINQ) and Rob Conery has a great series of articles on getting started with it in .NET

Does the NoSql movement have legs or is it just the most recent shiny object for developers to talk about?

I don’t know, but I like the idea of looking at new options for database engines, and plan to try them out in some test projects. I think we’re still at a point where we spend far to much time writing CRUD code. Maybe NoSql DBs can solve that?

View Comments

Next »