May 26

The Rails Development Pattern

Ruby, Tech 14 Comments »

The team that I am is kicking into gear with Rails now. I am finding an interesting pattern in how development is going…. and it has happened before with new technology but seems even more so now:

  1. Get new requirement
  2. Start hacking on new code to fulfill requirement (Solution: X lines of code)
  3. Chat with another team mate who knows of a plugin that does half of this (Solution: X / 2 lines of code)
  4. Look at Rails Recipes and realise there is a better way to get into it (Solution: X / 4 lines of code)
  5. Generalize the problem and use MOP to simplify it’s usage (Solution: X / 10 lines of code)

At the end of the day you sit there and realise that you spent the entire day writing 100 lines of code and then deleting 90 of them. :)

May 08

Scaling out 37 Signal-style applications is convenient

Ruby, Tech 4 Comments »

I had someone telling me that:

Ruby can scale. Basecamp prooves that.

Now, you all know that I do not think that Ruby has ANY problems with scaling. However, applications such as basecamp have a huge advantage for scaling: minimal shared data.

The key to scalability is minimizing access to the same data. The less anal you are about how “correct” the data is the better you will be.

Microsoft Word scales very well as when a million people are writing a document, they are not editing the same one (I know, they could be on a shared drive blah blah).

Caching and all of the tricks are ways in which we can cheat the system. We can make copies of our REAL data and access those instead. This works for a lot of applications, and a lot of data. This is why you see “this stock data may be up to 15 minutes old”. Imagine if everyone needed access to the stock price right NOW. I mean NOW. I mean…..

To scale probably, you want to minimize any locking. How stale can your data be in different aspects? The more stale that you can deal with the better.

Where does Basecamp and company fit in here?

One of the great advantages to those applications is that there is little shared data.

If I sign up for an account for my company I can have a large amount of data on fooinc.grouphub.com. Someone else can have barinc.grouphub.com, and no data is shared. I do not need (or should be allowed) access to their data.

This means that if they wanted too, we could be on two different machines with out own MySQL instance. One per user doesn’t make sense of course (unless the users are GE and Ford), but how about splitting up: A-M and N-Z.

If load keeps going up you split again, and again, and again.

If you are in this situation you are a lucky man, and should be able to scale up anything :)

If you have an application where there is more shared data then you may need to get more creative. A lot of web apps are heavy on reads so you can scale up nicely via MySQL replication and putting out more slaves, but at some point the master will not be able to handle the writes. This is when you need to Give the DB a break! and use caching, and tweaking your archicture into pieces.

We do this with out Rails apps by making parts and pieces web services that we can scale up separately, but there is always the bottleneck on some part of the darn data!

Apr 20

Consultants, Startups, Students, and Rails

Ruby, Tech 1 Comment »

As I hang out at Rails user groups, chat with friends using Rails, and others at conferences and the like, I have seen a few groups of Rails users out there.

Consultants

Ah the consultants. If you have been to a show like No Fluff Just Stuff you would have noticed that last years season had more questions on Rails than Java (or so it felt, which was a little painful!).Many of the people up on the panel were able to answer the questions (or at least give their opinion) since they had actually used Rails. Many of them were talking about JSF and other Java web frameworks the year before, but had moved on for some of their projects.

Why have these alpha geeks moved on?

  • Positive view: Consultants often get to start new projects. They do not have the same baggage (baggage in this case == legacy code that runs and makes the business money!) that IT departments often have. If you have a million lines of code in Java, WebWork, Spring, Hibernate, would it make sense to jump over to Rails? You have the knowledge of those frameworks inside and out. You have helper libraries to make your life easier. You have nailed deployment. Does it make sense to change? The consultant moving on to client.next gets to start a new project from scratch and wants to play with the new toy. He has heard about the potential of Rails and wants to test out the hype. This has always happened, and is the reason that many have deployed Struts, WebWork, JSF, and Tapestry applications in a fairly short time period. For many of the current crop, they enjoyed the Rails experience, and they haven’t jumped to another framework….. yet!
  • Negative view: Consultants need new technology to master to sell themselves! The yet from above means that this year they gamble on Rails, but who knows what it will be next year. I personally think that Rails has legs, and the length of time that a consultant spends with a technology shows how changing that technology is. For example, I had used Spring on every Java project for the last 1.5+ years. Spring was useful enough to me that it made sense to use it on all of those projects. Therefore, major points for Spring. This can be said for JUnit (until TestNG comes in ;) and many other tools (even IntelliJ IDEA!).

