<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CaelumObject Developers&#039; Blog</title>
	<atom:link href="http://www.caelumobjects.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.caelumobjects.com</link>
	<description>CaelumObject Developers&#039; Blog</description>
	<lastBuildDate>Mon, 20 Jun 2011 17:53:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Concise code: brevity and clarity</title>
		<link>http://www.caelumobjects.com/2011/06/20/concise-code-brevity-and-clarity/</link>
		<comments>http://www.caelumobjects.com/2011/06/20/concise-code-brevity-and-clarity/#comments</comments>
		<pubDate>Mon, 20 Jun 2011 17:53:40 +0000</pubDate>
		<dc:creator>Guilherme Silveira</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[quality]]></category>

		<guid isPermaLink="false">http://www.caelumobjects.com/?p=867</guid>
		<description><![CDATA[A few years ago, with the wave of new (and old) languages growing its acceptance rate in the market, some people appeared defending code with the intention of being &#8220;concise&#8221;. Being concise means express a lot, with a few words; being clare and sucint; brief, but with all the required information; having characteristics of brevity [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.buildingwebapps.com/articles/79190-2007-the-ruby-on-rails-year">A few years ago</a>, with the <a href="http://blog.caelum.com.br/scala-sua-proxima-linguagem/">wave</a> <a href="http://blog.caelum.com.br/a-jvm-e-as-outras-linguagens-voce-esta-preparado/">of new (and old) languages growing its acceptance rate in the market</a>, some people appeared defending code with the intention of being &#8220;concise&#8221;.</p>
<p><a href="http://blog.caelum.com.br/wp-content/uploads/2011/06/concise.jpg"><img src="http://blog.caelum.com.br/wp-content/uploads/2011/06/concise-300x228.jpg" alt="" title="Conciso" width="300" height="228" class="alignright size-medium wp-image-4473" /></a></p>
<p>Being concise means <a href="http://www.answers.com/topic/concise">express a lot, with a few words; being clare and sucint</a>; <a href="http://en.wiktionary.org/wiki/concise">brief, but with all the required information</a>; <a href="http://en.wiktionary.org/wiki/succinct">having characteristics of brevity and clarity</a>. Note how all definitions imply in being brief, but also about the clarity of the information. Those are two fundamental factors for <a href="http://www.caelum.com.br/curso/pm-87-agile-praticas-ageis/">searching high quality code</a>, easy to be maintained in the long run, affecting the project&#8217;s maintainability as much as its architecture does.</p>
<p>Let&#8217;s take the act of saving an user in the only database accessed by the application as an example:</p>
<pre class="brush: ruby; title: ;">
user.saveInTheDatabase(database)
</pre>
<p>It&#8217;s clear, it&#8217;s even redundant <a href="http://blog.caelum.com.br/em-busca-do-nome-adequado-metodos-variaveis-e-classes/">once the name of the method is &#8220;typified&#8221;</a> whilst repeating the word <code>database</code>. The following code keeps the same clearness related to the same responsibility, but its also succint:</p>
<pre class="brush: ruby; title: ;">
user.save
</pre>
<p>In <b>another situation</b>, the same code presented above might be implemented by executing other tasks, such as inserting objects related to the user in somewhere else:</p>
<pre class="brush: ruby; title: ;">
def save
  super
  machines_to_install.each do |instance|
    create_machine(instance)
  end

  # or any other effect, collateral or returned
end
</pre>
<p>The same code is still succinct, but not clear:</p>
<pre class="brush: ruby; title: ;">
user.save
</pre>
<p>In fact, it lies. It does not say what it will actually do. The search for the &#8220;shortest&#8221; possible code introduced the possibility of misreading, misinterpreting, even worse, the name of the method induces the error: the code is not concise, it&#8217;s just brief.</p>
<p>For this reason, some advanced techniques, such as AOP or even reflection, should be used with care when dealing with domain code. Transparent remotability, EJBs, JPA, ActiveResource, ActiveRecord and any other libraries  that work with a layer that it tries to obfuscate might generate problems if the end developer does not fully understands whats beyond it &#8211; and the developer who just joined the company *does not*. This is the case where multiple remote invocations or N+1 sql queries, which the mentioned frameworks might induce if not used properly.</p>
<p><a href="http://revistalingua.uol.com.br/textos.asp?codigo=12308">Concise does not mean a brief text</a>. One of the biggest challenges of an author is to be concise, trying not to bore his readers, keeping the text&#8217;s clarity. Some languages or even libraries might speed up or down the process to say something in a few words, which does not mean the code will be easier to understand and, consequently, to maintain in the long run.</p>
<p>Writing less &#8211; the lines of code metric &#8211; brings the shortest code, <a href="http://martinfowler.com/bliki/CannotMeasureProductivity.html">but not necessarily the clearest or best</a>. In the following example, is the client just being saved or is there something else going on, and this &#8220;pseudo-conciseness&#8221; is tricking us?</p>
<pre class="brush: java; title: ;">
cliente.save()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.caelumobjects.com/2011/06/20/concise-code-brevity-and-clarity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When inheritance and mixins become a design issue</title>
		<link>http://www.caelumobjects.com/2011/03/09/when-are-inheritance-and-mixins-evil/</link>
		<comments>http://www.caelumobjects.com/2011/03/09/when-are-inheritance-and-mixins-evil/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 17:09:38 +0000</pubDate>
		<dc:creator>Guilherme Silveira</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[coupling]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://www.caelumobjects.com/?p=832</guid>
		<description><![CDATA[One object, more than 300 public methods, 560 instance and 300 class or static methods. It is easy to see that those objects tipically present low cohesion, more than one responsibility, tight coupling and a huge interface. A pattern known as &#8220;God Class&#8221;. You can create them in Java using class inheritance, or in Ruby [...]]]></description>
			<content:encoded><![CDATA[<p>One object, more than 300 public methods, 560 instance and 300 class or static methods. It is easy to see that those objects tipically present low cohesion, more than one responsibility, tight coupling and a huge interface. A pattern known as &#8220;God Class&#8221;.</p>
<p>You can create them in Java using class inheritance, or in Ruby using class inheritance or module mix-ins. It is the &#8220;inheritance way&#8221;. Typically connected with &#8220;global variables and methods&#8221; and &#8220;thread locals&#8221;.</p>
<p>In this post we will go through an example of such object with hundreds and methods and show how to decouple our code from that. Moving away from the &#8220;Inheritance way&#8221; into the &#8220;Favor composition over inheritance&#8221; way, totally unrelated to language of choice.</p>
<p><a href="http://magicscalingsprinkles.wordpress.com/2010/02/08/why-i-love-everything-you-hate-about-java/">Nick Kallen has recently described how to use OO principles to compose behavior in any desired aspect</a>. <a href="http://yehudakatz.com/2010/02/15/abstractqueryfactoryfactories-and-alias_method_chain-the-ruby-way/">Yehuda Katz showed how to implement the same behavior in Ruby</a>.</p>
<p>Nick complains about some Ruby code he has seen around, while Yehuda about the Java, and this is the real problem: there is bad OO design out there, no matter which language. Both are correct in their design complains, and both languages can provide the good design techniques and results they are expecting. The question is not about the language, but about the design pattern. </p>
<p>For instance, <a href="http://pivotallabs.com/users/rolson/blog/articles/1162-redefine-a-method-from-a-module-like-a-gentleman">Rob Olson suggested that</a>, for a typical inheritance problem, the solution was to use meta programming. Yehuda came up with a simple and better solutions, simply use OO: &#8220;super&#8221;. The original problem arrived because mixing in a module present the same kind of inheritance coupling as from inheriting from a class. So Yehuda&#8217;s solution is good for a module with a couple of methods, but dangerous for the design when several mix-ins are included (is 30 too many?) and hundreds of methods made available in the same scope.</p>
<p>But does Ruby code have to end up with hundreds of methods in one object? Douzens of mixins? Surely not. Although, sometimes, it does, as we will see in the following example. As with some Java code sometimes ends up with amazingly huge inheritance trees.</p>
<p>There is no problem in using mix-ins or inheritance once you are aware of its effects in your design. Pretty much in the same way, anyone can do a lot of bad code in Java (and any other OO language) if he is not aware of good OO design principles.</p>
<p>Let&#8217;s move to an example of bad usage of inheritance, that can be done either in Java (through mutiple class inheritance and interface implementation) and Ruby (through class inheritance and multiple mixins).</p>
<p><b>Mixins, coupling issues and the single responsibility principle</b></p>
<p><b>The</b> example of &#8220;over usage&#8221; of inheritance and mix-ins: Rails has greatly improved web applications productivity due to its Convention over Configuration approach. Still, its internal design choices show some famous object oriented design issues. Between those, one that is easily spotted is the need to inherit from ActionController and ActiveResource.</p>
<p>Class inheritance or mix-ins inclusions in Ruby imply in tighter coupling, and a simple test can show how much this coupling implies in 560 methods being inherited and due to Ruby design, private methods also affect this coupling:</p>
<pre class="brush: plain; title: ;">
rails console

&gt; ActionController::Base.instance_methods.size
306

&gt; OMG
NameError: uninitialized constant Object::OMG

&gt; (ActionController::Base.instance_methods + ActionController::Base.private_instance_methods).size
410
</pre>
<p>An object having 36 ancestors, 410 instance methods and 353 class methods indicate loss of cohesion, and breaks the <a href="http://en.wikipedia.org/wiki/Solid_(object-oriented_design)">SRP and ISP principles from solid</a>.<br />
Usually those approaches with a few scopes and several methods come from procedural programming, while functional programming would  use functions as a a higher order element<br />
for composing behavior &#8211; which would be great! Unfortunately in this case, those methods are used as almost-global procedures. This can be easily found in other OO languages and frameworks too, just try to find code based in inheritance which provides a huge interface with hundreds of methods being exposed.</p>
<p>This loss of cohesion can be seen when a controller has in its scope methods related to html rendering,<br />
http request and response processing, uri lookup, scope access and more: everything within an instance of ActionController::Base. Cohesion gets weaker when adding new unrelated methods to an ApplicationController, the typical approach.</p>
<p>Unit testing, a technique that easily shows loss of cohesion and tight coupling, easily shows the problem. One needs to either test the class alone by setting expectations to methods contained in the parent class (such as any invocations to param and path methods), or test it only with its parent, by<br />
creating an instance and invoking the desired method. Both approaches show that to create a Controller one needs information from several<br />
different sources, with different goals. This is the sign of coupling and loss of cohesion.</p>
<p>This post implements a work around Rails to show how to remove that coupling and avoid inheritance and mix-ins, while defining a framework (on top<br />
of Rails) that is capable of providing the same functionalities. It is just a working proof of concept. Although it can be used, it needs a lot of enhancements<br />
to provide helpers for every controller-coupled-functionality.</p>
<p>The first example is an action using a few of those different-responsibilities contained within the controller to log in a client:</p>
<pre class="brush: ruby; title: ;">
class ClientsController &lt; ApplicationController
  def create
    @client = Client.find(params[:client])
    session[:current_user] = @client
    flash[:message] = &quot;Client logged in unit!&quot;
    redirect_to client_home_path(@client)
  end
end
</pre>
<p>Some of those methods could be extracted to ApplicationController, with the same lack of cohesion (those methods would be inherited).<br />
Instead of having the responsibility to deal with parameters, let&#8217;s leave it to the framework:</p>
<pre class="brush: ruby; title: ;">
class ClientsController &lt; ApplicationController
  def create(client)
    session[:current_user] = client
    flash[:message] = &quot;Client logged in unit!&quot;
    redirect_to client_home_path(client)
  end
end

class ApplicationController

  private

  def send_action(sym)
    params = ParamsExtractor.extract_for(method(sum), self)
    super(sym, *params)
  end

end
</pre>
<p>Instead of containing the responsibility of the flash scope, a conversational artificial &#8220;http&#8221; scope; the session lookup;<br />
and the redirecting, all in one object, those responsibilities can be broken and one would be able to:</p>
<pre class="brush: ruby; title: ;">
class ClientsController &lt; ApplicationController
  def create(client, current_user, redirect_to)
    current_user.login(client)
    redirect_to.client_home(client)
  end
end

class CurrentUserHelper
  def initialize(controller)
    @controller = controller
  end
  def login(client)
    @controller.session[:current_user] = client
    @controller.flash[:message] = &quot;Client logged in unit!&quot;
  end
end
</pre>
<p>Now its time to implement the parameters provider:</p>
<pre class="brush: ruby; title: ;">
class ParamsExtractor
    def extract_for(method, controller)
      types = method.parameters
      if has_parameters(types)
        provide_instances_for(types, controller)
      else
        []
      end
    end

    private

    def has_parameters(types)
      types.size!=0 &amp;&amp; types[0]!=[:rest]
    end

    def provide_instances_for(params, controller)
      params.collect do |param|
        providers.provide(param[1], controller)
      end
    end

end
</pre>
<p>One needs to implement a provider for each and every desired behavior. For example, to instantiate AR objects:</p>
<pre class="brush: ruby; title: ;">
    class Instantiate
      def extract(controller, name)
        name.camelize.constantize.new(controller.params[p])
      end
      def handles?(controller, name)
        defined?(name.camelize.constantize)==true &amp;&amp; name.camelize.constantize.is_a?(ActiveRecord::Base)
      end
</pre>
<p>Inheritance as a way to get access to new methods is not required any more. Notice how unit testing will provide feedback as higher cohesion and lesser coupling:</p>
<pre class="brush: ruby; title: ;">
class ClientsControl # no inheritance FTW
  def create(client, current_user, redirect_to)
    current_user.login(client)
    redirect_to.client_home(client)
  end
end
</pre>
<p>Therefore its time to trick Rails to &#8220;remove&#8221; the inheritance need internally: </p>
<pre class="brush: ruby; title: ;">
def method_for_action(method)
  # TRICKing rails... no inheritance support
  method
end

def send_action(sym)
  type = self.class.name
  control_type = remove_ler_from_controller(type)
  if (class_exists?(control_type, sym))
    type = control_type.constantize
    control = di_instantiate(type)
    params = extract_params_for(control.method(sym))
    ret = control.send sym, *params
    control.instance_variables.each do |x|
      value = control.instance_variable_get x
      instance_variable_set x, value
    end
    super(sym)
  else
    params = extract_params_for(method(sym))
    super(sym, *params)
  end
end
</pre>
<p>But Rails will complain that at some point the type did not even exist. It shows that checking the existence of the type, method and so on is used in more than one place (loss of cohesion, tighter coupling). Unfortunately, changing all of them requires knowing them all, therefore let&#8217;s hack it:</p>
<pre class="brush: ruby; title: ;">
  def pimp(what)
    eval &quot;class #{what.to_s.camelize}Controller &lt; ApplicationController; end&quot;
  end

  pimp :clients
</pre>
<p><a href="https://github.com/caelum/rails-and-solid">You can see sample helpers, handlers and a few results on what can be achieved with composition instead of inheritance here</a>.</p>
<p>Someone with more knowledge of Rails codebase could remove the pimp hack itself but will soon realize that several points of Rails rely on the fact that this inheritance exists, portraying the high level of coupling and low cohesion of the original procedural approach. The problem with a simple scope control<br />
(one huge object, lots of methods, lots of internal state) is that as more and more code is produced against those expectations, this God object becomes<br />
more and more tighter coupled and the cohesion drops.</p>
<p>This is a proof of concept. Other design change that can be applied is removing the use of thread local variables through public global acessors, which can be redesigned into well-controller scoped objects. Let&#8217;s do it?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.caelumobjects.com/2011/03/09/when-are-inheritance-and-mixins-evil/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Effectiveness, knowledge and the progress curve</title>
		<link>http://www.caelumobjects.com/2011/03/02/effectiveness-knowledge-and-the-progress-curve/</link>
		<comments>http://www.caelumobjects.com/2011/03/02/effectiveness-knowledge-and-the-progress-curve/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 20:55:19 +0000</pubDate>
		<dc:creator>Guilherme Silveira</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[knowledge]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[market]]></category>
		<category><![CDATA[new technology]]></category>
		<category><![CDATA[progress]]></category>
		<category><![CDATA[teaching]]></category>

		<guid isPermaLink="false">http://blog.caelumobjects.com/?p=771</guid>
		<description><![CDATA[In a recent post, Michael Feathers talked about the skill level in the software development industry. Knowledge requires practice and takes time to settle, so it is natural to see that, in a currently fast paced changing industry like ours, some individuals are amazingly away out of the mean quality. Feather suggests a graph showing [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://michaelfeathers.typepad.com/michael_feathers_blog/2011/02/the-pinned-progress-curve.html">In a recent post</a>, Michael Feathers talked about the skill level in the software development industry.</p>
<p><a href="http://en.wikipedia.org/wiki/Learning_curve">Knowledge requires practice and takes time to settle</a>, so it is natural to see that, in a currently fast paced changing industry like ours, some individuals are amazingly away out of the mean quality. Feather suggests a graph showing the distribution of people in terms of efficiency. The X axis represents the efficiency and the Y axis the % of people (their representation) in the industry.</p>
<p>Our market does not usually behave in a stabilized way so that a normal distribution would be a perfect fit. <a href="http://en.wikipedia.org/wiki/Long_Tail">A long tail distribution</a>, as the market grows every year, seems more plausible. Most of those distributions (including the Normal) are part of <a href="http://en.wikipedia.org/wiki/Exponential_family"> the exponential family</a>.</p>
<div class="wp-caption aligncenter" style="width: 622px"><img alt="Exponential family based distribution of efficacy: taking in consideration newcomers and specialists" src="https://docs.google.com/drawings/pub?id=1uheB1Wo-lIzK_xGYtYx2xYHYspLL_PZ8SgS7BRmQhMk&#038;w=459&#038;h=351" title="Exponential family based distribution of efficacy: taking in consideration newcomers and specialists" width="459" height="351" /><p class="wp-caption-text">Exponential family based distribution of efficacy: taking in consideration newcomers and specialists</p></div>
<p>Points in that distribution are related to people. Over time, points (people) that move to the right increases the mean. People that move to the left decreases it. If a small group moves to the right, the mean might increase more than the deviation. If more people arrive in the market on the left side of the distribution, the mean might decrease and the deviation might decrease or increase.</p>
<p>A mathematic comparison has to fix one variable, and the results of that comparison are related to that variable. Comparing different groups over time is neither a comparison of time nor groups. A fair comparison would be the same domain over time or different domains at the same point in time. Therefore, it is not possible to conclude that improving your skills increases the mean (domain analysis) or that the industry does not evolve because of the mean.</p>
<p>We could focus on the efficiency of a few individuals, boosting them and creating super specialists who produce amazing code in a short period of time &#8211; a &#8220;must have&#8221; in a big enterprise. This will improve just one individual&#8217;s efficiency, with very little effect in the market.</p>
<p>Ideas and technologies which only a specialist was able to benefit from, over time, are better understood and taught to the market: increasing the entire market efficiency.</p>
<p>If my students were able to increase their efficiency by 10% over the course of one year while I, as a teacher, increased mine by 20%, I would have achieved a much more valuable result for the industry (and mankind) than doubling my efficiency. Fortunately, I believe most of our students increase their efficiency by numbers much higher than 10%.</p>
<p>Either way, surely it is not true that <em>&#8220;you can&#8217;t have the goal of advancing the whole of the industry. It isn&#8217;t going to happen.&#8221;</em>. The industry is advancing, nowadays we develop software that 10 years ago was unthinkable of. Finding real teaching and learning practicing are the basis of efficiency improval. Teaching is not about exposing ideas. Coming from a family of teachers, there are methods that increase the efficiency of acquiring knowledge and a teacher must know how to use those.</p>
<p>One single person improving himself affects the entire industry in a minimal way, while teaching newcomers the wrong way affect the mean in a negative way.</p>
<p>Some will choose to improve their knowledge, slowly increasing the variance, others will choose to aid the industry, slowly increasing the average. Both are important for the industry. We have chosen to improve efficacy of the industry and, from the results we have been achieving, we shall not give up so soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.caelumobjects.com/2011/03/02/effectiveness-knowledge-and-the-progress-curve/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>REST and Web development: new VRaptor and Restfulie releases</title>
		<link>http://www.caelumobjects.com/2011/02/16/rest-and-web-development-new-vraptor-and-restfulie-releases/</link>
		<comments>http://www.caelumobjects.com/2011/02/16/rest-and-web-development-new-vraptor-and-restfulie-releases/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 20:06:22 +0000</pubDate>
		<dc:creator>Guilherme Silveira</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[neo4j]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[restfulie]]></category>
		<category><![CDATA[vraptor]]></category>

		<guid isPermaLink="false">http://blog.caelumobjects.com/?p=765</guid>
		<description><![CDATA[Since VRaptor 3 inception, the team has focused on good practices related to design issues such as &#8220;avoiding inheritance&#8221;, &#8220;ThreadLocal&#8221; and &#8220;public static mutable singletons&#8221;. Both releases keep their focus on design, less code, more results. In one of its latest releases, VRaptor had a performance enhancement of 60% according to Lucas benchmarks. In an [...]]]></description>
			<content:encoded><![CDATA[<p>Since<a href="http://vraptor.org/en"> VRaptor 3</a> inception, the team has focused on good practices related to design issues such as &#8220;avoiding inheritance&#8221;, &#8220;ThreadLocal&#8221; and &#8220;public static mutable singletons&#8221;. Both releases keep their focus on design, less code, more results.<br />
In one of its latest releases, VRaptor had a performance enhancement of 60% according to Lucas benchmarks. In an attempt to check Restfulie&#8217;s DSL impact in a project, <a href="https://gist.github.com/829616">a patch to Neo4J entire test suite results in 5% less code</a>, compraing just the Rest client library code, the numbers are even higher.</p>
<p>VRaptor was an early adopter of <a href="http://paranamer.codehaus.org">Paul&#8217;s Paranamer</a> and constructor DI, several years after its first public release, a typical controller is a simple:</p>
<pre class="brush: java; title: ;">
@Resource
public class ClientsController {

  private final Clients clients;
  private final Result result;
  ClientsController(Clients clients,
                               Result result) {
     this.clients = clients;
     this.result = result;
  }

  @Post @Path(&quot;/clients&quot;)
  void add(Client client) {
    clients.save(client);
    result.redirectTo(ClientsController.class)
                  .show(client);
  }

  @Path(&quot;/clients/{example.id}&quot;)
  Client show(Client example) {
    return clients.find(example);
  }

}
</pre>
<p>VRaptor and Restfulie are refactor friendly: those who use Java must avoid &#8220;string based programming&#8221;, as shown in the redirection example, where renaming the show method, or changing its path will neither result in a failing test or failing feature.</p>
<p>VRaptor&#8217;s DI allows easy (real) unit testing as its coupling to its dependencies is minimized; and it is built on top of either Spring, Guice and PicoContainer.</p>
<p>Inheritance is only used to partially modify a component&#8217;s behavior and, if required, one own&#8217;s component can be provided with just one single annotation. Your models or controllers do not inherit dozens of methods that do not belong to your class domain, minimizing public method exposition.</p>
<p>Intercepting behavior is simple either on VRaptor (server) and Restfulie (client), through Interceptors and Request/ResponseFeatures. Creating components to be injected is also trivial such as the DAO from the Clients example:</p>
<pre class="brush: java; title: ;">
@Component
class ClientDao implements Clients {
  // thats all
}
</pre>
<p>On the client side, Restfulie usage is straightforward and the default marshalling mechanism is provided through XStream:</p>
<pre class="brush: java; title: ;">
String uri = &quot;http://localhost:8000/clients/15&quot;;
Result r = Restfulie.at(uri).get();
System.out.println(r.getCode());
</pre>
<p>The <b>at</b> method has no side effect and is a domain entry point (instead of <b>new</b>).  Navigating through hypermedia is also easy:</p>
<pre class="brush: java; title: ;">
Result result = Restfulie.at(uri).get()
Client client = result.getResource();

result = resource(client).getLink(&quot;payments&quot;).get();
</pre>
<p>With such performance and code improvements,<br />
<a href="http://vraptor.caelum.com.br/en">VRaptor</a> and <a href="http://restfulie.caelumobjects.com">Restfulie</a> stay on track of not only solving problems, but following good design principles that try to minimize maintainance costs over time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.caelumobjects.com/2011/02/16/rest-and-web-development-new-vraptor-and-restfulie-releases/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hypermedia and the future of the integration over the web</title>
		<link>http://www.caelumobjects.com/2011/01/31/hypermedia-and-the-future-of-the-integration-over-the-web/</link>
		<comments>http://www.caelumobjects.com/2011/01/31/hypermedia-and-the-future-of-the-integration-over-the-web/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 17:28:24 +0000</pubDate>
		<dc:creator>Guilherme Silveira</dc:creator>
				<category><![CDATA[restful]]></category>
		<category><![CDATA[hypermedia]]></category>
		<category><![CDATA[infoq]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[restfulie]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://blog.caelumobjects.com/?p=750</guid>
		<description><![CDATA[Systems integration over the web has been successfully growing in a pace incomparable to any internal company attempt to centralize its services. Those REST systems are available and consumed everywhere over the web. Yet there is one thing one can add to some of those systems that might make clients and services less bound to [...]]]></description>
			<content:encoded><![CDATA[<p>Systems integration over the web has been successfully growing in a pace incomparable to any internal company attempt to centralize its services. Those REST systems are available and consumed everywhere over the web. </p>
<p>Yet there is one thing one can add to some of those systems that might make clients and services less bound to each other. Hypermedia. <a href="http://www.infoq.com/presentations/Hypermedia-Web-Integration">On my talk at QCon San Francisco 2010</a> I was able to show how <a href="http://www.amazon.com/Pull-Power-Semantic-Transform-Business/dp/1591842778">the future of the systems integration over the web might look like</a>.</p>
<p><a href="http://restfulie.caelumobjects.com">Restfulie</a>&#8216;s first attempt to create a Ruby client for hypermedia services was in late 2009 with 100 lines of spaghetti ruby code. Eighteen months and lots of contributions later, Restfulie Ruby 1.0 is out: tackling both the server and client side on hypermedia based systems.</p>
<p>On the server side it is compatible both with Rails, Sinatra, while the its template engine can also be used anywhere else. On the client side, Restfulie provides an api that allows developers to bind their code to the media type and link relations, as expected with REST systems. Navigating a service is easy:</p>
<pre class="brush: ruby; title: ;">
# entry points
response =Restfulie.at(order_uri).get
puts response.body

# unmarshalling
order = response.resource
puts order.price

# using hypermedia
response = order.link.payment.post(my_payment)
</pre>
<p>Restfulie has grown to support other media types such as open search:</p>
<pre class="brush: ruby; title: ;">
description = Restfulie.at(&quot;http://myserver.com/opensearch.xml&quot;)
    .accepts('application/opensearchdescription+xml')
    .get.resource
items = description.use(&quot;application/xml&quot;)
    .search(:searchTerms =&gt; what, :startPage =&gt; 1)
</pre>
<p>We will be releasing the series Rest from Scratch again, using this latest release of Restfulie, wait for upcoming posts.</p>
<p>In the near future, <a href="http://github.com/caelum/restfulie">Restfulie Ruby</a> shall support forms and more. What are you waiting for to start decoupling those nasty client ideas of early 2000s? Or are you sticking to plain old coupling?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.caelumobjects.com/2011/01/31/hypermedia-and-the-future-of-the-integration-over-the-web/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Driving design: adding a touch of our domain to our APIs</title>
		<link>http://www.caelumobjects.com/2011/01/21/driving-design-adding-a-touch-of-our-domain-to-our-apis/</link>
		<comments>http://www.caelumobjects.com/2011/01/21/driving-design-adding-a-touch-of-our-domain-to-our-apis/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 11:13:21 +0000</pubDate>
		<dc:creator>Guilherme Silveira</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[designing code]]></category>
		<category><![CDATA[driving design]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[simple form]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://blog.caelumobjects.com/?p=738</guid>
		<description><![CDATA[In this second screencast from the Driving Design series, the amazingly simple form gem is shown along with a simple DSL implementation. Its current API uses a fluent interface through Ruby hashes that allows easy output customization. This is the current version of simple_form that allows one to configure the building process of a form: [...]]]></description>
			<content:encoded><![CDATA[<p>In this second screencast from the Driving Design series, the <a href="https://github.com/plataformatec/simple_form">amazingly simple form gem</a> is shown along with a simple DSL implementation.</p>
<p>Its current API uses a fluent interface through Ruby hashes that allows easy output customization. This is the current version of simple_form that allows one to configure the building process of a form:</p>
<p><script src="https://gist.github.com/788199.js?file=association.rb"></script></p>
<p>The video shows how one could add a domain specific language on top of its API and remove some of our api code without breaking compatibility. Using the implemented DSL:</p>
<p><script src="https://gist.github.com/788199.js?file=dsl.rb"></script></p>
<p><iframe src="http://player.vimeo.com/video/18333687" width="600" height="337" frameborder="0"></iframe></p>
<p><a href="https://github.com/guilhermesilveira/simple_form/">The commit can be found here</a> and you are welcome to enhance the DSL further.</p>
<p>If you have any suggestions for our next screencast, let us know at <a href="http://twitter.com/guilhermecaelum">@guilhermecaelum</a> and subscribe to our channel.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.caelumobjects.com/2011/01/21/driving-design-adding-a-touch-of-our-domain-to-our-apis/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Evolving software and improving algorithms</title>
		<link>http://www.caelumobjects.com/2011/01/13/evolving-software-and-improving-algorithms/</link>
		<comments>http://www.caelumobjects.com/2011/01/13/evolving-software-and-improving-algorithms/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 11:35:17 +0000</pubDate>
		<dc:creator>Guilherme Silveira</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[bubblesort]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[dynamic programming]]></category>
		<category><![CDATA[evolution]]></category>
		<category><![CDATA[knapsack]]></category>
		<category><![CDATA[priority]]></category>
		<category><![CDATA[quicksort]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[sorting]]></category>
		<category><![CDATA[xp]]></category>

		<guid isPermaLink="false">http://blog.caelumobjects.com/?p=666</guid>
		<description><![CDATA[Recently Bob Martin has posted a series of transformations that aid developers whilst implementing an algorithm. Following steps and in order to improve our code and achieve something is key to refactoring, TDD and other tools are out there that gives up that kind of feedback. Bob posts a few questions that are important for [...]]]></description>
			<content:encoded><![CDATA[<p>Recently <a href="http://cleancoder.posterous.com/the-transformation-priority-premise">Bob Martin has posted a series of transformations that aid developers whilst implementing an algorithm</a>. Following steps and in order to improve our code and achieve something is key to refactoring, TDD and other tools are out there that gives up that kind of feedback.</p>
<p>Bob posts a few questions that are important for the community to find better ways to solve problems. One of them is whether it is possible to find an ordered set of simple transformations that, applied in a series, favoring the ones at the top whenever possible, until all tests are passing, gives us the <b>best</b> algorithm?</p>
<p>An important point is that <a href="http://blog.caelumobjects.com/2011/01/10/simple-changes-might-not-lead-to-simple-solutions/">simple steps might give the best solution but do not guarantee it</a>, as it envolves knowledge from the developer that he might not have prior to that.</p>
<blockquote><p>It is better (or simpler) to change a constant into a variable than it is to add an if statement. So when making a test pass, you try to do so with transformations that are simpler (higher on the list) than those that are more complex.</p></blockquote>
<p><a href="http://www.jbrains.ca/permalink/an-example-the-difference-between-simple-and-easy">Simple and better are not the same concept</a>, so it might be simpler to change a constant into a variable but it might be better to add the if statement. In an, at least, amazing example, Bob shows us how one priority last is capable of giving the quicksort result to a sorting problem, while not using it might lead the developer to bubble sort (known to be worse, although one can argue that it is simpler to understand).</p>
<p>The priority list used for this example favors stateless code, code that does not change a variable pointer, as variable assignment is the lowest priority on the list. Another question posed is whether this priority list is &#8220;the best one&#8221;, and Bob mentions that it probably is not, eventhough it led to a great solution to the sample problem. In order to find a counter example for this priority list, one needs to pick an algorithm where maintaining state is important for a better solution which again, might, might not be the simplest. Calculating fibonacci(n) or <a href="http://en.wikipedia.org/wiki/Dynamic_programming">other dynamic programming problems</a> have this characteristic.</p>
<p>Taking Fibonnaci as an example and the following set of tests:</p>
<ol>
<li>f(0) =1</li>
<li>f(1) =1</li>
<li>f(2) =2</li>
<li>f(3) =3</li>
<li>f(4) =5</li>
<li>f(5) =8</li>
</ol>
<p>Following the sample priority list and implementing the constant rule (2nd rule), both tests f(0) and f(1) pass:</p>
<pre class="brush: java; title: ;">
int f(int k) {
  return 1;
}
</pre>
<p>Adding an if (6th conditional rule) solves f(2):</p>
<pre class="brush: java; title: ;">
int f(int k) {
  if(k&lt;2) return 1;
  return 2;
}
</pre>
<p>Looking closely on the list priority list, one will find that adding an if is top priority than doing recursion so the solution would be the usage of the 6th rule again, thus the solution for all prior tests and f(3) is now:</p>
<pre class="brush: java; title: ;">
int f(int k) {
  if(k&lt;2) return 1;
  if(k==2) return 2;
  return 3;
}
</pre>
<p>Following the same priority list, it turns out that adding extra ifs is always a perferable step than recursion. As a <strong>single step</strong>, adding an if is simpler than recursion, but seen as a series of steps we are aware it is not, that&#8217;s why refactoring is important &#8211; allowing the change of the simple step decisions that were made in the past. In this example, <b>finding the simplest solution is not the same as following the steps from that specific priority list</b>. Still, we can rearrange the list and check if favoring recursion would give us the best solution:</p>
<pre class="brush: java; title: ;">
int f(int k) {
  return k&lt;2 ? 1 : f(k-1) + f(k-2);
}
</pre>
<p>Using the one where recursion had precedence over the ifs, one is able to end up with a simple solution to all tests &#8211; possibly the simplest solution ever. But recursion is known not to be the fastest solution for fibonacci. Following <strong>simple steps</strong> and solving our problem gave us a solution which is not the <b>best</b> one.</p>
<p>That only means that following the two lists do not guarantee the best (or the simplest) solution. Those two lists guided the developer through simple steps, which is positive thing, together with prior developer knowledge of the problem, its possible solutions and refactoring, one can improve the resulting code.</p>
<p>Creating an array (7th rule), during a loop (10th rule) and attributing different values to it than the default one (12th rule) would give the <b>best</b> (as in fastest &#8211; in the same way as the quicksort x bubblesort) solution. That means using a completely different list of priorities, a more dynamic one.</p>
<p>One could argue that assigning value to the array, overriding its default value, is not the use of the 12th rule (although it has already broken the priority list when following the 7th and 10th). In this case, other dynamic programming problem which envolves reassigning values to an array, <a href="http://en.wikipedia.org/wiki/Knapsack_problem">such as the knapsack</a>, would result in sub-optimal solutions, because the optimal solution involes reassigning values to variables (copying arrays would be suboptimal, again).</p>
<blockquote><p>What’s more, when you pose a test, you try to pose one that allows simpler transformations rather than complex transformations; since the more complexity required by the test the larger the risk you take to get that test to pass.</p></blockquote>
<p>Simple steps differ from simple and better solutions: the simplest step to take might not lead the code neither to the simplest nor the best solution, but they aid the developer to not take a huge step which might be hard to step back from. Together with refactoring, as described in Bob&#8217;s first paragraph, and problem solving knowledge, a priority list is a good tool to help avoiding some pitfalls, as shown on the bubble sort example. </p>
<p>The functions that takes the current code, the current set of tests, and a new test case, giving us the best, simplest and simple step change that solves the new set of tests always depend on the current code.</p>
<p>The impasse problem is somehow related to how TDD is done during DOJO sessions, where the steps are so small that they might not give you the direction to the best and simplest algorithm and when the developer realizes it, it is too late, all the code needs to be rewritten. This could have been avoided if the steps were not so small; instead of baby ones, children ones, or if the code was under constant refactoring. Test first, refactor all the time and priorizing simple steps over complex ones are important for good software quality and algorithm implementation, but they still rely on the developer knowledge. Someone who never implemented the knapsack problem might not come up with the solution in a reasonable timeframe, but the three practices (suggested in different parts of time by Bob Martin) will be there to aid the developer find his way.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.caelumobjects.com/2011/01/13/evolving-software-and-improving-algorithms/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple changes might not lead to simple solutions</title>
		<link>http://www.caelumobjects.com/2011/01/10/simple-changes-might-not-lead-to-simple-solutions/</link>
		<comments>http://www.caelumobjects.com/2011/01/10/simple-changes-might-not-lead-to-simple-solutions/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 18:26:24 +0000</pubDate>
		<dc:creator>mauricioaniche</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[baby steps]]></category>
		<category><![CDATA[features]]></category>
		<category><![CDATA[practices]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[solutions]]></category>
		<category><![CDATA[xp]]></category>

		<guid isPermaLink="false">http://blog.caelumobjects.com/?p=659</guid>
		<description><![CDATA[The process of delivering a new feature is consisted in implementing or fixing something that the current state is not capable of. Given the set of all problems that your software solves at this moment, there are many different ways to solve them. All of those possible solutions are valid and would end up in [...]]]></description>
			<content:encoded><![CDATA[<p>The process of delivering a new feature is consisted in implementing or fixing something that the current state is not capable of. Given the set of all problems that your software solves at this moment, there are many different ways to solve them. All of those possible solutions are valid and would end up in working software, but some are cleaner, easier to mantain and simpler than others.</p>
<p>The image below presents a situation where a new feature needs to be implemented because the software does not solve the current problem the company is facing:</p>
<p>a) <span style="color: #ff0000"><strong>red</strong></span>: represents all possible systems that do not solve the problem;<br />
b) <span style="color: #ffcc00"><strong><span style="color: #95971f">yellow</span></strong></span>: the current situation of our software;<br />
c) <span style="color: #008000"><strong>green</strong></span>: possible solutions for both the previous solved problems and the current one.</p>
<div id="attachment_3454" class="wp-caption aligncenter" style="width: 289px"><img src="http://blog.caelumobjects.com/wp-content/uploads/2011/01/m1.png" alt="m1" title="m1" width="279" height="235" class="alignnone size-full wp-image-672" alt="Possible solutions for a problem" /><p class="wp-caption-text">Possible solutions for a problem</p></div>
<p>However, inside the possible solutions, there are those that are <strong>simple to be done</strong>. For example, writing an &#8220;if&#8221; or simply do a copy and paste some piece of code. This is a little step, a simple change, a <em>baby step</em>. The graphic below represents <strong>simple changes that solve the problem</strong> in dark green:</p>
<div id="attachment_3454" class="wp-caption aligncenter" style="width: 289px"><img src="http://blog.caelumobjects.com/wp-content/uploads/2011/01/m2.png" alt="m2" title="m2" width="279" height="235" class="alignnone size-full wp-image-675" /><p class="wp-caption-text">Simple changes</p></div>
<p>In addition, there are the simpler solutions for the problem. The simpler solution might be to extract a class or to make use of a library that does the logic. The diagram below represents the simpler solutions, in blue:</p>
<div id="attachment_3455" class="wp-caption aligncenter" style="width: 310px"><img src="http://blog.caelumobjects.com/wp-content/uploads/2011/01/m3.png" alt="m3" title="m3" width="279" height="235" class="alignnone size-full wp-image-676" /><p class="wp-caption-text">Simple solutions</p></div>
<p>It is possible to make some small changes, <em>baby steps</em>, that will put our system back in the track: inside the set of situations where a simple change solves the problem. But the simplest solution to our problem might be something completely different. It might not envolve the simplest change, it might even be on the different direction; doing small simple changes might lead us to a increasingly bigger technical debt. A typical 90&#8242;s example of that is the copy and paste solution, that will solve a lot of problems &#8211; and even professional developers stick to it in some situations &#8211; but will increase our debt over time, going in the wrong direction.</p>
<p>Even worse, the blind adoption of baby steps or simple changes <b>with no practices to improve the quality of the design</b> may take the code to a situation where <b>it would be impossible to go back to a simple solution</b>: your system becomes a <a href="http://en.wikipedia.org/wiki/Big_ball_of_mud" target="_blank">big ball of mud</a>. This is the worst situation: baby steps are not capable to <a href="http://en.wikipedia.org/wiki/KISS_principle" target="_blank">keep things simple</a> anymore, a typical situation where clients will say &#8220;we need to restart this project even before it was released&#8221;.</p>
<div id="attachment_3458" class="wp-caption aligncenter" style="width: 270px"><img src="http://blog.caelumobjects.com/wp-content/uploads/2011/01/m4.png" alt="m4" title="m4" width="260" height="682" class="alignnone size-full wp-image-677" /><p class="wp-caption-text">The pure use of baby steps do not assure quality. Too much simple steps may lead your system to negative situations.</p></div>
<p>In some situations, <em>baby step</em> may imply in one of the best solutions. But, to make it possible, the developer must have a deep knowledge in the technology, in the business domain, software design and programming language, which is not always true.</p>
<div id="attachment_3463" class="wp-caption aligncenter" style="width: 522px"><img src="http://blog.caelumobjects.com/wp-content/uploads/2011/01/m5-1024x436.png" alt="m5" title="m5" width="512" height="215" class="alignnone size-large wp-image-679" /><p class="wp-caption-text">Baby step by a developer with strong knowledge in the technology, language, business domain and system.</p></div>
<p>As it is hard to make a smooth step-by-step and come to a simpler solution, developers require extra techniques, such as refactoring. Each simplification step through refactoring puts the code closer to the ideal system: the simplest thing that solve the set of required problems.</p>
<div id="attachment_3462" class="wp-caption aligncenter" style="width: 522px"><img src="http://blog.caelumobjects.com/wp-content/uploads/2011/01/m6ok.png" alt="m6" title="m6" width="512" height="426" class="alignnone size-full wp-image-682" /><p class="wp-caption-text">Refactoring that takes the code closer to the best solution.</p></div>
<p><a href="http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672">With continuous refactoring</a>, each step programmers take to implement a new feature keeps the code still close to simple solutions. Even more important than doing tiny steps (baby steps) is to walk in direction that takes to the better solution (and not only to the simplest change). In order to do that, programmers can not forget to refactor. And not only low-level refactoring (i.e. renaming variables, extracting methods, etc), but high-level refactoring (e.g. creating new abstractions).</p>
<p>The following piece of code is responsible for calculating the salary of a employee. It depends on the employee&#8217;s position on the company. </p>
<pre class="brush: java; title: ;">
public class SalaryCalculator {

  public SalaryCalculator(FiscalRules fiscalRules, ...) {
    // ...
  }

  public double calculate(Employee f) {
    if(f.getPosition() == Position.SALESMAN) {
      // calculate salesman salary using fiscal rules, etc.
    }

    if(f.getPosition() == Position.MANAGER) {
      // calculate manager salary using fiscal rules, etc
    }
  }
}
</pre>
<p>Suppose that the company has a new position. The software should calculate the salary for this new employee as well. The simplest code that solve the problem would be:</p>
<pre class="brush: java; title: ;">
public class SalaryCalculator {

  public SalaryCalculator(FiscalRules fiscalRules, ...) {
    // ...
  }

  public double calculate(Employee f) {
    if(f.getPosition() == Position.SALESMAN) {
      // calculate salesman salary using fiscal rules, etc.
    }

    if(f.getPosition() == Position.MANAGER) {
      // calculate manager salary using fiscal rules, etc
    }

    if(f.getPosition() == Position.MARKETING) {
      // calculate marketing salary using fiscal rules, etc
    }
  }
}
</pre>
<p>However, this is not the best solution. Moreover, the code gets more and more far from the best solution after any new &#8220;if&#8221; inserted in the code. Design gets more rigid. And worse: it makes the code harder to refactor: even the second &#8220;if&#8221; wasn&#8217;t the simplest solution.</p>
<p>When implementing a new feature, the programmer <a href="http://www.agiledata.org/essays/tdd.html" target="_blank">should check if the current design enables him to move his system to the next stage of simplest solutions</a>, which might not be the simplest step. If the current design already provides an easy way to implement it, go ahead. Otherwise, the developer <strong>should refactor the design in order to make the implementation of this feature as easy as possible</strong>.</p>
<p>Steps do not need to be the smallest as possible. If the shortest step is a baby one, developers are free to do children steps when those will improve the software in question. Every design decision requires more and more knowledge out the developer, the small step and refactor techniques are one way to get good feedback to a software designer, allowing him to make good decisions, but still limited to his reachings.</p>
<p>In the example above, one solution would be to create an Strategy (GoF) to calculate the right salary for each position. And each position would be responsible to give the right algorithm:</p>
<pre class="brush: java; title: ;">
public class SalaryCalculator {

  public SalaryCalculator(FiscalRules fiscalRules, ...) {
    // ...
  }

  public double calculate(Employee f) {
    SalaryAlgorithm calc = f.getPosition().getCalcAlgorithm(fiscalRules);
    return calc.calculate();
  }
}
</pre>
<p>It is hard to say if this is the best solution. Yet, it is much better than the ones before. Now, if the programmer needed to implement another salary algorithm, that would be much easier. Now, the programmer can go back to <em>small steps</em>, as the current implementation is on a safe place.</p>
<p>All this post may be summarized in one phrase that came up during a conversation between <a href="http://twitter.com/guilhermecaelum">Guilherme Silveira</a> and <a href="http://www.twitter.com/mauricioaniche">Mauricio Aniche</a>: </p>
<blockquote><p>The simplest change that allows you to solve a problem is not necessarily the simplest solution in the long run.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.caelumobjects.com/2011/01/10/simple-changes-might-not-lead-to-simple-solutions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Designing code: fluent interfaces and your domain</title>
		<link>http://www.caelumobjects.com/2011/01/03/designing-code-fluent-interfaces-and-your-domain/</link>
		<comments>http://www.caelumobjects.com/2011/01/03/designing-code-fluent-interfaces-and-your-domain/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 20:03:58 +0000</pubDate>
		<dc:creator>Guilherme Silveira</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[ddd]]></category>
		<category><![CDATA[refactor]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://blog.caelumobjects.com/?p=652</guid>
		<description><![CDATA[Together with coworkers, we have been talking about the influence of Test First in our design: it is not only about testing, or testing all the time. The discussion is on how developers should learn from understanding feedback from every type of tests (unit, integration and so on) and act accordingly. We have begun a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://aniche.com.br">Together with</a> <a href="http://vidageek.net">coworkers</a>, we have been talking about the influence of Test First in our design: it is not only about testing, or testing all the time. The discussion is on how developers should learn from understanding feedback from every type of tests (unit, integration and so on) and act accordingly. We have begun a series of screencasts showing how most design practices can fit together. </p>
<p>In this first video, we show how to enhance <a href="http://github.com/apotonick/cells">the amazing Cells gem</a> by providing a simple DSL on top of it, leaving only your domain language. In Rails code, that is translated to &#8220;no appearances of the words render, partial or alike&#8221;. Testing first and trying to<a href="http://jamesshore.com/Agile-Book/ubiquitous_language.html"> bring some of the domain language into the code</a>.</p>
<p>This is a 6 minute video going through adding a new feature into the gem, it should be straight forward even for non ruby developers.</p>
<p><iframe src="http://player.vimeo.com/video/18333921" width="500" height="281" frameborder="0"></iframe></p>
<p>This implementation makes use of method_missing, which envolves dispatching the invocation twice. It should be no user perceived performance bottleneck in a typical scenario &#8211; we are using an interpreted language with IO through the network in two endpoints (to the browser and to the database). For those willing to contribute, the next improvements would be to only respond to method invocations that are really a cell.</p>
<p>Another one is to dinamically add the methods instead of using method_missing.</p>
<p>Send in any suggestions for the next episodes: open source suggestions with any of the following characteristics:</p>
<ul>
<li>code to be refactored</li>
<li>great apis that can be improved with domain specifics</li>
<li>legacy code without tests, waiting to be tested</li>
<li>libraries with integration tests, with no unit ones</li>
<li>libraries with unit tests, without integration ones</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.caelumobjects.com/2011/01/03/designing-code-fluent-interfaces-and-your-domain/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Restfulie is almost there: first beta out</title>
		<link>http://www.caelumobjects.com/2010/11/04/restfulie-is-almost-there-firts-beta-out/</link>
		<comments>http://www.caelumobjects.com/2010/11/04/restfulie-is-almost-there-firts-beta-out/#comments</comments>
		<pubDate>Thu, 04 Nov 2010 20:16:22 +0000</pubDate>
		<dc:creator>Guilherme Silveira</dc:creator>
				<category><![CDATA[restful]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[chain]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[respondie]]></category>
		<category><![CDATA[restfulie]]></category>
		<category><![CDATA[version]]></category>

		<guid isPermaLink="false">http://blog.caelumobjects.com/?p=642</guid>
		<description><![CDATA[Rhaiger and Ricardo Nakamura have contributed with support to formurlencoded (issue 152), now simple form posts are also supported. In parallel, through Respondie one is capable of extending and composing behavior on resource rendering. The following example shows a simple trait that renders an etag whenever the resource responds to etag: Respondie is a Rails [...]]]></description>
			<content:encoded><![CDATA[<p>Rhaiger and Ricardo Nakamura have <a href="https://github.com/caelum/restfulie/commit/61aaa6ed342398c7d05221a39bc64bcf58e5f599">contributed with support to formurlencoded</a> (issue 152), now simple form posts are also supported.</p>
<p>In parallel, <a href="http://github.com/caelum/respondie">through Respondie</a> one is capable of extending and composing behavior on resource rendering. The following example shows a simple trait that renders an etag whenever the resource responds to etag:</p>
<p><script src="https://gist.github.com/662734.js?file=respondie.rb"></script></p>
<p>Respondie is a Rails Responders extension that <a href="http://en.wikipedia.org/wiki/Mixin">avoids mixins</a> and thus <a href="http://stackoverflow.com/questions/406081/why-should-i-avoid-multiple-inheritance-in-c">allows us to avoid multiple inheritance hell</a> (at least for the end programmer: a common problem is the  <a href="http://en.wikipedia.org/wiki/Diamond_problem">diamond one</a>) and compose your responder behavior by configuring it through composition:</p>
<p>In order to return to thread safe mode, some objects within the DSL were changed to become immutable although not all of them have already been moved.</p>
<p>Restfulie features can be composed in many different ways using an interceptor stack &#8211; much similar to servlet&#8217;s filter, a chain alike pattern. This means, client programmatic configuration as:</p>
<p><script src="https://gist.github.com/662734.js?file=feature.rb"></script></p>
<p>Opensearch support is now built in and as easy as:</p>
<p><script src="https://gist.github.com/662734.js?file=restfulie-1.0.0beta1.rb"></script></p>
<p>Several other issues were closed in this new release and we can only wait for a new release with even nicer support to Tokamak templates and partial rendering: that will make our 1.0 ship. Again, this release of Restfulie is Rails3 compatible.</p>
<p>There is a sample application used <a href="http://qconsf.com/sf2010/presentation/Rest+from+Scratch">during the workshop at QCon San Francisco </a><a href="http://github.com/caelum/restfulie-restbuy">that can be found at github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.caelumobjects.com/2010/11/04/restfulie-is-almost-there-firts-beta-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
