Fast Forward To MVC ‘ONE’

Recently, I worked on adding a feature to legacy webapp of my client, based upon MVC one model. And  it’s simplicity and getting work done, made me think again, about MVC one based webapps. I am always on hunt for simple web framework, which i can embark on for proof of concept of my startup ideas.

This is year 2010 and we as java developers, have spent countless time in arguing and reading (fun though) about various java web frameworks in play. Many bloggers publish their findings, opinions and countless others copied their content, republished them anyway. One common subject has been, which web framework? Cult is increasing everyday, for Spring MVC, Wicket, now JBoss Seam. I had personally spent time thinking about choosing one framework of choice, for my own projects, but I could never conclude on one. Spring MVC has become strong contender and safe choice, because I will be using spring for services and data access layer. Have we ever took step back and thought, we have surrounded ourselves plethora of frameworks for unlimited reasons, but never thought of ROI and time to market any product. Java always been treated as enterprise solution for big companies with big projects with big budgets. What about simple B2C startup projects which has limited user base and no funds. In today’s real web applications, PHP is thriving as before. People are still coding & adding more to PHP based projects. And those projects have been more successful and widely accepted. Example would be ‘WordPress’ , ‘Drupal’, ‘OSCommerce’. (Even springframework.org used drupal. Not sure whether they still using it). So what is main charishma or any characteristics of PHP? We all have argued, bloggoed about How PHP is inferior compare to Java, but PHP is productive.

Having said that, lets come to drawing board, as new developer or even CIO of a company. What we need in a web application (lets assume startup webapp, upto 100 concurrent users in one cluster)

  1. Pretty interface, which users to love to use it. (Example mint.com)
  2. Interactive & Intuitive interface.
  3. Functional interface. It does what it promises and always does that.
  4. Low or almost NIL learning curve for any new developer.
  5. Able to extend interface + functionality by 3rd party developers. (That strives any web product)
  6. Quick turn around of code to market
  7. Able to remove or disable code or by choice of end user. (user is deployer)

Having listed all the requirements, how many requirements really demand for use of MVC II framework?

First two are more of DHTML only.

Number 3 is quality of code and how well tested code is.

Number 4 is not good for MVC II frameworks like spring or wicket or even struts. They have some learning curve and you need resources, comfortable on that.

Number 5, people can argue, here MVC II excels. But at what cost? Lets analyze that more (I will use example of Spring MVC, because of popularity. Nothing against it)

First drawback is, to write any java code, you need to be java developer. It eliminates pool of casual web programmers who just like to write scripting (like PHP) and DHTML. Second is, if you write anything in JAVA, webapp has to be repackaged (and ofcourse released again). So there is no on-fly programming or releasing code on running webapp. (Lets forget about OSGi for now. It’s different ball game).

What about writing code using JSPs only?

That’s this post is all about. I know, many of you, thinking, c’mon man, Nineties called, they want their MVC one back. But lets entertain this idea for a while. For example, I want to write simple webapp ‘java press’ blogging engine, able to deploy it with in couple of weeks and my available heap size is 64MB (pretty common for VPS plans). If I go by spring mvc route, it will take me a couple of weeks, just enough to setup my environment, DBs, etc etc. I will have re-hash my knowledge of spring, and spring mvc controllers etc etc. But if I just pick JSPs model, i am ready to convert static HTMLs with-in a day.

Using JSPs and JSTL tags, I get lots of java functionality baked in. I can divide my jsps using includes (keeping option of apache tiles open). I can keep two sets of JSPs, presentation jsp and worker jsps. I can use extensively extra request parameters, to drive backend jsp, where to forward or redirect my request after finishing work.

If we still on this concept, few custom tags can be written and being delivered as part of SDK. So anyone who wants to customize it or extend it, he has JSPs, JSTL and some custom util tags at his disposal.

Advantages or trying to look at positive aspects.

  1. For deployments for small companies or concept deliveries or Y combinator kinda projects, time to deliver is small.
  2. You don’t have to muck around which framework to use. You think of doing something, and you doing it.
  3. Think of 3rd party developers pool, you get access to. If you document well, even PHP developer can pick JSP skills in few days and write JSPs for your webapp. (Imagine hiring PHP developer for spring MVC work. I don’t have time & budget for training).
  4. With new JEE specs coming out, you are always safe to upgrade your app and take advantages of new features without rewriting anything. (That’s what spring says, we give you another layer of abstraction. But you have upgrade code for spring 3.x now, isn’t it?)
  5. For scalability, it’s cheaper than before, clustering solutions based upon clouds. So my one deployment supports 50 concurrent sessions, I will just throw couple extra virtual tomcat instances, with in same cloud instance. or couple other different ways.
  6. I am less worried about performance, because recent benchmarks for tomcat 6 using JDK 6, is impressive.
  7. Using data source pooling, getting connections from JSP isn’t resource intensive. (As part of SDK, some classes with static methods can provided, to provide some encapsulation on common used API calls)
  8. web.xml supports basic security model. And again, as part of SDK, some common servlet filters can be provided for cross cutting concerns like security, logging, transactions.
  9. DB Caching can be ignored for now, assuming DB server and tomcat instance are co-located or installed in same instance. Caching adds lots of code maintenance, research & testing. Benefits of using caching diminishes in small db and small users.
  10. Well known advantage of JSP, do code change and see changes immediately on web browser. Hence time to see results, while doing development is almost nil. We all have taken coffee breaks in our past projects while waiting for server to bounce.

This post is not comparison between MVC I and MVC II model. It’s more of another look at MVC I model and putting on my thoughts, why It could make sense to use it.

1 thought on “Fast Forward To MVC ‘ONE’

Comments are closed.