JRuby trunk – issues with JDBC connectivity

2007/12/28

Following the book on JRuby I am discovering small differences when trying the examples. After installing activerecord-jdbc gem which is available in version 0.5, the shoplet application fails with Rails 2.0, as soon as you click on the ‘About your application environment’ link.

=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready.  TERM => stop.  USR2 => restart.  INT => stop (no restart).
** Rails signals registered.  HUP => reload (without restart).  It might not work well.
** Mongrel 1.1.2 available at 0.0.0.0:3000
** Use CTRL-C to stop.

Processing InfoController#properties (for 127.0.0.1 at 2007-12-23 23:13:25) [GET]
Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--9791be23205677745e457b5bf62c50eba6e3813f
Parameters: {"controller"=>"rails/info", "action"=>"properties"}
Exception in thread "Ruby Thread11043409" java.lang.NoSuchMethodError: org.jruby.runtime.builtin.IRubyObject.setInstanceVariable(Ljava/lang/String;Lorg/jruby/runtime/builtin/IRubyObject;)Lorg/jruby/runtime/builtin/IRubyObject;
at JdbcAdapterInternalService.set_connection(JdbcAdapterInternalService.java:122)
at JdbcAdapterInternalServiceInvoker$set_connection_FS1.call(Unknown Source)
at org.jruby.runtime.callback.FastInvocationCallback.execute(FastInvocationCallback.java:55)
at org.jruby.internal.runtime.methods.SimpleCallbackMethod.call(SimpleCallbackMethod.java:70)
at org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:158)
at org.jruby.runtime.CallSite$ArgumentBoxingCallSite.call(CallSite.java:103)
at org.jruby.evaluator.ASTInterpreter.fCallNode(ASTInterpreter.java:1092)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:345)
at org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:626)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:293)
at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:168)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:147)
at org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:158)
at org.jruby.runtime.CallSite$ArgumentBoxingCallSite.call(CallSite.java:76)
at org.jruby.evaluator.ASTInterpreter.vcallNode(ASTInterpreter.java:1734)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:474)
at org.jruby.evaluator.ASTInterpreter.blockNode(ASTInterpreter.java:626)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:293)
at org.jruby.evaluator.ASTInterpreter.rescueNode(ASTInterpreter.java:1499)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:442)
at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:168)

I found out that there is newer version of activerecord-jdbc, which is also renamed to activerecord-jdbc-adapter. It is important to uninstall the old gem as well as install the new one, otherwise the application will not work.

$ jruby -S gem install activerecord-jdbc-adapter
Successfully installed activerecord-jdbc-adapter-0.7
1 gem installed
Installing ri documentation for activerecord-jdbc-adapter-0.7...
Installing RDoc documentation for activerecord-jdbc-adapter-0.7...
$ jruby -S gem install activerecord-jdbcmysql-adapter
Successfully installed jdbc-mysql-5.0.4
Successfully installed activerecord-jdbcmysql-adapter-0.7
2 gems installed
Installing ri documentation for jdbc-mysql-5.0.4...
Installing ri documentation for activerecord-jdbcmysql-adapter-0.7...
Installing RDoc documentation for jdbc-mysql-5.0.4...
Installing RDoc documentation for activerecord-jdbcmysql-adapter-0.7...

$ jruby -S gem list activerecord

*** LOCAL GEMS ***

activerecord (2.0.2, 1.15.6)
ActiveRecord-JDBC (0.5)
activerecord-jdbc-adapter (0.7)
activerecord-jdbcmysql-adapter (0.7)

$ gem uninstall ActiveRecord-JDBC
Successfully uninstalled ActiveRecord-JDBC-0.5
miroslav-adamys-macbook-pro:shoplet miro$ gem list ActiveRecord-JDBC

*** LOCAL GEMS ***

activerecord-jdbc-adapter (0.7)
activerecord-jdbcmysql-adapter (0.7)

After this, everything works and shoplet connects to database – as you can see from the console log.


iPod Touch: which to choose – 8GB or 16GB ?

2007/12/27

A friend asked me this question today – and here is my take on it (slightly expanded) answer to his email :-) :

Hi Shane
I have purchased the 8 GB because I had no choice – the 16 GB versions were sold out at the Futureshop at the time, and I was too impatient to wait for two more weeks until delivered from Apple Online store :-) .

From usage perspective – whether 8 GB is enough really depends how much video you plan to put on. I am not watching too much video content other than YouTube via WiFi (which is streamed and does not take any space on the device), so for me 8 GB is enough. Main reason why I am not watching video is that I usually listen while walking or driving and one cannot walk very far while concentrating on the screen without bumping into something (I tried that). With driving it is even worse (I did NOT try this one …). If you are willing to sit while watching, the image quality of the device is surprisingly good.

