Robert Cowham's Weblog 5 of 12 articles Syndicate: full/short

Regular Expressions in Ruby and Python   27 Mar 06
[print permalink all comment ]

A personal foible perhaps but I do find Ruby's regular expression syntax remains in my brain much more easily than the Python equivalent.

Maybe it's the Ruby inheritance from Perl that makes the difference. For simple scripts I can just write standard regexps without any recourse to documentation and they just work! For example:

some_var = "prefix interesting_match some suffix"
if some_var =~ /prefix (\w+) some suffix/
  interesting_bit = $1
  print "Match found: ", interesting_bit, "\n"
end

In order to do the same in Python I find myself faffing around with the documentation (using ActiveState Python it's great to have a proper help file, but I would really like more links between the class reference and real examples of usage to help me out) and trying to remember if I want re.search or re.match and how do I get a match group and use it, etc. I have sundry Python scripts floating around that I open up and copy relevant examples from, but it does rather take time.

import re
some_var = "prefix interesting_match some suffix"
pat = re.compile('prefix (\w+) some suffix')
m = pat.match(some_var)
if m:
    print 'Match found: ', m.groups(0)[0]

Now I have to admit that it's not a huge deal in terms of the resulting code, but it took me 5-10 minutes just now to code and debug the Python version as opposed to the Ruby version which I typed in and which worked first time.

The net result is that I am noticeably  more productive in Ruby for those little scripts that make life easier, or when I am under strict time pressure. Now this is not to say that I don't like Python, or indeed that when I have a little more time I don't get use it and enjoy it. Having done some reasonably significant work in Python, e.g. rework P4DTI for PVCS (now Serena) Tracker I feel reasonably qualified to comment.

I also took the time to get sufficiently proficient in Python extensions to enhance and maintain P4Python. Mind you I now feel somewhat humbled by the most recent efforts at a Perforce integration (PyPerforce) - shows a depth of Python extensions knowledge before which I can only bow in admiration! (Minor aside - Ruby extensions are much easier to write than Python ones due mainly to the different garbage collection models).

Finishing up, I am definitely Perl-averse these days. There are a few Perl scripts that I maintain and can't be bothered, or can't find a convincing "business" case to rewrite, but anything new is Ruby or Python.

Review of 59 Minute Scrum   02 Feb 06
[print permalink all comment ]

I went to the 59 Minute Scrum  session last October which sounded interesting - from the blurb:

"This session will give attendees a unique opportunity to experience agile practices first hand in a non-technical environment."

I had good expectations but was left a little under-whelmed at the actual event. Now I have to admit that I arrived late and missed the intro so maybe it's all my fault and the intro answered everything! (Discussion over a beer afterwards showed I wasn't totally alone though).

The format was to split up into teams and discuss various scenarios. These were implementation projects including marketing, programmes and anything else we fancied on topics such as: a theme park around "spam", a health club for pets and a space tourism project.

The event was fairly tightly timetabled so we had a slot to discuss our backlog, then split up further in our teams to actually come up with ideas on particular areas. Then round 2 for more implementation. Finally, all the teams (8 if I remember correctly - typically 2 per idea) presented their solutions to the whole group and touched briefly on how well they had addressed the backlog/made progress etc.

There was then an all-too-brief Q&A session at the end.

For me the format didn't really work. I was left with too many questions and faffing about in the exercise had very limited benefit. I would much rather have had a well though through presentation on Scrum with lots of time for questions. At most half an hour of some exercises and then a presentation and lessons learnt would have worked much better for me.

Maybe I am just becoming a stick-in-the-mud?! I am likely to stear clear of such sessions in the future though unless there is time for a solid hour or more afterwards to get into details and ask questions.

Changing Hosts   19 Nov 05
[print permalink all comment ]

There have been a few blogging delays due to such family things as a new son! But also changing hosts - everything now hosted at Textdrive.

As ever, migrations always take time and indeed the blog got left on the old ISP for quite a while as I couldn't face moving it! It has taken some fiddling to get everything working as it should. In the meantime I failed to get to grips with the new setup for some weeks and committed the cardinal sin of breaking old URLs to blog entries - for which I can only apologise and take my medicine like a man!

Have been playing with Subversion as installed here as the new mechanism of getting stuff up to the Textdrive machine since straight FTP is outlawed and my previous mechanism involved a hack of KFTPUpdater - a Python script which only uploaded changed files, but did it via vanilla FTP. I must admit it is nice to have Subversion installed and available for versioning as part of my account. That said I had a few niggles getting it actually working - finally found the relevant bits of information and made it. (p.s. I don't find Textdrive's Webmin admin interface the easiest thing since sliced bread). Even better I now have Perforce available to me as well, and have a server running as the Textdrive guys nicely gave me a port to use. Hassles there too as originally the binaries for FreeBSD4.1 core dumped when run on FreeBSD5.4 so I put it aside for a bit. However, some server upgrade later and they magically now work fine. Thanks to Gordon Tetlow I even have P4Ruby installed locally since I couldn't compile against the Perforce API built with GCC 2.95 when Textdrive have GCC 3.4 installed (and I didn't fancy faffing around with a local VMWare install just to get things fixed).

