<?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>Pereira&#039;s blog &#187; Software</title>
	<atom:link href="http://jpereira.eu/category/software/feed/" rel="self" type="application/rss+xml" />
	<link>http://jpereira.eu</link>
	<description>It&#039;s just that, a blog, my blog :)</description>
	<lastBuildDate>Tue, 06 Dec 2011 19:01:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How to improve productivity when developing JEE based web applications</title>
		<link>http://jpereira.eu/2011/12/06/how-to-improve-productivity-when-developing-jee-based-web-applications/</link>
		<comments>http://jpereira.eu/2011/12/06/how-to-improve-productivity-when-developing-jee-based-web-applications/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 19:01:38 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[SCRUM]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=482</guid>
		<description><![CDATA[The title of this post was stolen from Stackoverflow, from this discussion: http://stackoverflow.com/questions/645746/how-to-improve-productivity-when-developing-jee-based-web-applications I really like and agree with this point: Being “the enterprise stack”, it is often used to create boring, ugly, “good enough” applications and, in general, enterprises tend not to attract great developers who love programming, and think and care about what [...]]]></description>
			<content:encoded><![CDATA[<p>The title of this post was stolen from Stackoverflow, from this discussion:</p>
<p> <a href="http://stackoverflow.com/questions/645746/how-to-improve-productivity-when-developing-jee-based-web-applications">http://stackoverflow.com/questions/645746/how-to-improve-productivity-when-developing-jee-based-web-applications</a></p>
<p>I really like and agree with this point:</p>
<p><strong>Being “the enterprise stack”, it is often used to create boring, ugly, “good enough” applications and, in general, enterprises tend not to attract great developers who love programming, and think and care about what they do. The quality of software in the enterprise world is not great.</strong></p>
<p>There are exceptions, of course, but mainly from what I&#8217;ve seen from the past 10 years, this is, sadly, true. Why?</p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2011/12/06/how-to-improve-productivity-when-developing-jee-based-web-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming testing</title>
		<link>http://jpereira.eu/2011/12/03/programming-testing/</link>
		<comments>http://jpereira.eu/2011/12/03/programming-testing/#comments</comments>
		<pubDate>Sat, 03 Dec 2011 17:59:15 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[SCRUM]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=476</guid>
		<description><![CDATA[Recently I&#8217;ve researched a little about programmer testing, which resulted in a slide set that I&#8217;m now sharing with you. These slides are the basis for a training, which included a lot of exercises, as I like to do. It includes some information about: Agile testing Test driven development Unit testing with JUnit Test doubles [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve researched a little about programmer testing, which resulted in a slide set that I&#8217;m now sharing with you. These slides are the basis for a training, which included a lot of exercises, as I like to do.</p>
<p>
It includes some information about:
</p>
<ul>
<li>
Agile testing</li>
<li>Test driven development</li>
<li>Unit testing with JUnit</li>
<li>Test doubles and Mockito</li>
<li>Code coverage</li>
</ul>
<div style="width:425px" id="__ss_10448283"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/joaomiguel.pereira/programmer-testing-10448283" title="Programmer testing">Programmer testing</a></strong><object id="__sse10448283" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=programmertestingblog-111203114534-phpapp02&#038;stripped_title=programmer-testing-10448283&#038;userName=joaomiguel.pereira" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><param name="wmode" value="transparent"/><embed name="__sse10448283" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=programmertestingblog-111203114534-phpapp02&#038;stripped_title=programmer-testing-10448283&#038;userName=joaomiguel.pereira" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/joaomiguel.pereira">Joao Pereira</a>.</div>
</div>
<p>
If you have any feedback or question, please let me know by leaving a comment or send me an email.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2011/12/03/programming-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fluent interfaces while trying to make sense of Prototype Pattern</title>
		<link>http://jpereira.eu/2011/10/12/fluent-interfaces-while-trying-to-make-sense-of-prototype-pattern/</link>
		<comments>http://jpereira.eu/2011/10/12/fluent-interfaces-while-trying-to-make-sense-of-prototype-pattern/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 23:18:43 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[SCRUM]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=464</guid>
		<description><![CDATA[Sometimes I don&#8217;t have great opportunities to apply some nice concepts, but I have some time to learn them. While trying to make some sense of the Prototype Pattern, I was doing some experiments and I needed, of course, the tests to prove my experiments. It was when coding the tests, trying to define the [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes I don&#8217;t have great opportunities to apply some nice concepts, but I have some time to learn them.</p>
<p>While trying to make some sense of the Prototype Pattern, I was doing some experiments and I needed, of course, the tests to prove my experiments. </p>
<p>It was when coding the tests, trying to define the client interface (not user interface <img src='http://jpereira.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ), that to my mind came this article from Martin Fowler: <a href="http://martinfowler.com/bliki/FluentInterface.html">Fluent Interface</a>. </p>
<p>Well, what it matters are these two points:</p>
<ul>
<li>
Making your tests first helps you, a lot, to define not only the behavior, but also importantly, the client API.</li>
<li>Using Fluent Interface with a Builder, it&#8217;s a great way to send our message to the objects implementing the API. </li>
</ul>
<p>Example of using a fluent interface:</p>
<pre class="brush: java; title: ; notranslate">
package eu.jpereira.trainings.designpatterns.creational.prototype;

import static org.junit.Assert.*;

import java.util.List;
import java.util.Properties;

import org.junit.Test;

import eu.jpereira.trainings.designpatterns.creational.prototype.exception.CannotHaveZeroPartsException;
import eu.jpereira.trainings.designpatterns.creational.prototype.exception.CouldNotCloneLastObjectException;
import eu.jpereira.trainings.designpatterns.creational.prototype.exception.NeedToPackLastVehicleException;
import eu.jpereira.trainings.designpatterns.creational.prototype.exception.VehicleDoesNotHavePartsException;
import eu.jpereira.trainings.designpatterns.creational.prototype.model.Shell;
import eu.jpereira.trainings.designpatterns.creational.prototype.model.Tire;
import eu.jpereira.trainings.designpatterns.creational.prototype.model.Vehicle;
import eu.jpereira.trainings.designpatterns.creational.prototype.model.VehiclePartEnumeration;
import eu.jpereira.trainings.designpatterns.creational.prototype.model.VehiclePartPropertiesEnumeration;
import eu.jpereira.trainings.designpatterns.creational.prototype.model.Window;
/**
 * @author jpereira
 *
 */

public class ClientTest {

	/**
	 * Integration Test
	 * @throws CouldNotCloneLastObjectException
	 * @throws CannotHaveZeroPartsException
	 * @throws NeedToPackLastVehicleException
	 * @throws VehicleDoesNotHavePartsException
	 */
	@Test
	public void testCreateBUS() throws CouldNotCloneLastObjectException, CannotHaveZeroPartsException, NeedToPackLastVehicleException, VehicleDoesNotHavePartsException {
		Client client = new Client();

		//create a bus car
		//Create props for tire
		Properties tiresProps = new Properties();
		tiresProps.put(VehiclePartPropertiesEnumeration.SIZE,10);

		//Create props for shell
		Properties shellProps = new Properties();
		shellProps.put(VehiclePartPropertiesEnumeration.COLOR,&quot;blue&quot;);

		Properties windowProps = new Properties();
		windowProps.put(VehiclePartPropertiesEnumeration.WIDTH,20);
		windowProps.put(VehiclePartPropertiesEnumeration.WIDTH,20);

		//client.createVehicle().with(new Tires()).times(4).
		Vehicle vehicle = client.vehicleBuilder().createVehicle().with(new Tire(tiresProps)).times(3).with(new Window(windowProps)).times(8).with(new Shell(shellProps)).times(1).packIt();

		//Get all windows
		List&lt;VehiclePart&gt; parts = vehicle.getParts(VehiclePartEnumeration.WINDOW);
		assertEquals(8, parts.size());

	}
}
</pre>
<p>A hypothetical Builder implementation with a fluent interface:</p>
<pre class="brush: java; title: ; notranslate">
package eu.jpereira.trainings.designpatterns.creational.prototype;

import java.util.ArrayList;
import java.util.List;

import eu.jpereira.trainings.designpatterns.creational.prototype.exception.CouldNotCloneLastObjectException;
import eu.jpereira.trainings.designpatterns.creational.prototype.exception.CannotHaveZeroPartsException;
import eu.jpereira.trainings.designpatterns.creational.prototype.exception.NeedToPackLastVehicleException;
import eu.jpereira.trainings.designpatterns.creational.prototype.model.Vehicle;

/**
 * @author jpereira
 *
 */
public class SimpleVehicleBuilder implements VehicleBuilder {

	private List&lt;VehiclePart&gt; vehicleParts;

	public SimpleVehicleBuilder() {
		this.vehicleParts = createNewPartsBag();
	}

	@Override
	public VehicleBuilder createVehicle() throws NeedToPackLastVehicleException{
		//Just check this is allways the first call on the builder
		if (vehicleParts.size()!= 0) {
			throw new NeedToPackLastVehicleException();
		}
		return this;
	}

	@Override
	public VehicleBuilder with(VehiclePart part) {
		this.vehicleParts.add(part);
		return this;
	}

	@Override
	public VehicleBuilder times(int times) throws CouldNotCloneLastObjectException, CannotHaveZeroPartsException {
		if (times==0) {
			throw new CannotHaveZeroPartsException();
		}
		//get the last one and clone it xtimes
		if ( this.vehicleParts.size()&gt;0) {

			VehiclePart lastObject = this.vehicleParts.get(this.vehicleParts.size()-1);
			//add it xtimes
			for (int i=0; i&lt; times-1; i++) {
				//new object
				try {
					this.vehicleParts.add((VehiclePart)lastObject.clone());
				} catch (CloneNotSupportedException e) {
					//Could not clone it. Wrap exception
					throw new CouldNotCloneLastObjectException(e);
				}
			}
		}
		return this;

	}

	@Override
	public Vehicle packIt() {
		Vehicle vehicle = new Vehicle();
		vehicle.setParts(this.vehicleParts);
		//clear this reference for the chicle parts.
		this.vehicleParts = createNewPartsBag();
		return vehicle;

	}

	//Can be overriden by subclasses
	protected List&lt;VehiclePart&gt; createNewPartsBag() {
		return new ArrayList&lt;VehiclePart&gt;();
	}

}
</pre>
<p>That&#8217;s it</p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2011/10/12/fluent-interfaces-while-trying-to-make-sense-of-prototype-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>You do not understand, yet, why do you need tests!</title>
		<link>http://jpereira.eu/2011/09/14/you-do-not-understand-yet-why-do-you-need-tests/</link>
		<comments>http://jpereira.eu/2011/09/14/you-do-not-understand-yet-why-do-you-need-tests/#comments</comments>
		<pubDate>Wed, 14 Sep 2011 13:18:16 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[SCRUM]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=454</guid>
		<description><![CDATA[Why do I need tests in my software project? Keep bugs away? Yes! Keep quality high? Maybe. Can you define quality? I see that people often justify the demand for a high test coverage with their desire to have quality in software projects, however they&#8217;re only seeing a part of the quality, the bugs visible [...]]]></description>
			<content:encoded><![CDATA[<p>Why do I need tests in my software project? Keep bugs away? Yes! Keep quality high? Maybe. Can you define quality?</p>
<p>I see that people often justify the demand for a high test coverage with their desire to have quality in software projects, however they&#8217;re only seeing a part of the quality, the bugs visible to the customer. Quality, that word alone, can be very subjective, meaning different things to different people. Of course, having a bug free software means a high quality software, but if I have a bug free software and cannot add new features or improve existing ones, is this software a high quality software?</p>
<p>Now that we&#8217;re all doing &#8220;agile development&#8221; (right? at least you may think you&#8217;re doing, because you have daily meetings, review, sprints, etc), everyone should bear in mind one of the critical purposes of tests. </p>
<p>Big up-front designs do not work anymore, never worked for that matter (you soon loose integrity between the code and the design in the papers). We&#8217;re no able to make decisions based on the unknown (though some people may think they can), so we leave every decision to the last possible moment, until we have all, or most, information needed to make a reasonable decision.</p>
<p>One fundamental aspect of agile development is that you evolve your system as you go, you do it in iterations and every iteration is focusing only on what is needed to deliver the features you committed for that iteration. Your system will evolve, iteration after iteration. </p>
<p>With this evolution of your system, you will also evolve your architecture and design. You will not add database support on the first iteration if you don&#8217;t need a database, right? It&#8217;s waste. Right? So, from iteration to iteration your architecture and design will evolve, based on the features you have to develop and those you have developed. This is what <a href="http://martinfowler.com/articles/designDead.html">evolutionary architecture and deign</a> looks like, according to <a href="http://martinfowler.com/">Martin Fowler</a>. </p>
<p>But, how do you evolve your design and architecture? One of the key practices to do that is refactoring. Refactoring, again using Fowler&#8217;s knowledge, is &#8220;the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure. It is a disciplined way to clean up code that minimizes the changes of introducing bugs.&#8221;</p>
<p>Refactoring is one of the key practice of any project using any kind of agile development methodology, backed by testing and continuous integration. There is no way you can refactor your code if you do not have a safety net, i.e., if you don&#8217;t have something that keep you away from breaking existing functionality. <strong>This is a key point of tests, to allow you to evolve your system design and architecture.</strong>. Of course these test must be automated, needless to say that. </p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2011/09/14/you-do-not-understand-yet-why-do-you-need-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GWT Quickstart Project with Maven+GWT2.3+GIN1.5</title>
		<link>http://jpereira.eu/2011/07/14/gwt-quickstart-project-with-mavengwt2-3gin1-5/</link>
		<comments>http://jpereira.eu/2011/07/14/gwt-quickstart-project-with-mavengwt2-3gin1-5/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 13:57:01 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[GWT]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[WEB 2.0]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=424</guid>
		<description><![CDATA[This post will show you, and remind me in the future, how to quickly setup a GWT 2.3 project with maven and GIN 1.5.]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>Been a while&#8230; This post will show you, and remind me in the future, how to quickly setup a</p>
<p><a href="http://code.google.com/webtoolkit/">GWT 2.3</a> project with <a href="http://maven.apache.org/">Maven2</a> and <a href="http://code.google.com/p/google-gin/">GIN 1.5</a>. I&#8217;m using Ubuntu, but the essential steps should be the same in any operating system.</p>
<p>Let&#8217;s start.</p>
<p>Assuming you have maven installed, just run:</p>
<pre class="brush: plain; title: ; notranslate">
mvn archetype:generate -DarchetypeRepository=repo1.maven.org -DarchetypeGroupId=org.codehaus.mojo -DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.3.0-1
</pre>
<p>Then, enter the details for you new GWT 2.3 project. Don&#8217;t forget that the property for &#8216;module&#8217; should be a valid Java Class name, so use camel case when setting the name of module.<br />
My configurations are something like:</p>
<pre class="brush: plain; title: ; notranslate">
Define value for property 'groupId': : eu.jpereira.gwt
Define value for property 'artifactId': : quickstart
Define value for property 'version': 1.0-SNAPSHOT:
Define value for property 'package': eu.jpereira.gwt:
Define value for property 'module': : Quickstart
Confirm properties configuration:
groupId: eu.jpereira.gwt
artifactId: quickstart
version: 1.0-SNAPSHOT
package: eu.jpereira.gwt
module: Quickstart
</pre>
<p>Now, we just need to add the dependency to GIN 1.5. Open the generated POM for the Quickstart project and add the dependency for GIN 1.5:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!-- GIN Stuff --&gt;
&lt;dependency&gt;
	&lt;groupId&gt;com.google.gwt.inject&lt;/groupId&gt;
	&lt;artifactId&gt;gin&lt;/artifactId&gt;
	&lt;version&gt;1.5.0&lt;/version&gt;
	&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
</pre>
<p>Now you have a GWT 2.3 project with GIN 1.5 and Maven.<br />
To finalize, let just remind how to setup GIN with the GWT project.<br />
Generate the eclipse project:</p>
<pre class="brush: plain; title: ; notranslate">
mvn eclipse:eclipse gwt:eclipse
</pre>
<p>Open the project in eclipse and edit the *.gwt.xml (in my case, this is the file Quickstart.gwt.xml) file, located under &#8220;src/main/resources/&#8221; to import the GIN module:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;inherits name=&quot;com.google.gwt.inject.Inject&quot; /&gt;
</pre>
<p>Create the GinModule, the class file that will configure the dependency injection for your application. You can have any number of GinModules. Check the documentation here: <a href="http://code.google.com/p/google-gin/wiki/GinTutorial">http://code.google.com/p/google-gin/wiki/GinTutorial</a><br />
I like to keep everything related to GIn under the package *.client.gin. My Module is this:</p>
<pre class="brush: java; title: ; notranslate">
package eu.jpereira.gwt.client.gin;

import com.google.gwt.inject.client.AbstractGinModule;
import com.google.inject.Singleton;
import eu.jpereira.gwt.client.QuaickstartApplication;

public class QuickstartGinModule extends AbstractGinModule {

	@Override
	protected void configure() {
		bind(QuaickstartApplication.class).in(Singleton.class);

	}
}
</pre>
<p>Here I&#8217;m only binding the QuickstartApplication object, which is my main application, like this:</p>
<pre class="brush: java; title: ; notranslate">
package eu.jpereira.gwt.client;

import com.google.gwt.user.client.Window;

public class QuaickstartApplication {

	public void run() {
		Window.alert(&quot;Hello World!!!&quot;);
	}
}
</pre>
<p>Back to Gin setup, let&#8217;s create the Ginjector. Create a new Interface that extends from Ginjector:</p>
<pre class="brush: java; title: ; notranslate">
package eu.jpereira.gwt.client.gin;

import com.google.gwt.inject.client.GinModules;
import com.google.gwt.inject.client.Ginjector;
import eu.jpereira.gwt.client.QuickstartApplication;
@GinModules(QuickstartGinModule.class)
public interface QuickstartInjector extends Ginjector{
	QuickstartApplication getQuickstartApplication();
}
</pre>
<p>Finally, it&#8217;s time to use it. In the Quickstart.java, which contains the entry point to the application, remove everything, create the injector and start your application.</p>
<pre class="brush: java; title: ; notranslate">
package eu.jpereira.gwt.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;

import eu.jpereira.gwt.client.gin.QuickstartInjector;

/**
 * Entry point classes define &lt;code&gt;onModuleLoad()&lt;/code&gt;.
 */
public class Quickstart implements EntryPoint {

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		QuickstartInjector injector = GWT.create(QuickstartInjector.class);
		injector.getQuickstartApplication().run();

	}

}
</pre>
<p>Now, run the application with:</p>
<pre class="brush: plain; title: ; notranslate">
mvn gwt:run
</pre>
<p>And you should see the &#8220;Hello World!!&#8221; alert.</p>
<p>BTW, you can download the project <a href="http://jpereira.eu/wp-content/uploads/2011/07/quickstart.zip">here</a>.</p>
<p>Happy coding!!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2011/07/14/gwt-quickstart-project-with-mavengwt2-3gin1-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My first WordPress Plugin</title>
		<link>http://jpereira.eu/2011/03/16/my-first-wordpress-plugin/</link>
		<comments>http://jpereira.eu/2011/03/16/my-first-wordpress-plugin/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 23:19:09 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=404</guid>
		<description><![CDATA[Today I managed to finished my first WordPress plugin. It&#8217;s not that difficult, even if you know little (close to nothing) about PHP. I started with one of many available plugins out there and started  tweaking the code, testing, more tweaking, more testing and voilá, my first wordpress plugin saw the light. The plugin is [...]]]></description>
			<content:encoded><![CDATA[<p>Today I managed to finished my first WordPress plugin. It&#8217;s not that difficult, even if you know little (close to nothing) about PHP. I started with one of many available plugins out there and started  tweaking the code, testing, more tweaking, more testing and voilá, my first wordpress plugin saw the light.</p>
<p>The plugin is simple, just to put in a client&#8217;s site where people can subscribe RSS feed, follow him in Twitter, become a facebook fan, etc, etc.</p>
<p>Here&#8217;s some screenshots:</p>
<p><strong>First tab with some options</strong></p>
<p><a href="http://jpereira.eu/wp-content/uploads/2011/03/screen_1.png"><img class="size-full wp-image-405 alignnone" title="First Tab" src="http://jpereira.eu/wp-content/uploads/2011/03/screen_1.png" alt="" width="300" height="114" /></a></p>
<p><strong>Second tab with a form (the code of the form can be configured)</strong></p>
<p><a href="http://jpereira.eu/wp-content/uploads/2011/03/screen_2.png"><img class="size-full wp-image-406 alignnone" title="Second tab" src="http://jpereira.eu/wp-content/uploads/2011/03/screen_2.png" alt="" width="322" height="225" /></a></p>
<p><strong>And finally the configuration, in the admin area</strong></p>
<p><a href="http://jpereira.eu/wp-content/uploads/2011/03/screen_3.png"><img class="size-full wp-image-407 alignnone" title="Admin" src="http://jpereira.eu/wp-content/uploads/2011/03/screen_3.png" alt="" width="353" height="740" /></a></p>
<p>If you want to get your first wordpress plugin running, just download the source code to get started.</p>
<p><a title="First plugin" href="http://jpereira.eu/labs/sp-tab-share-wg.zip">Dowload it.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2011/03/16/my-first-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacking a Rails controller and template inheritance strategy</title>
		<link>http://jpereira.eu/2011/02/15/hacking-a-rails-controller-and-template-inheritance-strategy/</link>
		<comments>http://jpereira.eu/2011/02/15/hacking-a-rails-controller-and-template-inheritance-strategy/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 00:27:51 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[RubyOnRails]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=395</guid>
		<description><![CDATA[Developing with Ruby on Rails can be fun, but sometimes, especially for newbies like me, we can get stuck somewhere. I&#8217;ll document my strategy for single model inheritance and how I did with the controllers and templates. I have two types of users in my app, User (a common user) and ThingsAdmin (a user, but [...]]]></description>
			<content:encoded><![CDATA[<p>Developing with Ruby on Rails can be fun, but sometimes, especially for newbies like me, we can get stuck somewhere. I&#8217;ll document my strategy for single model inheritance and how I did with the controllers and templates.</p>
<p>I have two types of users in my app, User (a common user) and ThingsAdmin (a user, but can have and administer Things). The two type of users basically share the same attributes and the same behavior, though the ThingsAdmin user can have and administer many Things.</p>
<p>For more about Single table inheritance, check the docs <a href="http://api.rubyonrails.org/classes/ActiveRecord/Base.html">http://api.rubyonrails.org/classes/ActiveRecord/Base.html</a></p>
<p>Let me show you my code for the models:</p>
<pre class="brush: ruby; title: ; notranslate">
class User &lt; ActiveRecord::Base
   #attributes, validations, filters, methods and other stuff for User model
end
</pre>
<p>And the ThingsAdmin is something like this:</p>
<pre class="brush: ruby; title: ; notranslate">
class ThingsAdmin &lt; User
   has_many :things
   #Specific attributes, validations, filters, methods and other stuff for ThingsAdmin model
end
</pre>
<p>In the migration, I just needed to add a new field &#8220;type&#8221;:</p>
<pre class="brush: ruby; title: ; notranslate">
  def self.up
    change_table :users do |t|
      t.string :type
    end
  end
</pre>
<p>It&#8217;s not needed to create a new table for ThingsAdmin.</p>
<p>Having these two models defined like this, when I create a new User, the field type is set to nil but If I create a new ThingsAdmin, the field &#8220;type&#8221; is automatically set to &#8220;ThingsAdmin&#8221;, i.e., the name of the model.</p>
<p>I can test this in the rails console:</p>
<pre class="brush: plain; title: ; notranslate">
irb(main):008:0&gt; user = User.new
irb(main):009:0&gt; user.type
=&gt; nil
irb(main):008:0&gt; admin = ThingsAdmin.new
irb(main):009:0&gt; admin.type
=&gt; ThingsAdmin
</pre>
<p>Now, I can have two different classes of users and it&#8217;s time to move to the controllers. I decided to start by mapping all things_admin resources to the controller User, something like this in my routes.rb:</p>
<pre class="brush: ruby; title: ; notranslate">
resources :things_admins, :controller=&gt;&quot;users&quot;
</pre>
<p>However, this does not works as expected because in my UserController the new action is something like:</p>
<pre class="brush: ruby; title: ; notranslate">
class UsersController &lt; ApplicationController
  def new
     @user = User.new
   end
   ##rest of the controller
end
</pre>
<p>So, how can I distinguish between the request for a new User or request for a new ThingsAdmin? My first though was to have a parameter moving around so I can differentiate the type of user I want to create, something like:</p>
<pre class="brush: ruby; title: ; notranslate">
class UsersController &lt; ApplicationController
  def new
      @user = User.new if params[:role]=='user'
      @user = ThingsAdmin.new if params[:role]=='admin'
   end
   ##rest of the controller
end
</pre>
<p>But this will bring some ugly things into my code, for example in the create action I would need to do something like:</p>
<pre class="brush: ruby; title: ; notranslate">
class UsersController &lt; ApplicationController
  def create
      @user = User.new(params[:user]) if params[:role]=='user'
      @user = ThingsAdmin.new(params[:things_admin] if params[:role]=='admin'
   end
   ##rest of the controller
end
</pre>
<p>I cannot forget about moving the param &#8220;role&#8221; when doing these operations&#8230; </p>
<p>So, I decided to try other solution, which I thing is cleaner. I created a controller for ThingsAdmin that only contains the actions &#8220;new&#8221; and &#8220;create&#8221;:</p>
<pre class="brush: ruby; title: ; notranslate">
class ThingsAdminsController &lt; UsersController
  def new
      @user = ThingsAdmin.new
      render &quot;users/new&quot;
   end

  def create
      @user = ThingsAdmin.new(params[:things_admin] if params[:role]=='admin'
      create_user(@user)
  end
   ##rest of the controller
end
</pre>
<p>And modified the UsersController to looks something like:</p>
<pre class="brush: ruby; title: ; notranslate">
class  UsersController &lt; ApplicationController
  def new
      @user = User.new
   end

  def create
      @user = User.new(params[:things_admin] if params[:role]=='admin'
      create_user(@user)
  end
  protected
  def create_user(user)
       #Code to create users (User or ThingsAdmin)
   end
   ##rest of the controller
end
</pre>
<p>Now, I have to tell the rails routing engine to redirect every action for business_admins to the UsersController except for &#8220;new&#8221; and &#8220;create&#8221; actions. My routes.rb look something like:</p>
<pre class="brush: ruby; title: ; notranslate">
resources :users
match &quot;/things_admins/new(.:format)&quot; =&gt; &quot;things_admins#new&quot;, :via=&gt;[:get], :as=&gt;:new_things_admin
match &quot;/things_admins(.:format)&quot; =&gt; &quot;things_admins#create&quot;, :via=&gt;[:post], :as=&gt;:things_admins
resources :things_admins, :controller=&gt;&quot;users&quot;, :except=&gt;[:new, :create]
</pre>
<p>Now, every action concerned to a User or ThingsAdmin will be handled by the controller UsersController, except the &#8220;new&#8221; and &#8220;create&#8221; action.</p>
<p>There is something more I have to do, now concerning the update action. To have only one action handling the update of both User and ThingsAdmin, I just need to modify one line in the UsersController:</p>
<pre class="brush: ruby; title: ; notranslate">
class  UsersController &lt; ApplicationController

  def update
      @user = User.find[params[:id])
      ##This method is handling both the update of BusinessAdmins and Users....
      if @user.update_attributes(params[@user.class.name.underscore])
        flash[:success = &quot;User updated&quot;
        redirect_to user_path(@user)
     else
         flash[:error] = &quot;Could not update user&quot;
        render :edit
     end
  end
     ##rest of the controller
end
</pre>
<p>Now, everything works as expected. Really, I don&#8217;t know if this is the best strategy because it&#8217;s the first one I tried. If you have a better solution, please share because I would like to know.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2011/02/15/hacking-a-rails-controller-and-template-inheritance-strategy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The problem with Java Web development frameworks is&#8230;</title>
		<link>http://jpereira.eu/2011/02/08/the-problem-with-java-web-development-frameworks-is/</link>
		<comments>http://jpereira.eu/2011/02/08/the-problem-with-java-web-development-frameworks-is/#comments</comments>
		<pubDate>Tue, 08 Feb 2011 14:30:08 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[WEB 2.0]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=384</guid>
		<description><![CDATA[Well, from my point of view, the problem of Java Web development frameworks is that there are too many. Each one has its strengths and weaknesses, like anything else. I&#8217;m excluding those that are proprietary and you have to pay to use them. Really, why would people pay for such kind of thing? Focusing on [...]]]></description>
			<content:encoded><![CDATA[<p>Well, from my point of view, the problem of Java Web development frameworks is that there are too many. Each one has its strengths and weaknesses, like anything else. I&#8217;m excluding those that are proprietary and you have to pay to use them. Really, why would people pay for such kind of thing? </p>
<p>Focusing on what is open source, you just need to see those supported by Apache: <a href="http://projects.apache.org/indexes/category.html#web-framework">http://projects.apache.org/indexes/category.html#web-framework</a> </p>
<p>Then you can see a list of Java web development frameworks (result of a Google search):<br />
<a href="http://java-source.net/open-source/web-frameworks">http://java-source.net/open-source/web-frameworks </a></p>
<p>There&#8217;s are so many and the community does not focus on building a complete Java Web Development Framework. The one I like more is <a href="http://www.playframework.org/">Play! Framework</a> because it&#8217;s a complete stack of java technologies that really help the development of web apps and it borrows many concepts from Ruby on Rails, which it&#8217;s my favorite.</p>
<p>I don&#8217;t know every Java web development framework, of course, and each must have their strengths and serve different purposes, but my feeling is that if there were only a few, then the community will focuses on improving those and we&#8217;ll end with a truly good framework.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2011/02/08/the-problem-with-java-web-development-frameworks-is/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Getting Rails 3.0.3 running with Mysql</title>
		<link>http://jpereira.eu/2011/02/05/getting-rails-3-0-3-running-with-mysql/</link>
		<comments>http://jpereira.eu/2011/02/05/getting-rails-3-0-3-running-with-mysql/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 17:49:33 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=375</guid>
		<description><![CDATA[Just as a memory aid for me and though I can share this. While experimenting the Ruby on Rails 3.0.3, I created an application that by default uses SQLite, but I want to use MySql instead. So here the steps I gone through: 1) Install MySql Server 2) Install MySql client dev package 3) Create [...]]]></description>
			<content:encoded><![CDATA[<p>Just as a memory aid for me and though I can share this.</p>
<p>While experimenting the Ruby on Rails 3.0.3, I created an application that by default uses SQLite, but I want to use MySql instead. </p>
<p>So here the steps I gone through:</p>
<p>1)  Install MySql Server</p>
<pre class="brush: plain; title: ; notranslate">
sudo apt-get install mysql-server
</pre>
<p>2) Install MySql client dev package</p>
<pre class="brush: plain; title: ; notranslate">
sudo apt-get install libmysqlclient-dev
</pre>
<p>3) Create a new mysql user to use during my development and tests<br />
3.1 ) Connect to mysql</p>
<pre class="brush: plain; title: ; notranslate">
mysql -u root -p
</pre>
<p>3.2 Create a user</p>
<pre class="brush: plain; title: ; notranslate">
create user 'railsuser'@'localhost' identified by 'somepass';
</pre>
<p>3.3) Grant all privileges to the user, so rails can do everything for me, such as creating the databases:</p>
<pre class="brush: plain; title: ; notranslate">
grant all privileges on *.* to 'railsuser'@'localhost';
</pre>
<p>4) Edit my app Gemfile:<br />
Comment, or remove, the following line</p>
<pre class="brush: plain; title: ; notranslate">
gem 'sqlite3-ruby', :require =&amp;gt; 'sqlite3'
</pre>
<p>Add this line:</p>
<pre class="brush: plain; title: ; notranslate">
gem 'mysql2'
</pre>
<p>5) Run the <a href="http://gembundler.com/rails3.html">Bundler</a> tool, the dependency management tool for Rails app:</p>
<pre class="brush: plain; title: ; notranslate">
sudo bundle install
</pre>
<p>Hopefully, everything went just fine till here.</p>
<p>Now, just configure my database.yml to use MySql as a database:</p>
<pre class="brush: plain; title: ; notranslate">
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: myapp_development
pool: 5
username: railsuser
password: somepass
socket: /var/run/mysqld/mysqld.sock

test:
adapter: mysql2
encoding: utf8
reconnect: false
database: myapp_test
pool: 5
username: railsuser
password: railsuser1234
socket: /var/run/mysqld/mysqld.sock
</pre>
<p>For production, just use the MySql user that I want in production.</p>
<p>6) Let rake create my databases, by running:</p>
<pre class="brush: plain; title: ; notranslate">
rake db:create
</pre>
<p>It&#8217;s done.</p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2011/02/05/getting-rails-3-0-3-running-with-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Yeahh, I&#8217;m building it with enterprise ready technologies&#8230; who cares?</title>
		<link>http://jpereira.eu/2011/02/05/yeahh-ia-building-it-with-enterprise-grade-technologies-who-cares/</link>
		<comments>http://jpereira.eu/2011/02/05/yeahh-ia-building-it-with-enterprise-grade-technologies-who-cares/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 14:45:57 +0000</pubDate>
		<dc:creator>jpereira</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[WEB 2.0]]></category>

		<guid isPermaLink="false">http://jpereira.eu/?p=372</guid>
		<description><![CDATA[If you have an web product idea and want to test it, i.e. put it in front of your users, what it&#8217;s the most critical aspect to consider first? I usually get my head into a conflict, because I&#8217;m used to work with the so-called &#8220;enterprise ready technologies&#8221;, namely JEE. My mind if formatted to [...]]]></description>
			<content:encoded><![CDATA[<p>If you have an web product idea and want to test it, i.e. put it in front of your users, what it&#8217;s the most critical aspect to consider first? I usually get my head into a conflict, because I&#8217;m used to work with the so-called &#8220;enterprise ready technologies&#8221;, namely JEE.  My mind if formatted to think about all aspects that a good enterprise product should have.  I start giving more attention to a set of quality attributes like performance, usability, reusability, testability, portability, modifiability, etc, etc, and give less attention to one critical aspect, if I want to get a product in front of the users fast: productivity.</p>
<p>So, I start looking to what is out there that is enterprise ready, like EJBs, JSF, Hibernate, JBoss, Tomcat, whatever, and start getting the pieces together&#8230;. out there in the world there was some a guy with the same product idea, but  considered first the productivity aspect of the equation and started to materialize the idea with, let&#8217;s say, Ruby on Rails&#8230;. guess who&#8217;s the winner?</p>
<p>I&#8217;m not against the use of JEE, of course, I just think that in some cases it does not make sense. I also have this false argument in my mind: What if I start building it with PHP and then hit a performance problem with my 1Million users? Well, If I ever had one million users, I&#8217;ll be happy to deal with these performance issues <img src='http://jpereira.eu/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://jpereira.eu/2011/02/05/yeahh-ia-building-it-with-enterprise-grade-technologies-who-cares/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

