Interview with Jeremy Evans about Sequel and not only

октября 22, 2011  |  Published in Sequel, Интервью

Russian version: Интервью с Джереми Эвансом (Jeremy Evans) о Sequel и не только

Hello Jeremy, please introduce yourself for RubyDev readers.

My name is Jeremy Evans.  I work for the California Bureau of State Audits, a small state government department that audits other government departments.  I’m the lead technical staff member here, responsible for the department’s programming, system administration, network administration, and database administration, among other things.

Outside of computers and programming, my main hobby is playing with my three year-old son.

Jeremy, tell me please what is the Sequel and how an idea of creating Sequel  born in your mind?

is a database toolkit for ruby.  It’s designed to provide an easy, database independent API for interacting with SQL databases.  It supports advanced SQL features not supported by other ruby database libraries.  It also ships with a powerful and flexible ORM called Sequel::Model.

I am not the original author of Sequel.  The original author was Sharon Rosner, and I believe the reason he originally created Sequel was because he was frustrated with ActiveRecord and wanted to create something better.  Sharon was working on a web framework called ServerSide, and Sequel was originally added as the database component of that (ServerSide::Database) in November 2006.  He extracted the database component into a separate library named Sequel in March of 2007.

From March 2007 until February 2008, he developed the library, and in March 2008, he decided he didn’t want to maintain it anymore.  I had recently submitted patches to add associations support to the ORM part of Sequel, and when he decided he didn’t want to maintain it, he emailed me and a few other developers asking if one of us wanted to take it over.  I accepted and have been working on improving the library since then.

What major features do you want to add to Sequel in near future?

My todo list is actually getting a little short, as there has been a lot of features recently committed, such as much better DB2 and Oracle support, support for PostgreSQL 9.1 features, and the ability to hook into transaction completion using an after_commit or after_rollback hook.  The next feature I plan to implement is a plugin that allows you to call association methods on datasets:

Artist.one_to_many :albums
Album.one_to_many :tracks
# Gives all tracks where the album starts with B and the
# artist starts with A

How many developers actively commit to sequel except you?

I probably write about 90-95% of the code that is committed to Sequel. The answer to the question depends on what you mean by «actively commit».  For example, there have been 16 other Sequel users who have committed patches this year.  But I’m probably the only one actively working on improvements to Sequel.

What are the most visible difference between Sequel and ActiveRecord or DataMapper ORM’s?

The first difference is that Sequel is not an ORM, though Sequel ships with an ORM called Sequel::Model.  So if you just want to connect to a database and interact with it without creating a bunch of model classes, Sequel makes that much easier than ActiveRecord or DataMapper.

The main difference between Sequel::Model (Sequel’s ORM) and ActiveRecord is that Sequel::Model is generally more flexible. ActiveRecord was designed to be used with new databases where you control the schema, and it is difficult to use ActiveRecord with databases that don’t use ActiveRecord’s conventions. For example, ActiveRecord doesn’t support composite keys, either for model classes themselves or for associations, while Sequel supports both.

Sequel::Model is also much more modular than ActiveRecord.  It has a small core module that covers basic CRUD features.  It also by default includes an associations module that is more flexible than ActiveRecord’s, with many more customization options.  Everything else ships in separate modules, so the user can decide which features they
want to use.

I’d say the most visible difference between Sequel::Model and DataMapper is that DataMapper supports non-SQL databases and Sequel does not, but I don’t know DataMapper well enough to comment otherwise.

What tools except Sequel::Model does Sequel add? Can you give me some simple characteristics of Sequel tools.

I’m not sure if I understand what you mean by tools, but some features that Sequel has ships with that aren’t supported by other database libaries are:

a) Master/slave configurations: Send your SELECT queries to your read-only slave servers and all other queries to your master server, with only a few lines of configuration and no code changes.

b) Sharding support: Pick which shard/partition a given query will execute on.

c) Prepared Transactions/Two-Phase Commit: Deal with transactions in distributed databases by ensuring that either all are committed or none are.

d) Prepared Statements: Create prepared statements with a simple API that works on all databases.

