José Mota — Web engineer & architect

Categorized under Development

Sacrilege: a rather lousy rant on Java for the web

Let me start out saying I’m glad I never had to make web apps in Java. Boostrapping the crap out of a Maven + Struts archetype is insane. I honestly don’t know what to feel for Java programmers.

It’s been an hour and a half since I’ve started reading the Apache Struts 2 Web Application Development book and I’m going nuts. I’ve dealt with more XML in this hour and a half than most of the time in my degree.

Story told short:

  1. I’ve installed Netbeans and an Apache Tomcat 7 server.
  2. I’ve created a new Maven Web application.
  3. I’ve copied a struts routing example, along with the respective action POJO.
  4. Tried to reach the URL; no luck.
  5. Looked up for a web.xml example, in order to correctly load Struts.
  6. Project won’t deploy. FML.

At an hour and a half, reading and typing, I could have done so much more in Rails or Sinatra. Sorry.

I don’t care what people think about me comparing Java to Ruby at such an early stage in trying to learn. But hey, it’s 2012, software ought to be easier to accomplish. Why does it have to be so difficult to understand how a simple controller is executed? Why is the Java way so convoluted?

I’ll update this post when I can create a Struts action properly, perhaps with an interceptor. If I can make it to apply some TDD along the way, I pat myself in the back. Until then, I stay with the attitude.

February 10th, 2012 — 1 comment so far

Same class associations in Rails 3

[TL;DR] Even though the selected events conceptually belong to a record, the latter has the foreign keys to former. So technically, has_one is to be changed to belongs_to.


This is the first time I’ve ran into something like this and it was interesting to realize what it actually means when developing a business logic in Rails.

Context

In this app I’m building, I have Students that have a Record per year. Each record has several Events. These records also have two specific events: a test and an audition, registered in the schema as id‘s in the record’s table.

So what did technically happen?

I wasn’t able to access those specific events through the associations specified in the model. Given r = Record.first, when I tried to access the audition, by using r.test, Rails would use a SQL query that would correspond to r.events.first instead.

After acknowledging that, I turned to @varandas and we both thought it might be a bug in the Rails framework. Turns out it wasn’t; all I had to do was switch from has_one to belongs_to (thanks @drogus!). The reason for that is the foreign key is on the records table. From the framework’s perspective, it looks like the record actually belongs to the event, when in practice it’s not.

Code sample

December 9th, 2011 — Leave a comment!

Piscean programming

For those who don’t care about astrology, try to follow along; the principle is pretty practical.

TL;DR – Being bossed around compromises inovation, creativity and it destroys one’s true sense of purpose. Don’t let that destroy you.

Read the rest of this entry »

November 12th, 2011 — Leave a comment!

Does Datatables need better integration?

Over these last two months, I’ve been working with Datatables, an amazing easy-to-setup steroid machine for HTML tables. For the kind of work I’m doing right now, it suits my needs just perfectly.

A couple of weeks ago I needed to build a plugin for DT: MultipleFilters, something that would allow me to filter data by a range. Each column would have a pair of fields and I would have to mix them into the bowl of parameters to send to the server . It looked fun, so I started doing it, hoping to achieve a beautiful Javascript prototype object that would do magic when plugged in by a single letter. As I was finishing building it, I realized some issues had to be fixed.

Read the rest of this entry »

September 1st, 2011 — Leave a comment!