Startups

Startups such as ODEO, of course 37 Signals, and the like have been strong users
of Rails. They get the benefit of…. being startups!

The green field is what they see, and their goal is to come up with technology a
s fast as possible to start to make some $ somehow (or the business model may be
to do a beta and get bought out by G/Y/MSFT).

They do not have the luxury of legacy code (again: code that runs and makes $) but they do have the luxury of making a choice from scratch.

Rails thrives on green field projects.

Students

About half of my local Rails group consists of students at the local college. The first presentation was from a student. Rails fits them nicely as it is a quick environment to whip out their projects.

I remember using this same advantage back when I was at university. The class was using C++ to build a web app, and I hacked together something using Perl, and had far more time to enjoy the fun parts of college life.

The head Java instructor is very much in the Rails camp. He talks about how hard it is to teach Java in comparison. There is so much to teach in public static void main(String args[]) and he has tried top down, bottom down, andevery other way (using BlueJ and …).

Of course…

This isn’t a definitive list and of course it doesn’t mean that any other type isn’t using Rails, but it was a little interesting.

Apr 19

Rails Recipes: Stuff you need

Ruby, Tech 1 Comment »

If you have used Rails for non-trivial applications, you have probably run into a lot of “Hmm, what would be the best way to do this?” moments.

As soon as you tread off of the simple path, you need to think :)

Rails Recipes has been a saviour for a few of the items that I care about. The Wiki doesn’t cut it. A co-worker spent a few hours working on ideas from the Wiki. Then he cracked open Rails Recipes, found an exact solution, and it actually worked right away :)

The book is in beta form now, and will shortly be finished. I am sure there will be several versions in the future as Chad finds more and more useful ideas.

Mar 25

Ruby is not ready for production. Definitive proof.

Java, Ruby, Tech 10 Comments »

A lot of people who snipe at Rails claim that it does not, and can not scale or be used in “production”. The funny thing about this is that I haven’t heard this from people who have tried and just failed miserably (although this will happen, because you can create something that can’t scale very easily. Trust me, I have done it :)

But, we finally have proof. Hani has been biling away at TheServerSide Symposium and said:

I was tremendously pleased by the audience’s responses. It turns out that the majority of TSS attendees:

Do not/will not deploy Ruby On Rails in a production environment (except 2 guys)

This was a shocker. For those that do not know, TSS Symposium is not just a Java show, but an Enterprise Java show. Not only is it Enterprise Java, but its life started out as a portal for all things EJB.

And these attendees aren’t all hacking on Rails?

That shocked me as much as the show of hands for catholic bishops who do not want women to join them on high.

I think that is is great to be skeptical, and I do not believe that “Java is dead” like many on the kool aid elsewhere feel.

There is room for everything. However, saying that Rails isn’t a good solution for anything is wrong. Does it have room to grow wrt helping people with deployment? I think it does. Do I believe in keeping everything in the database and not scaling out caches? No. memcached works great for /., livejournal, and others.

Another interesting tid-bit from the conference was that a panel was asked about “what is cool about Java in 2006″ and “POJOs” and “Ajax” were responses.

Does anyone else think it is ironic that we had to create an acronym for using Objects and keeping things simple? And Ajax is of course not limited to Java.

This too isn’t a bad thing. I wrote before about the boredom of YAFramework. Now we can start getting work done, and sharing real experiences on solving real problems.

Dislaimer: This is not a James Governor posting. There is no need to wonder if I am serious with the title. I am british. I like sarcasm. Don’t make me put “just kidding” at the end of any sarcasm. Oh, and I know it is the lowest form of wit

Mar 20

Code-to-learn ratio: Getting work done with Ruby

Ruby, Tech 3 Comments »

I have been working on a fun new project, where I get to work in Ruby.

After spending some time submerged in Ruby land, I am having some interesting thoughts.

The biggest point is that the code-to-learn is very high in Ruby.

You go from thinking “Hmm, I need to send an email in my code….” having never touched an email module, to writing the simple Net::SMTP code in minutes.

This happens with more complicated parts and pieces too, and I find myself spending way less time on websites and Google trying to work out a bizarre issues, and more time writing code to get my work done.

