Ruby – First (almost) disappointment

When you are learning a new language, when something is different often the first reaction is that it is bad – after all we fear change.
As I was learning about Ruby objects, I was learning that all members variables are private and that the only way to get at the variables was through setters and getters. I got used to setters and getters when I went from C++ to Java – it has always bugged me that I had to add 10 lines of code and 8 lines of comments just to access a dang member variable the “cool Java” way.
With one of the tenents of Ruby is to dispense with unnecessary cruft – “convention versus configuration” I was surprised when all the books immediately introduce setters and getters right away. I would have thought that there would be a simple way to do this – code like this bothered me:
class Thermo
def set_temp(x) # a setter
@temp=x
end
def get_temp # a getter
@temp
end
end
And they described this in books as if this was a *good thing*. To me it was crap and too much “me-tooing” Java patterns – it was the absolute antithesis of “convention not configuration” – it was overblown syntax – something I hoped to get away from in Ruby – but here in Chapter 3 – was creeping cruft – when would it end? And with this crufty syntax needed for *every* member variable – as far as I was concerned – Ruby was already a failure at delivering on “convention not overblown wasteful, repetitive, and redundant syntax”. Grr. I was only a few weeks into the new language.
So I started reading my five Ruby books and looking in the indexs and searching for things like “ruby sucks” and “ruby setters and getters suck” in Google and trying to learn if there were others as peeved about this as me. I found some peeved folks – and even some folks peeved about this issue. But somewhere along the line I got a clue.
Actually I had a clue all along – ActiveRecord does *not* use the setter/getter pattern faux-Java style – and since ActiveRecord is written in Ruby – it must be doing something much niftier than faux-Java setters and getters. You just refer to
thermo.id
Not
thermo.get_id thermo.set_id(1234)
To get the Id of an active record object – I liked that – how do they do that? So the hunt was on.
By the way there needs to be a newbie list where people like me can ask dumb questions like this and get a boot to the head to quickly learn this stuff. Like dummies@ruby.org or some such.
So I was sure there was a better idea – there was hope. I will bypass all the pages that I waded through until I found this one.
http://www.ruby-doc.org/docs/UsersGuide/rg/accessors.html
It shows two patterns of setters that make a LOT of sense – far more sense than the drivel above. I will switch to his code here:
class Fruit
def kind=(k)
@kind = k
end
def kind
@kind
end
end
f2 = Fruit.new
f2.kind = “apple”
f2.kind
Now that is a sweet syntax – particularly when accessing and setting the member variable. Kind of like C++ again – operator overloading – a nice clean syntax that allows me to do things “in context” – working with the compiler as my pal rather than pounding it with syntax as in Java (sorry – still a little bitter about the loss of operator overloading when I left C++ five years ago).
Of course – Ruby does this one better below.
This *is* “convention over configuration” – or at least “don’t repeat yourself”. “Don’t repeat yourself” is a very important concept in programming as it keeps us from making transcription mistakes. So the super-sweet Ruby-regains-absolute-advantage syntax is as follows:
class Fruit
attr_accessor :kind
end
f2 = Fruit.new
f2.kind = “apple”
f2.kind
Ah – I am back happy with Ruby again – no wasted moves – all graceful – like a ballet dancer – I can express what I want in a concise syntax that clearly communicates my intent to the future reader of the code. And if I want to add a little “special stuff” to my setter – simply drop back to the attr_reader and do my own setter as in the previous example.
Whew! I was kind of grouchy with Ruby for a few hours – but I am feeling better now – and in addition the Ruby approach is am improvement beyond C++ and Java IMHO – simple syntax for simple situations with the option to go deeper using more syntax only when there is a real need.
Also I got a little back on the operator overloading front… Cha-Ching.
Let me know if there is a mailing list to help me get through these mental blocks more easily.

Pedagogy: Teaching with Sakai – pre-class start

I will be putting up notes about how I am teaching with Sakai – I will code them all with the string pedagogy in them to make searching easier in amonsgt all the nerdy posts as well.
So far I am having great fun with Sakai – pre class start I have made my course site and published it – I have very few tools enabled:
Announcements
Polls
E-Mail Archive
I set it up knowing that students are still adding and dropping the course – as soon as they see it – they see the “welcome announcement” and are told to review the E-Mail archive.
I am taking a very valuable (both to me and the students) poll to gauge student experience level and am involving the students in the book selection via the E-Mail archive.
I make it very clear in the welcome announcement that any pre-class start participation is completely *optional*. Being able to later delete announcements is pedagocialy important to me because once class starts – the pre-class announcement is no longer relevant at all and would be distracting if I could not delete it.
This is a good reason to let faculty pre-setup and publsh their classes under their own control – not waiting for tech support to run some script. I will reveal Sylabus, Resources, iTunesU, etc on my schedule – not tech support’s schedule.

