<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>cfis : Making Rails Better - Fixing Architecture Flaws in Active Record</title>
    <link>http://cfis.savagexi.com</link>
    <atom:link rel="self" type="application/rss+xml" href="http://cfis.savagexi.com/2007/08/11/making-rails-better-fixing-architecture-flaws-in-active-record?format=rss"/>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Charlie Savage's Blog</description>
    <item>
      <title>Comment on Making Rails Better - Fixing Architecture Flaws in Active Record by John</title>
      <description>&lt;p&gt;Yep, give it a few more versions and maybe AR will begin to measure up to some of the Perl ORMs from two years ago ;)&lt;/p&gt;</description>
      <pubDate>Sun, 12 Aug 2007 19:23:32 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:f1950b10-d30b-4ef6-b080-a4eaea95de02</guid>
      <link>http://cfis.savagexi.com/2007/08/11/making-rails-better-fixing-architecture-flaws-in-active-record#comment-4186</link>
    </item>
    <item>
      <title>Comment on Making Rails Better - Fixing Architecture Flaws in Active Record by Jon</title>
      <description>&lt;p&gt;Would this break portability?  One of the &amp;#8216;cool&amp;#8217; things about rails seems to be that you can move it to another DB without breaking anything, the migrations should just automagically create the schema and you&amp;#8217;re ready to roll.&lt;/p&gt;

&lt;p&gt;That being said, breaking portability in order to use advanced DB features seems worth it to me.  Migrations are cool, but quite simple in what they can do.  (But, to support SQLlite, they sort of have to be)&lt;/p&gt;</description>
      <pubDate>Sun, 12 Aug 2007 19:54:39 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:c367ca7d-5b12-44ca-9755-deb8e448ddd7</guid>
      <link>http://cfis.savagexi.com/2007/08/11/making-rails-better-fixing-architecture-flaws-in-active-record#comment-4187</link>
    </item>
    <item>
      <title>Comment on Making Rails Better - Fixing Architecture Flaws in Active Record by Charlie</title>
      <description>&lt;p&gt;Hi Jon,&lt;/p&gt;

&lt;p&gt;No, by default it wouldn&amp;#8217;t break portability - its just a better way of packaging ActiveRecord&amp;#8217;s existing code.&lt;br /&gt;
&lt;/p&gt;

&lt;p&gt;Of course if added your own custom data type, then it would be up to you to port it across databases if you needed database portability. But in reality, I think database portability is way over-rated.  Its hard enough getting one database setup right, let alone several.&lt;/p&gt;</description>
      <pubDate>Sun, 12 Aug 2007 20:06:18 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:0d03b00a-6760-4b44-a09c-2df19deb48b4</guid>
      <link>http://cfis.savagexi.com/2007/08/11/making-rails-better-fixing-architecture-flaws-in-active-record#comment-4188</link>
    </item>
    <item>
      <title>Comment on Making Rails Better - Fixing Architecture Flaws in Active Record by wilsonm@yahoo.com</title>
      <description>&lt;p&gt;Having real bind variables would also be a big win.  They probably cause a larger amount of time spend waiting than anything else.&lt;/p&gt;

&lt;p&gt;Does anyone know if/when they will be available?&lt;/p&gt;</description>
      <pubDate>Mon, 13 Aug 2007 09:25:46 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:8a0cc15a-e7cd-4835-9b0b-8bf3b4aba1a1</guid>
      <link>http://cfis.savagexi.com/2007/08/11/making-rails-better-fixing-architecture-flaws-in-active-record#comment-4192</link>
    </item>
    <item>
      <title>Comment on Making Rails Better - Fixing Architecture Flaws in Active Record by Charlie</title>
      <description>&lt;p&gt;Wilsonm,&lt;/p&gt;

