Wednesday, April 2, 2008

How Much Do We Need to Repeat Code

With the new paradigms in Software , I find that the same validations need to be repeated over many of the tiers of the application software. The same validation is repeated in Javascript , Middle Tier and the database layer. This means more maintenance, keeping the n parts in sync and more hardware horsepower to maintain and run the application. Sigh!


Ashish Basran said...

I strongly agree.
What would be your suggestion to reduce the repeation?

Raju Lalvani said...

One way to go backwards and have a monolithic architecture, which is now not possible. Instead of manual code writing if there are code generators
that will generate the code for the various layers, this will reduce the problem

Suyash said...

Pragmatic Programmer book talks about DRY principle - Don't Repeat Yourself. Tou can read Conversation with Andy Hunt and Dave Thomas(authors of Pragmatic Programmer) in which they talk about DRY & code genartion

Sujit K Singh said...

Though repeating the code cannot be reduced 100%, there are ways of implementing validation which will be helpful to maintain.
There are various kind of validation which we need to implement in a software system.

Business entity validation - whether entities are valid to be stored or to be used in any transaction/calculation

Request validation - request which is not altered between the different tier/system.

And business processing rules which could be dynamic and highly dependent on the context of runtime data. In this case user should get the response of any validation failure quickly to correct it.

In my opinion if we implement validation logic along with our entity they will be carried across the different tier and any change would be done at just one place at the entity level.

For implementing request validation, this is specific on the software architecture and could be implemented on the communication layer which could be used for request and response of tiers/systems.

Even after implementing such kind of validation there could be need of implementing the validation at presentation tier to quickly give feedback to the user, To ensure that these validation are always in sync, automated test routine could be developed and executed along with builds to ensure the code integrity.

Regards, Sujit