Dec 06

Tim Drury of Bright Green Projects recently penned a post about A Very Long (Agile) Engagement. In it he makes some excellent points about why it is in a consultant’s interest to secure very long client engagements, thus breaking the sell-deliver-signoff cycle of short consulting engagements. I encourage you to read it. One point that I found intriguing is the idea of the Agile Agents. These are client employees who are searching for new requirements based on the agile model of the business process. Then they rely on the consultants to quickly implement the new requirements which opens up the opportunity for the Agile Agents to discover more improvements to the business.

It is an interesting idea; although, I am not sure Tim has convinced us of the need for the consultants to action the backlog. Based on my own agile project experience, I believe it is based on their ability to deliver code in an agile environment. Thus, making it a win-win situation for both the client and the consultant. Perhaps Tim will have a follow-up post to detail that part.

In turning the multi-client sell-deliver-signoff cycle into a single client sell-deliver cycle, one aspect of Agile which can help turn those employees into Agile Agents is that by being on the same team and interacting daily with the consulting developers, the employees may discover new business requirements faster. For example, new ideas for features or new products can be put forward during the sprints that may never be discovered otherwise. These ideas that occur “in the moment” are often forgotten otherwise and never make it out of the team in a legacy methodology.

Have you seen any businesses who have changed employee roles to take advantage of the Agile Development Methodology? If so, I’d love to hear about it.

Tagged with:
Oct 14

It can be common for developers to be involved in the creation and design of databases for an application they are developing. Since most developers aren’t trained as Database Administrators, it is important that they develop some sound approaches to writing SQL and Data Definition Language (DDL). I’ve previously reviewed Database in Depth: Relational Theory for Practitioners by C. J. Date in the post, Book Review: Database in Depth. I highly recommend getting it as a guide to best practices for any relational database work.

Singular or Plural

One of the choices that invariably occurs is what to use for table names. Sometimes the particular RDMS may restrict the choices, but often this is pretty wide open. What I’m interested in is the small decision of whether to use the singular or plural form of a noun for the name. A common example is the table where user data is held. Should the table be named user or users?

My Choice

I am not sure there is a standard answer. This has been discussed before (for example, see Database table naming conventions), but I haven’t seen anyone justify why it is better to make the choice for theoretical reasons. Some frameworks or DDL tools will make the choice for you as I discuss below for Ruby on Rails. My own choice has been to use the singular name. I think this leads to improved code quality because:

  1. It leads to consistency in Foreign key names (order.user_ID references user.ID).
  2. It makes ORM a 1:1 match (the user object reflects a row in the user table).
  3. It avoids some of the annoyance of the English language pluralization rules (see Rails below).
  4. Then there are small things like ordering of tables. For example, user, users, userOrder, and user_line_order may not sort in the most effective way.
  5. I believe it is the simplest design that works. Using the plural form makes me think there is a singular table from which the plural form is distinguished. Would that be a table which is guaranteed to only have a single row?

Rails makes a default choice?

So what happens when you use the command script/generator scaffold user in a Rails project. Rails generates a DB migration for creating a users table. There are ways to control the model names and DB migration, but it is interesting that the developers of Rails decided to make the default choice of using plural table names. (See Agile Web Development with Rails for example syntax on how to not use defaults).

But what about that tricky English language? Well, script/generate scaffold person produces people. Pretty cool. And woman produces women. But then goose becomes gooses. Woops! Now you may have no need for a goose object in your application, but I am sure there are other examples like this. Alas, this appears to be a bug in the Rails framework, but just think how easy it is for you to bump into this yourself when trying to remember the plural form of the object you are working with. In addition, these names show up in the URL for Rails routing. Thus they can become public. I’d rather see geese in applications I work on.

I realize there are pros and cons to the choice of using singular or plural names. In terms of producing quality code, what do you use and why?

Tagged with:
Sep 23

On October 12, 2010 the FedTalks conference is taking place at the Sidney Harman Hall in Washington, DC. I’ve been invited to attend and am excited to be a participant. If you’ve never attended, this conference features keynotes by Federal government technology executives as well as executives in commercial and non-profit entities. Noted speakers include David Dejewski, Arianna Huffington, Chris Kemp and others. The conference theme is about improving government with technology. Please check out http://www.fedtalks.com/ for complete information.

It looks like @fedtalks has already established #fedtalks as the Twitter hashtag for the event. Look for my tweets on that day as well. If you plan to attend, let me know if you want to meetup to discuss technology and DC.

FedTalks

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 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 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:
Jun 08

Refactoring is the process of changing software such that it does not alter the functional behavior of the code while improving the internal structure. The first key point is that code which is already written is being improved. The second key point is that the behavior of the software is not being altered. This is not a process for fixing bugs. I’ve previously discussed motivations for refactoring in Why Refactor.

Below are 5 refactorings that I frequently use in practice:

  1. Extract Method

    One of the most common refactorings I use. It involves taking a section of code and putting it into a method whose name explains the purpose of the method. This has two advantages for me. First, it breaks up longer methods into shorter, clearer methods to read. Second, it is useful for applying the DRY principle when you have the same code repeatedly in a class or multiple classes. You may need to determine how to make code sections look exactly alike so that this can be done. For example, passing in nulls to the method in certain classes, but not in others. I believe this is an example of Parameterize Method

  2. Rename Method

    This is the process of changing a method name such that the name is more informative by clearly showing the purpose of the method. I often perform this refactoring when introducing another new method to the same class which is similarly named.

  3. Move Method

    Another common refactoring for me. I use this when I want better cohesion in my classes. This leads to simpler designs and better understanding of the responsibilities.

  4. Introduce Parameter Object

    I introduce a new data object (with getters and setters) when I have a group of parameters that are related and frequently accessed together. This then may lead to use of Move Method if there is also associated behavior with these parameters.

  5. Introduce Explaining Variable

    This is one that I wish I used more often. I think the best examples I have seen are to introduce a boolean for a complex expression in an if statement. By using a name that adds clarity, reading the if statement can be improved substantially. For super complex conditional logic expressions you can reuse this repeatedly to simplify the code. It can really make code maintenance much simpler in the future.

Agile methodologies make refactoring an enjoyable process. With the principles of test-first design and simple design, refactoring becomes a complementary exercise. It makes it easier to keep the design simple and the unit tests provide the confidence needed to make frequent changes to the code during refactoring sessions. Perform your favorite refactoring and run the tests to be sure no functional behavior was broken.

What are your favorite refactorings? For more insight into refactoring, I highly recommend Refactoring: Improving the Design of Existing Code (Amazon Affiliate link) by Martin Fowler.

Tagged with:
Jun 07

Was discussing this today. Refactoring is the process of modifying code without changing the external functionality of the code. Check out Refactoring: Improving the Design of Existing Code (The Addison-Wesley Object Technology Series) (Amazon Affiliate link) by Martin Fowler for more detail. Off the top of my head I came up with the following examples of why:

  1. Increasing readability (changing variable names, method names, etc.)
  2. Increasing performance (faster sorting, introducing caching, clustering techniques, etc.)
  3. Decoupling classes
  4. Increasing class coherence
  5. Fixing broken windows (unused objects, unreachable code fragments, etc.)
  6. Simplifying (Introducing Enumerations, constants, putting common functionality into a single method)
  7. Reorganizing packaging of classes
  8. Further abstraction and extensibility

For the principles exemplifying 3, 4, 7 & 8 see Uncle Bob’s Principles of OOD. All of the above (except # 2) can be thought of as reducing complexity. And it is a lot easier to be successful at #2 if you can reduce complexity.

Tagged with:
preload preload preload