Aug 21

Recently I learned of an issue with an application where presentation of a resultset in the UI led end users to assume the order of the resultset was a feature of the application. This is a pretty common scenario that I have seen with many applications both on the web and off. Usually it is the result of not using an ORDER BY clause in the SQL query or not having any logical column to sort by in the resultset. The problem is amplified in the case where the end user is the one who created the data in the first place and believes that the order they created the data (via the GUI normally) is perserved by the application. In time, the resultset from the scenario described above may be returned in a different order. Consult your RDMS guru for all the scenarios where this might happen. I have seen it occur during import/exports of data, database replication, and during updates to tables where all rows are affected.

Regardless of the cause, the net result is guaranteed to be user complaints about an issue with functionality (ordering of the resultset in the UI) which was never intended to be a function of the application. This is what I term accidental perceived functionality (no doubt, somebody has a better name). Please post other examples of this (so we can all learn) in the comments.

Tips to avoid this situation:

  1. Hire a good business analyst to capture all requirements (including eliminating possible points of confusion). This won’t necessary avoid the problem, but will increase the odds.
  2. Make it a habit to always include an ORDER BY clause in all SELECT statements.
  3. During table definitions always provide a column that allows ordering of results in accordance with the desired functionality (capture by requirements)
  4. Thoroughly unit test the results sets (including order) of your DAOs.

Tagged with:
Jul 28

Today I am continuing a series of posts in which I will be reviewing some of the books which are related to the development of quality software. They may be specific to a certain technology or a software development methodology.



The Pragmatic Programmer: From Journeyman to Master by Andrew Hunt and David Thomas is aimed at developers who want to write software systems that are easy to design, build, test and extend. Andy and Dave have revealed some of the basic practices that they follow during the full software lifecycle as well as project management and career development. I am an enthusiastic fan of their work and believe this book should be read by every developer early on in their career.

This book is also one of the easiest books I have ever read. The chapters are concise nuggets of information and I found myself flying through them and then stopping to reflect on what I had just read. Even though the chapters are grouped, each chapter is mostly independent of the others and it makes it easy to stop/start without having to recall the details of the previous chapters. So, the book is one that you can pickup months or years later and go right to a chapter that you want to reread without needing to read the whole book again. In that sense, it is almost a reference book.

Good-Enough Software

Of the many gems in the book, one of them is “Good-Enough Software”, which is about creating software that users qualify as being good enough. This approach can be capture by empowering users to be a part of the process and to shift quality into requirements specs. In the Agile world this is related to producing the simple design over the complex one with the caveat that the design must work.

DRY Principle

Another great idea is the DRY (Don’t Repeat Yourself) principle. The idea is to eliminate any duplication of functionality and define a single authoritative location for it. This creates consistency, simplicity and reduces many maintenance headaches. Not only is this important in a single software system, but with the invention of Service Oriented Archictectures (SOA), you can apply it across systems.

Broken Windows Theory

One further nugget is the idea that leaving “broken windows” (bad code) unrepaired in a system will eventually compound and pretty soon you will have a whole system (building) full of broken windows and a team that doesn’t mind throwing stones occasionally. The idea is to take the time to repair your code as soon as you see an issue so that the software doesn’t deteriorate.

Consider this to be a must have for your collection and get a copy of The Pragmatic Programmer: From Journeyman to Master today.

Tagged with:
Jul 28

I am currently looking for help on a great project. Before replying, please affirm the following:

  • Are you interested in working with some of the best Agile developers in the DC area?
  • Do you want to learn from top Software Craftsmen as they concentrate on code quality and delivery of working software?
  • Do you possess J2E skills?
  • Do you like to share knowledge?
  • Are you comfortable putting the success of the team ahead of yourself?
  • Do you like daily interaction with the end users of the software you are developing?

If so, please contact me via my contact page ASAP.

Tagged with:
Jul 15

I thought it might be useful to list some of the thought leaders in technology (particularly software development) and software craftsmanship who I follow on twitter from http://twitter.com/dcpatton.

  • pragdave Dave Thomas of The Pragmatic Programmer
  • bryanl Brian Liles discusses Ruby, Macs and web technology
  • unclebobmartin Robert Martin discusses programming approaches and techniques
  • WardCunningham discusses Agile, Patterns, etc.
  • packetlife  Jeremy Stretch talks networking
  • martinfowler discusses software developement methodologies
  • KentBeck discusses programming and methodologies
  • aglover Andrew Glover discusses development and testing
  • RonJeffries discusses Extreme Programming

