5 Mistakes Developers Make That Causes Bugs Without Even Noticing

1 – Using business code in View layer

Well, as the name says, View layer is not used for coding business logic.

Your objective when using View layer is to implement what is necessary for user interaction. Whatever framework you are using, it’s possible to implement the MVC pattern. If you can use your View logic on your Controller layer, do it!

For example, if you are using JSP, implement the logic of your View on your Servlet.

Don’t fill up your JSP with ifs or any other code. It’s better to use Taglibs instead.

2 – Using business rules in Controller layer

The Controller layer needs to be used as a connection between the View and Model layers. If you have business code in your Controller layer, check it again, and move it to the Model layer.

The Controller layer also can be used to implement the View code.

For example, if you need to load a Combobox after an action or add some format rules in your ‘inputText’ components.

You have to think, does this rule only apply to the View layer? If your answer is yes, then you should use this logic in your Controller. It does not make sense to move code that is only related to the View layer to the Model layer. The best thing you can do is to encapsulate View logic in the Controller layer.

3 – Using a lot of different architectural patterns in your project

Define a pattern to be followed in your project.

If you are using Java EE, it’s a good idea to follow an architectural pattern so that developers will more easily understand what is happening in the code.


  • (View) XHTML
  • (Controller) Managed Bean
  • (Model) Façade – (Business) EJB

4 – Creating a lot of unnecessary layers in your project

If you perceive there is a layer just invoking another layer, something is wrong.

Most times it does not make sense.

For example, you can be using the DAO (Data Access Object) layer for nothing!

If you are invoking a lot of layers in one line, all this code is unnecessary. You can remove the DAO (Data Access Object) layer and do your query in your “Service”. But remember, use your SQL code in a separate XML file.

5 – Showing code log everywhere

Hey! It’s not necessary to show code log everywhere in your application. You can just throw your Exception to the View layer and show the error in a Dialog. Remember, use words that make sense to the user!

Use your log ONLY where you catch your Exception. You will have the stackTrace, so why show log in every throw statement?

If you really need to know everything that is happening in your project, use AOP (Aspect Oriented Programming)! Don’t repeat code for logging all your system! Imagine all the trouble you will be in if you need to change your log!

Keep up the good work!

Follow me on Twitter to learn more great programming techniques. I will be sharing it every day!

Get a free E-Book about 5 great techniques to double your programming speed and have less bugs on NoBugsProject!

Share it!

5 Mistakes Developers Make That Causes Bugs Without Even Noticing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s