Saturday, August 05, 2006

Practices are only "best" based on context

If you use (and believe in) the phrase "best practice", it is likely that you haven't spent enough time understanding what you're actually doing and what is actually happening.

Harsher version:

Anyone who uses the phrase "best practice" hasn't spent enough time understanding what is actually happening.

4 comments:

Anonymous said...

Can you give me an example of a practice that is "best" for a certain context?

Aslak

Dave Nicolette said...

Well, here's an example of a case when we started to use dependency injection to facilitate unit testing, and eventually team members started to think we were using it just because delegation is a widely-recognized best practice for object-oriented development. But the truth is we weren't trying to apply the strategy pattern as such, based on some requirement about the way the solution had to behave, we were just making it easier to use mocks and stubs to isolate unit tests. In context, we were using dependency injection to make our code easier to test, but some developers believed dependency injection should always be used no matter what, just because it's a "best practice."

The relevance to Jason's point is, I think, that we should always stop and consider why we are using any given development practice, and not just blithely code away according to some static definition of "best practices." If some of the developers from this team went on to other projects and built their code this way by rote, when there was no real need for it, they would only be making their solution more complex than necessary.

taowen said...

and we are starting to use "Better Practice"...

Jason Yip said...

Hi Aslak,

I'm going to use a non-software example.

In fencing there is a rule called "Arm First", which is about extending your sword arm first before stepping forward. For the context of a long, sharp weapon against an unarmoured opponent, it's a best practice.

Change the length of the weapon OR add armour OR use blunt or no weapons and the appropriate approach changes.

"Practices are only best based on context" is about understanding your current context in sufficient detail to decide what actually is "best". Obviously what is considered "best" may vary based on expertise.