It isn’t all perfect though. I still wish that:

  • I had a JVM (JRuby)
  • Ruby could look ahead and not have to read my def before I use it
  • I admit it. I like { } as delimiters. A lot more than “end end end end”
  • IntelliR :(

That being said, these are all MINOR nitpicks (apart from IntelliR). I am having a great time solving problems at a nice, high, functional level of abstraction.

Oh, and I haven’t had a RuntimeException due to passing in the wrong type yet.

Jan 10

Yes Ruby in the Browser, No it won’t take off?

JavaScript, Ruby, Tech 6 Comments »

Obie Fernandez wants No Ruby in the Browser, after Paul Hammant discussed it in Ruby vs. JavaScript for Web 3.0.

I am actually a fan of JavaScript these days. It isn’t as evil as you think.

However, I would love to have Ruby integrated as well as JavaScript it.

We could then have true libraries, and if we could version them all within the browser etc, we could share them between apps so we don’t duplicate painful downloads (not that we can’t add this to JS, but we could use rubygems).

Having true packages and namespaces, and a full environment like ruby in which we can share code in both worlds would be great. No need for Ruby to JSON etc. Send Ruby on down.

The reality is that it would be hard to get the ball rolling. JavaScript is part of the majority of browser suites, including the Flash VM, and getting groundswell around a Ruby plugin would be tough.

But in another dimension Marc A put Ruby into Netscape and we are all happy.

Dec 05

20.weeks.ago vs. java.util.Calendar

Java, Ruby, Tech 7 Comments »

After playing with a Rails project that needed to do a lot of date maniupulation, I was shown another of the many “small” differences that make you so glad you are in Ruby-land.

With Ruby, and the time extensions that Rails adds to the Ruby time module, you get to do things like:

20.minutes.ago
20.hours.from_now

now = Time.now
now.at_beginning_of_year
now.midnight
now.last_month
now.monday
now.next_year
now.tomorrow
now.yesterday
now.seconds_since_midnight

This is just a touch of what you can do.

The thought of doing a lot of this work in Java with the great java.util.Calendar and java.util.Date makes me cringe. I have a DateUtil that I use to do a lot of work, and there are other utils like JodaTime etc, but none compare in my opinion.

Nov 09

Symlinks and directories, versus EAR files

Java, PHP, Ruby, Tech 4 Comments »

Another post in the realm of dynamic platforms, and this time my thoughts are on deployment.

I have been working on a large web application, that is now in production.

The project before this one was on a large stack (WebSphere) and the deployment was a nightmare.

In development we had simple war’s and developers were all setup with expanded versions so they weren’t wasting time ziping up changes for a simple text change :)

However, the deployment issues were another story. They needed to be ear’d and run through a million checks on this, that, and a bit of the other.

We had to have our build system scripted to handle this all, and there were constant problems.

From that, I am now on a system where there are no such beasts as EARs. You just have good ole files and directories that the server looks too. Development is pretty much the same as deployment (bar a few optimizations that are taken care of via environment).

To jump between releases we can easily change a symlink and we are moved. An issue? we can move right back. No need to deploy/redeploy/undeploy in containers.

Bah I hear you scoff. What about all of the tools for deployment! How mickey mouse is this file based crud!

We have nice scripting via tools like Switchtower, which handles deployment very nicely indeed, and is easy to extend to do you will.

Lighter, and yet simple. Switchtower is still new-ish, so it may not do everything that you need in your deployment world… but it is getting there.

Oct 24

Pruning past iTunes podcast content

Ruby, Tech No Comments »

I keep running across the same feature that I wish I had in my applications. As someone who subsribes to a lot of content, I really need to be able to cap the amount in some feeds.

E.g. I want to say “This planet feeds gets a ton of traffic, so just keep a rolling max of 100 so I don’t turn around and see it full with 4000 entries”

This problem is even more important when subscribing to content such as pod/vidcasts. Before I look around, my hard drive is screaming about my podcast directory.

Since iTunes didn’t seem to help me out, I ended up writing a tiny Ruby script that would allow me to nuke any content longer than X weeks. This is far from perfect, as I would like to set it up on a podcast basis. Some podcasts I like to keep around. Others, I don’t really care about, and I only listen to when on long trips and I have exhausted the rest :)

The bulk of the script is simply:

Find.find(PODCAST_DIRECTORY) do |path|
if FileTest.file?(path) && older_than_given_weeks?(path)
puts "Deleting '#{path}' which had the mod time of '#{File.mtime(path)}'"
File.delete(path)
end
end

iTunes, aggregators, please let me setup queue maximums :)