Saturday, July 27, 2013

Case # 123403984-1: JavaScript v. JSP

Opening: I've been a back-end developer (database, messaging, services, etc) all of my IT career and only done front-end (web page, scripts, graphics, etc) stuff on my own time. This week, I've exposed myself to more practical HTML, JavaScript and REST services with JSON delivery. I had previously been coding the viewing of the data in JSPs with an MVC format when needed. I've realized that the JSP / MVC model has it's uses, but the flexibility of JavaScript is what drew me in. I really liked how I could separate the presentation layer (what you see on the screen) from the data collection / back-end layer and make reusable services where you could effectively write new pages without disturbing the existing ones or the REST services behind them.

For JSP: I think the largest win here is when your page has a lot of manipulation to do and you want to run that on the server side instead of the client side. I'm sure your server cluster is more powerful and can deliver that page better than a client side rendering. The other argument I think is necessary here is hiding how the page was really built. When I write the JSP, it looks nothing like what is delivered to the consumer as all of the Java is replaced with HTML. I think that is a big positive for JSPs.

Against JSP: With JSPs, I've found that I've been a bit hard pressed to test my pages. To truly find out if my page is working, I have to start up my web app server and try to break it. When using MVC or just a servlet to deliver the page, I've found that I'm locking in the page to be delivered with the service that I just coded.
For JavaScript: In general, you can just do more with the manipulation of the page. This week, I've been able to prevent the default actions on buttons, make AJAX get and post calls, create new HTML and more. Further, with jQuery you can do a lot of JavaScript actions more simplistically. Since it's HTML and script code that is decoupled from the web app server, I can write the code in gedit/Notepad and test in the browser while my web app server is always up.

Against JavaScript: For me, the notation is a bit clunky to get started with. The use of functions compared to Java methods doesn't really match up where it's still called 'Java'. The other draw back is that you have to get used to how a browser processes a page to manipulate it. This is very different for a back-end developer.

Summation: JavaScript is another tool in my box now and I think I might have to use it more than I used JSPs. I do like how I can build those REST services and use them at will. I like how I can develop a new page to replace the old one without disturbing the existing one or writing a new service. Testing is a big win since I don't have to recycle the web app server when I make changes.

No comments:

Post a Comment