Interesting Book...

Posted by Peter Morris Mon, 08 Feb 2010 09:10:00 GMT

The article I mentioned about AREL mentioned a book that I really intend to look into.

Structure and interpretation of computer programs

YERS! get in there! Rails 3.0 FtW

Posted by Peter Morris Mon, 08 Feb 2010 08:48:00 GMT

For the last 5 years I have classed myself as a Ruby on Rails developer. More recently, I realise I might possibly not be able to say that. I have been using Django a lot. I love RoR, but Django has some nice features. One of them is its ORM query mechanism, but things are changing....

Wait, stop, I have been doing it wrong for 20 years.

Posted by Peter Morris Mon, 08 Feb 2010 08:24:00 GMT

IT, as in IT work.


I have been a professional coder (don't laugh) for over 20 years. Yesterday, My son(Alex, 12) and I where in the car, and as is natural, our discussion got around to copyright. Where it has been, where it is going, why it is as it currently is. During the discussion, I realised, I have run my career all wrong.

Coffee, Coding and Geographical Irrelevence

Posted by Peter Morris Mon, 01 Feb 2010 14:25:00 GMT

A new coffee shop cum cafe opened up within walking distance recently, I have high hopes and detailed aspirations.

Django/Python Epix Phail #5 - don't be evil.

Posted by Peter Morris Fri, 29 Jan 2010 13:15:00 GMT

Every language has its rough spots.


Ruby for instance does not handle array slices very nicely.

>> a = [1, 2, 3]
=> [1, 2, 3]
>> a[0]
=> 1
>> a[0..1]
=> [1, 2]
>> a[2, 3]
=> [3]
>> a[3, 4]
=> []
>> a[4, 5]
=> nil

 

Now, thats evil. Why should a[3, 4] give you an empty array (which is expected) but a[4, 5] give you nil!

But, Ruby gets some things right.....

>> a='1,2,3'
=> "1,2,3"
>> a.split(',')
=> ["1", "2", "3"]
>> a = '1'
=> "1"
>> a.split(',')
=> ["1"]
>> a = ''
=> ""
>> a.split(',')
=> []
>>
 
See that? an empty string gets you an empty array.

Theoretically, it SHOULD give you an array with a single empty text element, but it is nicer than that.

Not Evil.

Python on the other hand....

>>> a = '1,2,3'
>>> a.split(',')
['1', '2', '3']
>>> a = '1'
>>> a.split(',')
['1']
>>> a = ''
>>> a.split(',')
['']

Evil! pure and simple.

And lets look at slicing....

>>> a=(1,2,3,)
>>> a[0:1]
(1,)
>>> a[0:2]
(1, 2)
>>> a[0:3]
(1, 2, 3)
>>> a[0:4]
(1, 2, 3)
>>> a[1:4]
(2, 3)
>>> a[2:4]
(3,)
>>> a[3:4]
()
>>> a[4:5]
()
>>> a[6:7]
()
>>> a[7]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: tuple index out of range
 

In some ways that is better, slicing works nicely, but indexing a single element raises an index error.

Surely, if it is happy to slice the array outside of its limits and return a valid result, why not handle

accessing an element outside of the limits too?

 

Out with the old, in with the new. 8

Posted by Peter Morris Sat, 02 Jan 2010 11:49:00 GMT

Every year I do a bit of a clear out of my bookshelves.


I have two shelves above my desk in my office where I hold my books, the lower shelf, is my 'working set' the books I reach for all the time. The upper shelf are the 'good to haves' but are books I don't need every day. Every year, I review the books in the upper shelf, and move a selection to the boxes in the loft, so that I can push books from my 'working set' shelf up and to free space on my working set for books I need as I move speciality.


So, into the loft this year goes...

  • PIC 16cXX Assembler data book
  • DC01 Television Tuners
  • Zilog Z8 microcontroller handbook
  • Microchip Data book
  • Keil 8051 Assembler/C51 manuals
  • Java in a nutshell
  • Programmers Guide to the Netbios
  • Palm Programming
  • iAPX88 Book

The assembler data books probably should have gone a couple of years ago, but
 I was a bit sentimental, I loved doing assembler coding.

From my working set to the 'upper shelf' (sort of like being demoted from the cabinet to the back benches I suppose

  • Lisp (Winston & Horn)
  • K&R The C Programming Language
  • Managing Projects with Make

And new in the working set is a section on Django and Python.

Django, epix phail #4 - The road to hell. 7

Posted by Peter Morris Fri, 01 Jan 2010 13:04:00 GMT

The road to hell is paved with good intentions, Djangos MTI gives you the tools to pave yourself right into the abyss.

My 9 year old daughter.... 8

Posted by Peter Morris Thu, 31 Dec 2009 16:04:00 GMT

.... just used the word 'Obligated' in a sentence (talking to her brother) correctly!

Boy, is she going to have a hard time in secondary school.

Python and Ruby, siblings? 25

Posted by Peter Morris Tue, 29 Dec 2009 11:38:00 GMT

I have written code in many languages (Basic, dBase, C, Sculptor 4GL, Assembler(many flavours) Perl, VBA, Javascript, Ruby and finally, Python.

For much of my experience of Ruby, I viewed Python as a sibling language. I thought Ruby and Python where rough equals in capability and complexity.

It took me about 3 months of Python coding to realise that this is very far from the truth.

Ruby and Python are not compadres, they are not friends, they don't work at the same level.

Ruby is much simpler than Python, it has far less 'language' there. For a start, python is a compiled bytecode language (you do notice all those PYC files all over the place don't you?).

That and its explicit binding mechanism (all those import statements at the head of a python file just make my ruby sensibilities scream!) make for a much quicker language than Ruby.

When you add to that all this stuff about decorators, metaclasses etc, that takes some getting used to. The whole idea that methods associated with an instance are actually method instances that need calling (forgetting @property for the moment).

When I read about that, my mouth started watering, there must be some REALLY interesting uses for that! But then I let it stew for a while.

Really, all that does is force the coder to recognise that there are properties and then there are methods, and to require the user to know the difference.

With ruby, you don't need that. Well, really, with ruby, there are really ONLY ever methods, this forces encapsulation much more completely than Pythons default behaviour does.

Looking more deeply into decorators and metaclasses, I realise that they are trying to give the same sort of versatility to Python that Rubys blocks give to it.

Blocks affect EVERY aspect of Ruby, without blocks ruby is a rather dull, flat language. With them, it is a rich, expressive language that allows for some truely lovely DSL applications. Python tries to get the same functionality from metaclasses, decorators etc, but it just feels that much more forced. Having to use several different but interlocking constructs to ALMOST do what Rubys blocks do. This MIGHT be as a consequence of limitations enforced on the language by its bytecode underpinnings, I don't know enough yet to be able to say.

So, I suppose my final word on the issue is that Ruby is NOT a sibling of Python, its probably more of a teenager to Pythons twentysomething. There is a LOT more depth to Python than there is to Ruby, but thats not because the depth brings anything extra, it's more because Rubys simplicity is sufficient for the task. Python IS faster though, and probably always will be.

The later the binding, the slower the runtime performance.

All hail, Django models. 8

Posted by Peter Morris Tue, 29 Dec 2009 11:27:00 GMT

I have been spending a lot of time writing Django code (as you have probably noticed). In the past, I have been quite derisory about Django, there are many things that I don't like. Djangos ORM is NOT one of the problems. Well, fundamentally, it isn't. On the surface it stinks. So, lets get the nasty out of the way first. Some examples. In Rails, how do I find a particular instance if I know the ID? instance = Model.find(123) in Django instance = Model.objects.get(pk=123) Thats UGLY. This whole idea of managers, is a nice idea, but it is not entirely pretty. Now for the good thing. in Ruby if you do... object_list = Model.find(:all) you will get a big array filled with instances of all the objects in the database. Needless to say, this can SWALLOW your system. So, you have to be careful with AcriveRecord::Base, you get what you ask for, and if you ask for the moon, your system will fall to its knees and die. in Django if you do.... object_list = Model.objects.all() You will get an object that pretends to be an array, and only when you access chunks of it will it actually go over to the DB and pull back the required information. Thats NICE. BUT, it means you have to be a bit more careful, as it lulls you into a false sense of security. You have to remember that if you DO ask for the list of objects, you WILL get them. So, you have to remember. In rails, you know up front that you have to be careful, so its not quite as nice, but you aren't coddled. So, I do like Django models, it works in a more scalable fashion than Rails' ActiveRecord:Base. This leads me down the road of drawing comparisons between Ruby and Python. But thats the subject of a whole nother post.