Archive for November, 2007

Ruby, Python, Haskell and Objective-C Feed Survey

Antonio Cangiano November 27th, 2007

Having little time to follow the blogosphere and its crazy rhythms of publication is not a good enough excuse for not being up to date. This rings particularly true for me as a technical evangelist at IBM, and as someone who is deeply passionate about the development and the information technology world. The biggest challenge is to quickly and efficiently divide the wheat from the chaff or, in other words, filter out the noise from the overload of signals put out there. For me, feed readers are life savers, I couldn’t cope without them.

I recently adopted a setup that seems to be working particularly well. I purchased NetNewsWire for my Mac and FeedDemon for Windows, and automatically got a one-year subscription to the online premium service from the fine folks at newsgator. The two programs are a joy to use, especially for handling very large group of feeds in a short amount of time, as I often need to do. Each program automatically synchronizes with the newsgator service, therefore no matter which computer I’m using, I’m always dealing with the same folders, subscripted feeds and saved clipping. Sure, there are free services out there like Google Reader or Bloglines, but to me there is no comparison between the experience that I have when using a sluggish web interface and a rock solid, well designed desktop application. If I have the option, I’ll always choose the latter, especially since newsgator allows me to take advantage of a centralized repository of feeds from my desktop programs, just like as if I were using their online service through Firefox. For a few dollars, I got a setup that is working awesomely well for me and it’s saving me huge amounts of time. It also helped me to identify non-updated blogs, and those that I was no longer paying attention to, therein allowing me to reduce my over-all amount of feeds (granted with a conscious effort on my part) to a more manageable total of 160.

As mentioned above, my subscribed feeds are important to me, with a list that changes dynamically over time, as I add and remove entries. That said, I was looking at my Ruby and Rails folder when I decided to share my feeds with you. The list is understandably incomplete (after all, there are thousands of Ruby related blogs) and the presence of planets, aggregators and tags in bookmark services like del.icio.us, generate a few unavoidable duplicates. These are the Ruby/Rails blogs and sites that I currently subscribe to:

  1. alternateidea.com
  2. antoniocangiano.com
  3. blog.codahale.com
  4. blog.fallingsnow.net
  5. blog.grayproductions.net
  6. blog.innerewut.de
  7. blog.jayfields.com
  8. blog.leetsoft.com
  9. blog.segment7.net
  10. blog.talbott.ws
  11. blog.zenspider.com
  12. blogs.thoughtworks.com
  13. brainspl.at
  14. chneukirchen.org/blog
  15. dablog.rubypal.com
  16. db2onrails.com
  17. del.icio.us/popular/rails
  18. del.icio.us/popular/ruby
  19. demo.mephistoblog.com
  20. drnicwilliams.com
  21. eigenclass.org
  22. eli.thegreenplace.net
  23. errtheblog.com
  24. glu.ttono.us
  25. groups.google.ca/group/comp.lang.ruby
  26. groups.google.ca/group/rubyonrails-talk
  27. headius.blogspot.com
  28. hivelogic.com
  29. intertwingly.net/blog
  30. memeagora.blogspot.com
  31. metaatem.ne
  32. mir.aculo.us
  33. ntschutta.com/jat
  34. nubyonrails.com
  35. ola-bini.blogspot.com
  36. on-ruby.blogspot.com
  37. onestepback.org/index.cgi
  38. peepcode.com/products
  39. planetruby.0×42.net
  40. pragdave.blogs.pragprog.com/pragdave
  41. rubyblogs.org
  42. rubyforge.org
  43. ryandaigle.com
  44. tomcopeland.blogs.com/juniordeveloper
  45. twsummary.blogspot.com
  46. weblog.jamisbuck.org
  47. weblog.rubyonrails.com
  48. www.adaruby.com
  49. artima.com/buzz/community.jsp?forum=123
  50. chadfowler.com
  51. clarkware.com/cgi/blosxom
  52. cornetdesign.com
  53. danwebb.net
  54. igvita.com/blog
  55. jroller.com/obie
  56. juixe.com/techknow
  57. loudthinking.com
  58. oreillynet.com/ruby/blog
  59. pjhyett.com
  60. quotedprintable.com
  61. railscasts.com
  62. railsenvy.com
  63. robbyonrails.com
  64. rubyinside.com
  65. rubyonrailsblog.com
  66. rubyquiz.com
  67. slash7.com
  68. softiesonrails.com
  69. technorati.com/tag/ruby
  70. technorati.com/tag/rails
  71. therailsway.com
  72. urbanhonking.com/ideasfordozens

You can download the file Ruby-Rails.opml to easily import all of the above feeds into your own reader.