Continue reading

I just got SVN to work on hostmonster.com

I tried SVN 1.3 and SVN 1.4 – it would not get through configure.
SVN 1.2.0 worked – but it even spewed some errors – but it worked well enough to get command line svn working – which was all I cared about.
cd
mkdir dev
cd dev
curl -O http://subversion.tigris.org/downloads/subversion-1.2.0.zip
unzip subversion-1.2.0.zip
cd subversion-1.2.0
./configure –prefix=`pwd` –without-berkeley-db –with-zlib –with-ssl
make
make install (this failed with an error message)
./subversion/clients/cmdline/svn help (yay)
cd
alias svn=~/dev/subversion-1.2.0/subversion/clients/cmdline/svn
mkdir zap
cd zap
svn co https://source.sakaiproject.org/contrib/csev/trunk/scripts/ zzz
This bit was helpful:
http://www.hostmonsterforum.com/showthread.php?t=1294&highlight=subversion

Open Letter to www.1and1.com

I sent this letter to 1and1 tech support – figured I would share it here.
Domain: dr-chuck.com
I just wanted to drop you a note about Ruby on Rails hosting. I really like 1and1 a *lot* – I have used it for four years – and while I started in the free professional package – I have spent a lot of money and felt that my 1and1 services were a good value – I am so pleased that I put 1and1 ads on all my main pages.
Recently I became interested in Ruby on Rails – I initially tried to get ROR running on my 1and1 account and was even thinking of adding a second hosting plan just to do RoR – but since it was hard to set up – I decided to go with a service that simply supports RoR directly – hostmonster.com.
I will stay with 1and1.com – probably forever for my basic web hosting and domain name stuff – but as my interest grows in RoR – I will naturally begin to do new work at hostmonster.com.
So I am just wishing and suggesting that you come up with a supported RoR service – I would be happy to pay another $5-10 for it and happy for it to be another service. I really would like to stick with one vendor – keeps my life simpler for these hobby web sites.
Thanks for such a fine service.
Dr. Charles Severance
www.dr-chuck.com

Getting a Java + Maven 2 Application on the NMI Testbed

