3

I came from an interview and the CTO (Chief Technology Officer) told me that there have a system (which has been running for over 5 years) and they still prefer not to use MVC purely on performance. I know most MVC uses reflection to invoke methods (which is, in essence slow) but many MVC (I know Struts does it, I read the code) cache the methods it invokes so I doesn't have to "find" the method to invoke all the time.

For now, they stick to scriptlets (and they don't use JSPTags). I wonder, is there a huge performance going purely scriplets than MVC? They prefer stateless vs stateful sessions to avoid session migration, session tracking, etc.

If what the CTO says is true, why is MVC still preferred (I know why MVC is there, but with regards to performance).

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • 3
    Doesn't sound like a company I'd like to work for. Writing a commercial Java web app *without* usng some form of MVC based framework is stupid. Also scriptlets invite XSS and should be banned, not encouraged. – Qwerky Nov 18 '10 at 16:29
  • Pass! I may have left the interview early. – Chris Wagner Nov 18 '10 at 18:34

3 Answers3

3

Contra arguments:

  • Reflection isn't that slow anymore since a good couple of years.
  • Hardware performance has insanely been increased the last couple of years.
  • MVC leads finally to faster development. Less wasted time = more $$$ saves.

I'd pass the job.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

That's rather strange logic from the CTO; I don't think he knows what he's talking about (hint: pass the job!) If he's so worried about efficiency, why not rewrite the whole webapp in assembly language?

Arguments against scriptlets

  • I don't like scriptlets because they are notoriously difficult to maintain. They are also prone to abuse. The biggest thing is also that they mix up view-logic with business-logic, or at the very least, make it extremely easy and tempting to do the same.

  • You could judiciously separate out your concerns and use services that pull in data (and thus promote re-use). But more often than not, I've seen developers write JSPs like PHP code (i.e., code mixed in with markup).

I am not saying that you can't write good code with JSPs. It's just that it's harder (I feel MVC has more safeguards) and also (I feel) JSP's are more prone to abuse.

Arguments for MCV

  • To answer your second question, MVC is preferred because by nature, it promotes separation of concerns and doesn't allow logic from the separate areas to bleed into the other areas.

  • The view layer is solely concerned with rendering the view. You get metadata from your controller, and you display the data using the view. You are not concerned about the business logic here (and you shouldn't be).

  • The controller acts like a traffic-cop, redirecting your requests to their proper destinations. Controllers usually end up calling services that perform all the business logic.

  • The model is in charge of the data and behavior of the application domain. The model will respond to requests about its state (so this is the metadata that you're sending to the view) and will also respond to instructions that tell it to change state (from the controller).

  • Reflection really isn't that slow. Also, computers are pretty fast these days and come with a lot of memory. Performance isn't that much of a concern.

  • The MVC pattern promotes a clean separation between the different concerns that makes it easy for the developer to write clean, robust, and maintainable code.

Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
  • Considering I've stated `I know why MVC is there`, you actually went to do exactly that...but it's good to share knowledge nonetheless.... – Buhake Sindi Nov 18 '10 at 15:57
  • @The Elite Gentleman oops, sorry I got carried away :) I was trying to illustrate why MVC is better than scriptlets. I thought that's what you wanted :) – Vivin Paliath Nov 18 '10 at 15:58
  • I wanted only for performance comparison. I strongly go for MVC. I rephrased my question title to make it all clear. Don't edit your answer, it will help the guy next door ;) – Buhake Sindi Nov 18 '10 at 16:00
  • @The Elite Gentleman gotcha. I did mention that in my arguments. But I think as a whole, explaining what MVC is also helps make the performance argument stronger (it points out the shortcomings of using scriptlets). – Vivin Paliath Nov 18 '10 at 16:02
0

Advantages of MVC over scriptlets is perfectly described in other answers, but one point is missed.

Reflection introduces some an overhead compared to direct method calls. It matters when you use reflection to call simple methods frequently. But overhead introduced by a single reflective call doesn't matter compared to the overall request processing time in a typical web application. Therefore decision not to use reflection for performance reasons in this particular case sounds strange.

axtavt
  • 239,438
  • 41
  • 511
  • 482