Python and Ruby, siblings? 40
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. 14
Evidence of Adhocracy? 5
I really like open source, it gives clients comfort, developers solid foundations and end users never need to know about it. Why should they care!
Today, being the thick headed person that I am, I realise in my gut, what it actually means to companies. And this may be the biggest blow to the adoption of opensource.
To companies it means they no longer have a hold on things, no longer have ownership. To me, that’s a good thing, but to them I can see it would be scary.
Let me explain.
This morning I see an item on Slashdot (if you need a link, you just aren’t ready to read on!)
Sun’s JRuby Team Jumps Ship To Engine Yard
reading that, I realise, ‘software wants to be free’ is not just about being able to use ‘free software’ anywhere, it means the software itself is not tied to any company to develop it. The news of this team of developers jumping wholesale from one company to another AND TAKING THE PRODUCT WITH THEM is a sobering example of what this means. Companies do not ‘own’ the opensource projects they foster, they are mearly the custodian, and this custodianship is contingent entirely on them stepping up and being good citizens. That cannot translate to the balance sheet and the earnings call. I can see how, in the shareholder culture, opensource could be a very dangerous and difficult sell.
Finally, will MYSQL follow? Or, should the question be, when will it follow?
Web development frameworks and SQL ghettos. 2
My platform of choice is Ruby on Rails.
In an early project, I implemented some reports by coding special purpose sql statements embedded within model methods. This worked well, and allowed the reports to run reasonably speedily.
As I continued to maintain the application and requirements changed, I found that I was reluctant to change the way the model objects interacted as it would require not only changing the model code, but sifting through the mounds of complex and convoluted sql.
What had been an efficient way to handle a problem (generating the reports quickly but in coding time and in runtime) had resulted in ‘scar tissue’, or maybe a fossilisation of my object model structure within the body of the sql.
Over time, this caused me to change the way I was altering the design, by forcing me to add layers around classes instead of refactoring within them.
After I finished on that project, I reviewed what I had done and vowed never to create sql ghettos again.
I think it is an apt term ‘sql ghetto’. An area in your application that you almost dare not go. that hinders future development, forcing it to work around it.
Resist the temptation to make ghettos, for they will surely come back to haunt you.
Danger Will Robinson
I like RSPEC, I LOVE RSPEC. But, this morning, I found a flaw in its beauty.
If you are using a lambda to verify that a block of code raises an exception it works fine.
A problem occurs if you are using a lambda like….
lambda {
… do some stuff …
}.should_not raise_error(SomeSpecificErrorClass)
to check that an error of that type is not raised.
The problem is, that the ‘raise_error’ will trap errors looking for the specific type of error you are asking for, but, in doing so, it only takes notice of the specific type of error you mention, and traps but ignores all others. So, if an expectation within the block fails, this will not be reported.
Significant problem!
in_batches_of
Rails is nice. Rails is REAL nice, but, you would expect me to say that, I am a rails developer.
One thing that rails is not nice about is efficiency.
It’s elegant, its compact, but, the simplest things can have unforseen consequences unless you understand at a fundamental level, whats going on.
The persistence layer of Rails is a class called ActiveRecord (Specifically, most of it is tied up in ActiveRecord::Base)
When you want to do something with every row in a table, or with a subset of rows, you want to do something like this…
ModelClass.find(:all).each do |item| ... do stuff ... end
Take it from me, that would be bad.
What it would do is instantiate every row in the table as an object and build an array of those objects in memory. Thats fine if you have 10, 100, 1000 rows in that table, but what happens when you have 100000 or a million? Well, we would be in for a long wait.