* I mean modules that included in Sequel and situated in plugins/ directory. Can you tell about some most interesting of ones?

a) Class Table Inheritance: Supports inheritance in the database using a single database table for each class in a class hierarchy.

b) Instance Hooks: Allows you to apply specific after_save and related hooks to individual model instances.

c) Lazy Attributes: Like DataMapper, doesn’t select all columns by default, and can lazy load them on access.

d) Many Through Many: Allows creating an association between any two tables, even if there are an arbitrary number of join tables in between them.

e) RCTE Tree: Uses a recursive common table expression to quickly load all ancestors and descendants for a tree like structure.

f) Sharding: Works with Sequel’s built in sharding support so that model objects retrieved from a shard are automatically saved back to that shard.

g) Tactical Eager Loading: Like DataMapper, implicitly eager loads associations so you don’t need to do so manually.  Unlike DataMapper, supports implicit eager loading to an abitrary depth (see slides starting on ).

ActiveRecord 3.1 ships with identity map. Does sequel implement this pattern for more stable and faster work?

Sequel has shipped with an identity_map plugin for over two years. It is used to implement the lazy_attributes plugin, but outside of that I don’t recommend using it except in limited cases.  Global identity maps can cause problems and the (usually minor) speed improvement they offer generally isn’t worth it.  ActiveRecord 3.1 turns the identity map off by default.

Where are you using Sequel? Are you using ActiveRecord or DataMapper in some of your projects, or you devoted to only Sequel?

I use Sequel for all of my projects at work and at home.  I have 3 Rails 3.1 apps that are using Sequel, all of which were started before Rails 1 was released.  They were originally using ActiveRecord, and switched over to Sequel after I became maintainer in 2008.  I have around 10 Sinatra apps that use Sequel as well.

The only time I use ActiveRecord or DataMapper is for testing a project I have called Scaffolding Extensions that supports both Sequel, ActiveRecord, and DataMapper (as well as 5 separate web frameworks).

I know that most people use Sequel only in bunch with Sinatra Framework.  Does the cause of this is that Sequel is more lightweight and more faster than ActiveRecord?

Sequel is fairly popular in the Sinatra and Ramaze communities, and I think part of that is because it is faster and more lightweight, but I think the main reason is that Sequel is easier to use and more flexible.

I think ActiveRecord will always be more popular than Sequel in the Rails community, simply because it is the default.

Jeremy please tell me about the most famous and the biggest projects  that use Sequel.

The largest uses of Sequel that I’ve heard of are:

a) Heroku (Platform-as-a-service): Heroku’s data team uses Sequel to analyze their large PostgreSQL databases.

b) OMGPop (Online gaming): I’m not sure exactly how they are using it, but supposedly they are dealing with hundreds of millions of rows.

c) (Coupons): Using Sequel to process hundreds of millions of transactions.

Except for Sequel, in what projects you take a part? Can you tell about ones.

Outside of Sequel, the major project I’m involved in is OpenBSD.  I’m the maintainer of most of the ruby ecosystem in OpenBSD, including the four main ruby interpreters (MRI 1.8, MRI 1.9, JRuby, and Rubinius).

I have many small projects that I work on, which are hosted on github ().

I don’t know anything about Rubinius, so can you tell me what is the main difference between MRI 1.9.2 and Rubinius? Does anybody use Rubynius in production or it’s not ready for real-world projects yet?

Rubinius is a ruby implementation that is attempts to implement most of ruby in ruby itself, unlike MRI where the core is written in C.  There is a small part of Rubinius written in C++, but most of it is written in ruby.  Rubinius uses LLVM to JIT compile your ruby code, and in some cases is much faster than MRI 1.9.2 (in other cases, much slower).
Rubinius 2.0 will be removing the GIL, allowing multiple ruby threads to run simultaneously (similar to JRuby).

I wouldn’t know if anyone is using Rubinius in production, but in my usage it is very stable.  My production apps run on 1.9.2, though.

How did you start programm in Ruby? What is the most beautiful moments for you in learning and programming Ruby?

