Charles Engelke's Blog

May 26, 2009

An “Incident” on the Highway

Filed under: Uncategorized — Charles Engelke @ 9:22 am

Laurie was driving, and I was working on my laptop.  We were on our way down to Sanibel Island in south Florida when suddenly there was a loud bang and a bright flash, and Laurie quickly pulled over to the side of I-75.  We’d hit (actually, we think we’d been hit by) this:

Jack Shaft

Jack Shaft

That’s apparently a jack shaft from a tractor-trailer; both Laurie (former Army transportation officer) and the Highway Patrolman agreed on that.  This piece is less than half of what hit us; we broke it, and the other piece is even larger and heavier.  This part is about two feet long and about 25 pounds.

It shredded a tire, cracked all the way through the wheel rim, and because of how it hit the car, made the two passenger side airbags deploy.  It similarly disabled four other cars.  The truck it fell off of apparently kept on going.

Being hit by airbags is no fun.  Four days later my hearing’s still a bit off; the first day I could hardly hear at all.  I’ve got a bruise on my arm where it hit me, and I was really shaken up the rest of the day.  Worst of all – we spent all most all Saturday of our long weekend in Sanibel at the car dealer instead of the beach, and we’ve got to run around to insurance adjusters, dealers, and an audiologist today.  And I’ve got to catch a flight this afternoon.

Advertisement

May 6, 2009

Rails Metal, Rack and Sinatra

Filed under: Uncategorized — Charles Engelke @ 2:17 pm
Tags: ,

Great talk by Adam Wiggins here at RailsConf.  But this post is more a reminder to me than a synopsis for you.  Find out more at adam.blog.heroku.com and railscasts.com/episodes/150-rails-metal.

Use Named Constants

Filed under: Uncategorized — Charles Engelke @ 12:53 pm
Tags: ,

This morning’s keynote speaker at RailsConf mentioned, in passing, working on some code without named constants.  When something needed to be changed you’d have to find the right instance of it and change it, and hope you changed it everywhere you needed to. It’s elementary that you should use named constants for just that reason.  But this story reminded me of an early programming experience I had with FORTRAN IV on a CDC 6400.

You see, when you write a 1 in your code, you’re kind of using a named constant.  That 1 is is the name of a value (that happens to be one, or 000000000000000000000000000000000000000000000000000000000001 in bits on the 6400).  We always expect that the value of the constant named 1 has to be one.  But in my freshman programming class, I managed to change the value of 1 in my source code to zero.  FORTRAN programmers will probably know how I did that.

This made for a wonderfully oddly behaved program.  The first time through a loop always worked, later ones always failed, and it didn’t matter what values I set before each run.  The story had a happy ending: I learned how to read core dumps and a bit more about machine language, and moved on to other programming languages that make it harder to change the values of literal constants.

May 5, 2009

Testing Your JavaScript

Filed under: Uncategorized — Charles Engelke @ 5:32 pm
Tags: ,

Test your JavaScript in a headless Java browser, as a normal Rake task.  I’m not going to put notes here (I was paying too much attention to write).  Instead, look for the presentation and the necessary plug-in at github.com/relevance/blue-ridge and thinkrelevance.com.  It looks very promising.

RailsConf Keynote

Filed under: Uncategorized — Charles Engelke @ 1:11 pm
Tags: ,

David Heinemeier Hansson is opening the conference, quite appropriately, and saying a lot of interesting things about the past and future of Rails.  The conference is going to post video of the keynote in a day or so, and I recommend watching it.  But what got me sitting up straight and listening more alertly was when he started talking about something else.  Requirements.

David says that programmers treat requirements as commandments from on high.  And that they shouldn’t do that.  The stakeholders aren’t are committed to the requirements as programmers think.  They know what they want, but they’d be just about as happy with a lot of other solutions, too.  And those other solutions might be a whole lot less expensive to provide.

His example concerns chocolate.  He’s got a sweet tooth.  Ask him for requirements to satisfy that sweet tooth, and he’ll specify top quality Belgian chocolates.  Meeting those requirements will take a lot of money and a lot of time.  Maybe that’s necessary.  But try offering a Twix bar right now for just a buck or so instead, and most of the time he’ll actually be happier with that.

The real key to programmer productivity is saying no to requirements as stated, and instead understanding what the stakeholders want to accomplish and opening negotiations with them on the best way to do that.  Requirements are a starting point to that.  They’re not handed down to us on stone tablets.