Since I’m sure there are plenty of other “must have” Ruby feeds and blogs that are not currently on my radar (no word of a lie, I’ve already added more since I put the list together), I openly invite you to write a small entry in your blog as well, and show us what feeds you subscribe to. Please link back to this original post, or I won’t be able to easily find your answer. Consider it a sort of Ruby and Rails feed survey.

And since we’re on the topic, and the amount of feeds that I follow is dramatically reduced now, I’d like to extend an invite for you to do the same thing with Python/Django, Haskell, and Objective-C, assuming you are into any of these communities respectively. Those are the languages that interest me the most and I’d like to start following a good selection of feeds on these topics. If you don’t wish to blog about it, or use the comment section below, you can always write me privately at acangianoATgmail.com, specifying if you are okay with me crediting your list to you. I’d like to collect and organize the most interesting ones in a “results” type of post.

I thank you in advance, as I think it’s an interesting “experiment” that can be quite useful, especially for those who are just starting to learn any of the languages above.

Give Ruby.NET 0.9 some love

Antonio Cangiano November 23rd, 2007

Ruby.net Logo

A few days ago Microsoft announced the final release of Visual Studio 2008 and .NET 3.5. As expected, .NET developers were impatiently awaiting such a major release, which introduces countless improvements and new features within the IDE, the framework and the compilers for the two main languages, C# 3.0 and Visual Basic 9. It didn’t take long for the news to spread across the blogosphere, with all sorts of details for those interested in the Microsoft platform.

What didn’t get much attention, as far as I can see, is the almost concurrent release of the first community edition of Ruby.NET (version 0.9). For us Ruby lovers, this is a significant event which deserves to be the focus of this post.

Back in July of this year, Queensland University of Technology (QUT) decided to entirely transfer the control and ownership of the project — that was initially sponsored by Microsoft Research — to the Ruby and .NET open source communities. The project was formerly known as Gardens Point Ruby.NET and the first beta of the compiler was made available back in June of 2006 by the leaders of the project, Dr. Wayne Kelly and Prof. John Gough. Renaming the compiler was a choice that aimed to reflect the desire to make the project truly independent and open source; code from the community for the community. It is however reassuring to know that QUT’s staff (who has a solid track record of delivering compilers) continues to be heavily involved with the project and their commitment, along with the work of the community, has permitted the launch of this community edition release in the span of just a few months.

Ruby.NET 0.9 includes substantial improvements, and amongst the many bug fixes, it is worth mentioning the improved Ruby and .NET interoperability, the possibility to visually design Windows Forms application within Visual Studio, the creation of .NET delegates through Ruby blocks, and .NET sub-typing.

Ruby.NET should not be confused with IronRuby, the alternative project I mentioned in a couple of posts, a few months ago. There are several differences between the two projects, but I feel that the two strongest distinguishing factors at this stage are the maturity and, I suspect, the affiliation of the projects. IronRuby is hosted at RubyForge but it’s still in pre-alpha mode, but no files have been released to date on RubyForge (albeit you can grab the code directly from its repository). Ruby.NET on the other hand, is at version 0.9 and is almost production ready. The final test — being able to run Rails — has not been passed yet, but it is clear that the project is getting closer and closer to a production quality 1.0 release. Furthermore, Dr. Kelly is open to work together (w.kellyATqut.edu.au) with those who intend to use the compiler for production purposes, as a form of showcasing examples of real world usage.

From an affiliation and legal standpoint then, IronRuby as a Microsoft project, is released under the Microsoft Permissive License, while Ruby.NET can be considered fully open source and independent from any vendors at this stage (and it has a BSD license). Depending on how you see this, it can either be an advantage or a drawback.

When discussing languages such as Java and C#, it’s rarely the JVM or the CLR (Common Language Runtime) which is the subject of harsh criticism, but it’s rather the language itself, for its verbosity, complex design patterns required to solve simple tasks, or its lack of advanced features, in the eyes of the experienced programmer who has experimented with Ruby, Python, Lisp, Haskell, Erlang and similar languages. In response to these needs, the industry has reacted with a couple of trends. The first approach is that of using a common virtual machine and also offering a handful of advanced but less common languages for it. Ruby.NET, IronRuby, IronPython, JRuby and Jython are all examples of this. At least in theory, this offers developers the possibility to program in their favorite language while still integrating their code with the existing one, and relying on “enterprisey” runtimes, frameworks and libraries that are accepted also by the least adventurous IT managers.

The second trend, adopted by both Microsoft and Sun is that of improving upon the main promoted languages, C# and Java respectively, by integrating functionalities and programming paradigmas taken from functional, distributed and research languages. The two approaches are somewhat complimentary but they end up meeting asymptotically when advanced, research, “toy” and less common languages become more “real” and are fully integrated on the Java and .NET platforms, and mainstream languages like C# become advanced and sophisticated enough to please the most refined developers.

