I’ve been coding web front-ends in jsp for 6 years now, and I’ve dabbled in PHP and asp.net a bit as well. I’m writing this article both to rant and to give some insight as to any other prospective web developers. I can’t really get into asp.net because I don’t know much about it, but my reasons for disliking it are pretty much narrowed down to 2: Visual Studio (the program you have to use to code in asp.net) is a giant resource hog, and all code runs on a Windows server. Windows is not a decent server platform (this is pretty much accepted as fact today).
In the beginning, life was good
I learned how to make dynamic web applications by creating things known as “servlets”. Basically, whenever you request a page in your browser (whether that be by typing in a url, clicking a link, or submitting a form) it goes to this servlet. Without getting into great detail about the difference between what a “get” and “post” request is, basically a “post” is when you submit a form full of data to the servlet, and a “get” is when you type in a url or click a link that takes you to the servlet. More advanced people will tell me I’m technically wrong here, but for the purposes of this article, that’s really all you need to know with regards to how they’re used.
A servlet has both a “get” and “post” method to handle the request depending on whether the request was a “get” or a “post”. This is very straightforward, because everything else after that was just connecting to databases and crunching data.
After about 4 years of this, I’d gotten pretty good at it. Code made sense, the paradigm made sense, it was very easy to follow, and everything was running smoothly. And then my company decided to try and be “hip” and “with it”.
Then the frameworks came…
I’d done some research on web development frameworks in java. The one I was most pleased with was Stripes. It seemed very straightforward, and cut down on a lot of coding. It was more event-driven, so you were more explicit as to what you wanted from the server rather than lumping everything into a get or post request. Not bad, and while it had a learning curve, it at least proved to be a better development experience.
But my company didn’t want Stripes; they wanted SpringMVC. To put it bluntly, SpringMVC sucks. You don’t have to take my word for it; plenty of other people will attest to the same thing. SpringMVC is a giant, bloated, overcomplicated, and counterintuitive framework, wrought with countless xml and xsd configuration files all over the place. So much of the logic is black-boxed to the point where it’s near-impossible to follow and see what it’s doing. In many cases, it insists on doing things for you, and it doesn’t do them in the way that would probably best fit your situation.
SpringMVC is controlled by a building management software piece called maven. To use maven, you’ll need to spend shit loads of time preparing countless xml files (in addition to the ones SpringMVC already has). First, there are the build/package/test/deploy configurations, and then there are all the other xml files that detail how each and every little plugin you want is supposed to work.
Then they insisted on changing how the database connections worked. See, the normal way you get data from a database is to write an SQL statement that retrieves a table full of values based on it. You then did whatever work you needed with that table of values. Pretty standard stuff. But no, now we need to give up using SQL and instead use some sort of hybrid query language called JQL, along with more ridiculous xml configurations to connect tables to java objects (that are then connected into SpringMVC’s paradigm). This is known as JPA. This forces every record in a given table (or view) to correlate as a java object. The intention here is ok, but honestly… what’s the point? By doing this, you get little to no control over the process that’s happening, and every time you change the table’s definition (for instance, adding another column) you now need to go back and edit the JQL that connects the data to the object. You also force a certain structure into the tables that makes them less relational (it is, after all, a relational database management system [RDBMS]).
As if the coding wasn’t bad enough
When running this monstrosity, it uses far more memory and resources than necessary. The time to setup, let alone train people on it, is a huge cost to the company, and a needless one. I spend about 2-3 extra days on every project just trying to get my environment set up and working. And if I check my code into a source control repository, it may not even work on other machines, requiring me to then go back and figure out how to make it more generic.
Maven is a pain in the ass to set up, and the plugins in our IDE’s that surround maven aren’t really even exact, requiring me to leave the IDE, and open up a command line. This means everything isn’t in one place, and the process for developing, testing, and building is split up into multiple steps that can easily be forgotten/missed.
Also, as a java developer, we’re pretty much stuck using Eclipse as our IDE, and Eclipse is slow. We also use a locally-installed enterprise application server to deploy to, which is also very slow. If anyone out there has ever worked with java, you can nod your head in shared empathetic pain when I say: java is fucking slow!
I know, I know… I’ll get flame for this because there are some software geeks out there that want to say “well, in recent years, benchmarking tests proved that java is just as fast as C++, and in some cases even faster!” I’m sure certain implementations of java are faster, but my 6 years of experience with it as a web development language have proven otherwise. Nevermind the actual runtime of the code when it’s finally deployed… That part’s negligible when benchmarked against other languages. What I’m referring to in respect to it being slow is the process of developing in it.
Nearly every time I use Eclipse, it’ll freeze and hesitate for 10 seconds at times. Deploying my code to the server to test it? Sometimes it takes 1.5 minutes, other times it takes 10. Trying to stop the server, or restart it? Be prepared to wait another 10-15 minutes, assuming it responded to your mouse click at all. Sometimes I have to click something multiple times to get it to register that I have, indeed, asked it to do something.
Many times with java I’ll see no red errors in my IDE, but when I try to deploy, it suddenly cannot find imported code. Even though it’s right there, and even though it’s correct in the IDE, for some reason, when it runs, it fails and is unable to find anything. After fiddling with configuration files, and rebooting the server (and sometimes restarting the IDE), it’ll magically spring to life. I’ll leave it up overnight, and walk in the next day to find it suddenly stops working again.
“Java is a horrible language” – Linus Torvalds
After a meeting I just had on how to set up everything in maven, and the ridiculous level of setup it’ll take, I’m discovering that it’ll only get worse from here. This brings me to an alternative: PHP
Here’s the major difference in coding with java, and coding with PHP: If you want to test your PHP code, simply save the file, then open your browser to test it. Hell, you can use the command-line to test your code if you want to. In java, you first have to compile everything, and hope it was able to figure out where everything is. Then you have to deploy this compiled code to the server, and you have to hope it’s not gonna freeze in the process of doing this. After 20 minutes, you can finally test whatever change you just made. Then after fiddling with more configurations to make sure everything can be found, you recompile the code, redeploy the code to the server, and reload your browser.
Let me reiterate…
PHP = save file, load page.
Java = compile, build, deploy, reconfigure, compile, build, deploy, load page, cross fingers, die a little inside.
PHP is an interpreted language, and the Apache server will run the code in it on the fly. Apache servers boot up in all of about 10 seconds, and aren’t giant bloated monstrosities.
PHP is simple. That doesn’t mean it’s limited in functionality (far from it), rather it means it’s a hell of a lot easier to code in, test, and use. You have nearly any choice for an IDE, and in fact I just use Notepad++. The only thing I use Eclipse for with java is to be able to step through a program line by line and watch it execute. You can do this as well in PHP using XDebug and Notepad++. Notepad++ is far less bloated, and a much smaller install. Takes only a few seconds to boot up.
Everything about the process of PHP is faster, and the code is more logically-geared towards being a web development language. JSP feels hacky… as though it’s a generic language which people have re-engineered to be used as a web programming language, and nobody seems to like its implementation (hence all the configuration). Oh wait, maybe it seems that way because that’s what it is! PHP was created from day 1 to be a server-side scripting language; web development is precisely what it was created to do.
PHP has frameworks as well, and the most popular ones out there that I’ve read about aren’t hard to use. They’re logical, intuitive, and save even more time.
In closing…
Please, I beg you: avoid java. If you want any kind of peace in programming, stay as far away from it as possible. PHP is cross-platform just like java, and it’s far less of a headache to code in.