A longer list is available at http://twitter.com/dcpatton/techies.

Are there others in the software craftsmanship area you follow?

Tagged with:
Jul 12

Today I am continuing a series of posts in which I will be reviewing some of the books which are related to the development of quality software. They may be specific to a certain technology or a software development methodology.



I’ve chosen to continue this series with Database in Depth: Relational Theory for Practitioners (amazon affiliate link) by C. J. Date. The target audience of this book is experienced database practitioners, not novices. If you’ve been involved with writing lots of SQL and DDL, then I believe the book is aimed at you. It explains the basic principles of relational theory in depth. The book is completely independent of any particular products and the SQL standard. One of the fascinating aspects of the book is the revelation of how few (if any) commercial database products truly implement the relational theory.

The author C. J. Date, worked closely with the E.F. Codd (inventor of the relational model), strongly influenced the development of database technology, and is considered to be a master in the field. For such an theoretical book, I found his writing style to be very lucid.

Theory discussed includes relations, types, tuples, relational variables, relational algebra and database design theory. One of the most applicable sections is the discussion of normalization. Another principle that I have taken to heart is the prohibitions of nulls. What is a method of implementing this principle? Well here is one. First suppose you have the following situation:

User
id username hair
1 user1 black
2 user2 NULL

To avoid the NULL in the table, you can design the schema to be like the following:

Table 1:

User
id username
1 user1
2 user2

Table 2:

User Hair Color
user_id hair
1 black

By breaking up the original table into two tables we have avoided the use of NULLS. Complimenting this approach to database design is the use of OUTER JOINs in SQL.

If you want to become a better developer, I recommend reading Database in Depth: Relational Theory for Practitioners (amazon affiliate link).

Tagged with:
Jul 08

Today I was looking through my RSS reader of choice, Google Reader, and looking at the software development articles that I have starred. It occurred to me that you might benefit from knowing whose feed I am following. Here are my top five:

  1. Uncle Bob’s Blatherings

    This is a category on the Object Mentor Blog dedicated to Robert Martin’s writing. It is one of my favorite for both practical coding advice as well as thoughts on methodologies and mentoring programmers.

  2. PragDave

    Dave Thomas’s Pragmatic Programmer Blog is full of small tidbits of useful insight on coding and also some pointers to the books his company puts out.

  3. Martin Fowler’s Bliki

    As Martin describes it, this is A cross between a blog and wiki of his partly-formed ideas on software development. This is chock full of industry news and his thoughts on different methodologies

  4. Google Code Blog

    If you do any kind of web development, this Google blog is full of information on free APIs and techniques which will improve your skillset.

  5. Joel On Software

    This is Joel Spolsky’s site where he promotes his consultancy and views on running a software consultancy. I threw this one out there as a site to consider reading even if you don’t necessarily agree with his approach. Sometimes being able to rationally debate an idea about software craftsmanship is extremely valuable.

Whose feed are you reading?

Tagged with:
Jul 06

