Andrew Channels Dexter Pinion

Wherein I write some stuff that you may like to read. Or not, its up to you really.

April 27, 2004

Outsourcing

Is it just me, or is the current fashion for sending jobs offshore (Shell being the latest) in any way reminiscent of the great outsourcing boom of the 80's and 90's? I'm talking about when the IT strategy du jour was to hand over great chunks of your company to IBM, EDS, CSC or Cap Gemini in the expectation of saving millions of pounds (shekels, euros, dollars, whatever) in costs a year?

Does everyone remember how successful that was? I've been involved in a few companies where various IT functions have been outsourced and none of them have ever lasted beyond the initial contract. The end of result is usually that IT returns in house and all talk of cost savings is forgotten. If I had to give a reason for this observed behaviour I would say it is because an external supplier is focussed on maximising their profits whilst an internal team should be focussed on maximising yours. The cost savings are always thought to be in reducing the number of people working on providing your IT services because the supplier you choose must be more efficient than your own people, right? Either that or you can share a mainframe with other companies and reduce your expenses. Oh, hang on, even people who run mainframes don't have spare capacity these days so that argument is shot down very quickly.

That's not to say that you can't outsource/offshore specific pieces of work like development projects or specific infrastructure upgrades. These are the real strengths of outside suppliers. But just shifting bodies from one location to another isn't going to save you any money, in fact it will probably end up costing you more.

Posted by Andy Todd at 09:55 AM | Comments (1)

April 22, 2004

Date Arithmetic in SQL Object

Date Arithmetic in SQL Object

Reading this thread (alternate source) on the SQL Object mailing list today I wondered how I would write a similar method using dates instead of integers.

Often in a database you will record, for instance, a person's date of birth but want to be able to display their age as well. This looks like a perfect place for a Python descriptor, as described in this how-to.

This is all well and good until you consider the actual date arithmetic. The problem being that Python hasn't, until recently, had a standard date datatype so comparing dates is always a little tricky. This is complicated further when you introduce databases into the mix as they all have their own (slightly different naturally) date datatypes. In essence, with two points in time you could be dealing withfour different interpretations (or data types) one each from the database and Python for either of the dates. Like I said, it can get a little complicated.

The Python standard database API can help us a little here. Although the only requirement for compliance is that the module author provides a Date(year, month, day) method to construct an appropriate date object. The way in which dates are stored is up to the module author. Therefore it isn't possible to take a value returned from one database module and compare it with one returned from another. But we at least have a standard interface to them.

To turn a date of birth into an age we count the number of whole years between the supplied value and today. For which you need to know (in the correct data type) what today is. This is probably best illustrated with an example. Given a SQL object class;

from SQLObject import *
class Person(SQLObject):
    firstName=StringCol(length=20)
    surName=StringCol(length=20)
    dateOfBirth=DateTimeCol()

We want to add a descriptor method to return an 'age' attribute, something like;

    def _get_age(self):
        "Return the person's age in years"
        return (today-self.buyDate)/365

But, of course, we need to define a value for today and make sure the arithmetic returns the correct values.

When you are writing your own database code this isn't an issue, simply use the Date method supplied by your friendly database module to define today and then your arithmetic is on like objects. In SQL Object, however, you don't necessarily know which database module you are using so you can't use it's Date constructor. Although it is perfectly possible to do so if you want. In this solution I'm trying to be as generic as possible, just because I can.

Luckily, Python 2.3 introduced a standard date and time module. So, if we can get our two dates into objects that this module understands then life starts to get easier. For today's date it's quite easy;

        today=datetime.date.today()

What will seal the deal is if we can convert dateOfBirth into a datetime object. My solution is;

        dob=self.dateOfBirth
        bDate=datetime.date(dob.year, dob.month, dob.day)

And yes, the first line is just a shortcut to make the second line look better on a web page. Once we've done this the arithmetic is really rather simple;

        difference=today-bDate
        return difference.days/365

And voila, when you get an instance of Person and refer to it's age attribute our method is executed. For instance;

>>> people=Person.select()
>>> andy=people(1)
>>> andy.firstname
'Andy'
>>> andy.dateOfBirth
<DateTime object for '1968-10-11 00:00:00.00' at 402eb448>
>>> andy.age
35
>>> 

Posted by Andy Todd at 10:18 AM | Comments (5)

April 20, 2004

Open Source Databases vs Oracle

Courtesy of PHP Everywhere: a nice discussion of the merits of MySQL, PostgreSQL and the old stagers themselves, Oracle.

All interesting stuff and well worth the read. Ken Jacobs quite rightly says that MySQL is missing some features that have been in Oracle (and PostgreSQL) for quite a while (triggers and views in particular). He says that these features are necessary for "enterprise applications" but misses that point that not that many people are building enterprise apps these days. Those that are generally use object oriented programming languages and object relational mapping tools. Which move the focus of your logic from the database to the application layer. Meaning that you can cope without these advanced features in your database and forgo the cost of the Oracle licenses.

