Book Review – The Passionate Programmer by Chad Fowler

September 18th, 2011

I decided to buy The Passionate Programmer by Chad Fowler based on the glowing reviews on Amazon.com and from seeing it on several other people’s must read lists.
The author starts the book explaining his reasons for writing it which explains its original title(My Job Went to India (And All I Got Was This Lousy Book)) and the reasons why it was changed.

Although the book is geared towards programmers, I think many professions could benefit from the career advice it contains. Asking us to view ourselves and our skills as a business product, the author guides us through the corresponding steps to design, build, market and maintain our software careers. Much emphasis is placed on understanding the business domain and cultivating people skills, two areas often overshadowed by the quest for technical skill. Along the way, the book gently reminds us that much of the fun and challenge that attracted us to programming can be found in all our tasks, if we are willing to evaluate the way we view our work.

The author makes use of a series of analogies with his own career as a musician which in an interesting ways to explain things as like a musician, a programmer can never stop learning and practicing.

The book contains 53 short chapters about various career topics. Some of my favorites are:

From Choosing Your Market: “Coding Don’t Cut It Anymore” – the author says you should learn the business domain of your product, which is absolutely essential to not only survive in IT but to become more than just another developer. I also liked “Be a Generalist” and “Be a Specialist” in this section. Why both? Because you need to know how things work outside your (small) job label to be really effective. And, you need to know specialized content to be great at a job.

In the Marketing section, there’s a lesson called “Build Your Brand,” where the author describes how to think about your brand (your name) and which types of projects to affiliate yourself with. There is also a lesson called “Let Your Voice Be Heard”, which is a reminder to keep your blog updated as a way of marketing yourself.

Also in the Marketing section, a lesson called “Release Your Code” described a concept called “Refactotum”. I had never heard of this before, but it is a good way to get your feet wet on an open source project. It involves finding an open source project and run the unit test through a code coverage analyzer to find areas that are not covered by unit tests. Write tests for that part of the system, and look for ways to refactor that code to make it more testable.

In the Maintaining section, the lesson I liked best is “Avoid Waterfall Career Planning.” As the author says, your career is the most complex project you’ll ever have to manage. Careers are not linear. If you look at successful people, they took advantage of opportunities. (This is why I hate the interview question, “Where do you want to be in 5 years?”)

I’m of mixed minds about this book. On one hand, it’s well written, easily digested, and offers practical advice for anyone who is feeling maybe a bit stagnated in their software career. On the other hand, most of the advice given seems intuitively obvious to anyone who has worked more than a couple of years in IT. Though it does have some helpful tips, it reads too much like an autobiography, and the author’s constant analogies to his musical background are distracting and really do not contribute much to the theme of the book. If you’re someone looking to climb the corporate ladder, you’re better off getting a book on business or management. If you’re truly passionate about programming and technology, get a more technical book instead.

I believe that everyone experiences peaks and valleys of job satisfaction throughout their career. This is a good book to read during the valleys. It really does makes you rethink your career and look at things from a different perspective. I found myself energized and enjoying my job again after reading this book.

What I liked about this book:
- The chapters are short and to the point, and can be easily read in a few minutes.
- The book is well written and easy to read and understand.
- It makes you rethink your career and (hopefully) understand what you like about your job.

What I did not like about this book:
- Too many stories about his career as a musician. This added nothing to the book and violated the “No Fluff Just Stuff” principle.
- Many of the lessons in the book are common sense items that most of us have already experienced.

SQL update multiple rows using 3 tables

November 25th, 2010

Problem:
You need to update the value of a column in one table with the value
of a column in a different table, for multiple rows. The two tables
are not directly joined, but they are both joined by a third table.

In this example, we have three tables – Survey, SurveyCommon, and SurveyYearly. We need to update the column “discode” on the table SurveyCommon with the value from the table SurveyYearly. However, those two tables cannot be joined directly, but they can be joined through the use of a third table (in this case, the Survey table).

Solution:

update sc
set sc.discode = ra.discode
from SurveyCommon sc
inner join Survey s
on sc.surveyid = s.surveyid
inner join SurveyYearly ra
on s.surveyyearlyid = ra.surveyyearlyid
and sc.discode is null

This statement joins the 3 tables and sets the discode value on the SurveyCommon table to the value in the SurveyYearly table only when the discode is null.

Set Event Handlers For Row Elements With Prototype

January 10th, 2010

This article describes how to set event handlers for row elements using Prototype. This is especially handy when dynamically creating new elements on a page.