Since I have been posting some of my favorite refactorings (5 Great Code Refactorings) and re-reading Refactoring by Martin Fowler lately, I thought I would discuss five refactorings that I wish I used more.

  1. Move Method
  2. While I use this refactoring on a regular basis, I’d like to use it more in a specific case. Specifically I want to move more behavior into my data classes so that they don’t just contain simple get and set methods and private fields. It may even be possible to make the get and set methods private at some point. By using this refactoring in the specific case of data classes, I believe that my classes will have improved cohesion in the OOD sense.

  3. Replace Magic Number with Symbolic Constant
  4. I also use this on a regular basis when I am coding. For example, I might use the literal 1024 several times within a class. I usually will replace it with a constant that explains what it is so I only need to change it in one place. This is fine. However, I resolve to replace some magic numbers with a constant even if they are only used a single time. The reason for this is that by naming the constant appropriately, I can achieve improved readability for my code.

  5. Encapsulate Collection
  6. This is a refactoring that I have never used and resolve to try this year. The idea is to refactor a class containing a method that returns a modifiable collection into a class with a method that returns a read-only collection and has add and remove methods for the collection. In Java, this is done by using the Collections interface methods unmodifiableList(), unmodifiableSet(), etc. This produces proper encapsulation and leaves the responsibility for manipulating the values of the collection up to the class which owns the collection. Thus the coupling is now similar to that of a data class with get and set on non-collection objects.

  7. Introduce Null Object
  8. This is one of my favorite refactorings. I saw it presented at a user’s group meeting many years ago in a discussion of the null object pattern. The basic idea is to replace repeated checks for a null value with a null object. Normally you test if an object is not null and then call a method on the object. Instead of doing that you can create a null object and then call the method and get the appropriate behavior. The refactoring involves creating a null object (a subclass of the same type as the non-null object) which contains the methods needed to produce the same behavior in your code as would be done when the test of the null value for the object is true. I infrequently use this refactoring and resolve to use it much more this year. One of the biggest motivations is when looping through objects for display purposes. I can eliminate all those tests for null values that just lead to displaying blanks.

  9. Replace Nested Conditional with Guard Clauses
  10. I’ll give a very simple example of this here:
    if (i==1) { result=odd1; } else if (i==2) { result=odd2; } else if (i==3) { result=odd3; } else { result=normal; } return result can be refactored to if (i==1) return odd1; if (i==2) return odd2; if (i==3) return odd3; return normal;
    The above method reflects the unusual case where i equals 1,2, or 3. It “guards” against them. This refactoring provides more clarity within the code and I resolve to use it more.

If you have any questions about how to perform the above refactorings, I encourage you to leave them in your comments here and also I highly recommend picking up a copy of Refactoring.

I believe that each of these refactorings will contribute to better code quality based on Why Refactor. What are your favorite refactorings?

Tagged with:
Jun 26

I have been trying to determine strategies for implementing sessions via Ruby on Rails. I am particularly concerned about scalability and session replication across multiple servers in large scale sites. What is the proper choice? Here are some options for session management with Rails:

  1. No session
  2. PStore
  3. ActiveRecordStore
  4. MemCacheStore

Using PStore writes to a local file system, which doesn’t scale across multiple servers unless it is a shared directory visible to them all. This isn’t very practical across multiple data-centers. ActiveRecordStore uses a DB which means each access of the session objects may use DB resources. Again this isn’t scalable.

Thus, MemCacheStore looks like the way to go for most web applications. There is a great discussion of it by Stefan Kaes.

Anybody else using another solution?

Tagged with:
Jun 14

I’ve added some convenient links to some of my favorite software development and business books in my aStore (amazon affiliate link). I’ve found these books to be extremely useful in my endeavors and I hope that you also get value from them. Let me know if you like any of them or have other suggestions. If you decide to purchase anything via the links, it is much appreciated. Thank you.

Tagged with:
Jun 11

Today I am continuing a series of posts in which I will be reviewing some of the books which are related to the development of quality software. They may be specific to a certain technology or a software development methodology.



Software Craftsmanship: The New Imperative (amazon affiliate link) by Pete McBreen is the best book I have ever read about software development. It is written for programmers who want to produce the highest quality code and project managers who want to work with and nurture those type of programmers. Pete emphasizes that software is best developed by small teams and developers can reach the top of their craft via the mentoring that occurs among the apprentices, journeymen, and experienced craftsmen in these teams. I am a enthusiastic supporter of the approach explained by Pete and believe all software developers and project managers should read this book repeatedly.

Some of the topics covered include:

  • Understanding customer requirements
  • Identifying when a project may go off track
  • Selecting software craftsmen for a particular project
  • Designing goals for application development
  • Managing software craftsmen

The most important aspect of the book is the questioning of the popular Software Engineering approach to development and how Software Craftsmanship differs. It all boils down to valuing the people over process.

This book appeals to me so strongly because it reflects the reality of my own experience. The highest quality software (maintainable, bug free, simple design, and providing the most value to the user) I have seen developed has always been done by small teams with strong craftsmen leadership. I think Pete also does a good job of emphasizing how important it is to create the proper environment for fostering the craft of software development.

Do you have a copy of Software Craftsmanship: The New Imperative (amazon affiliate link)? If so, what is your favorite piece of sage advice from it?

Tagged with:
preload preload preload