I'm not saying that this is always the right approach, but it's certainly cost effective. I'm not a fan of simply using the database as an object store - as mentioned here - but if that's your architecture choice then there it doesn't matter a lot which database you use.

Just steer clear of DB2 UDB ;-)

Posted by Andy Todd at 08:51 PM | Comments (6)

Invoking HTML Tidy from VIM

I'm editing a lot of HTML pages at the moment. I wondered if there was a way to call HTML Tidy from within VIM.

Of course there is. Thanks to paragraph 15.5 on this page I found out that it's a two step process. Within VIM type;

  :compiler tidy

To tell the editor that you want tidy as your compiler of choice (I don't know why, I just make it work), then within your HTML page just save and then type;

  :make

And Bob is really your Aunty's live in lover. Tidy will tell you what, if anything, you've got wrong. I love this editor.

Posted by Andy Todd at 02:05 PM | Comments (0)

April 16, 2004

PythonCard 0.7.3.1

PythonCard is a GUI construction kit for building cross-platform desktop applications on Windows, Mac OS X, and Linux.

Release 0.7.3.1 includes over 40 sample applications and tools to help users build applications in Python, including codeEditor, findfiles, and resourceEditor (layout editor).

This is the last planned "prototype" release of PythonCard. We've started cleaning up the framework code and finalizing the API for a 1.0 release sometime in early summer. There will be at least two more releases before then, so if you would like to get involved in the PythonCard project, now is a great time to join the mailing list.


All the information you need about PythonCard can be found on the project web page at:
http://pythoncard.sourceforge.net/

The installation instructions and walkthroughs are available on the main documentation page:
http://pythoncard.sourceforge.net/documentation.html

You can download the latest release at:
http://sourceforge.net/project/showfiles.php?group_id=19015

For a list of most of the samples that have been built with PythonCard and screenshots of them in action go to:
http://pythoncard.sourceforge.net/samples/samples.html

The kind people at SourceForge host the project:
http://sourceforge.net/projects/pythoncard/

If you want to get involved the main contact point is the Mailing list:
http://lists.sourceforge.net/lists/listinfo/pythoncard-users

PythonCard requires Python 2.2.1 or later and wxPython 2.4.1.2 or later.

Posted by Andy Todd at 07:23 AM | Comments (1)

April 13, 2004

VIM and SQL Plus

One for the Oracle-ites reading this blog, Vimming with SQL*Plus is an article on OTN about using the world's best editor with a popular database.

It's fairly introductory but it is quite thorough and covers how to make VIM your editor of choice within and without Oracle. Particularly interesting is the syntax definition for SQL and PL/SQL.

Posted by Andy Todd at 11:08 AM | Comments (0)

VIM in Mozilla

Fed up of those nasty textareas in web forms? Banish them from your life with mozex, the Mozilla external editor plugin.

I can now write all of my blog posts in VIM. Life is practically complete ;-)

[Courtesy of this page on Ian Bicking's new wiki]

Posted by Andy Todd at 10:23 AM | Comments (0)

April 08, 2004

Python better than Java?

According to Wes Felter Sleepycat rewrote Berkeley DB in Java. Specifically to avoid the "pain" of having to use JNI. JNI is the standard way of calling non-Java code from within Java.

The Java programmers that I disparaged in my last post have expressed similar misgivings about using this technology and tend to avoid it like the plague.

Whereas in Python you can extend the language in C, invoke operating system commands, interact seamlessly with java, write extension modules in Python but compile them to machine code and even call Berkeley DB using a a standard interface.

I know which programming language I'd choose.

Posted by Andy Todd at 09:19 PM | Comments (4)

RDBMS in an Agile (OO) Project

Mark Rittman writes a well thought out and interesting piece today on the role of the RDBMS In an Agile Development Project. Definitely worth a read.

As I've touched on before (with a nod to VS Babu) I think the best approach is to use the strengths of your database in combination with the strengths of your programming language. On the continuum between fully object oriented and fully database centric I think that the sweet spot lies somewhere in the middle. If you veer to far to one side or the other then you are doing yourselves (and your customers/users) a disservice.

Of course all of the Java programmers that I used to work with don't agree with me. But then they haven't got me around to make their databases work any more. So I'll just have to keep an eye out and see what they get themselves into.

If you are interested in the meeting of databases and object orientation a good resource is the Agile Data site.

Posted by Andy Todd at 07:39 PM | Comments (0)

April 06, 2004

Opening Another file in VIM

Every day I learn to love my favourite editor/ide/programmer's swiss army knife just a little bit more.

Today's reason? Courtesy of this tip I discovered the command "gf". It opens the file whose name is currently under your cursor in another buffer ready for editing. It's a godsend when editing, for instance, the HTML for a web page. Wherever there is a link to another page just place your cursor after the HREF and press the magic keys.

Posted by Andy Todd at 08:10 PM | Comments (0)