<?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>Basil Vandegriend: Professional Software Development &#187; reuse</title>
	<atom:link href="http://www.basilv.com/psd/blog/tag/reuse/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.basilv.com/psd</link>
	<description></description>
	<lastBuildDate>Thu, 17 May 2012 14:31:08 +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>Creating Custom Tags Using JSP</title>
		<link>http://www.basilv.com/psd/blog/2008/creating-custom-tags-using-jsp</link>
		<comments>http://www.basilv.com/psd/blog/2008/creating-custom-tags-using-jsp#comments</comments>
		<pubDate>Thu, 24 Apr 2008 22:12:01 +0000</pubDate>
		<dc:creator>Basil Vandegriend</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[reuse]]></category>
		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://www.basilv.com/psd/blog/2008/creating-custom-tags-using-jsp</guid>
		<description><![CDATA[Java Server Pages (JSP) is a Java technology for rendering dynamic web pages. Unlike servlets written directly in Java, JSP files contain special markup to identify java or JSP code. The normal (non-markup) text is interpreted as HTML. Early in JSP's evolution, custom tags were introduced as a way of providing reusable functionality, particularly reusable [...]]]></description>
			<content:encoded><![CDATA[<p>Java Server Pages (JSP) is a Java technology for rendering dynamic web pages. Unlike servlets written directly in Java, JSP files contain special markup to identify java or JSP code. The normal (non-markup) text is interpreted as HTML. Early in JSP's evolution, custom tags were introduced as a way of providing reusable functionality, particularly reusable UI widgets, across JSP files. The original mechanism for creating these custom tags was very clunky: each tag had to be written in Java code (similar to servlets) and required extra configuration in XML to package into a tag library.</p>
<p>As of JSP version 2.0, available since Java EE 1.4, there is now support for creating custom tags using only the JSP syntax. No Java or XML is required. Each individual custom tag corresponds to a <em>tag file</em>, which is nothing more than a JSP file with a <code>.tag</code> extension located in a special directory within the WAR file: <code>/WEB-INF/tags</code>.</p>
<p>Attributes can be supplied to the tag file using a JSP directive <code>&lt;%@attribute name="&lt;some-name&gt;" required="{true|false}"%&gt;</code>. Attributes are referenced within the tag file like any other JSP variable using EL (the expression language). </p>
<p>This JSP tag library within your WAR can be referenced by other JSPs using the taglib directive: <code>&lt;%@taglib tagdir="/WEB-INF/tags" prefix="tags"%&gt;</code>.</p>
<p>The following example shows this in action. First the custom tag file <code>WEB-INF/tags/title.tag</code>:</p>
<pre class="prettyprint">
&lt;%@attribute name="title" required="true"%&gt;
&lt;%@tag description="Standard Title" pageEncoding="UTF-8"%&gt;

&lt;h1&gt;${title}&lt;/h1&gt;
</pre>
<p>Now a normal JSP file that uses this custom tag:</p>
<pre class="prettyprint">
&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
&lt;%@taglib tagdir="/WEB-INF/tags" prefix="tags"%&gt;
&lt;html&gt;
&lt;body&gt;
&lt;tags:title title="Hello World"/&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Prior to JSP 2.0 I have made reusable JSP fragments using the import directive, but this new mechanism is just as simple and much more convenient. Smart JSP editors can in fact provide lookup/completion functionality when you are invoking your custom tags.</p>
<p>The capabilities of these custom tags go far beyond what I have shown here. For more information see <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPTags.html">Sun's Custom Tags Tutorial</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.basilv.com/psd/blog/2008/creating-custom-tags-using-jsp/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Reuse Trap in Software Design</title>
		<link>http://www.basilv.com/psd/blog/2006/the-reuse-trap-in-software-design</link>
		<comments>http://www.basilv.com/psd/blog/2006/the-reuse-trap-in-software-design#comments</comments>
		<pubDate>Thu, 07 Sep 2006 15:00:39 +0000</pubDate>
		<dc:creator>Basil Vandegriend</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[reuse]]></category>
		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://www.basilv.com/psd/blog/2006/the-reuse-trap-in-software-design</guid>
		<description><![CDATA[I stared at my code on the screen, but inspiration wouldn't come. I was trying to design a new feature which shared some commonalities with the existing code base. In particular, there were a couple classes that I knew I could reuse. I just wasn't sure how they would have to be modified because I [...]]]></description>
			<content:encoded><![CDATA[<p>I stared at my code on the screen, but inspiration wouldn't come. I was trying to design a new feature which shared some commonalities with the existing code base. In particular, there were a couple classes that I knew I could reuse. I just wasn't sure how they would have to be modified because I was still figuring out the structure of the new feature. This also was difficult - I didn't have a clear picture of how those reused classes would fit in. Around and around my thoughts went, without any progress. I was stuck in the reuse trap.</p>
<p>Does this story sound familiar? I have been ensnared by the reuse trap many times, especially early in my career. At first I labored in vain, wondering why I was making no progress, oblivious of the trap I was in. As I gained experience, I become aware of the reuse trap and learned techniques and skills to avoid or escape it. </p>
<p>The <em>reuse trap</em> is a term I coined to describe the situation when one becomes stuck trying to design new functionality while simultaneously attempting to reuse existing code that needs some modifications. I believe this happens because we are trying to solve two separate yet interrelated problems: one, implementing the new functionality, and two, modifying the code to be reused. The new functionality depends on the reusable code, and the way we modify this code depends on how it will be used by the new functionality. Trying to reason about both issues at the same time imposes too high a cognitive load, so we fail to make progress on either front. </p>
<p>How can we escape the reuse trap? Simply put, don't try to do two things at the same time. You need to produce the new functionality, so you can't avoid working on this problem. The solution, therefore, is to defer the code reuse problem. Trying to achieve reuse is the <a href="http://www.basilv.com/psd/blog/2006/how-to-do-root-cause-analysis">root cause</a> of this trap, and is the key to escaping it. The first step is to just start developing the new functionality. You can reuse code, but only as is, like you would do for a third party library. If you need to modify it, then just ignore it (for now). When you reach points where you could reuse existing code with some modification, feel free to take a copy of this existing code and change it as needed. This is also called cut-and-paste reuse, which is generally frowned upon. The use of it here is only temporary, as you'll see. Your goal is to finish enough of the new functionality to know that the design will work. This may mean finishing it completely, or just writing a basic skeleton. In either case, once you reach this point the next step is to eliminate duplication in the code base. Any sections of new code that you copied (cut-and-pasted) from existing code will be primary targets for your efforts. During this step, it is helpful to follow a disciplined refactoring process as described in <a href="http://www.amazon.ca/exec/obidos/redirect?link_code=as2&#038;path=ASIN/0201485672&#038;tag=basilvandegri-20&#038;camp=15121&#038;creative=330641">Martin Fowler's refactoring book</a><img src="http://www.assoc-amazon.ca/e/ir?t=basilvandegri-20&#038;l=as2&#038;o=15&#038;a=0201485672" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />. </p>
<p>In this second refactoring step, I deliberately omitted the word <em>reuse</em> and instead used the term <em>eliminating duplication</em>. Reuse implies thinking about the future - how can this code be re-used in a different context? By its very nature, it is more abstract, more uncertain, and thus more difficult to reason about. Eliminating duplication is more concrete and focused on what exists now, in the present. Adopting a mindset of eliminating duplication rather than up-front reuse therefore helps you avoid the reuse trap. This relates closely to some of the principles of <a href="http://www.amazon.ca/exec/obidos/redirect?link_code=as2&#038;path=ASIN/0321278658&#038;tag=basilvandegri-20&#038;camp=15121&#038;creative=330641">Extreme Programming</a><img src="http://www.assoc-amazon.ca/e/ir?t=basilvandegri-20&#038;l=as2&#038;o=15&#038;a=0321278658" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />: "You ain't gonna need it", "Do the simplest thing that could possibly work", and "Once and only once".</p>
<p>As your design experience grows, it becomes easier to avoid the reuse trap. You become more adept at knowing how to modify existing code to reuse it without really having to think hard about the problem. This allows you to focus on the problem of developing the new functionality, which is also likely easier. Therefore, your overall cognitive load is reduced - you can solve both problems at once - and the reuse trap is avoided. However, even experienced developers will still encounter difficult situations for which their experience is insufficient. That is when you need to know how to escape the reuse trap.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.basilv.com/psd/blog/2006/the-reuse-trap-in-software-design/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