That means programmers have to be much more involved with stakeholders, and take more responsibility for the ultimate outcome of their efforts.  But they’re going to create a lot more value if they do that.

May 4, 2009

RailsConf 2009 Tutorial – Sinatra

Filed under: Uncategorized — Charles Engelke @ 7:31 pm

My second tutorial of the conference is called “A Hat Full of Tricks with Sinatra”.  Unlike the morning session on jRuby on Rails, I don’t have any specific plans on how I’d use what I learn here.  But the framework looks interesting to me, and I hope to get some good ideas from it even if I never use it for real.

We start by building the minimal “Hello, World” of Rack applications:

run lambda {|env|
[
200,
{‘Content-Length’ => “2”,
‘Content-Type’   => “text/html”},
[“hi”]
]
}

run lambda {|env|
[
200,
{‘Content-Length’ => “2”,
‘Content-Type’   => “text/html”},
[“hi”]
]
}

Put that in a file, like “config.ru” and run it with rackup, for example

rackup config.ru -p 3000

The “.ru” extension is for rackup.  You can call it “.rb”, but then you have to set more things up in the application because it’s actually running regular Ruby code, instead of being read and interpreted in a special context by rackup.

It’s starting out as a very hands-on tutorial, very basic.  But that’s what I want.  If it slowly builds from here, I’ll be happy.

Rack runs an application that is given an environment and emits a response.  The structure allows you to easily write “middleware”.  When Rack’s told to run an application, instead it calls your middleware which can do other things and eventually call your app.  This can be chained.  It’s a simple and powerful tool.

Okay, now getting into Sinatra.  Here’s the core of the application:

require ‘rubygems’
require ‘sinatra’

Huh?  Where’s the code?  That starts up the framework and gets it all working.  If you put those two lines in application and run it (with Ruby) it will start a web server on port 4567.  When you open that in a web browser, you’ll get a blurb for Sinatra and suggestions to proceed.

Want to handle a request to a particular path?  Here’s code that will respond to requests for the root URL and to /greet:

get ‘/’ do
“Welcome to my Sinatra server”
end
get ‘/greet’ do
“Hello!”
end

Nice and clean.  It can also respond to other HTTP verb requests in a similar way.

Now just create a subdirectory of your application directory called “views”, and put a file named “index.erb” in it containing HTML.  Change the code that responds to “/” to:

get “/” do
erb :index
end