This convergence is harder in practice, especially if we get into the topic of side effects and purely functional languages. But for mixed paradigm languages like Ruby, the advantages deriving from projects like Ruby.NET or JRuby are clear. As a Technical Evangelist, for example, I interact with many consultants and their most frequent question is always about suggestions on how to introduce Ruby into environments that are typically against anything new and “not yet proven”, especially if open source. For shops that heavily rely on Java or .NET, a production ready JRuby or Ruby.NET is a free ticket to the introduction of Ruby within the company, without requiring too many changes, risks or raising any alarms in conservative settings. In the case of Ruby.NET, it works with Mono too, so it doesn’t have to be limited to Windows either.

Let’s give some love to this important project, as it may help us to soon write Rails applications which seamlessly interact with ASP.NET, or visually design nice desktop ones whose program logic is powered by Ruby (and we all know what a boost in productivity that can be).

I invite you to blog about the release of Ruby.NET 0.9 and if you know at least a bit of Ruby or C#, to contribute to this very promising project. You can start by reading the page for the contributors and the PDF paper Ruby.NET: A Ruby Compiler for the Common Language Infrastructure for an architectural overview of the implementation.

Guide to setting up the IBM Ruby and Python drivers for DB2 on Linux (32 or 64 bit)

Antonio Cangiano November 14th, 2007

IBM provides the community with, among others, Ruby and Python open source drivers for DB2 (more exactly IBM databases). Ruby has a gem that packages the Rails adapter for DB2 and its prerequisite driver. As a result, the easiest way to get the Ruby driver for DB2 is to install the ibm_db gem through rubygems. The Python driver is instead currently provided as a tar.gz archive of source code. In both cases, on Linux, the installation builds the binary from source. This procedure is supposed to be very straightforward and user-friendly, and as long as you’re aware of the prerequisites and a few important steps, you can be up and running in no time. Unfortunately, if you aren’t aware of these things, as often happens with Linux, you may end up spending a good deal of time trying to figure out what’s wrong with your environment and setup procedure. This short - largely step-by-step - guide aims to resolve this, by providing you with clear instructions for setting up both the Ruby and Python drivers, respectively, for DB2 on Linux. The instructions below are tailored for Ubuntu 7.10 and its variants (including for example Kubuntu 7.10, 32 and 64 bit), but the same principles can be applied to other distros as well.

Prerequisites

Depending on which of the two drivers interests you, you will need to have Ruby or Python installed, along with a modern version of DB2 (e.g. 9.1.2 or 9.5). Please note that if you are still using DB2 Express-C 9.1, FixPack 2 or greater is required, so make sure that you grab the latest FixPack, FP4. For everyone else, you can get DB2 Express-C 9.5 from the official site for free. Please also note that if you were to run the DB2 9.5 setup on (K|X)Ubuntu 7.10 out of the box, you’d get an error similar to the one below.

ERROR:
 The required library file libstdc++.so.5 is not found on the system.
ERROR:
 The required library file libaio.so.1 is not found on the system.
 Check the following web site for the up-to-date system requirements
 of IBM DB2 9.5
  http://www.ibm.com/software/data/db2/udb/sysreqs.html
 http://www.software.ibm.com/data/db2/linux/validate