I usually carry 3-5 audiobooks on it (which adds up to about 2 GB), lots of podcasts (TWIT, Macbreak, Security Now, Windows Weekly, HanselMinutes, and few Ruby podcasts) which adds up to another gig or so – as I have only few last episodes to listen to.

In addition to that, I carry about 4 GB is music in case I need something for the treadmill or at work for background noise canceling. It works great. So far, even the most annoying/loud voice from cubicle next to me had not have any chance to compete with Rammstein :-) . I found out that keeping about 0.5 – 1 GB free is good idea – in case there is larger chunk to sync. I also use the iTouch as PDA, but even with few hundreds contacts and calendar events, the size of data is very small.

Having 16 GB would only allow me to have more music – I cannot really subscribe to more audio podcasts because of time limits to listen and having more than 4-5 books adds little value. Even with 16 GB version I would not be able to have ALL my music with me – so the main advantage of not having to select which music you carry with you could not be achieved anyway.

But of course, YMMV – and if the above sounds like rather long rationalization of the choice I have already made and cannot change, well – maybe that is not quite wrong either. But it certainly makes me feel good about my selection :-) . Besides the price difference between 8 GB and 16 GB is also a thing to consider.

From all the above it looks like 8 GB is sufficient and better deal than 16 GB. Right ? Well – there is a possible catch. When the new iPhone / iTouch SDK will be available (Jan/Feb 2008), it is VERY reasonable to expect that lots of new applications for iPhone/iTouch will be available soon. The most obvious choices will be an offline reader for PDF formats, mail program that will allow read and process your emails offline, News and Feeds offline readers and various forms of Google-gear like applications for various data management with disconnected mode and synchronization via iTunes/http+WiFi. All these have one in common: they will need and utilize local storage. With that in mind, maybe the additional 8 GB can be eventually very valuable and can make real difference how useful the gadget will be.

Your question about using for couple of hours without interaction – sure, no problem. Just make long enough playlist and you never have to touch your iTouch :-) . Longest time I did that was 4 hour walk back in November, with only one break to pause it while buying coffee, so that I could understand what the friendly Timmi’s employee was asking.

Good luck with your choice. But I would still listen to Steve’s keynote first – 15th Jan is pretty close. Chances are there may be announced updated version of iPod for the same price – which usually causes price drop at the previous models.


Installation of Mongrel gem on JRuby

2007/12/23