Now when you run your application and get the root URL, the HTML in that index.erb file gets returned.  (ERB is “embedded Ruby” even though we didn’t bother to embed any in that HTML.

I’m really liking how this is set up.  Simple always appeals to me, but there’s a lot of power here without messing up that simplicity.

By the way, the sample Sinatra application I’m playing with works just fine under jRuby, too.

I do have one complaint about this tutorial.  It’s not well-structured or planned.  The speaker seems to think he can just open a terminal window and edit and run source code, and we’ll all have no trouble following.  But as soon as one thing is missed, the student has a hard time getting back in sync.  He needs to go slower, he needs to describe what he’s about to do and why, he needs to do it, then he needs to tell what he did and why.

He also needed to plan and rehearse every single example he was going to show.  Instead, he’s winging a lot of it.  The material is trivial to him, but when you’re teaching a class you’ve got to know ahead of time every single tiny glitch you’ll encounter and have to explain.

Another tutorial falls apart in the second half.

Diet Coke Must Die!

Filed under: Uncategorized — Charles Engelke @ 6:33 pm
Tags: ,

I’m here at RailsConf looking for a bit of cold, free, sweet caffeine at the break.  There are plenty of sodas, and they’re even the right brand – Coca-Cola.

But unless I want a lot of empty calories, my only choice is Diet Coke.  Which is drinkable, but only barely.  (Pepsi fans: don’t gloat.  No other brand of diet cola reaches even that level.)

This is a travesty because now Coke Zero exists.  Somehow they’ve managed to create a diet cola that really tastes like Coke (the only cola that has ever mattered)!  But you can almost never get it at a meeting or restaurant because they’ve got the old standby Diet Coke.  And Coca-Cola is fine with that because it helps in their goal to fill supermarket shelf space with several thousand different products all called Coke.

Coke Zero is a better choice than Diet Coke in every single circumstance.  Coca-Cola, you’ve got a responsibility to us – fix your advertising and branding and GET RID OF DIET COKE!  Let Coke Zero take off and fly!

And while you’re at it, get rid of Cherry Coke, Caffeine Free Coke with Lime and Splenda but without added Vitamins, and all those other stupid variations.  There are only two drinks worthy of the name “Coke” – Coca-Cola and Coke Zero.

RailsConf 2009 Tutorial – jRuby on Rails

Filed under: Uncategorized — Charles Engelke @ 12:06 pm
Tags: , ,

I’m starting this year’s RailsConf with a tutorial on jRuby on Rails.  I’ve fiddled with it a few times, and I have the distinct impression that it’s a more stable production platform than the regular Ruby interpreter.  But there are a few issues I’ve had.  I hope today’s tutorial will help me resolve them.

I’m not much of a note taker, so this (and other posts this week) will probably be pretty thin, with just reminders of core information tidbits I glean here.

The speaker is Nick Sieger of Sun Microsystems, and he’s put his slide desk online at his blog.  The link to the actual slides isn’t there (yet), so I won’t put it here, either.  It looks like he’ll probably soon put up a post with the link.

The talk is going to start from absolute zero.  Since I’ve actually installed and used jRuby (very casually) there will be some familiar stuff for me at first.

Download GlassFish, a Java application server we’ll be using.

Download jRuby, too (this is the latest production version as of today).

You’ll need the real JDK, too.

Install the JDK.  Add its bin subdirectory to your path, and set an environment variable named JAVA_HOME to the root of the JDK install.  Test it by running “java -version”.

Install jRuby by unpacking it anywhere you want.  Add its bin subdirectory to your path (he emphasizes adding it to the end of the path).  Test it by running “jruby -v”.  Run irb or other Ruby tools by prefixing them with “jruby -S”, as in “jruby -S irb”.

Run jRuby with the Java “server” VM with “jruby –server”.  That’s better overall performance, at the cost of slower startup.  You can pass a variety of Java arguments to the JVM with “jruby -J<argument>”.

Oh, you want jRuby at the end of the path so that its utilities don’t run when you want the regular Ruby ones.  So “rake” gives the regular Ruby rake, “jruby -S rake” gives the jRuby one.

jRuby has all the standard 1.8.6 Ruby things – the libraries, RubyGems, Rake, RSpec.  It’s also integrated with the Java libraries.  Go into jRuby’s irb, and type

java.lang.System.out.println “Verbose Hello”

It works!  Not that you’d want to do that, but I’m sure I’m going to want to use the Java cryptographic tools.

Install a bunch of needed gems (I had to be in a command shell with administrative privilege to do this in Windows 7):

jruby -S gem install rails mongrel jruby-openssl

Now, just create a Rails application with “jruby -S rails appname”.

Install ActiveRecord-JDBC or MySql or SQLite3 (or both):

jruby -S gem install activerecord-jdbcmysql-adapter
jruby -S gem install activerecord-jdbcsqlite3-adapter

Now fix your Rails application’s database.yml to point to the JDBC version of the appropriate database adapter.  For example, “adapter: jdbcsqlite3”.

Now here’s a trick I could have used (and will be using)!  Use embedded Ruby to have a single configuration file work for both jRuby and MRI.  Put this in database.yml:

<% jdbc = defined?(JRUBY_VERSION) ? ‘jdbc’ : ” %>
development:
adapter: <%= jdbc %>mysql

[I just noticed that WordPress is “fixing” my single and double quote marks, even in code.  It’s easier for me to tell you figure out that they’re really all straight quotes than to figure out how to get them in WordPress right now.]

And now create a Rails application in the regular ways.  Just remember to use “jruby” instead of “ruby”, and to prefix other commands (like rake) with “jruby -S”.

Found a bug (in jRuby? in Rails? hard to say, but probably either in Rake, or in a Rails Rake task): if your Rails application’s environment.rb specifies needed gems, you can usually install them with:

rake gems:install

But, if you use:

jruby -S rake gems:install

it says it works, but it doesn’t (“jruby -S gem list” doesn’t show them).  It appears that it installs these gems under MRI instead of under jRuby.  Of course, you can just manually install each needed gem with “jruby gem install”.  It’s just the Rake task that gets derailed.  Note that this happened under Rails 2.2.2, which is what our existing application under development is currently using.  I haven’t checked to see if it still happens in Rails 2.2.3 (the current version as of today).

You can speed up Mongrel under jRuby by removing the mutex it no longer needs.  You have to edit Mongrel’s source to do this.  Look for the block starting “@guard.synchronize” and comment it out.  You have to also set “config.threadsafe!” in your application’s appropriate environment file to have this help (or change it globally for Rails under jRuby by editing lib/initializer.rb there.

The speaker’s JRuby-Rack gem allows you to run any Rack-based application (like Rails) under any Java Servlet API server.  That sounds promising for production use.  I’ve got to learn a lot more about the Java server ecosystem to take advantage of it.

The talk is now really turning to ways an experienced Java shop can run Ruby on Rails well in their infrastructure.  There’s a lot of background I don’t have, so this can point me to the right place to start, but I can’t understand it well enough to use it as a result of this talk.

Lots of talk on Warbler – I don’t have the context to understand it now (or know why I should care).

Google App Engine with jRuby.  Now, this interests me.  There’s going to be hackfest on Wednesday night at CabooseConf (a side meeting to RailsConf) that I’m going to want to visit.  Of course, Java support on Google App Engine is very preliminary, and there are lots of restrictions.  But the speaker says that jRuby on Rails works!  Well, except for a few minor issues like no ActiveRecord.  Not real practical yet.  But very encouraging.  There’s a talk at 11:45 AM this Wednesday that goes into more details.

[Side note: I’ve been trying to get our current development application running here in different configurations, and found I couldn’t get it to run under MRI using MySql (jRuby with MySql, or either with SQLite3 worked fine).  This isn’t related to the talk, but I found the solution on Google.  If you’re running a 64 bit version of Windows, you either need to be running MySql 5.0.x instead of 5.1.x, or else get the libmysql.dll file from an older version of MySql and put it in your Ruby’s bin subdirectory.  I don’t want to forget that the next time I wipe and reinstall everything on my laptop, hence this note.  It would be really nice if the precompiled gem for MySql gets fixed to avoid this problem, but I’ve noticed that the Windows platform is often not given much attention in the Ruby and Rails communities, so I’m not holding my breath.]

The tutorial has hit a real lull for me.  The Java ecosystem is incredibly rich, and layered upon layers.  It’s very hard for an outsider like me to keep track of the 27 billion different kinds of tools out there, and we’ve been talking for about an hour about those.  From the perspective of a Ruby person wanting to leverage some of that Java stuff, well… yawn.

We’re wrapping up now.  There was a lot of value to me in the first half of the talk, but not in the second half.  And I don’t think it’s just me.  It seems like the speaker got really bogged down at this point.  Overall, worthwhile, but it could have been even better.

May 2, 2009

Kindle Demographics

Filed under: Gadgets,Notes — Charles Engelke @ 4:26 pm
Tags:

Engadget pointed me to a post on the Kindle Culture blog that claims that most Kindle owners are over 40.  The research behind the claim is a bit informal, but it seems credible.

So (assuming this is true) why are Kindle owners older than other gadget owners?  The Kindle’s expensive, but I don’t think that’s it.  A lot of extremely expensive gadgets are very popular with teenagers and twenty-somethings.  The ability to change the font size may be a small factor, but I don’t think that’s behind this either.

I think it’s because lifelong readers tend to keep a lot of their books, and eventually there are so many they’ve become overwhelming.  I’m 53, and based on rough estimates from linear shelf space and overload factors, my wife and I have somewhere between 5000 and 10,000 books in our house.  It just seems natural to hold on to them, but we’ll only reread a tiny fraction of them.

The Kindle (well, Kindles, one for each of us) lets us keep reading new books without adding to the shelves, piles, and mounds of books we’ve got.  I was very slow to get one because of the DRM – I don’t really own any of the books I’m buying, and I don’t expect to be able to still read them a few years down the road.  But if I want to reread a book in a decade or two or three, I’ll just buy another copy then.  Thanks to electronic publishing, anything I want is likely to still be “in print”, and it’s less expensive to buy a few duplicate copies than to get a bigger house to save all that paper.  And the Kindle is just about as good a physical reading experience as a typical paper book.

I will still buy some paper books.  The Kindle’s screen isn’t big enough for most technical books (in my opinion).  And there are books I’ll want to have and keep for sentimental reasons.  But I’d be pretty happy if I could get the paper book count in the house down below 1000 some day.

Blog at WordPress.com.