/home/antonio/Desktop/exp/db2/linux/install/../bin/db2usrinf:
error while loading shared libraries: libstdc++.so.5:
cannot open shared object file: No such file or directory
[: 609: 0: unexpected operator
/home/antonio/Desktop/exp/db2/linux/install/../bin/db2langdir:
error while loading shared libraries: libstdc++.so.5:
cannot open shared object file: No such file or directory
/home/antonio/Desktop/exp/db2/linux/install/../bin/db2langdir:
error while loading shared libraries: libstdc++.so.5:
cannot open shared object file: No such file or directory
DBI1055E The message file db2install.cat cannot be found.

Explanation:  The message file required by this
script is missing from the system; it may have been
deleted or the database products may have been loaded
incorrectly.

User Response:  Verify that the product option containing
the message file is installed correctly.  If there are
verification errors; reinstall the product option.


To prevent this, please install DB2 with its prerequisites:

$ sudo apt-get install libstdc++5
$ sudo apt-get install libaio-dev
$ sudo ./db2setup


When the DB2 Setup Wizard prompts you for the type of installation requested, ensure that you select “custom” and then, when prompted with the “Features” screen a couple of clicks later, select “Base application development tools” under the section “Application Development Tools” (the check box should switch from gray to white and be marked off). You will need these for building the Ruby and Python drivers during the installation. You can of course install them later, by running the setup again and choosing the “Work with existing” button in the launchpad, but if you’re installing from scratch, it’s easier to do it right the first time.

You can install Ruby or Python any way you prefer, but on Ubuntu (with the Universe repository enabled) you can install the required essential compiler tools (remember, on Linux, unlike Windows, the driver binaries are built from source), Ruby and Rubygems by running:

$ sudo apt-get install build-essential
$ sudo apt-get install ruby-full rubygems


If you are interested in Python, this comes already pre-installed on Ubuntu. Not all variations of Ubuntu however have the python2.5-dev package installed (I believe Kubuntu does), so just to be on the safe side, if you want the Python driver to be installed, get this development package by running:

$ sudo apt-get install python2.5-dev


Installing the Ruby driver for DB2

Now that you’ve ensured that your system has the proper requirements installed, the Ruby driver installation should be quite straightforward, thanks to the gem packaging system. Assuming you are installing it with an arbitrary user account (as opposed to the db2inst1 account), you will need to run the following commands, which will also take care of letting the compiler know where the current DB2 instance is located:

$ . /home/db2inst1/sqllib/db2profile
$ export IBM_DB_DIR=/home/db2inst1/sqllib
$ export IBM_DB_LIB=/home/db2inst1/sqllib/lib
$ sudo gem  update
$ sudo gem install ibm_db --include-dependencies


The last command should prompt you with a few options, please select the latest version of the ibm_db gem with a “(ruby)” next to it (usually option 1), since you are building on-the-fly rather then deploying a Win32 binary.

Installing the Python driver for DB2

In order for you to install the Python driver, you will need to grab ibm_db.tar.gz that contains the 0.1.0 version of the source code. Don’t be afraid of the version number though, despite being at a beta level, it’s a pretty solid driver which has benefited a lot from the maturity of the IBM API used by the PHP and Ruby ones (from which the Python driver was ported). Once you’ve extracted the archive in a given folder, from the shell, enter into that folder and run the following commands (do not worry about several warnings which appear during compilation).

$ . /home/db2inst1/sqllib/db2profile
$ export IBM_DB_DIR=/home/db2inst1/sqllib
$ export IBM_DB_LIB=/home/db2inst1/sqllib/lib
$ sudo python setup.py build
$ sudo python setup.py install


Connecting to the database

Now that at least one of the two drivers is installed, run a quick check to verify that the setup went fine and that you can connect to a database from Ruby or from Python. You can use any database, but if you are new to DB2, you may want to use the sample database called SAMPLE. To create it from your shell run the following:

$ sudo su db2inst1
$ bash
$ db2sampl


Inserting a couple of exit commands allows you to leave the Bash shell first, followed by the instance user db2inst1’s environment. Since you’re now back in the shell as a regular or arbitrary user (not as db2inst1), you’ll need to source the db2profile first, exactly as you’d do if you had just opened a new shell. You may want to consider inserting the following instruction in your shell profile as well if you plan to use the driver regularly.

$ . /home/db2inst1/sqllib/db2profile


Having performed this step, Python users can just run the python command to start the interactive shell, while Ruby users will have to require rubygems as well by running:

$ irb -rubygems


If you’d like to have this set in the profile of your shell as well, you can insert within it the command:

$ export RUBYOPT=rubygems


Ruby users can at this point run the following script interactively (insert one line at a time in irb):

require 'ibm_db'
conn = IBM_DB::connect("sample","db2inst1","mypassword")
sql = "SELECT * FROM SALES"
stmt = IBM_DB::exec(conn, sql)
while (row = IBM_DB::fetch_assoc(stmt))
  p row
end


The output should be a list of hashes, one for each record. Unlike in Python, in Ruby if the connection fails, the IBM_DB::connect method will just return false and not an actual error. The same is true for the IBM_DB::exec method. In such cases, you can run IBM_DB::conn_errormsg and IBM_DB::stmt_errormsg to gather further information on what caused the problem.

For those using the Python driver, you can establish a successful connection and retrieve a record from the Sales table by running the snippet below. The output will be a dictionary whose keys are the names of the columns in the table.

import ibm_db
conn = ibm_db.connect("sample","db2inst1","mypassword")
sql = "SELECT * FROM SALES"
stmt = ibm_db.exec_immediate(conn, sql)
print ibm_db.fetch_assoc(stmt)


Naturally, there is much more to the usage of this IBM API which is common amongst a few languages, but the essentials of working with it need to be part of a different guide. While I go about writing that, feel free to take a look at the PHP and DB2 reference which documents a lot of shared functionalities and naming conventions.

« Prev - Next »