I bought the Ola Bini‘s eBook on JRuby and started to work through the examples. The installation of the Mongrel gem in JRuby (trunk revision 5341 fails with the following error code:

$ jruby -S gem install -y mongrel
INFO:  `gem install -y` is now default and will be removed
INFO:  use --ignore-dependencies to install only the gems you list
Building native extensions.  This could take a while...
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
ERROR:  Error installing mongrel:
	ERROR: Failed to build gem native extension.

This error is logged in JIRA with id JRUBY-1771Workaround (possibly applicable for other gems is to explicitly specify the plaform:

$ jruby -S gem install -y mongrel --platform jruby
INFO:  `gem install -y` is now default and will be removed
INFO:  use --ignore-dependencies to install only the gems you list
Successfully installed mongrel-1.1.2
1 gem installed
Installing ri documentation for mongrel-1.1.2...
Installing RDoc documentation for mongrel-1.1.2...


Fix for the stalled downloads in Leopard

2007/12/22

I was experiencing the occasional weird behaviour on downloading large files in Leopard: the download would stall, but after stopping/restarting (which can be done in Safari and iTunes), the download would continue. It was not very consistent, and I suspected the NAT router or even Rogers – some sites were occasionally having this problem, while other sites would not.

While playing with JRuby over the weekend, this happened again and pretty much prevented the gem installation – because the multi-megabyte gem index would not download from http://gems.rubyforge.org/. Strangely enough, same download would work on Tiger, on Linux and on Windows using same router – which pretty much excluded router as a cause.

I found simple fix here – big thanks to Chris D Searle. Run the following:

sudo sysctl -w net.inet.tcp.rfc1323=0

(it replaces the default value of 1)

I do not know all the details of the fix – it switches off some TCP window optimization which may have been the cause of the problem. More on the parameter and how to set it in variety of OS-es can be found in the TCP tuning handbook.

To make change permanent, create (or edit) the file /etc/sysctl.conf with the content:

net.inet.tcp.rfc1323=0

Joel’s gems

2007/12/20

One of the most readable, original blogers out there, writing on software development practice and techniques – Joel Spolsky – published an excellent 3 part Talk at Yale: Part1, Part2 and Part3.

You will find out:

- what two computer science courses were most useful in his university studies
(one that was not really a comp-sci and one he decided to drop)
- why is it tough to be an in-house programmer
- why is the quality of many in-house systems so bad
- what is this “quality thing” anyway
- why is specification futile

Highly recommended.


Great Spring blog

2007/12/19

in case you have not noticed – Interface21 aka SpringSource (great name change, btw) runs a blog with lots of hidden treasures inside.

Recent article describes new addition to Spring portfolio which is territory within my “watched space”: enterprise integration. See the blog entry for more.

If you are in corporate space that is keen on “standards”, the comparison of Spring vs EJB3 is very good article as well. Not that EJB would matter too much these days (IMHO) – but a nice read nevertheless.

Recommended.


An advice to a fellow developer – 2

2007/12/14

The part 1 of the post is here.

— continuing —

So back again – different coffee shop (Starbucks at Carling), freshly charged battery, Grande Latte and no internet connection (which means no distractions from emails and the Web) – here we go again, part 2.

If I should single out one or two technologies that I think I have neglected and should have paid much more attention to it would be the Web trio of HTML/JavaScript/CSS as one and the SQL as second.

Let’s look at the Web trio first. It sounds weird – how can THIS be neglected, everybody knows HTML, right ? Wrong. What I mean is to have deep understanding of the HTML markup, so that you know when to use (and when not to use) tables, how to properly layout your page, fully understand the possibilities and implications of div and span, the box model and what can and cannot be done with styles and CSS. And I do not mean using Dreamweaver like tools or (god forbid) Frontpage to create the markup, I mean actually writing the markup. Ability to produce and maintain clean markup is very important for application lifecycle and evolution. Clean markup is at the beginning of every good looking site. Even if you get the first mockup version from your  designer, it is up to *you* to componentize the pages, convert them to JSP or ASP.NET or RHTML (or what server side stack you are using). And it is up to you not to mess it up in the process.

The CSS is trickier – it is considered to be “designer’s thing” between us, developers. And designers, they are those slightly weird artistic folks with Photoshop magic lassos and Macbooks that just somehow make things look great for no particular reason. They are so different species and us, developers who recognize 16 basic colors and do not mind using Times New Roman for everything will never be able to match their skills … This is partially true. It is hard to learn creative design. But even if you never will, it is still important to understand ENOUGH of CSS to know what can or cannot be done with it, so that you can maintain and enhance the design of the page without messing up the styles or the markup. You would not believe how big PITA it is to go through 100+ pages just to extract hard-coded font and size references, inserted there by the previous contractor who did not know any better … Do not do that to the guys that will maintain the app after you, it is very bad thing for your karma.

The HTML/CSS/JavaScript is also very important because it is the third platform, and despite JavaFX, SilverLight, Apollo and Flex flexing the muscles (pun intended) and a lot of buzz about the RIA, the traditional web technologies it is not going to go away any time soon. Listen to David H. Hansson interview for more. This stack is all you need to create Firefox extensions, new social network apps (like Facebook) and it will be important for the iPhone/iTouch and alike devices.

JavaScript is particularly tricky: the language itself is actually great and very powerful but got very bad reputation. Partly because it makes very easy to write very bad code, but mostly because many people using it have not enough experience or programming background and produce terrible mess. Not enough good books also contributes. I mean there are many books on JavaScript, but most of them bad or mediocre. We really need to learn or re-learn JavaScript and use it the proper way. I personally would pick JavaScript against Visual Basic any time.

The reason that I mention SQL is because most developers know just one part of it – how to select some data, insert or update. There is another part – that deals with creating tables, indexes etc and is usually “owned” by the professional DBA’s. Which is OK if you have one (and, btw, NEVER EVER trust a “DBA” that cannot create your database tables by ssh-ing to console on the server). In absence of dedicated database pros, many developers rely on GUI tools to get to initial stage of database structure, create tables, views etc. Problem in this that GUI tools cannot be version controlled and without having actual script that creates your database from scratch and loads all test data, your project environment is incomplete and you can never create good enough unit tests that will work. I have seen this to be an issue so many times that it is not even funny. Look at the migrations in Rails and how elegantly these guys solved the problem for Ruby world.

But enough about technologies, I’d like to add few closing more general remarks and mention some good books and sites.

Software development is a discipline somewhere between engineering and creative writing (it stubbornly resists applications of engineering methods like precise estimations :-) ). Same as with writing, similar path will lead you to improvement of your skills. If you want to become great writer, read a lot. Read and dissect the text, think about the storyline, plot, setup, way how the dialogs are constructed and words used. If you want to become great developer, you also need to read a lot – not only books (we will get to that), but also code. Reading good code is crucial and is very intellectually stimulating. Reading means understanding how it is designed, thinking about the relations, architecture, idioms and noting nice tricks and howtos. As with literature, the ease of reading will depend on the language (you are native Java speaker) and your preferences / predispositions. In both cases it is important to select high quality reading material. Fortunately, that is easier that it looks like as with books because there is a consensus how should good code look like. In Java world, going through the source code of Spring Framework will teach you a lot. Look at the source code repositories that do some pre-selection of the projects such as CodeHaus rather than general sites such as SourceForge. For .NET world, look at the CodeProject, select one of the highly rated contributions and chances are very high that you will be OK.

Last but not least – few books and sites.

One great book that would be IMHO just right for where you are at is Refactoring from Martin Fowler. This is very easy way how get the spirit of the design patterns – IMHO better than reading the Gang of Four as the start – which is absolutely a great book to read, but maybe not the ideal to start with.

There few great books covering the “craft” of software development. The classic Pragmatic Programmer (which started the whole company) and Software Craftsmanship will give you more good advice on career of software developer than you may ever need :-) . from Microsoft camp – even bigger classic  is Code Complete.

