<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Web development blog</title>
	<atom:link href="http://gusiev.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://gusiev.com</link>
	<description>How to make your web application</description>
	<pubDate>Thu, 15 Jul 2010 11:40:28 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>Ultimate rspec matcher to test named_scope or scoped</title>
		<link>http://gusiev.com/2010/07/bdd-rspec-matcher-to-test-named_scope-scoped-rails-3/</link>
		<comments>http://gusiev.com/2010/07/bdd-rspec-matcher-to-test-named_scope-scoped-rails-3/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 14:05:57 +0000</pubDate>
		<dc:creator>Bogdan Gusiev</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[ActiveRecord]]></category>

		<category><![CDATA[bdd]]></category>

		<category><![CDATA[matcher]]></category>

		<category><![CDATA[named_scope]]></category>

		<category><![CDATA[rspec]]></category>

		<guid isPermaLink="false">http://gusiev.com/?p=39</guid>
		<description><![CDATA[After having a good practice on using Ultimate rspec matcher to test validation I think it&#8217;s time to implement one for testing named scopes - custom finders. Testing these finders is daily task. Here is how it can be done with minimum amount of code and maximum readability.


Discovery (Animal Planet)

What do we expect from the [...]]]></description>
			<content:encoded><![CDATA[After having a good practice on using <a href="http://gusiev.com/2010/06/ultimate-rspec-matcher-to-test-validation/">Ultimate rspec matcher to test validation</a> I think it&#8217;s time to implement one for testing named scopes - custom finders. Testing these finders is daily task. Here is how it can be done with minimum amount of code and maximum readability.
<span id="more-39"></span>

<h3>Discovery <del>(Animal Planet)</del></h3>

What do we expect from the custom finder?
We expect that it should find assets A, B, C and should not find assets D, E, F.
And sometimes the order is important: it should find A, B C with exact order.

With respect to <em>let</em> rspec feature let&#8217;s take an example: Product has and belongs to many categories. We need to have a scope to filter products within the specified category:

<pre><code>describe "#by_category_id" do
      let(:given_category) do 
        Factory.create(:given_category)
      end
 

      let(:product_in_given_category) do
        Factory.create(
          :product,
          :categories => [category]
        )
      end

      let(:product_not_in_given_category) do
        Factory.create(
          :product,
          :categories => [Factory.create(:category)]
        )
      end

      # This might be tricky to redefine subject as the finder result
      # but in this way we can delegate the matcher to subject and 
      # avoid writing test descriptions.
      subject { Product.by_category_id(given_category.id) }

      it { should discover(product_in_given_category) }
      it { should_not discover(product_not_in_given_category) }

    end
</code></pre>

 

Factory girl was used in this example because factories kickass when we test finders. As you can see the example has a perfect readability with no one line of plain English text. I didn&#8217;t include the description in my examples but you can easily make them if they make sense for you.<br/>
Note: Be aware of the lazy loading of your finder. <em>let</em> is initialized lazy too. You should make sure it is called before the actual query to the database.
If you don&#8217;t want to care about lazy loading their is <em>let!</em> method that could be easily copy-pasted from Rspec 2.0. Unlike <em>let</em> it doesn&#8217;t have lazy initialization:

<pre><code>def let!(name, &#038;block)
  let(name, &#038;block)
  before { __send__(name) } 
end
</code></pre>

<h3>Testing sort order</h3>

If the ordering is done in non-trivial way let&#8217;s <em>discover.with_exact_order</em>. 

<pre><code>describe "#most_commented named scope" do
  let(:uncommented_post) { Factory.create(:post)}
  let!(:less_commented_post) { Factory.create(:post, :comments => [Factory.build(:comment)])}
  let!(:more_commented_post) { 
    Factory.create(:post, :comments => [Factory.build(:comment), Factory.build(:comment)])}
  }

  subject { described_class.most_commented }
 it {should discover(more_commented_post, less_commented_post).with_exact_order }
 it {should_not discover(uncommented_post) }
end</code></pre>

Be careful with default order. MySQL and Postgres sort objects as they were created by default.
That is why generate objects in reverse order e.g. <em>less_commented_post</em> before <em>more_commented_post</em> is important to make sure that ordering is your code behavior rather than default db behavior.
 

<h3> Summary </h3>

I &#8216;ve add this matcher to the <a href="http://gusiev.com/2010/06/ultimate-rspec-matcher-to-test-validation/">previous one</a>. Both matchers are available here <a href="http://github.com/bogdan/accept_values_for">accept_values_for</a>. Let&#8217;s start thinking of what else we can do.
]]></content:encoded>
			<wfw:commentRss>http://gusiev.com/2010/07/bdd-rspec-matcher-to-test-named_scope-scoped-rails-3/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ultimate rspec matcher to test validation</title>
		<link>http://gusiev.com/2010/06/ultimate-rspec-matcher-to-test-validation/</link>
		<comments>http://gusiev.com/2010/06/ultimate-rspec-matcher-to-test-validation/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 17:50:17 +0000</pubDate>
		<dc:creator>Bogdan Gusiev</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[ActiveRecord]]></category>

		<category><![CDATA[pattern]]></category>

		<category><![CDATA[rails]]></category>

		<category><![CDATA[rspec]]></category>

		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://gusiev.com/?p=38</guid>
		<description><![CDATA[After a first thousand of tests using Rspec I fount it very annoying to repeat my self testing the standard code as spec code is usually twice longer than code it test. I&#8217;ve started to look for a way to simplify the patterns and make it reusable. Among other nice rspec tricks there is possibility [...]]]></description>
			<content:encoded><![CDATA[After a first thousand of tests using Rspec I fount it very annoying to repeat my self testing the standard code as spec code is usually twice longer than code it test. I&#8217;ve started to look for a way to simplify the patterns and make it reusable. Among other nice rspec tricks there is possibility to write custom Rspec matchers. Spec the validation is just two lines of code for each attribute now.
<span id="more-38"></span>

<h3> Existing solutions </h3>

After doing some search around I found Shoulda and remarkable gems that provide a way of doing this. Here is one of remarkable variant (others are just ugly): 

<pre><code>it { should validate_numericality_of(:age, :greater_than => 18, :only_integer => true) }</code></pre>

But that is huge contradiction with BDD methodology because it doesn&#8217;t make you think about behavior. People use to copy-paste code from model to spec and all possible bugs within. As the result <strong>nothing is tested</strong>&#8230; I don&#8217;t even say about &#8220;test first&#8221;.

<h3> Easy DSL and Implementation </h3>

When I implement validation everything I care about is: what values should be accepted and what values should not. An easy DSL that realize this pattern would be:

<pre><code>describe User do
  it { should accept_values_for(:email, “john@example.com”, “lambda@gusiev.com”) }
  it { should_not accept_values_for(:email, “invalid”, nil, “a@b”, “john@.com”) }
end</code></pre>

 
That&#8217;s it! Two lines of code per attribute. And that is perfectly fine for &#8220;test first&#8221; principle.<br/>
Rspec authors take care about custom Rspec matcher. So the implementation is very easy.
Fork me on github: <a href="http://github.com/bogdan/accept_values_for">accept_values_for rpec matcher</a>. The <strong>accept_values_for</strong> pattern is a true BDD way and unlike Remarkable it really do testing.

<h3> validates_uniqueness_of </h3>

 
This is very special validation because you always need more then one record to test it. So, the pattern for uniqueness validation is:

<pre><code>describe User do
  context "if user with email 'aa@bb.com' exists" do
    before do
      User.create!(@valid_attributes.merge(:email => 'aa@bb.com')
    end
    it { should_not accept_values_for(:email, “aa@bb.com”) }
  end
end</code></pre>

<h3> Summary </h3>

Custom matcher is just 50 lines of code that make your life much easier. Do not scare to write your own. Custom matcher to test ActiveRecord#named_scope coming soon.
]]></content:encoded>
			<wfw:commentRss>http://gusiev.com/2010/06/ultimate-rspec-matcher-to-test-validation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Advanced non-flat controllers hierarchy with rails</title>
		<link>http://gusiev.com/2010/06/nesting-namespace-route-non-flat-controllers-hierarchy-rails/</link>
		<comments>http://gusiev.com/2010/06/nesting-namespace-route-non-flat-controllers-hierarchy-rails/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 21:14:37 +0000</pubDate>
		<dc:creator>Bogdan Gusiev</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[architecture]]></category>

		<category><![CDATA[controller]]></category>

		<category><![CDATA[rails]]></category>

		<category><![CDATA[route]]></category>

		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://gusiev.com/?p=37</guid>
		<description><![CDATA[REST became the best practice for organizing CRUD server side interface. 
But what to do when we have something more than hello-world application that 
goes forward from data CRUD and provides many presentations 
of the same data with different filters and different layouts?


How the flat controller architecture goes to hell

Starting from REST-full controller people use [...]]]></description>
			<content:encoded><![CDATA[REST became the best practice for organizing CRUD server side interface. 
But what to do when we have something more than hello-world application that 
goes forward from data CRUD and provides many presentations 
of the same data with different filters and different layouts?<br/>
<span id="more-37"></span>

<h3>How the flat controller architecture goes to hell</h3>

Starting from REST-full controller people use to stick to them and add more and more actions to the same class. And that is how the controller code goes to hell:

<pre><code>class UsersController &lt; ApplicationController
#
# Filters
#
skip_before_filter :check_user_is_valid, :only =&gt; [:edit, :update]
before_filter :require_user, :only =&gt; [
:update, :edit, :settings, :disconnect_twitter, :connect_facebook_account, :google_contacts
]

before_filter :load_user, :except =&gt; [
:index, :new, :create, :remote_validate_email, :autocomplete_for_user_full_name,
:remote_validate_facebook_uid, :google_contacts
]

before_filter :check_permissions, :only =&gt; [ :edit, :update, :settings, :update_photo, :connect_facebook_account ]

before_filter :load_invitation, :only =&gt; [:new, :create]
before_filter :ensure_authenticated_to_facebook, :only =&gt; :connect_facebook_account
before_filter :initialize_form, :only =&gt; [:edit]

#
# And 20 almost independent actions goes here
# And the twice longer tests file for this controller
#

end
</code></pre>

<h3> Namespaces and nesting </h3>

The root of the problem is in ignoring the following simple rule:
<strong>The default choice for implementing new feature is do it in other controller</strong>
It&#8217;s always better to have 20 controllers with one action then one controller with 20 actions.
Usually there is no compromise variant. And 20 controllers with one action ain&#8217;t as bad as you imagine.<br/>
<br/>

In order to handle the large number of controller we are actively using the namespaces and nested resources features. Let me give an example: User has many projects, Project belongs to category. We need to list projects per user and per category. In the flat hierarchy you would be confused but namespaces and nesting solves the problem.<br/>

<pre><code>map.resources :categories do |c|
  c.namespace :categories do |categories|
    categories.resouces :projects
  end
end
map.resources :users do |u|
  c.namespace :users do |users|
    users.resouces :projects
  end
end

class Categories::ProjectsController

  def index
    @projects = ....
  end
end

class Users::ProjectsController

  def index
    @projects = ....
  end
end</code></pre>

Everyone heard about restful authentication but not so many people applied this idea to other not so restful from the first sight things. Like TwitterConnectionController:

<pre><code>class Users::TwitterConnectionController < ApplicationController

  def create
  end

  def destroy
  end
end</code></pre>

Many people will be pushing all such staff to UsersController until their editors would run out of memory.

<h3>Out of scope</h3>

State control actions are not in REST but should be one day. Placing them in the same controller with CRUD is generally a good idea:

<pre><code>class ArticlesController 

  def {new, create, update, edit, destroy}
  end

  def publish
    @article.publish!
    redirect_to articles_path
  end

end</code></pre>

<h3>Some sugar from generators</h3>

Rails <em>generate</em> script supports namespaces very well:

<pre><code>$ ./script/generate <del>rspec_</del>controller users/categories
      create  app/controllers/users
      create  app/helpers/users
      create  app/views/users/categories
      create  spec/controllers/users
      create  spec/helpers/users
      create  spec/views/users/categories
      create  spec/controllers/users/categories_controller_spec.rb
      create  spec/helpers/users/categories_helper_spec.rb
      create  app/controllers/users/categories_controller.rb
      create  app/helpers/users/categories_helper.rb</code></pre>

And classes created in appropriate namespace and folder as well as specs for them.
The only one thing you should do manually is add routes. 

<h3>Drawbacks</h3>

Every engeneering solution has it&#8217;s drawbacks. While you have different controllers that operates on the same classes you might need to reuse functionality among them.
I preffer to solve it by mixing in a module:

<pre><code>class Users::ProjectController

 include UserNestedResource

end</code></pre>

Some people use inheritance instead. Both ways are almost the same. Nothing hard here as well.

<h3>Summary</h3>

At the end I &#8216;ll just repeat it again:<br/> 
Default policy for placing two actions that has some kind of connection is <strong>SPLIT</strong>.

]]></content:encoded>
			<wfw:commentRss>http://gusiev.com/2010/06/nesting-namespace-route-non-flat-controllers-hierarchy-rails/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DOM element class - css reference or javascript reference?</title>
		<link>http://gusiev.com/2010/04/dom-element-class-html-javascript-reference/</link>
		<comments>http://gusiev.com/2010/04/dom-element-class-html-javascript-reference/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 19:51:33 +0000</pubDate>
		<dc:creator>Bogdan Gusiev</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[class]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[dom]]></category>

		<category><![CDATA[element]]></category>

		<category><![CDATA[html]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://gusiev.com/?p=34</guid>
		<description><![CDATA[Designer have used element class attribute for CSS styling for ages. Nowadays classes are also used in javascript selectors. This overlapping cause additional problems: Changes in js may cause broken design and changes in design may cause broken js. The last one may be hard to detect especially when design and css are handled by [...]]]></description>
			<content:encoded><![CDATA[Designer have used element class attribute for CSS styling for ages. Nowadays classes are also used in javascript selectors. This overlapping cause additional problems: Changes in js may cause broken design and changes in design may cause broken js. The last one may be hard to detect especially when design and css are handled by different person.
<span id="more-34"></span>

<hr/>
Element class seems the best way to query the element from DOM in js code. Other variants like it&#8217;s relative possition to other elements are very fragile. Let&#8217;s say that we have the following DOM:

<pre><code>&lt;a&gt; Delete&lt;/a&gt;
&lt;a&gt; Edit&lt;/a&gt;</code></pre>

And both links are handled with javascript. How would you separate them? 

<ul>
	
<li><strong>By order</strong>(first, second) will cause problems if designer would like to change the order.</li>

	
<li><strong>By id</strong> will fail if you would have a list of elements where each has these links</li>

	
<li><strong>By label</strong> is just a fuck up and won&#8217;t work for multi language application</li>

</ul>

The only one variant that provide the best stability is reference <strong>By class</strong>.
But as stated above class also serves for another purpose - styling. 

The thing that might help is a special prefix(for example &#8220;js&#8221;) for all &#8216;JavaScript classes&#8217;.
Like:

<pre><code>&lt;a class="js-new-comment big-blue-button"&gt; New Comment &lt;/a&gt;</code></pre>

And the convention that classes with prefix should only be used in javascript selectors and classes without prefix in CSS.
<br/><br/>
Yes, sometimes it may look like:

<pre><code>&lt;input type='button' class="js-follow-button follow-button"&gt; Follow this person &lt;/input&gt;</code></pre>

But that makes sense to eliminate maintenance problem described above.
]]></content:encoded>
			<wfw:commentRss>http://gusiev.com/2010/04/dom-element-class-html-javascript-reference/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ruby1.8: &#8216;private&#8217; doesn&#8217;t give expected level of privacy</title>
		<link>http://gusiev.com/2010/04/ruby18-private-protected-incapsulatio/</link>
		<comments>http://gusiev.com/2010/04/ruby18-private-protected-incapsulatio/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 10:16:09 +0000</pubDate>
		<dc:creator>Bogdan Gusiev</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[criticism]]></category>

		<category><![CDATA[encapsulation]]></category>

		<category><![CDATA[method]]></category>

		<category><![CDATA[privacy]]></category>

		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://gusiev.com/?p=33</guid>
		<description><![CDATA[The classic OOP pattern usually called encapsulation implemented in ruby with private and protected keywords methods. The distinction between API and implementation works great with both. The problem is that private doesn&#8217;t hide method for inherited classes. 



See the simple example below:


class A
  private
  def implementation
    puts 'private A'
  [...]]]></description>
			<content:encoded><![CDATA[The classic OOP pattern usually called encapsulation implemented in ruby with <em>private</em> and <em>protected</em> <del>keywords</del> methods. The distinction between API and implementation works great with both. The problem is that <em>private</em> doesn&#8217;t hide method for inherited classes. 
<span id="more-33"></span>

<hr/>
See the simple example below:

<pre><code>
class A
  private
  def implementation
    puts 'private A'
  end
end

class B < A
  def api
    implementation
  end
end

B.new.api
</code></pre>

And we won&#8217;t get exception at the last line.<br/>
The real difference between protected and private methods is more specific.<br/>
At first: <em>implementation</em> method can not be called like <em>self.implementation</em> even from class A.

<pre><code>class A
  def api
    self.implementation #exception here
  end
  private
  def implementation
    puts 'private A'
  end
end

A.new.api
</code></pre>

Seamless pure gap. You can do such call if the method would be protected. Can&#8217;t imagine the case when this limitation is useful. <br/>
<br/>
The second difference is a bit esoteric. Two instances of the same class can access protected methods of each other but not private methods.

<pre><code>class A
  def api(another) #suppose to receive an instance of a
    implementation == another.implementation
  end
  protected
  def implementation
    puts 'private A'
  end
end
A.new.api(A.new)
</code></pre>

Fine for <em>protected</em> but fail for <em>private</em>. Well, this kind of protection do not make a real because of it&#8217;s rareness.
<br/><br/>

You might do any decision on the points above.<br/>
My conclusion is to not use <em>private</em> at all, because it doesn&#8217;t give the level of privacy that I expect. <em>private</em> is not suitable for such an extremely dynamic language as Ruby. 

]]></content:encoded>
			<wfw:commentRss>http://gusiev.com/2010/04/ruby18-private-protected-incapsulatio/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A dream to develop application that I will use</title>
		<link>http://gusiev.com/2010/03/quality-develop-application-improve-usability-design/</link>
		<comments>http://gusiev.com/2010/03/quality-develop-application-improve-usability-design/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 09:26:38 +0000</pubDate>
		<dc:creator>Bogdan Gusiev</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[application]]></category>

		<category><![CDATA[design]]></category>

		<category><![CDATA[quality]]></category>

		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://gusiev.com/?p=32</guid>
		<description><![CDATA[Developing sites for communities you never join, enterprise applications for company you never work in, services you never find useful&#8230; a serious problem of IT industry. All misunderstanding between customers and developers come from that reason.

It would be so great if we could always feel ourselves as a user of our applications and make  [...]]]></description>
			<content:encoded><![CDATA[Developing sites for communities you never join, enterprise applications for company you never work in, services you never find useful&#8230; a serious problem of IT industry. All misunderstanding between customers and developers come from that reason.
<br/><br/>
It would be so great if we could always feel ourselves as a user of our applications and make  something useful, but not spend time on improving features that won&#8217;t be familiar. Being a user of the developed application makes it really possible to develop ergonomic and pretty design.
<br/><br/>
Unfortunately most of the companies are ignoring that simple rule and unfortunately in some cases it is hard to follow. But anyway that is the only one way to build the best product.

]]></content:encoded>
			<wfw:commentRss>http://gusiev.com/2010/03/quality-develop-application-improve-usability-design/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Advanced SQL and named scopes stack with ActiveRecord</title>
		<link>http://gusiev.com/2010/01/sql-queries-activerecord-rails-named-scopes-stack/</link>
		<comments>http://gusiev.com/2010/01/sql-queries-activerecord-rails-named-scopes-stack/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 11:02:51 +0000</pubDate>
		<dc:creator>Bogdan Gusiev</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[ActiveRecord]]></category>

		<category><![CDATA[named_scope]]></category>

		<category><![CDATA[query]]></category>

		<category><![CDATA[rails]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://gusiev.com/?p=30</guid>
		<description><![CDATA[If you ever work with rails application that is a little bit more complex then a simple CRUD you would know that some of the ActiveRecord magic doesn&#8217;t work for complex SQL queries. I am primary talking about named scopes stack feature.



Let&#8217;s review the following named_scope that suppose to be usable in different combinations with [...]]]></description>
			<content:encoded><![CDATA[If you ever work with rails application that is a little bit more complex then a simple CRUD you would know that some of the ActiveRecord magic doesn&#8217;t work for complex SQL queries. I am primary talking about named scopes stack feature.<br/>
<span id="more-30"></span>

<hr/>
Let&#8217;s review the following named_scope that suppose to be usable in different combinations with others:

<pre><code>named_scope :network_of, lambda {|user|
{
:select => "u.*"
:from => "users u, followings f1, followings f2",
:conditions => "f1.follower_id = #{user.id} AND " + 
"f1.followed_id = f2.follower_id AND " +
"f2.followed_id = u.id"
}</code></pre>

It suppose to returns all people that are followed by people that are followed by the given person.
From the SQL point of view that is the simpliest and fastest way to do that with a plain SQL.
But this solution will have some issues with Active Record named scopes stack magic.
See that User.network_for(current_user).all(:limit =>5) will result in SQL exception primary because (:limit => 5) doesn&#8217;t know about the table alias &#8220;users u&#8221;.
We can not use it in fact.<br/>
The second problem comes to the foreground when we will try to use ActiveRecord features like
User.network_for(current_user).all(:include => :orders). ActiveRecord handles :include in the very different ways and in some cases you will see the SQL exception here as well.<br/>
The problem is that :include sometimes appends some joins to the query that is concatenated to the last table in the :from parameter. To solve that we should make &#8220;users&#8221; table to be the last one declared in :from parameter.

<pre><code>:select => "users.*"
:from => "followings f1, followings f2, users",
:conditions => "f1.follower_id = #{user.id} AND " + 
"f1.followed_id = f2.follower_id AND " +
"f2.followed_id = users.id"</code></pre>

Summary I would say that using :joins instead of :from/:conditions would give more flexibility and stackability to your named scopes but sometimes :from is more clear and here you got the tip how to use it.
]]></content:encoded>
			<wfw:commentRss>http://gusiev.com/2010/01/sql-queries-activerecord-rails-named-scopes-stack/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Vim as IDE - new development era for me</title>
		<link>http://gusiev.com/2009/12/vim-as-ruby-on-rails-ide-development-perfomanc/</link>
		<comments>http://gusiev.com/2009/12/vim-as-ruby-on-rails-ide-development-perfomanc/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 22:12:38 +0000</pubDate>
		<dc:creator>Bogdan Gusiev</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[perfomance]]></category>

		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://gusiev.com/?p=29</guid>
		<description><![CDATA[I was using Vim to do the minor editing in config files for ages. Vim is advanced on basic navigation and editing operations. However I was always prefer IDE for programming because of it&#8217;s specific to language navigation(&#8217;go to definition&#8217; feature is awesome!), integrated debugger. But while gaining the experience I noticed that all advanced [...]]]></description>
			<content:encoded><![CDATA[I was using Vim to do the minor editing in config files for ages. Vim is advanced on basic navigation and editing operations. However I was always prefer IDE for programming because of it&#8217;s specific to language navigation(&#8217;go to definition&#8217; feature is awesome!), integrated debugger. But while gaining the experience I noticed that all advanced features began to be less important then basic ones. And you should try Vim if you feel the same.<br/>
<span id="more-29"></span>

<hr/>

The basic concept of vim is that: Vim think in the same way as you do. For example: I want to delete &#8216;d&#8217; everything inside &#8216;i&#8217; brackets &#8216;)&#8217; and vim understands my command: di) <br/>
You shouldn&#8217;t type a dozen of button to move cursor around and finally delete the selected fragment. 
It&#8217;s hard to adapt because people are use to think in the way that there text editor do. Vim does vice versa. Some people are saying that they don&#8217;t like vim because it make them think a lot. That&#8217;s wrong! Vim is trying to make you free from thinking about editing and concentrate on the content.<br/>

General editing in Vim considered up to every small details. Ask yourself if there is some usual task that I am doing inefficiently and search the Vim feature to optimize that in 3-5 keys. And in ninety nine percent of cases you will find it as built in vim command or a plugin.

]]></content:encoded>
			<wfw:commentRss>http://gusiev.com/2009/12/vim-as-ruby-on-rails-ide-development-perfomanc/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Objects behaviour inheritance with RSpec</title>
		<link>http://gusiev.com/2009/10/objects-behaviour-inheritance-with-rspec/</link>
		<comments>http://gusiev.com/2009/10/objects-behaviour-inheritance-with-rspec/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 19:51:06 +0000</pubDate>
		<dc:creator>Bogdan Gusiev</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[behaviour]]></category>

		<category><![CDATA[inheritance]]></category>

		<category><![CDATA[rspec]]></category>

		<category><![CDATA[ruby]]></category>

		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://gusiev.com/?p=28</guid>
		<description><![CDATA[About half of a year ago I was writing about object interface and Liskov Substitution Princeple. In short: Any class instance that extends the base class should pass all unit tests behaviour tests written for base class instance. It was a surprise for me that this concept has already been implemented in RSpec.


My previous article [...]]]></description>
			<content:encoded><![CDATA[About half of a year ago I was writing about <a href="http://gusiev.com/2009/05/what-do-you-expect-from-interface/">object interface and Liskov Substitution Princeple</a>. In short: Any class instance that extends the base class should pass all <span style="text-decoration: line-through;">unit tests</span> behaviour tests written for base class instance. It was a surprise for me that this concept has already been implemented in RSpec.<br/><br/>

<span id="more-28"></span>
My previous article was primary inspired by Java programming language and it&#8217;s interface concept. Unlike Java, Ruby does not have interfaces, but behaviour inheritance is still actual for both languages. RSpec seems the first testing framework that provide the ability to validate LSP and behavior inheritance with &#8216;it_should_behave_like&#8217;. <br/>
With Ruby modules(mixins) feature we can build reusable code and include it in different classes<a href="http://ruby-doc.org/core/classes/Module.html">(read more)</a>. With RSpec we can bundle the tests as well.<br/>

<br/>

Let&#8217;s review the following module that uses one of the Rails callback and adds some logging:<br/>

<pre>
<code>
module LoggedModel
  def after_save
    super
    handle_logging
  end
end
</code>
</pre>

and the some tests group for this module:<br/>

<pre><code>
describe LoggableModel
  it "should be loggable" do
    LoggableModel.should ...
  end
end
</code>
</pre>

Now, we have a tested code that is going to be used in many cases like this:<br/>

<pre><code>class MyModel
  include LoggableModel
  def after_save
    do_some_other_thing
  end
end
</code></pre>

OK, let&#8217;s see what we have: after_save in MyModel overwrites after_save in LoggableModel and breaks the logging. This is simplest example when the behavior inheritance may be broken. Rspec shared examples groups allows you to ensure that the code in LoggableModel is used correctly from any inherited class. Let&#8217;s change the definithin of LoggableModel tests.<br/>

<pre><code>
shared_examples_for "logged model" do
  it "should be loggable" do
    subject.should...
  end
end
</code>
</pre>

&#8216;Subject&#8217; is the ultimate RSpec magic that let us make a simple abstraction with the tested class and reuse these shared examples in MyModel spec:

<pre>
<code>describe MyModel do
  it_should_behave_like 'loggable model'
end</code>
</pre>

In this way we will rerun the LoggableModel examples for MyModel and make sure that it&#8217;s behavior wasn&#8217;t broken.
]]></content:encoded>
			<wfw:commentRss>http://gusiev.com/2009/10/objects-behaviour-inheritance-with-rspec/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Computer science ain&#8217;t as good as it should be</title>
		<link>http://gusiev.com/2009/07/computer-science-programming-criticism-object-database-design/</link>
		<comments>http://gusiev.com/2009/07/computer-science-programming-criticism-object-database-design/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 10:25:06 +0000</pubDate>
		<dc:creator>Bogdan Gusiev</dc:creator>
		
		<category><![CDATA[IT-related]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[criticism]]></category>

		<category><![CDATA[database]]></category>

		<category><![CDATA[oop]]></category>

		<category><![CDATA[science]]></category>

		<guid isPermaLink="false">http://gusiev.com/?p=26</guid>
		<description><![CDATA[When I start studying computer science in the University class I truly believe that it is all I need to get started writing good programs. Algorithms > Functional programming > OOP > Databases > MVC is a step-by-step path of all people that learn programming of the web application. But&#8230;


Programming basics like conditions, variables, cycles [...]]]></description>
			<content:encoded><![CDATA[When I start studying computer science in the University class I truly believe that it is all I need to get started writing good programs. Algorithms > Functional programming > OOP > Databases > MVC is a step-by-step path of all people that learn programming of the web application. But&#8230;
<span id="more-26"></span>
<br/><br/>
Programming basics like conditions, variables, cycles and functions are mandatory for everyone just like writing and speaking for a baby.<br/> 

But more advanced knowledge are less useful and optional. All of these:

<ul>
	
<li>Object hierarchy</li>

	
<li>Normalized database model</li>

</ul>

are turned into dust by more important

<ul>
	
<li>Do it as fast as possible</li>

	
<li>Customer wants!</li>

</ul>

Each framework declare it&#8217;s own way to organize the application Classes. If you are working on CRUD(create-read-update-delete) data application you don&#8217;t need to think about object hierarchy yourself anymore. All you need to do is understand where you need place the function that handle data processing. And the principles a well declined in the framework manual. 
Normalized database is only a myth in a real world application. In 80% of cases the database design is evident to the developer. In other 20% the database couldn&#8217;t be normalized at all.<br/>
<br/>

When you start learning programming try to let your knowledge be &#8220;moved to production&#8221; as fast as possible. In other words: Have a programming practice as fast as possible and you will understand what kind of programming theory you really need. Concentrate your education on all cases you met and avoid learning things that you could possible come across.   

]]></content:encoded>
			<wfw:commentRss>http://gusiev.com/2009/07/computer-science-programming-criticism-object-database-design/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
