<?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>Turnleaf Design &#187; Programming</title>
	<atom:link href="http://www.turnleafdesign.com/tag/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://www.turnleafdesign.com</link>
	<description>Ramblings of a junior developer</description>
	<lastBuildDate>Thu, 21 Oct 2010 01:39:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Web developers should hate http</title>
		<link>http://www.turnleafdesign.com/web-developers-should-hate-http</link>
		<comments>http://www.turnleafdesign.com/web-developers-should-hate-http#comments</comments>
		<pubDate>Mon, 23 Aug 2010 13:00:32 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Java don't care]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unit testing]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=324</guid>
		<description><![CDATA[I don't mean that literally, what I do mean is a web developer should hate when Java's http specification is directly accessed in the code. This is a topic I briefly touched on in my 8 signs your code sucks post awhile back. I decided to return to this topic because it touches on a [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fweb-developers-should-hate-http"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fweb-developers-should-hate-http&amp;source=TurnleafDesign&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I don't mean that literally, what I do mean is a web developer should hate when Java's http specification is directly accessed in the code. This is a topic I briefly touched on in my <a href="http://www.turnleafdesign.com/8-signs-your-code-sucks" target="_blank">8 signs your code sucks</a> post awhile back. I decided to return to this topic because it touches on a very important and fundamental programming practice which is limiting dependencies in code. This article represents the initial entry into a new series I plan on covering called "Java don't care." As aforementioned this series will focus on reducing dependencies in code, as well as making your code less aware of the environment it is in, and how following these practices will help you as a developer. But back to the task at hand; why referencing Java's http specification is bad.<br />
<span id="more-324"></span></p>
<h4>The problems</h4>
<p>A long list likely could be made as to why you should not directly reference http in your code. Here are four of the more important:</p>
<p><strong>Testing</strong></p>
<p>Probably the most readily noticable and debately the most important; referencing http in code greatly increases the difficultly of writing tests. To even begin writing a unit test you will need a tool to mock the http request/session. This increase in the difficulty of writing unit tests leads to two problems; decreased unit test coverage and increased unit test complexity.</p>
<p><strong>Contract</strong></p>
<p>A somewhat overlooked issue, but important none the less, is the lack of a contract between the view and the backend code that supports it. There is no central location to figure out what is contained in the request/session. The HttpServletRequest does not (and could not) provide this information. This lack of a contract can make it difficult to understand what is happening in the application as well as what the developer has access to.</p>
<p><strong>Coupling</strong></p>
<p>Directly accessing the http specification makes the code more aware of a view's internal implementations than it should be. The controller, and certainly the model, should not know the names of the various fields and variables in the view. It creates a mud ball of an application where changes to one level unduly necessitate changes to other levels.</p>
<p>You also introduce an unnecessary requirement into the application. Obviously requiring a web based application to include the httpservlet library in its classpath isn't particularly burdesom, but in other areas it could represent an issue. In general it is a bad programming practice to force requirements on an application.</p>
<p><strong>Maintainability</strong></p>
<p>Fundamentally this is more of a meta-issue, it is the inevitable outcome of the above three issues (as well as others). When you have an application that is difficult to write unit test for, hard to figure out what is accessible where, and has unnecessary requirements to work, you have an application that is difficult to maintain. I would argue that writing a maintainable application is the second most important requirement of an application (the first of course being one that it meets business requirements).</p>
<h4>How to fix it</h4>
<p>There are many differnet ways to fix and/or prevent this issue from occurring. Many frameworks, like Spring, (can) handle the session and request for you. This would also typically be the best way of addressing the issue. Let's assume, for the purpose of this article, that such an option is not available. Below is the controller of a simple application that I wrote that makes extensive use of the http request.</p>
<pre name="code" class="java">public class NewUserFormController extends HttpServlet {

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String nextPage = createUser(req);
req.getRequestDispatcher(nextPage).forward(req, resp);
}

private String createUser(HttpServletRequest req) {
List errorMsg = new ArrayList();
UserDao dao = new UserDaoImpl();
validateUserInput(req,
errorMsg);
if(!dao.doesUserExist(req, errorMsg)){
dao.insertUser(req, errorMsg);
}
if(errorMsg.isEmpty()){
return "Complete.jsp";
} else{
req.setAttribute("errorMsg", errorMsg);
setRequestAttributes(req);
return "Form.jsp";
}
}

private void setRequestAttributes(HttpServletRequest req) {
String fName = req.getParameter("fName");
String lName = req.getParameter("lName");
String eMail = req.getParameter("eMail");
req.setAttribute("fName", fName);
req.setAttribute("lName", lName);
req.setAttribute("eMail", eMail);
}

private void validateUserInput(HttpServletRequest req, List errorMsg) {
String fName = req.getParameter("fName");
String lName = req.getParameter("lName");
String eMail = req.getParameter("eMail");
String password = req.getParameter("password");
String confirmPassword = req.getParameter("confirmPassword");
if (isEmpty(fName)) {
errorMsg.add("Must enter a first name!");
}
if (isEmpty(lName)) {
errorMsg.add("Must enter a last mame!");
}
if (isEmpty(eMail)) {
errorMsg.add("Must enter an email address!");
}
if (isEmpty(password)) {
errorMsg.add("Must enter a password!");
}
if (isEmpty(confirmPassword)) {
errorMsg.add("Must confirm password!");
}
if(!password.equals(confirmPassword)){
errorMsg.add("Passwords must match!");
}
}

private boolean isEmpty(String string) {
return string == null || string.trim().equals("");
}
}</pre>
<p>Entire source of the project can be viewed <a href="http://turnleafdesign.googlecode.com/svn/!svn/bc/10/trunk/HttpExample/" target="_blank">here</a></p>
<p>As you can see the access to the HttpServletRequest permeates near the entireity of the code base. As a result many of the issues I brought up are problems in this code (coincedence?). It would be difficult to write unit tests for this code, it's somewhat difficult to know what information is on the request, and I am dependant on the httpservlet in my code.</p>
<h4>The fix</h4>
<p>So clearly this code needs help. Our refacotring of the code has two major goals:<br />
1. Create a contract between the view and the rest of the application<br />
2. Reduce the depence on the http specification in the code</p>
<p>Typically in this situation I create a bean that holds all the fields in the request/session as well as a few additional meta fields (such as in this example the next page). This creates the previously mentioned contract. A developer can look at the bean class and know what fields are accessible in the application.</p>
<p>The usage of this bean will help accomplish goal number two. Instead of accessing the http request to get the data we need, instead I will dump all the data into the bean and access the bean and then reference it instead.</p>
<p>So here is what the new controller class looks like</p>
<pre name="code" class="java">public final class NewUserFormController {

private NewUserFormController(){

}

protected static String createUser(UserFormBean bean) {
UserDao dao = new UserDaoImpl();
validateUserInput(bean);
if(!dao.doesUserExist(bean)){
dao.insertUser(bean);
}
if(bean.getErrorMsg().isEmpty()){
return FormConstants.COMPLETE_PAGE;
} else{
return FormConstants.FORM_PAGE;
}
}

private static void validateUserInput(UserFormBean bean) {
if (isEmpty(bean.getfName())) {
bean.addErrorMsg("Must enter a first name!");
}
if (isEmpty(bean.getlName())) {
bean.addErrorMsg("Must enter a last mame!");
}
if (isEmpty(bean.geteMail())) {
bean.addErrorMsg("Must enter an email address!");
}
if (isEmpty(bean.getPassword())) {
bean.addErrorMsg("Must enter a password!");
}
if (isEmpty(bean.getConfirmPassword())) {
bean.addErrorMsg("Must confirm password!");
}
if(!bean.getPassword().equals(bean.getConfirmPassword())){
bean.addErrorMsg("Passwords must match!");
}
}

private static boolean isEmpty(String string) {
return string == null || string.trim().equals("");
}
}</pre>
<p>As can be seen the HttpServlet dependency has been completely removed from this code. The code is a bit simpler as I removed pretty much all local variables and use the bean instead. However the best part is I can much more easily write unit tests (which I did).</p>
<h4>So what does this mean to me?</h4>
<p>Well these changes fix much of the four problems I mentioned above. However there is a couple other addtional benefits:</p>
<p><strong>Increased modularity</strong></p>
<p>If a new form was created that had a lot the same fields, but a few additional ones (say city and address), instead of writing a bunch of new code to handle this form, instead these classes; the bean and the controller (removing the final modifier) could be reused. The developer then only needs to write code and test for the new fields.</p>
<p><strong>Separation of responsibilities</strong></p>
<p>With a contract in place there is less of a requirement for the developer writing the backend to be involved in writing the view portion of the application (or vice versa). This allows developers (or designers) to better play to their respective strengths and makes parallel development easier.</p>
<p>You can view all the source code for the entire project <a href="http://turnleafdesign.googlecode.com/svn/trunk/HttpExample/" target="_blank">here</a> (revision 13 is the last revision relevant to this article). The project also requires the <a href="http://www.oracle.com/technetwork/java/download-139443.html" target="_blank">Java servlet package (2.3+) </a></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Java' rel='tag' target='_blank'>Java</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a>, <a class='technorati-link' href='http://technorati.com/tag/Unit+testing' rel='tag' target='_blank'>Unit testing</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/web-developers-should-hate-http/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mocking JDBC Connections with MockRunner</title>
		<link>http://www.turnleafdesign.com/mocking-jdbc-connections-with-mockrunner</link>
		<comments>http://www.turnleafdesign.com/mocking-jdbc-connections-with-mockrunner#comments</comments>
		<pubDate>Wed, 11 Nov 2009 05:54:11 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Mock]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit testing]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=285</guid>
		<description><![CDATA[Last week I published an article, An Intro into Test Driven Development with Junit4, which got somewhat mixed reviews. One particular commenter on reddit suggested I didn't understand that unit tests shouldn't talk to its data source. I decided to do some investigating into his claims, you can check out my findings here. I was [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fmocking-jdbc-connections-with-mockrunner"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fmocking-jdbc-connections-with-mockrunner&amp;source=TurnleafDesign&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Last week I published an article, <a href="  http://www.turnleafdesign.com/an-intro-into-test-driven-development-with-junit4" target="_blank">An Intro into Test Driven Development with Junit4</a>, which got somewhat mixed reviews. One particular commenter on reddit suggested I didn't understand that unit tests <a href="http://www.reddit.com/r/programming/comments/9yq8p/an_intro_into_test_driven_development_with_junit4/c0f29uc" target="_blank">shouldn't talk to its data source</a>. I decided to do some investigating into his claims, you can check out my findings <a href="http://www.turnleafdesign.com/ramblings-should-unit-tests-talk-to-a-data-source" target="_blank">here</a>. I was however intrigued none the less and started looking for a tool that would allow me to easily mock a JDBC connection. I found <a href="http://mockrunner.sourceforge.net/" target="_blank">Mockrunner</a> to be the easiest to use of the ones I have found. Below is a brief tutorial on how to use Mockrunner. (Keep in mind that I am still fairly new to using Mockrunner)<span id="more-285"></span></p>
<p>In the class I am testing I am explicitly calling the columns I am retrieving by name. So I need to add these column names to my mock ResultSet.</p>
<pre class="java" name="code" style="display: none;">
result.addColumn("Date");
result.addColumn("High");
result.addColumn("Low");
result.addColumn("Condition");
result.addColumn("ID");</pre>
<p>Obviously I also retrieve data from a result set so I must also insert data into the mock ResultSet. There are several ways to do this, but the easiest I found was using a list. You must add elements to the list in the same order as you added columns to the ResultSet.</p>
<pre class="java" name="code" style="display: none;">
List&lt;Object&gt; rowItems = new ArrayList&lt;Object&gt;();
rowItems.add(new Date(0));
rowItems.add(72);
rowItems.add(56);
rowItems.add("Cloudy");
rowItems.add(1);</pre>
<p>In my actual test case I can verify that I am actually gathering the contents of the result set correctly and that the correct SQL statement was run.</p>
<pre class="java" name="code" style="display: none;">
prepareRS();
ForecastDAO dao = new ForecastDaoImpl(getConnection());
List&lt;Forecast&gt; forecasts = dao.getAllForecasts();

assertTrue(!forecasts.isEmpty());
verifySQLStatementExecuted("SELECT * FROM forecast");
assertEquals(73, forecasts.get(1).getHigh());</pre>
<p>This is but scratching the surface of MockRunner's potential and using mocks at large. I hope this brief tutorial was helpful in getting you started using MockRunner. You can checkout the entire test class <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/22/trunk/%20forecastaccuracychecker/forecastchecker/test/com/tld/dao/TestForecastDaoImpl.java" target="_blank">here</a> and the class that I am testing <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/20/trunk/%20forecastaccuracychecker/forecastchecker/src/com/tld/dao/ForecastDaoImpl.java" target="_blank">here</a>. If you want to get an entire working version of the project be sure to read the <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/20/trunk/%20forecastaccuracychecker/forecastchecker/src/com/tld/dao/ForecastDaoImpl.java" target="_blank">technical guide</a>. Let me know if you have any questions or want to add your own comments.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Mock' rel='tag' target='_blank'>Mock</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a>, <a class='technorati-link' href='http://technorati.com/tag/Testing' rel='tag' target='_blank'>Testing</a>, <a class='technorati-link' href='http://technorati.com/tag/Unit+testing' rel='tag' target='_blank'>Unit testing</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/mocking-jdbc-connections-with-mockrunner/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ramblings: Should unit tests talk to a data source?</title>
		<link>http://www.turnleafdesign.com/ramblings-should-unit-tests-talk-to-a-data-source</link>
		<comments>http://www.turnleafdesign.com/ramblings-should-unit-tests-talk-to-a-data-source#comments</comments>
		<pubDate>Thu, 05 Nov 2009 04:48:40 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Mock]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit testing]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=280</guid>
		<description><![CDATA[Last week I published an article on test driven development. One person who read my article (briefly) suggested I did not know that unit tests shouldn't talk to their data source. I plan on covering how to mock JDBC connections later this week, however I wanted to do some research to see if what my [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Framblings-should-unit-tests-talk-to-a-data-source"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Framblings-should-unit-tests-talk-to-a-data-source&amp;source=TurnleafDesign&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Last week I published an article on test driven development. One person who read my article (briefly) suggested I did not know that unit tests <a href="http://www.reddit.com/r/programming/comments/9yq8p/an_intro_into_test_driven_development_with_junit4/c0f29uc" target="_blank">shouldn't talk to their data source</a>. I plan on covering how to mock JDBC connections later this week, however I wanted to do some research to see if what my critic says is an industry standard or a philosophical choice.</p>
<p>Surprisingly there seems to be relatively little information on this subject, or I have been incapable of finding information. From what I have gathered though, the theory that data sources should be mocked is sound, but its may not always be practical to implement it. Below is two reasons why data source connections should be mocked and three reasons why they should not. <span id="more-280"></span></p>
<h3>Why you should mock connections</h3>
<p><strong>Speed –</strong> Talking to a data source is one the primary operations that slows an application's performance. Most data sources require some sort of network connection and retrieving data is often a processor intensive task. Obviously performing these tasks take time. Unit tests are most useful when they are run automatically and frequently to ensure changes being made are not breaking the application. Unit tests that are run automatically should be somewhat speedy, by mocking a data source connection, this can reduce considerably the amount of time it takes to run unit tests.</p>
<p><strong>Remove the reliance on the data source logic –</strong> Unit tests should be testing relatively small parts of code, individual methods and/or small collections of methods. By connecting to a data source you are depending upon the logic of not only how you are connecting, but how the data source operates. This goes beyond the scope of what a unit test should be testing.</p>
<h3>Why you shouldn't mock connections</h3>
<p><strong>It's time consuming –</strong> Writing mocks can be a quite laborious task. I often avoid writing mocks like the plague, because even relatively simple mocks can require a considerable amount of time to get running and running correctly. Even my very simple example of running a single query against a five column table took several hours to setup. Granted this was my first time creating a JDBC mock and future mocks would be easier and quicker to write, but it would still take longer than simply connecting to my database.</p>
<p><strong>It's ugly –</strong> It takes a lot of typing to get even relatively simple mocks working. A lot of the rules that apply to how real business code should be written need not be followed when writing unit tests, that said looking at the code of a unit test shouldn't make your eyes bleed. Unit tests that cannot be easily maintained often become ignored when they break and broken unit test have no value (if ignored).</p>
<p><strong>It's not real – </strong>Mocks don't really care what you put into or take out of them. Real data sources are often not so forgiving. If I misspelled a column or table name in a query, a mock would not pick up on this (you can verify the sql statements run, but again that could be misspelled), where as a real database would. By actually connecting to the real data source you can be more confident that the application will perform its intended tasks.</p>
<h3>Why you should use your head</h3>
<p>Even within the same project there will be instances where mocking a connection to a data source is the right choice and instances when you should actually connect to a real data source. In the early stages of a project using mocks can be more practical as the structure of the data source is more abstract and subject to change. Rewriting a mock is often quicker and easier than restructuring a data source. However as a project matures and the unit tests become more complex, connecting to the real data source may be more practical as it is not only (more) well defined, but writing the mocks begins to require more time. As with all practices, you need decide which one is best to follow (or not) based upon your requirements and restrictions. Though I think it is worth noting standards are standards for a reason. Feel free to weigh in with your own thoughts on the subject.</p>
<p>Additional reading:<br />
<a href="http://www.javaranch.com/journal/2003/12/UnitTestingDatabaseCode.html" target="_blank">http://www.javaranch.com/journal/2003/12/UnitTestingDatabaseCode.html</a><br />
<a href="http://www.buunguyen.net/blog/unit-testing-the-data-access-layer.html" target="_blank">http://www.buunguyen.net/blog/unit-testing-the-data-access-layer.html</a><br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Mock' rel='tag' target='_blank'>Mock</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a>, <a class='technorati-link' href='http://technorati.com/tag/Testing' rel='tag' target='_blank'>Testing</a>, <a class='technorati-link' href='http://technorati.com/tag/Unit+testing' rel='tag' target='_blank'>Unit testing</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/ramblings-should-unit-tests-talk-to-a-data-source/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Link dump 11/3</title>
		<link>http://www.turnleafdesign.com/link-dump-113</link>
		<comments>http://www.turnleafdesign.com/link-dump-113#comments</comments>
		<pubDate>Tue, 03 Nov 2009 06:07:01 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Link Dump]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=275</guid>
		<description><![CDATA[http://www.developerart.com – A new blog like my own. While not a whole lot yet, the content that is on his site is of high quality. Kind of a smallish link dump I know. I plan on getting some new articles posted this week, namely an update to my TDD article I posted last Monday. So [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Flink-dump-113"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Flink-dump-113&amp;source=TurnleafDesign&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.developerart.com" target="_blank">http://www.developerart.com</a> – A new blog like my own. While not a whole lot yet, the content that is on his site is of high quality.</p>
<p>Kind of a smallish link dump I know. I plan on getting some new articles posted this week, namely an update to my TDD article I posted last Monday. So check back soon.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x15, created 9/22/09 */
google_ad_slot = "6237316105";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/link-dump-113/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Intro into Test Driven Development with JUnit4</title>
		<link>http://www.turnleafdesign.com/an-intro-into-test-driven-development-with-junit4</link>
		<comments>http://www.turnleafdesign.com/an-intro-into-test-driven-development-with-junit4#comments</comments>
		<pubDate>Tue, 27 Oct 2009 04:26:16 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unit]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=260</guid>
		<description><![CDATA[Please read the technical guide before starting this tutorial. This article will mark the first of a long-term series covering professional software development. For the lowdown on this project check out this article. Be sure to give me your feedback as it will be vital in helping me develop better tutorials in the future. Test [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fan-intro-into-test-driven-development-with-junit4"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fan-intro-into-test-driven-development-with-junit4&amp;source=TurnleafDesign&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Please read the <a href="http://www.turnleafdesign.com/?page_id=263" target="_blank">technical guide </a>before starting this tutorial.</p>
<p>This article will mark the first of a long-term series covering professional software development. For the lowdown on this project check out <a href="http://www.turnleafdesign.com/?p=266" target="_blank">this article</a>. Be sure to give me your feedback as it will be vital in helping me develop better tutorials in the future.</p>
<p>Test driven development seemed like a natural choice as a lead off to my series of tutorials as I had to explain why I am writing all these tests. It is also a very good development methodology that will actually save a lot of time by reducing the amount of time spent debugging. For this tutorial and the entire project, I will be using Junit4. For a synopsis on test driven development you can check out the wikipedia article <a href="http://en.wikipedia.org/wiki/Test-driven_development" target="_blank">here</a>. If you need a brief refresher on JUnit you can read my tutorial <a href="http://www.turnleafdesign.com/?p=145" target="_blank">here</a> (written in Junit3).<br />
<span id="more-260"></span><br />
The goal of this tutorial, from a project stand point, is to get the connection to our (MySQL) database working. To do this we are going to need several things: a MySQL server, a client to access the server, and a JDBC driver to allow our application to access the server.</p>
<p>The MySQL server:<br />
I will be using MySQL server 5.0 for this project, you can download it <a href="http://dev.mysql.com/downloads/mysql/5.0.html#downloads" target="_blank">here</a>. The tutorial instructions will be based upon the user being “root,” the password “turnleaf,” and the url “http://localhost:3306.”</p>
<p>The MySQL client:<br />
I will be using <a href="http://www.heidisql.com/download.php" target="_blank">HeidiSQL</a> to query and manipulate the database. Once the client is installed import this sql file to setup the database and table.</p>
<p>The JDBC Driver:<br />
You can download the JDBC driver <a href="http://dev.mysql.com/downloads/connector/j/5.0.html" target="_blank">here</a>. Please include it on your projects build path.</p>
<p>To begin this project, please checkout revision 7 from the code repository.</p>
<p>Once you have downloaded the project go ahead and navigate around it a little bit. You will notice I already have several source files; Forecast, ForecastDao, and ForecastDaoImpl. Forecast is a bean for holding all weather information for a specific date (this bean will likely be modified in the future). We also have ForecastDao which is an interface and ForecastDaoImpl which implements ForecastDao. I plan on covering interfaces in more detail in the future, but if you are unfamiliar with the concept you can read a brief description <a href="http://java.sun.com/docs/books/tutorial/java/concepts/interface.html" target="_blank">here</a>.</p>
<p>Update to revision 8 and you will see I added in my first unit test. The unit test is checking to see if I get any returns when I run getAllForecasts(). Here is the code:</p>
<pre name="code" class="java">
@Test

public void testGetAllForecasts(){

List&lt;Forecast&gt; forecasts = dao.getAllForecasts();

Assert.assertTrue(!forecasts.isEmpty());

}
</pre>
<p>If you attempt to run the test you should get a null point error when you attempt to check if forecasts is empty. If you look at the implementation of getAllForecasts() in ForecastDaoImpl it is obvious why, getAllForecasts() is returning null. This is one of the tenants of TDD, write fail first tests.</p>
<p>Go ahead and update to <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/9/trunk/%20forecastaccuracychecker/forecastchecker/src/com/tld/dao/ForecastDaoImpl.java" target="_blank">revision 9</a>. You will see I have added connection information to getAllForecasts(). Don't worry about it being messy we will refactor it later. Go ahead and run the unit test again. You will still fail, but in the console shows we are successfully connecting to the database.</p>
<p>Update to <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/10/trunk/%20forecastaccuracychecker/forecastchecker/src/com/tld/dao/ForecastDaoImpl.java" target="_blank">revision 10</a>. I have made several more changes, most noticeably if you run the test it should now pass! (If not check to make sure your database is setup correctly) Before we start celebrating too much, lets actually check the contents of the list to make sure we are getting the right data. Update to <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/11/trunk/%20forecastaccuracychecker/forecastchecker/src/com/tld/dao/ForecastDaoImpl.java" target="_blank">revision 11</a>, I have added a few more checks, and we are in fact getting the correct data, awesome!</p>
<p><strong>Author note:</strong> For some dumb reason when you create a new Junit4 test class in Eclipse it does not automatically inherit TestClass. Anyways I inherit that class now so you can just do assertEquals(expected, actual) instead of Assert.assertEquals(expected, actual).<br />
If you checked the implementation of getAllForecasts() before updating to revision 10, you will noticed I am only setting the date value of my forecast bean. My new tests initially failed (I originally thought I was setting all fields), thus the importance of not only writing unit tests, but writing good unit tests.</p>
<p>So now it is time to start refactoring. With our unit test we now have a good baseline of how the system should behave. This way when we are making changes we can be confident we are not breaking the system because we will be getting the same output for the same input.</p>
<p>Update to <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/13/trunk/%20forecastaccuracychecker/forecastchecker/src/com/tld/dao/ForecastDaoImpl.java" target="_blank">revision 13</a>. You will see that I have created the getConnection() method and that contains the database connection logic.</p>
<pre name="code" class="java">
private Connection getConnection() {

Connection conn;

try {

String userName = "root";

String password = "turnleaf";

String url = "jdbc:mysql://localhost/weather";

Class.forName("com.mysql.jdbc.Driver").newInstance();

conn = (Connection) DriverManager.getConnection(url, userName,

password);

} catch (Exception e) {

throw new DataAccessException(e);

}

return conn;

}
</pre>
<p>I pretty much just copied and pasted (one of the VERY few times copying and pasting is ok) the connection logic into this method. The most noticeable change I made is in the catch clause. There is a bunch of different exceptions that could be thrown when attempting to connect to the database, sine they all end in the same scenario, unable to connect to the database, I kept the same generic catch(Exception). However you should never just throw exception so I created my own custom exception called DataAccessException. Inside the super(Throwable) constructor I set it up to add a message stating “Unable to connect to data source,” I also have it extend RunTimeException turning it into an <a href="http://java.sun.com/docs/books/tutorial/essential/exceptions/runtime.html" target="_blank">unchecked exception</a>.</p>
<p><strong>***Philosophical warning***</strong><br />
This is philosophical decision. As projects become more complex it can become difficult to catch and/or throw an exception at every level. However, you should catch the exception at some point to give the user a reasonable error message and let you know when the application is throwing exceptions. There is another school of thought that all exceptions should be checked as it lets a developer know what exceptions and method could throw, and other various reasons.</p>
<p>Between the message and the name of the exception, it should be pretty clear that when this exception is thrown it means the application failed to connect to the database. Running the unit test we will see everything is still passing so we can be confidant that the refactoring did not break the system.</p>
<p>Update to <a href="http://forecastaccuracychecker.googlecode.com/svn/!svn/bc/14/trunk/%20forecastaccuracychecker/forecastchecker/src/com/tld/dao/ForecastDaoImpl.java" target="_blank">revision 14</a> and you will see I refactored out the closing of the connection. Exceptions should never be ignored, personally I would say being unable to close a database connection could be a major issue. So instead of catching Exception I changed it to only catch SQLException and throw the DataAccessException except I will have my own message in their stating the connection could not be closed. Here is what the closeConnection() method looks like:</p>
<pre name="code" class="java">
private void closeConnection(Connection conn) {

if (conn != null) {

try {

conn.close();

} catch (SQLException e) {

throw new DataAccessException("Could not close connection", e);

}

}

}
</pre>
<p>From what it originally looked like, the getAllForecast() method is starting to look a lot better as well as the ForecastDaoImpl class in general. Adding new methods that retrieve data from the database will be easier as all I have to do to get a connection is call getConnection() and to close it closeConnection(Connection). On top of that if I need to change my database connection information I only have to do it in one area.</p>
<p>Despite this refactoring, this is hardly an ideal data access layer. With the test unit already created go ahead and continue to refactor getAllForecast(), a good place to start would be how I create a new Forecast object. I would also suggest adding some new functionality yourself a couple of examples might be; getForecastByDate(Date) or getForecastByCondition(String condition) (Remember create unit tests!). I will continue to refactor and update this work myself. So you can run updates and compare your work to my own.</p>
<p>Addendum and thanks:<br />
Because I am an idiot I couldn't remember how to write a JDBC connection. My initial connection method is predominantly based off of the code in this article: <a href="http://www.kitebird.com/articles/jdbc.html" target="_blank">http://www.kitebird.com/articles/jdbc.html</a><br />
For being able to go to a specific revision with a url:<br />
<a href="http://www.perhammer.com/2008/07/subversion-in-url-revision-browsing.html" target="_blank">http://www.perhammer.com/2008/07/subversion-in-url-revision-browsing.html</a><br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x15, created 9/22/09 */
google_ad_slot = "6237316105";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Java' rel='tag' target='_blank'>Java</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a>, <a class='technorati-link' href='http://technorati.com/tag/Unit' rel='tag' target='_blank'>Unit</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/an-intro-into-test-driven-development-with-junit4/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Comments are a sign of bad code and I am not sorry for saying it</title>
		<link>http://www.turnleafdesign.com/comments-are-a-sign-of-bad-code-and-i-am-not-sorry-for-saying-it</link>
		<comments>http://www.turnleafdesign.com/comments-are-a-sign-of-bad-code-and-i-am-not-sorry-for-saying-it#comments</comments>
		<pubDate>Fri, 23 Oct 2009 05:25:36 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=255</guid>
		<description><![CDATA[In my recent article, 8 signs your code sucks, one of my signs of bad code is: “You need to use comments to explain the code.” I have since taken a lot of flak for suggesting this and I want to clarify my point and why I am not backing down. Not javadoc - I [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fcomments-are-a-sign-of-bad-code-and-i-am-not-sorry-for-saying-it"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fcomments-are-a-sign-of-bad-code-and-i-am-not-sorry-for-saying-it&amp;source=TurnleafDesign&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>In my recent article, <a href="http://www.turnleafdesign.com/?p=246" target="_blank">8 signs your code sucks</a>, one of my signs of bad code is: “You need to use comments to explain the code.” I have since taken a lot of flak for suggesting this and I want to clarify my point and why I am not backing down.</p>
<p><strong>Not javadoc </strong>- I am NOT referring to <a href="http://en.wikipedia.org/wiki/Javadoc" target="_blank">Javadoc</a> or its equivalents in other languages. I absolutely do agree that a method or class should have accompanying documentation at its declaration stating its purpose and its inputs and/or outputs.<br />
<span id="more-255"></span><br />
<strong>Comments are not bad, the code is</strong> – I'm not suggesting to forgo the use of comments, but that they are only band-aids. When you don't have time to properly write a piece of code; do it the “messy” way, write a comment and give it a TODO as a reminder to go back and fix it later.</p>
<p><strong>Comments make code accessible </strong>- Code should not be written to the level of the dumbest developer, the dumbest developer should be brought to the level of the code (though I want to reiterate good code should be easily readable). If a developer is unwilling or unable to meet or at least understand the rest of the team's coding standards, then questions should be asked rather you want that developer to understand the code at all.</p>
<p><strong>They are more like guidelines</strong> – When it comes to design patterns there are no rules. From day one we are taught goto statements are evil and should never be used, but <a href="http://kerneltrap.org/node/553/2131" target="_blank">there is even a time and place for them</a>. There may be rare occasions when you have to write a comment to explain a piece of code, just like you may need to use a goto to simplify the code, but both occasions are rare and when encountered in code should be scrutinized.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/comments-are-a-sign-of-bad-code-and-i-am-not-sorry-for-saying-it/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>8 Signs your code sucks</title>
		<link>http://www.turnleafdesign.com/8-signs-your-code-sucks</link>
		<comments>http://www.turnleafdesign.com/8-signs-your-code-sucks#comments</comments>
		<pubDate>Thu, 22 Oct 2009 03:58:57 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=246</guid>
		<description><![CDATA[As a wide eyed junior developer when I first began working on large projects I simply accepted that it is difficult to fix bugs or find where an action is being executed. If only I knew then what I know now, I would had saved myself hours of frustration. The first step to writing good [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2F8-signs-your-code-sucks"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2F8-signs-your-code-sucks&amp;source=TurnleafDesign&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>As a wide eyed junior developer when I first began working on large projects I simply accepted that it is difficult to fix bugs or find where an action is being executed. If only I knew then what I know now, I would had saved myself hours of frustration. The first step to writing good code is accepting the code you write (or work on) is crap, but sometimes you need to know what to look for. Here are some signs that your code sucks.</p>
<p><strong>A method is larger than the screen </strong>– A method should only perform one specific task. A method should not contain the logic code to determine if the username field contains data, is valid, and that user exists. If a method is too large to fit within a single screen, that is a (very) good sign it is doing too much.<br />
<span id="more-246"></span><br />
<strong>You are reusing variables </strong>– Unless you are working on embedded devices, memory is cheap. Don't be a memory scrooge and knee cap code maintainability, which in nearly all instances trumps performance, by reusing the same variable for multiple uses.</p>
<p><strong>You are directly accessing the request/session </strong>– It not only makes writing unit tests (much) harder, but it is also difficult to know what data the application has access to. All data should be taken out of the session/request and stored in a bean. A bean, through its getters and setters, creates a “contract” of what data the application has access to, which greatly helps with code maintainability.</p>
<p><strong>You need to use comments to explain the code</strong> – Code should be able to explain itself and should be in a format that is easily readable. If you find yourself needing to explain what your code is doing then you may want to look into rewriting that code.<br />
<strong>EDIT:</strong> This is not referring to using comments (e.g. javadoc) to explain the purpose of a method/class and its inputs and outputs.</p>
<p><strong>An exception's stack trace doesn't return the original problem</strong> -  You should never “eat” an exception, that is catch an exception, but not print its stack trace. How can a bug be fixed if you don't even know where the bug is occurring?</p>
<p><strong>Your code is a mud ball</strong> – Just the name sounds ugly. A “mud ball” is when there is little separation between the layers or <a href="http://en.wikipedia.org/wiki/Concern_(computer_science)" target="_blank">concerns</a> of an application. Code should be modular allowing for ease of reusability and modifiability. Anything concerning the user interface happens in the view, program flow and usually data validation is the domain of the controller, handling business logic is the model's job, and only the model should be interacting with the data access layer.</p>
<p><strong>It is hard to write a unit test</strong> – If you find a bug or write a new piece of code and it takes you more than a few minutes to write a unit test then that portion of code is handling too complex of a task.</p>
<p><strong>The author is <a href="http://www.turnleafdesign.com/?page_id=2" target="_blank">Billy Korando</a></strong> – Wait what?!</p>
<p>Add your own experiences or signs for dealing with sucky code.</p>
<p><strong>UPDATE:</strong> There are differing opinions on my signs, since I am but a mere "grasshopper" I maybe wrong. Anyways <a href="http://www.reddit.com/r/learnprogramming/comments/9wp2a/8_signs_your_code_sucks/c0esu86" target="_blank">check it out and make up your own mind.</a><br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x15, created 9/22/09 */
google_ad_slot = "6237316105";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/8-signs-your-code-sucks/feed</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>12 Tips to make you more productive using Eclipse</title>
		<link>http://www.turnleafdesign.com/12-tips-to-make-you-more-productive-using-eclipse</link>
		<comments>http://www.turnleafdesign.com/12-tips-to-make-you-more-productive-using-eclipse#comments</comments>
		<pubDate>Tue, 20 Oct 2009 04:28:16 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Noob Corner]]></category>
		<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=240</guid>
		<description><![CDATA[Integrated development environments make developing application fair easier. They highlight syntax, let you know if you have a compilation error, and allow you to step through your code among so many other things. Like all IDEs Eclipse has a bunch of little shortcuts and tools that can make your life a lot easier, I've compiled [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2F12-tips-to-make-you-more-productive-using-eclipse"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2F12-tips-to-make-you-more-productive-using-eclipse&amp;source=TurnleafDesign&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Integrated development environments make developing application fair easier. They highlight syntax, let you know if you have a compilation error, and allow you to step through your code among so many other things. Like all IDEs Eclipse has a bunch of little shortcuts and tools that can make your life a lot easier, I've compiled a list of several that I use on a daily basis:</p>
<p><strong>1. Auto-complete</strong> – Eclipse has an auto-complete feature that can be accessed with ctrl + space. When clicked a small pop-up box is displayed with a list of context sensitive suggestions. If there is only one possibility then Eclipse completes it for you.<br />
<span id="more-240"></span><br />
<strong>2. Quickly format your code</strong> – Code that is being heavily modified can quickly become an ugly sight. Without proper indention it can become extremely difficult to determine what is happening in code. Code can be quickly formatted using the shortcut: Ctrl + shift + F. You can even setup your own style rules by going to: Project&gt;Preferences&gt;Java Code Style&gt;Formatter, check “enable project specific settings” edit the profile and then save it under a new name.</p>
<p><strong>3. Get rid of unnecessary code </strong>– Heavily worked on projects that aren't maintained well can quickly build up a bunch of unnecessary imports, casts, among other common easily detectable coding mistakes. Quickly remove these mistakes by running a code clean up. Right click on your project folder&gt;source&gt;clean up. Like the code formatter you can also customize your code clean up.</p>
<p><strong>4. Go to declaration</strong> – Want to know where that method, variable, or class is declared? This can easily be done by holding down ctrl and then clicking on the reference.</p>
<p><strong>5. Find all references</strong> – If you need to find all the references for a method, variable, or class highlight the desired reference right click&gt;reference and select the desired search scope.</p>
<p><strong>6. Quickly select groups of characters</strong> – Need to delete an entire string, or everything within a method's argument declaration? Select the enclosing character (e.g. the “ or "(" respectively), this will select everything within the enclosing characters. This even works with the bodies of classes and methods. You can also select an entire line by triple clicking.</p>
<p><strong>7. Rename all instances </strong>– If you need to rename a method, variable, or class you can rename ever instance by highlighting a reference and pressing alt + shift + r an box will highlight the reference and you can rename it. Upon pressing enter all instance will be renamed in your project.</p>
<p><strong>8. Change a method signature</strong> – If you need to change any part of a methods signature; a methods name, its arguments, or return type, you can quickly make a change to all references of the method in the project by highlighting the method and pressing alt + shift + c a pop-up box will appear giving you options to change the method's signature.</p>
<p><strong>9. Automatically generate getters and setters</strong> – Writing getters and setters is for suckers. After you write out all the members of a class right click anywhere in the code screen&gt;source&gt;generate getters and setters. Select the variables you want to have getters and setters made for.</p>
<p><strong>10. Javadoc is a cinch</strong> – Eclipse makes writing Javadoc easy, just type “/**” and press eneter above a declaration. Eclipse automatically creates context sensitive Javadoc annotations (i.e. a methods parameters, or the author of a class). After that you only have to write out what the method actually does.</p>
<p><strong>11. Run a unit test</strong> – To run a unit test highlight the unit test and press alt + shift + x followed by t. You can also run a unit test in the debugger by pressing alt + shift + <span style="text-decoration: line-through;"></span>d followed by t.</p>
<p><strong>12. Comment out code</strong> – If you need to quickly comment out a chunk of code, highlight the corresponding lines and press ctrl + /, you can uncomment code the say way.</p>
<p>Chime in with your own Eclipse shortcuts.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/12-tips-to-make-you-more-productive-using-eclipse/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Link Dump 10/13</title>
		<link>http://www.turnleafdesign.com/link-dump-1013</link>
		<comments>http://www.turnleafdesign.com/link-dump-1013#comments</comments>
		<pubDate>Wed, 14 Oct 2009 01:51:48 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Link Dump]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=224</guid>
		<description><![CDATA[http://www.codeigniter.com – An excellent and lightweight framework for developing PHP applications http://sites.google.com/site/yacoset/ - I may not agree with everything the author says and frankly he probably doesn't care. But there is plenty of good information on his site none the less. http://solitarygeek.com/ - If you like my site then you will probably love this one. [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Flink-dump-1013"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Flink-dump-1013&amp;source=TurnleafDesign&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.codeigniter.com " target="_blank">http://www.codeigniter.com </a>– An excellent and lightweight framework for developing PHP applications<a href="http://sites.google.com/site/yacoset/" target="_blank"></a></p>
<p><a href="http://sites.google.com/site/yacoset/" target="_blank">http://sites.google.com/site/yacoset/</a> - I may not agree with <a href="http://www.turnleafdesign.com/?p=144" target="_blank">everything the author says</a> and frankly he probably <a href="http://sites.google.com/site/yacoset/Home/how-to-read-this-site" target="_blank">doesn't care</a>. But there is plenty of good information on his site none the less.</p>
<p><a href="http://solitarygeek.com/" target="_blank">http://solitarygeek.com/</a> - If you like my site then you will probably love this one. Similar in writing style and purpose, just a more mature blog written by a more experienced developer.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Java' rel='tag' target='_blank'>Java</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/link-dump-1013/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Null Pointers; tips for day to day development 10/9</title>
		<link>http://www.turnleafdesign.com/null-pointers-tips-for-day-to-day-development-109</link>
		<comments>http://www.turnleafdesign.com/null-pointers-tips-for-day-to-day-development-109#comments</comments>
		<pubDate>Sat, 10 Oct 2009 04:04:43 +0000</pubDate>
		<dc:creator>Billy Korando</dc:creator>
				<category><![CDATA[Null Pointers]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.turnleafdesign.com/?p=200</guid>
		<description><![CDATA[Similar to link dumps, as I come across tips and ideas, that alone may not justify a blog post, but I think may be useful, I will bundle them into these posts. Some of these tips may be obvious, others esoteric, and some representing my personal preference, but I think there should be something in [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fnull-pointers-tips-for-day-to-day-development-109"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.turnleafdesign.com%2Fnull-pointers-tips-for-day-to-day-development-109&amp;source=TurnleafDesign&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Similar to <a href="http://www.turnleafdesign.com/?cat=6" target="_blank">link dumps</a>, as I come across tips and ideas, that alone may not justify a blog post, but I think may be useful, I will bundle them into these posts. Some of these tips may be obvious, others esoteric, and some representing my personal preference, but I think there should be something in here for everybody. Let me know if you have any others you want me to add.<span id="more-200"></span></p>
<p><strong>Use interfaces instead of implementations –</strong> This increases code portability and modifiability by not tying a method to a specific implementation of a type.</p>
<p><strong>Delete unused code –</strong> Unless you know the code will be used in the future remove it from your code base. Code that isn't there can't be broken and does not need to be debugged. If you do need the code, you can always retrieve it from your source repository.</p>
<p><strong>Don't use maps in place of beans –</strong> If you are using a map to hold different types of objects, then you should create a bean to hold that information. Beans have a contract, so you and every other developer can easily figure out what data that bean contains.</p>
<p><strong>Only have one return statement in a method –</strong> Control from a method should only leave in one area. By having multiple return statements it becomes more difficult to understand the flow of a program. Having multiple returns may also be suggest of a method that should be further broken down.<br />
<script type="text/javascript"><!--
google_ad_client = "pub-3063474103916505";
/* 468x60, created 9/14/09 */
google_ad_slot = "1115297999";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/Best+practices' rel='tag' target='_blank'>Best practices</a>, <a class='technorati-link' href='http://technorati.com/tag/Programming' rel='tag' target='_blank'>Programming</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.turnleafdesign.com/null-pointers-tips-for-day-to-day-development-109/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