As for sites and blogs – there are way too many blogs and feeds of interest, email me, I will send you my blog feed from Google Reader. From programmer’s news I am keeping and eye on Dzone, InfoQ, TheServerside.com and theserverside.net. They may be not the best, but I found out that to actually get some time to do some coding and code reading, one must limit the news consumption …

Thats about it.

Happy coding, may the Source be with you ;-)

PS: Thanks to all who managed to read until here and even bigger thanks for emails and comments to the part I. Your feedback is appreciated.


An advice to a fellow developer – 1

2007/12/12

We are recently interviewing quite a lot in anticipation of the great things coming. It is sort of similar task as we did year and something ago, but I enjoy this round much better. This time, rather than “we have to assemble the project team ASAP”, we have the luxury of longer term view and focus more on hiring the people that will be great match to the company culture, will be with us for longer period and will grow with the company.

What I really like about interviews is an opportunity talking to smart people, who are usually very interested and passionate about technology. In every one of our meetings, I like to give the candidates a good opportunity to ask questions, not only to answer them. One of questions I got few times, is “given my resume, what technology, programming language, platform, area etc would you recommend me to look at to make progress ?”.

I answered it, but after doing it second time, I got back to reviewing and expanding my answers. And because the “given resume’s” were not too far apart, I decided to answer it one more time this way. So here we have, Joe Developer, a solid intermediate software engineer with good foundation and few years of Java under his belt. Joe knows the platform quite well, has done some Web application (JSP) but not too large variety of them, and also used Java in non-Web environment, e.g. GUI or some networking stuff. Joe did some scripting, a bit SQL and some basic system administration, but so far did not encounter the “true enterprise” technology jungle.

So, what should I look at, asks Joe ?

Given your solid Java background, build on your strength. Java may not have the sexappeal of the “language of the week” (which seems to be Haskell or F# or Erlang …), but is solid, very dependable with good market penetration and it is here to stay. Making Java the center of your skillset is a good choice. If you have not look at Java 5, do it. I mean look at the NEW things available like generics, annotations, new API’s for concurrency, etc.

In Java Enterprise space, one single most important thing happening is Spring framework. There are way too many frameworks for anything you can imagine so it is risky bet to pick one and rely on its longevity – but Spring is safe bet. Currently in version 2.5, it pretty much sums up all important trends of 2004-2007: inversion of control, aspect oriented programming, design by interface, test driven development, agile design techniques support, extending Java platform by Domain Specific Languages. It does NOT implement everything, but it provides a glue, platform that can be found everywhere. And you can find it pretty much everywhere – from Web applications to rich clients. Solid understanding of principles it represents will make your programs easier to understand, integrate, test and enhance. Spring was even influencer of Java standards – the new, radically different EJB 3 is (roughly speaking) Spring plus ORM – not that I had too high opinion about this EJB idea :-) .

In Web application development – if you stay on Java platform – Spring has also much to offer. The Spring own MVC implementation is one of the very clean and extremely flexible approaches available for building your Web layer. Pluggable view technologies (you can mix and match the JSP/JSTL, Freemarker, Velocity, PDF), support for workflows (via Webflow), availability of security enhancements (Aecegi) makes it worthy exploring.

