Thoughts / Misc: July 2007 Archives

From an email:

just a quick announcement: ruby user group berlin has decided to organize the obligatory reject conf for rails conf europe in september.

when? tuesday, 2007-09-18, 21:00
where? secret place (i.e. we have not found the perfect location yet)

slightly different rules this time. anybody can talk about anything, but we ask you to present your talk as a micropresentation - that is: 15 slides, 20 seconds each, with a countdown which automatically brings up the next slide.

sounds weird, but i have seen it at reboot in copenhagen and it works really really well:

http://www.reboot.dk/artefact-466-en.html

I give them full permission to use my glorious artwork. :P

them: this brick wall keeps hurting my head every time I bash into it over and over!
them: it never changes! help! why doesn't it work?
me  : what are you actually trying to do?
them: bash my head through this brick wall!
me  : what are you actually trying to do?
them: I'm trying to bash my head through this brick wall!
them: why do you keep asking me that?!?!
me  : do you perhaps mean, get to the other side of the wall?
me  : why don't you just use that door?

There is a certificate course at the UW starting this fall. It is 3 quarters long starting at rubynewb, then rails/web development, then rubyjedi. no, not the real titles. You are not required to take all three courses. do what feels right. To take just one:

http://www.extension.washington.edu/ext/certificates/rby/rby_sce.asp

There is space available. apparently, plenty of space... so take make this a success, if you are interested or suspect someone you know is interested, PLEASE, help make it happen.

My theme for this year is shaping up to be "don't be clever, it doesn't suit you". Here is some real code we found and how it can quickly and easily be cleaned up to be much more readable, more correct, and more efficient all at the same time. (indeed, it took more time to benchmark and write this post than it did to fix the code)

The original code in all its clever glory:

if MODELS.keys.inject(true) {|b, klass| b and klass.constantize.columns.map(&:name).include? association.options[:foreign_key]}

pull out the foreign key, since there is no reason to do that in a loop:

fk = association.options[:foreign_key]
if MODELS.keys.inject(true) {|b, klass| b and klass.constantize.columns.map(&:name).include? fk}

pull out columns to improve readability:

fk = association.options[:foreign_key]
columns = MODELS.keys.map { |key| key.constantize.columns.map(&:name) }
if columns.inject(true) {|b, column| b and column.include? fk}

Oh look, now that we can read it, inject is totally wrong and slow:

fk = association.options[:foreign_key]
columns = MODELS.keys.map { |key| key.constantize.columns.map(&:name) }
if columns.all? {|column| column.include? fk}

Finally, while that map symbol to_proc hack sure looks cute, it sucks:

fk = association.options[:foreign_key]
columns = MODELS.keys.map { |key| key.constantize.columns.map { |c| c.name } }
if columns.all? {|column| column.include? fk}

Measure the change (slightly wrong after minor edits):

  1. 1 line, 132 chars, 131 avg len
  2. 2 line, 140 chars, 69 avg len
  3. 3 lines, 180 chars, 59 avg len
  4. 3 lines, 163 chars, 53.3 avg len
  5. 3 lines, 163 chars, 54.3 avg len

And finally, (rough) benchmarks:

\# of iterations = 100000
iter                      user     system      total        real
null_time             0.020000   0.000000   0.020000 (  0.012905)
benchmark-1          11.350000   0.030000  11.380000 ( 11.564039)
benchmark-2          10.900000   0.020000  10.920000 ( 10.975134)
benchmark-3          10.720000   0.010000  10.730000 ( 10.928107)
benchmark-4          10.520000   0.030000  10.550000 ( 11.300934)
benchmark-5           3.260000   0.010000   3.270000 (  3.275238)

(nevermind: don't look at the times, that wasn't the point... those that focused on the times missed the point.)

Sure does pay to not be clever...

We've not had anything reasonably challenging (at our perm job) since March, when I made the app 20x faster and massively cleaner/happier.

We'll (most likely) be going indie after this.

I'm hoping to finish up with some clients that I've currently got (I've been moonlighting) and take most or all of August off (or September if it gets pushed off too much). After that we'll come back to the consulting arena full force. rawr

About this Archive

This page is a archive of entries in the Thoughts / Misc category from July 2007.

Thoughts / Misc: May 2007 is the previous archive.

Thoughts / Misc: August 2007 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Pages

Powered by Movable Type 4.1