I started learning to program in ruby in late 2004, after a year of programming in PHP and a year programming in Python.  After working on a small ruby script to calculate and check CRC32 checksums, I jumped right into Rails, which I think was at version 0.8.5 or 0.9 at the time.

If I had to pick a single moment as the most beautiful moment of programming with ruby, it was probably when I had the realization that you could do something like:

def foo
f ='file', 'rb+') yield f
f.close if f

Coming from Python 2.4 (before context managers were added), I thought it was just so awesome that there was an easy way to encapsulate cleanup code.

What the programming languages do you use now in bunch with Ruby and what languages you had used before?

Well, in college around 1998-1999 I had a few classes in C++ and one in Java, which I liked but didn’t really consider programming as a career. I didn’t start programming again until early 2003 when I started using PHP.  I picked up Python in early 2004, and used as my main language until I discovered ruby.

My main languages these days are ruby and C, but since learning ruby, I’ve also done some basic work in Lua, Erlang, Clojure, Perl, and most recently Haskell.

What are you think about Java, Scala and so one? Can Ruby to kill Java-like languages?

It’s been a long time since I’ve programmed in Java, but more recently when I was using Java libraries via Clojure, I remembered how much work it takes to get even simple things done.

I do plan on playing with Scala at some point in the future, but I’m currently a little turned off by the syntax.

I don’t think ruby will kill Java-like languages, nor does it need to. Especially with JRuby, it’s easy for ruby and Java to coexist.

Jeremy, what you think about future of Ruby and Rails? How do you feel about new features in Rails 3.1 and what do you wait from Ruby 2.0?

Since Rails 1.2, I can’t remember Rails adding a feature I’ve needed. My Rails 3.1 apps are still written in a Rails 1 style.  To be fair to Rails, my Sinatra apps don’t use much if any of the features from newer Sinatra versions either.

In terms of ruby, other than speed I don’t see a large advantage of 1.9 over 1.8.  Of the things they are planning to add to 2.0, I think the ability to prepend modules is probably the feature I’m most looking forward to.  It’s fairly easy to get similar functionality in 1.8 and 1.9 by storing all methods in modules instead of classes, but other than Sequel::Model I’m not aware of libraries doing so.

What do you think about concurrency and parallelism in Ruby 2.0? Will C code of Ruby be thread-safe?

I don’t think MRI will be thread-safe by 2.0, at least in terms of running multiple ruby threads in parallel.  Possibly MRI 3.0 will do that.

Currently, if you want to write parallel ruby code, you have to use JRuby.

Can you share some of your secrets how to be a professional programmer and write great projects, like your Sequel for example?

I’m probably not the best person to ask about how to be a professional programmer, but I think the following things are important if you want to develop a good project:

a) Respond to issues as soon as possible.  The median response time on Sequel’s bug tracker is about an hour and a half, and users love the fact that they get very fast feedback to any issue they open.

b) Fix bugs in your library, even if they don’t affect you personally. If you are putting your code out there for other’s to use, either explicitly say that you aren’t maintaining it, or maintain it and try to fix any bugs in it.  Bug fixes should take priority over new features.

c) Write documentation.  I don’t like writing documentation, but I have written a lot of documentation for Sequel.  The more important the project, the better you want to document it.  Good documentation makes it easier for users to use the project, and means you are less likely to get asked the same questions over and over.

d) Be available.  Answer questions on the mailing list and the IRC channel.  Personal responses from the maintainer are great and show users that you care.

e) Test your code.  Don’t ship code with known bugs.  Use a coveragetool like RCov to make sure your code is getting tested.  My saying is «100% coverage means nothing, but less than 100% coverage means something».  Think about all possible corner cases for your code when testing.

f) Don’t cargo cult/don’t do things just because other people do them. For example, many rubists say you should always use test-first development.  Don’t do that unless you find it always works better for you to.  Personally, I use test-first development for some things, and test-last development for others.

What do you want to wish for RubyDev readers and for all Ruby newbies?

Ruby’s main focus is on programmer happinness, so don’t forget to have fun.




Tags: , , ,

Leave a Response

Для подсветки кода используйте BB - коды: [language]...[/language], где language может быть: ruby, javascript, css, html.