Wait, stop, I have been doing it wrong for 20 years.
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.
SoundCloud: Twitter vs. Facebook 3
I was recently introduced to SoundCloud, specifically, through the music of NathanQ
Now, while listening to the interesting dance beats of NathanQ, I also noticed the UI of the site.
In doing so, I realised it was a nice implementation of some of the ideas that I had been involved with while working on a project for one of my clients.
The soundcloud implementation was much simpler and lower function than our attempts and in thinking about it, I realised that it satisfied the requirements very cleanly. A bit like how twitter and facebook are both in the same space, but are trying to satisfy different levels of result.
To me(being older) I feel that twitter is more successful, at least in part because it IS simpler, and it could be that there is a lesson here. If you can’t get all of your ideas just right, step back, pick one aspect and try to satisfy that one aspect simply and cleanly.
Something to ponder.
Lost in the desert of freedom 9
In this time of frameworks and development tools, we rarely start from scratch. There is always some prescribed structure in place when we start a new project.
But, when there isn’t, we realise how much that structure leads us.
Rails to_xml, thar be dragons.
Ok, so I have been using to_xml to handle generating xml serialised lists for a restful xml interface.
I came across this interesting situation.
If you are serialising a collection which is implemented as a set of subclasses using STI, the to_xml will generate different xml depending on which class of items it sees first.
For instance, if you start the list with an instance of the base class, it will generate a list encapsulated with the plural name of the class name, and each element will be a singular of the class name for the base class, irrespective of which classes each of the objects are.
BUT, if the first item in the list is one of the subclasses, the to_xml call will see that it is a heterogenious list (presumably because the successive items don’t all return ‘true’ for .kind_of? of the class of the first item, and will generate a xml list encapsulated as <record> entities within a <records> list.
Oh, that makes me SOO happy.
101 Greate Computer Quotes
There is really nothing I can say about this….
Just, go there, go there NOW, and read.
Doctest, a 'gateway drug'?
I am quite a proponent of TDD/BDD, my framework of choice being RSPEC within Rails
But, I also understand that for people unused to TDD, the upfront investment seems daunting. So, I was very interested to be told about…
This seems to be a nice light introduction into TDD. I can see that for extensive test coverage it is going to be a bit of a problem, there being no concept of fixtures etc. But I can definitely see someone adopting DOCTEST and then moving on to Unit testing or RSPEC later.
If you do not already embrace TDD, and recoil at its apparent heaviness, give doctest a look, but remember, tdd can be habit forming.
Horrified, but not Surprised 1
A friend pointed me towards an interesting article.
And after reviewing it, I can say I am both horrified and unsurprised.
Why?
Because I have met several people who claim they are coders, who, when actually confronted with coding work, just can’t DO it.
You ask them about linked lists, and data structures, binary chop and recursion.
They nod their head, make some reassuring NOISES.
But, when you show them some code and ask them to change something, they go blank, fumble and say they will get back to you.
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.
Models make decisions, views and controllers ask PERMISSION 2
Rails uses MVC.
Its important to correctly partition what each section does.
Views and Controllers should NEVER make decisions.
Models should make decisions, and controllers and views should ask models for permission.
For instance, if you have a a User model and some other model like, for instance something that remembers it position and is owned by a user, the view can ask the model whether it allowed to alter the object before it puts the user interface to allow movement.
in the view…
<% if moveable_thing.editable_by?(logged_in_user) >
… interface to move the object …
< end %>
Well, thats ok, BUT, it embeds a decision in the view.
What decision? well, whether an editable object is moveable of course. Later on, a user may be able to edit the contents of the object but not its position, and to make that change you have to now scan all controllers and views.
Better by far…
<% if moveable_thing.movable_by?(logged_in_user) %>
Now, we have removed ALL decision making from the view.
If this means we have to do silly things in the model like….
def editable_by?(user)
…
end
def moveable_by?(user)
editable_by?(user)
end
then, so be it, its a small price to pay.
An evening wasted... 2
I tend to use music as I code.
I like to do about two albums worth of coding and then take a break.
My current music player is gnomes musicbox and it does not have a feature to allow me to queue up two albums and just let it go. Its support for tagging sucks, so I thought, hey, why not write a little rails app to allow me to do all those neat things.
I had done something similar before, but it foundered through lack of interest, and I have learned a lot about rails since then.
So, I thought I would spend an evening writing the start of that, enough to be able to use it for the next days music fueled coding sessions.
And here, is where the evening took a turn for the wasteful…