&lt;p&gt;That&amp;#8217;s good point - its another place where ActiveRecord could be significantly improved.&lt;/p&gt;</description>
      <pubDate>Mon, 13 Aug 2007 11:10:07 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:497b2052-da6e-4275-b14e-3dbee16eb371</guid>
      <link>http://cfis.savagexi.com/2007/08/11/making-rails-better-fixing-architecture-flaws-in-active-record#comment-4197</link>
    </item>
    <item>
      <title>Comment on Making Rails Better - Fixing Architecture Flaws in Active Record by topfunky</title>
      <description>&lt;p&gt;ActiveRecord is the largest library in Rails. Any increased efficiencies in the library would definitely help Rails applications in general.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;d love to see a prototype that uses some of these ideas. It might break some third-party plugins but could be well worth the work to update them.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://geoffreygrosenbach.com/system/assets/1144684900_normal.png" rel="nofollow"&gt;http://geoffreygrosenbach.com/system/assets/1144684900_normal.png&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Tue, 14 Aug 2007 15:14:49 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:79e0770b-f4b1-4315-8d2c-cac4902c8af6</guid>
      <link>http://cfis.savagexi.com/2007/08/11/making-rails-better-fixing-architecture-flaws-in-active-record#comment-4224</link>
    </item>
    <item>
      <title>Comment on Making Rails Better - Fixing Architecture Flaws in Active Record by Crescent Fresh</title>
      <description>&lt;p&gt;So how would one go about mapping a db field to a column object (TimeColumn, FloatColumn, etc)? Would there still not be a need for a big case statement? Eg&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;def klass
  case type
    when :float     then FloatColumn
    when :datetime  then TimeColum
    # ...
  end
end
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Wed, 15 Aug 2007 08:10:11 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:736202f4-ca0d-432a-b2cc-c80ffc4521f0</guid>
      <link>http://cfis.savagexi.com/2007/08/11/making-rails-better-fixing-architecture-flaws-in-active-record#comment-4232</link>
    </item>
    <item>
      <title>Comment on Making Rails Better - Fixing Architecture Flaws in Active Record by Charlie</title>
      <description>&lt;p&gt;Hi Crescent Fresh,&lt;/p&gt;

&lt;p&gt;Depends at which point you mean. What I mean is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Have a hash table per adapter class that is keyed on column type (a string, defined by the current database) with values being the correct Ruby column class for that type (you of course have to implement these classes).  So:&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;   mappings =
   {&amp;#8216;varchar&amp;#8217; =&gt; StringColumn,&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;'integer' =&amp;gt; IntegerColumn,
'geometry' =&amp;gt; GeometryColumn}
&lt;/code&gt;&lt;/pre&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;At startup, read data dictionary info from database to get list of columns (Rails of course already does this).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For each column, look up the Ruby column class in the hash table setup in #1.  Create an instance of the ruby column object.  Store it in another hash table, called columns, keyed on the column name.  So each table has a columns hash table.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;You&amp;#8217;ve now avoided all case statements, so the code will be faster.  And its easy to extend - a developer could just add a new mapping to the hash table defined in part #1.&lt;/p&gt;

&lt;p&gt;Does that help?&lt;/p&gt;</description>
      <pubDate>Wed, 15 Aug 2007 11:58:34 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:9f773b96-10c4-4241-829f-3c5e2014369d</guid>
      <link>http://cfis.savagexi.com/2007/08/11/making-rails-better-fixing-architecture-flaws-in-active-record#comment-4236</link>
    </item>
    <item>
      <title>Comment on Making Rails Better - Fixing Architecture Flaws in Active Record by Crescent Fresh</title>
      <description>&lt;p&gt;So you&amp;#8217;ve replaced case statements with a hash table, correct? And this allows easily and elegantly adding custom column types. Agreed. Are hash table lookups really faster than case/switch statements though (in any language)? Less code, sure, but faster?&lt;/p&gt;</description>
      <pubDate>Thu, 16 Aug 2007 09:17:49 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:ed7a6af5-3191-40bc-9146-c3b015cb8a2e</guid>
      <link>http://cfis.savagexi.com/2007/08/11/making-rails-better-fixing-architecture-flaws-in-active-record#comment-4246</link>
    </item>
    <item>
      <title>Comment on Making Rails Better - Fixing Architecture Flaws in Active Record by Charlie</title>
      <description>&lt;p&gt;CrescentFresh,&lt;/p&gt;

&lt;p&gt;Sort of.  Use a hash table to create the right column objects, and then just use inheritance/duck typing from there.  Each column would have an api like:&lt;/p&gt;

&lt;p&gt;def serialize
end&lt;/p&gt;

&lt;p&gt;def unserialize
end&lt;/p&gt;

&lt;p&gt;As far as hash lookups versus case statements in an interpreted language like Ruby, its hard to tell.  Depends on the length of the case statement, and what code it executes.   Either way, I wouldn&amp;#8217;t imagine one to be much faster than the other.  The equation changes for a compiled languages of course, but that&amp;#8217;s not the issue here.&lt;/p&gt;</description>
      <pubDate>Thu, 16 Aug 2007 10:35:15 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:6ee3fd61-8d7a-459a-9b0b-485369e096ba</guid>
      <link>http://cfis.savagexi.com/2007/08/11/making-rails-better-fixing-architecture-flaws-in-active-record#comment-4247</link>
    </item>
  </channel>
</rss>