Last week I got Sakai automatically building on the NMI test facility at Wisconsin. Here is a status page:
http://grandcentral.cs.wisc.edu/pavlo/index.php?page=results%2Foverview&opt_user=csev
Here are my scripts in SVN:
https://source.sakaiproject.org/contrib/csev/trunk/nmi/sakaimvn/
The submit file is the master control – here is my sample:
$ cat sakaiMaven2.submit
project = sakai
component = Trunk Build
component_version = 1.0.0
description = Auto-build of Sakai trunk (cron)
run_type = Build
inputs = sakaiMaven2.scp, sakaiMaven2.svn, m2-repo.scp
remote_task = buildSakai.sh
remote_task_args = “sakai/trunk sakai”
platforms = x86_macos_10.4
prereqs_x86_macos_10.4 = java-1.5.0_06
notify = csev@umich.edu
I need Java 1.5 – the simplest is to use the mac OS 10.4 systems for my builds. Later I will develop scripts for other operating systems.
The inputs specify what you want on your execution machine and how to get it there. I have three inputs.
The first copies all my shell scripts from the current directory to the destination machine using SCP.
[csev@nmi-s003 sakaimvn]$ cat sakaiMaven2.scp
method = scp
scp_file = /home/csev/sakaimvn/*.sh
recursive = true
The second input checks a particular tag out of SVN of the Sakai source.
[csev@nmi-s003 sakaimvn]$ cat sakaiMaven2.svn
method = svn
url = https://source.sakaiproject.org/svn/sakai/trunk sakai
The third copies a copy of a populated Maven 2 repository from my home directory on the submitting machine to the executing machine.
[csev@nmi-s003 sakaimvn]$ cat m2-repo.scp
method = scp
scp_file = /home/csev/.m2
recursive = true
As the source changes the .m2 repo will become out of date so I have to tar up a full repo from my dev machine from time to time and copy it over.
The script to be run is pretty complex – I will point out a few important steps.
In link-repo.sh the key line is
ln -s `pwd`/.m2 ~/.m2
The input directive will insure that the .m2 directory makes it into the execution directory – by soft linking it into home, Maven 2 will find it.
In nmi-bootstrap.sh the code is a bit tortuous – probably the clever bit is downloading a copy of Maven 2 and using the local copy.
I debugged this script separately on my mac before making it work on the NMI test bed.
I instlal Maven 2 each time the script runs – I use:
curl -O http://mirrors.ibiblio.org/pub/mirrors/apache/maven/binaries/maven-2.0.7-bin.tar.gz
Then extract it into my local directory and simply use
`pwd`/maven-2.0.7/bin/mvn
As my call to maven 2. This way I install my own pre-requisite and don’t have to depend on anything except for Java.
Once this is done, I put in a crontab to automate this:
[csev@nmi-s003 ~]$ crontab -l
MAILTO=csev@umich.edu
22 04 * * * $HOME/nightly.sh
[csev@nmi-s003 ~]$ cat nightly.sh
#!/bin/sh
PATH=$PATH:/nmi/bin:/usr/local/condor/bin
cd sakaimvn
nmi_submit sakaiMaven2.submit
Thanks to Jim Basney and everyone who helped walk me through the process. it took less than a day to get it all working.
Also thanks to the folks at Wisconsin who walked me through the process.

Continue reading

Making a cool Query for Sakai

I am down at NCSA right now working on pulling site membership info out of Sakai for the Maeviz project so it can be stuffed into SAML assertions to pass to other systems. We are using MyProxy and GridShib.
My job was to come up with a queru whcih for a particular Enterprise ID (i.e. csev) – find all the sites they are in, give the site ID, Site title, and whether they were the owner or just a member (I used site.upd for this).
I seldom get to play in the DB – after a few hours I came up with this query. Feel free to criticize – it only works on MySql 2.3 for sure:

SELECT SAKAI_SITE.SITE_ID,SAKAI_SITE.TITLE, NOT ISNULL(SAKAI_REALM_RL_FN.FUNCTION_KEY) AS POWER
FROM SAKAI_USER_ID_MAP
JOIN SAKAI_SITE_USER
ON SAKAI_USER_ID_MAP.USER_ID = SAKAI_SITE_USER.USER_ID
join SAKAI_SITE
ON SAKAI_SITE_USER.SITE_ID = SAKAI_SITE.SITE_ID
JOIN SAKAI_REALM
ON SAKAI_REALM.REALM_ID = CONCAT('/site/',SAKAI_SITE.SITE_ID)
JOIN SAKAI_REALM_RL_GR
ON SAKAI_REALM.REALM_KEY = SAKAI_REALM_RL_GR.REALM_KEY
AND SAKAI_SITE_USER.USER_ID = SAKAI_REALM_RL_GR.USER_ID
LEFT JOIN SAKAI_REALM_RL_FN
ON SAKAI_REALM.REALM_KEY = SAKAI_REALM_RL_FN.REALM_KEY
AND SAKAI_REALM_RL_GR.ROLE_KEY = SAKAI_REALM_RL_FN.ROLE_KEY
AND SAKAI_REALM_RL_FN.FUNCTION_KEY IN (SELECT FUNCTION_KEY FROM SAKAI_REALM_FUNCTION WHERE FUNCTION_NAME = 'site.upd')
WHERE
SAKAI_USER_ID_MAP.EID='tmclaren'
;

Here is sample output:

+---------------------------------------+--------------------------+-------+
| SITE_ID                               | TITLE                    | POWER |
+---------------------------------------+--------------------------+-------+
| !admin                                | Administration Workspace |     1 |
| ed4fd8d8-a717-4a3d-00f0-f1e368ac1faa  | MAEviz                   |     0 |
| ~1d722376-bd33-44a0-80ba-de56ba912175 | My Workspace             |     1 |
+---------------------------------------+--------------------------+-------+

Good fun.

Teaching With Sakai

I am going to record my notes/thoughts/ideas as I teach with Sakai this next year. Here are a few first thoughts:
– It is really cool to make the course sites myself and choose when to publish the sites – and control what tools appear on the site. I already have published my site and am using E-Mail and polls in the weeks prior to the start of class to help me plan.
– UM does not have the page order tool enabled :( I really like the tool – not so much for the reordering feature – but more for the show/hide feature.
– UM has tech support for CTools available on IM – AWSOME!!! I needed Poll tool added to my site (cause it is stealth at UM) and 5 minutes later it was done via iChat – I was able to paste course IDs in and all – nice nice nice.
– I sent out my first not to my Ruby on Rails calss with a simple poll – will see how much response I get …
I don’t have admin privs on CTools – so I get the real faculty experience – also I will resist the temptation to go straight to the developers and management just because I know them – I want ot use tech support and do the real faculty thing and get the whole experience.
I also hope to set parts of the course for public viewing – we will see – some features in 2.4 trunk are not in 2-4-x that make anon viewing better – perhaps next semester.