In this example, we have a data grid displayed as a table element. The id of the table is ‘myTableId’. We are going to set up two event handlers for each table row. On a single mouse click event, we’ll call a function that highlights the selected row. On a double click, we’ll call a function that opens the row data for editing. Both of these functions are omitted for brevity.

function setEventHandlers() {
    //get all row elements under element with id ‘myTableId’
    var rows = $$('#myTableId tr');
    rows.each(function(rowElement) {
        rowElement.observe('click', highlightRow);
        rowElement.observe('dblclick', editRow);
    });
}

Once again, Prototype does the dirty work of handling the differences in event handling between browsers. All we have to do is attach an event handler function to an element using the observe() method, and Prototype handles the rest.

Check out the details on the options available on the Event object in Prototype.

JBoss JNDI datasource not releasing connections with Spring/Hibernate

October 24th, 2009

I recently had a problem with my application not releasing the database connections when I switched to using JNDI. This was a JEE application that used Spring and Hibernate. Here are the versions that I was using:

  • JBoss 4.0.4
  • JDK 1.5
  • Spring 2.5.5
  • Hibernate 3.2.6

Solution

In my Spring applicationContext.xml file, I added the datasource JNDI entry for “Kramerica”. I referenced it in the Hibernate session factory bean:

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
  <property name="jndiName" value="java:comp/env/jdbc/Kramerica"/>
</bean>
 
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
  <property name="dataSource" ref="dataSource"/>
  <property name="hibernateProperties">
    <props>
	<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
	<prop key="hibernate.show_sql">false</prop>
	<prop key="hibernate.connection.release_mode">after_transaction</prop>
    </props>
  </property>
</bean>

The key entry is the property “hibernate.connection.release_mode”.
This property specifies when Hibernate should release JDBC connections.

By default, a JDBC connection is held until the session is explicitly closed or disconnected. For an application server JTA datasource, use “after_statement” to aggressively release connections after every JDBC call. For a non-JTA connection, it often makes sense to release the connection at the end of each transaction, by using “after_transaction”.

You can also set it to “auto”, which will choose “after_statement” for the JTA and CMT transaction strategies and “after_transaction” for the JDBC transaction strategy.

You can find more detail on the Hibernate connection settings at the Hibernate site. Happy coding!

JBoss error: java.rmi.server.ExportException: Port already in use: 1098

October 24th, 2009

I’ve encountered this error using JBoss within MyEclipse on several occasions. The JBoss server fails to start for no apparent reason. After reviewing the server log, the root cause is “ERROR [org.jboss.naming.NamingService] Starting failed jboss:service=Naming java.rmi.server.ExportException: Port already in use: 1098; nested exception is: java.net.BindException: Address already in use: JVM_Bind”. This is followed by an endless list of ClassNotFound exceptions, as well as other exceptions.

The problem is that some other process is running on port 1098. Fortunately, there is an easy solution. If you are using Win XP, you can run “netstat -a -n -o” from the command line to find out what process id is listening on port 1098. Use the task manager to find out what process id belongs to that application, and end that task. You should be able to start JBoss with no problems.

Common port 1098 uses are for Oracle and ICQ.

Iterate over a Map using Java 5 generics

August 2nd, 2009

One of the coolest features in Java 5 is the enhanced for loop. Instead of having to use clunky Iterators to loop through a Map, you can use the enhanced for loop just as though you were iterating over an array, a List, or other collection. Read the rest of this entry »

JavaScript validation of dynamically added form fields

July 5th, 2009

This article describes how to use JavaScript and the Prototype library to validate form fields that can be dynamically added at runtime. For example, let’s say that we have a table and the user can insert one or many new rows. Each row might contain multiple input text fields, which must be validated upon form submission.
Read the rest of this entry »

Managing legacy user login object with Spring (Part 2)

June 26th, 2009

In part 1 of this article, we discussed some alternatives to handling a user login object that is controlled by a legacy application framework outside of Spring. We also discussed some disadvantages with our approach. Read the rest of this entry »

Using Hibernate Validator for your Java classes

June 12th, 2009

This article discusses how to use the Hibernate Validator for your Java classes. Read the rest of this entry »

Managing legacy user login object with Spring (Part 1)

June 7th, 2009

Using Spring to manage your Java beans for dependency injection is fairly straightforward, but what do you do when you want Spring to manage beans that were created outside of the Spring container? I encountered this issue on a recent project. The user login credentials were handled by a legacy system and stored in the HTTP session. Read the rest of this entry »