But what else than Java ? There are so many other languages – which are worth the time investment ? My take on this that you should not learn a new language that does not change your views about programming. Unless, of course you have very convincing reason to do so – like having is a long term project with dare need of this skill – this is how I learned VBA back in 1993.

There is a lot of “software enlightement” value to be found in exotic languages, that are often impractical and unsuitable for commercial skill marketplace, such as Lisp, Smalltalk or Prolog. Lot of fun and little money. Good middle ground between educational value, beauty and commercial usability is Ruby. It is real fun to use, gives you power of Perl (without the cryptic syntax), elegance of Python (with added cleanness and consistency). Ruby is also available in JVM implementation (JRuby) and offers an inroad to something really novel and interesting – Rails.

From this point of view, mastering “the other platform” (.NET) will not teach you too much. The C# 2.0 is so close to Java that learning it for experienced Java programmer is a no-issue (of course, mastering libraries and frameworks available is completely different story). The really new additions into Windows development toolkit with .NET framework 3.x are features as LINQ (in many areas – SQL, XML) and WPF (as replacement for Winforms ??). Certainly interesting, but they are often “me too” solutions than something really new. They are not bad, if your projects bind you to .NET platform, they are certainly worth of learning – but IMHO the real fun is elsewhere.

Unfortunately, one cannot avoid the feeling that not too much innovation is coming from Redmond in last couple of years – just check Zune vs iPod, Vista vs OS-x, Windows Live vs. Google offering etc. On the positive side, there is strong market demand for Windows based solutions, from Enterprise point of view, their server products are often better than their reputation. SQL Server 2005 has great price/performance ratio and is generally very good database server, development environments (VS 2005/2008) and comparable and close to what the Java world has (Eclipse, Idea, Netbeans).

In Web development on Windows – aka ASP.NET – an experienced Java developer will feel both surprised (by very rich controls offering) and limited (by not so great pagecentric postback-based navigational model and lack of usable MVC implementation). Compared to richness of Web framework implementations in Java, this is very sobering experience. Currently, even Microsoft seems to feel the need to address this – see Scott Guthrie and first Beta versions of true Model-View-Controller for ASP.NET. It’s about time …

What you need to be aware of is that in long term, Microsoft loves to do these right-angle-technology-turns (RATTs) that will invalidate your investment into mastering particular technology. I learned it the hard way – none of the expertise in MFC and C++, ATL or COM/DCOM has too much market value today. As Joel On Software outlines, I am not alone (read more here). And I have the nagging feeling that maybe transition from Winforms to WPF may be yet another RATT. But I may be wrong, I have not really spent enough time in WPF (unlike in Winforms). To sum it up – from opportunities perspective, Microsoft technologies are good investment and tradeoff for pretty much guarantee of more opportunities coupled with (usually) less fun.

Both Java and C# are language of similar “altitude” or expressive power. Quite often trying to rise your altitude and work with very high level language is quite eye-opening experience. There are many scripting languages out there, I would pick two. First is (obviously) already mentioned Ruby. If you want to stay closer to Java integration, look at Groovy – an in-JVM high level scripting language, with not as pretty syntax, but easier to intermix with Java – although as we know, beauty is in the eye of the beholder. Besides, the Groovy folks seem to be copying implementing ruby-esque features like crazy, including the killer app, which is in Groovy named Grails :-) .

Hmm, looking back, this post is getting pretty long and battery in my MacbookPro is running low (I am typing this in Zavida Coffee which has free WiFi but only few tables where you can plugin your power supply. I guess I finish it tomorrow.
– to be continued –


Absurdity of the DMCA

2007/12/11

If the world of physical objects would governed with the same rules as the Digital Millennium Copyright Act does impose on all things digital, scissors would be illegal and you could end up in jail for manufacturing, and maybe even owning or using them. Crazy ? Well, see this presentation and judge for yourself.

This “law” is currently impacting our friends south of the border only, but it is very real that it will soon become a law in Canada as well.

If you think that DMCA is a bad idea, here is couple of things you CAN do about it.


How to show preview for CHM file in Leopard

2007/12/10

The CHM files (Microsoft compiled HTML help files) are often used for eBooks. They are readable on OS-X using excellent open source CHMOX application. If you want to get more useful preview in OuickView than the not very helpfull static icon, get this plugin.

Download here
https://sourceforge.net/project/showfiles.p…group_id=211847

How to install it: Unzip it, take the proper package for your system (the ZIP file contains several architectures, on modern Intel-based Mac’s you want to use x64), put it inside

/System/Library/Quicklook

and enjoy !

Big thanks to the developer Qian Qian – whoever that is.


Follow

Get every new post delivered to your Inbox.