I have been doing some research into new blogging engines and rather like the look of Typo (and need an excuse to get to grips with Rails!), so am hoping to head in that direction. However, I will first need to tweak it to add some article versioning - am still amazed that people gaily chuck all this text into databases and don't version it in any form... (Have heard regular horror stories of databases being wiped and stuff being lost through injudicious SQL statements - no thanks). Given that I now have P4Ruby installed here, I am rather hoping that it will be very easy to make a few mods and save versions in Perforce as articles are added/edited etc. Will post on my experiences.

Awareness of Agile Development Methods   22 Feb 05
[print permalink all comment ]

I was at an event fairly recently where I did a short presentation on Agile SCM. During the presentation, I surveyed the audience about their awareness of agile development methods and practices and was rather surprised at the result. There were about 50 people, most of whom were very experienced developers who tended to be working on contract and were well up-to-date on Microsoft tools etc.

Remarkably few had even heard of things like XP (eXtreme Programming), FDD (Feature Driven Development), SCRUM and DSDM (for example 3 people said they were doing agile development and another 3 or so said they knew of it). That said, when I went in to some agile practices such as continuous integration another half a dozen put their hands up.

There are a couple of responses to this:

  • There is a marketing problem for Agile Methodologies
  • Developers are not keeping up to date with the industry

Regarding the first response, I think that this is progressively being addressed through internet articles, books, seminars etc.

The second perhaps shouldn't have surprised me so much, although it did. It would appear that there are a large number of developers and others involved in software development who just treat it as a job - go to work, do it, go home. They seem to keep their heads down, not read magazines, articles and related things, and basically not stay abreast of developments in their industry. These are bright and clued up people technically! But think of a dentist who didn't keep up-to-date - how long would he or she keep their patients? My dentist has his certificates of "continuing professional development" up on his wall - it gives me a good feeling when I'm lying in the chair!

I think that professional development is a pre-requisite for anyone in any field. And excellent treatise for software development is Dave Thomas's "How to Keep Your Job"; and a couple of useful points at Coding Horror: Be Good at your Job. An interesting take is How to Prevent Offshoring Taking Your Job

Perhaps on a related note I can singe the praises of the geographical and specialist groups - the people that I see attending these meetings are the ones who will do well. The BCS provides some excellent professional development support to individuals and to companies.

I'd also like to put a plug in for Toastmasters International - a global organisation for improving your public speaking skills. I have found it very useful myself (and can recommend London Corinthians for those who can get to Victoria!).

Using OpenSSL from Ruby to access secure web sites   31 Dec 04
[print permalink all comment ]

One of my background tasks requires administration of bookings for conferences or events. I created an online registration form with javascript validation of credit card numbers and other sundry checks, and if the user submits a registration it is stored as a fairly simple text file on a secure server. The problem I had was to access the secure server forms for plugging stuff into a database etc. For a couple of events, this has all be done manually by my administrator - somewhat of a pain, especially if she was away and we were close to the event and I had to process them myself!

My attempts to automate this were stumped by https access (using OpenSSL). Some brief trials in the past with Ruby failed dismally. I even managed to download OpenSSL and build it and install the Ruby extension - all seemed to work fine but I couldn't for the life of me manage to successfully login and get the contents of a web page from my secure server. Frustrated, I put it on to the back burner at the time.

Just recently I noticed that the latest Ruby One-Click installer now included the OpenSSL module (which saves lots of hassle, especially as I had had to reinstall my laptop losing the previous OpenSSL installation). This prompted me to search again for examples of how to use it, and this time I eventually turned up a sample from the new Programming Ruby 2nd Edition.

This worked straight off the bat for me and allows me to proceed with the rest of the processing. This is likely to include parsing of the text into an Excel spreadsheet or even Access database.

Code

This is it:

require 'net/https' 
USER = "xxx" 
PW = "yyy" 
site = Net::HTTP.new("www.securestuff.com", 443) 
site.use_ssl = true 
response = site.get2("/cgi-bin/cokerecipe.cgi", 
             'Authorization' => 'Basic ' + ["#{USER}:#{PW}"].pack('m').strip) 
print response.body 

Easy when you know how!! Thanks to the Pragmatic Programmers!

 

Copyright © 2008 Robert Cowham