Monday, February 25, 2008

Ruby: a first look

It is an interpretive language that recently gained a lot of attention. http://www.ruby-lang.org/en/

Whoa, you can try it right on the web brower without installing anything. http://tryruby.hobix.com/

It is interpreted. Somewhat like BASIC on the Commodore 64. Does it remind you of functional languages such as the Read-Eval-Print nature of LISP or Scheme?
Yes, it does have all that lambda things that functional language purists love.

I LIKE the pretty tutorials in the site. Besides more "syntax sugar" in Ruby as CS purists call it, I don't see how it revolutionize software development... Ok, it can do OOP (which LISP doesn't).
Strange, bloated syntax: LOTS of punctionations used &, @, also @@, %, :, even the absolute value pair ||,... The condition for if-statements can come behind!
Too complex for my taste. See here for details.

But is there anything truly revolutionary about OO from C++ or Java besides the bloated syntax?

Some people are obsessed with OOP. where the second O stands for obsession: Object Obsessed Programming, like those arguing Smalltalk is pure but C++ is not (in the 90s). Just what do you get when you treat a number as an object? Out of all the OO languages that I have seen, I like java the best.

The real attention of Ruby comes its killer application Rail: Ruby on Rail, which can do everybody's favorite MVC.
The neat idea is also associate controller object with a programmable html (like ASP, JSP).
Here is a great tutorial site: http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html?page=1
With Ruby's rather strange language, I see little productivity.

I see in one article saying Ruby is programmers favorite toy now like Turbo Pascal was in the 80s. I failed to share this enthusiasm.

Thursday, February 21, 2008

On programming frameworks

The world enjoys the simplicity of HTML: simple text with formatting information. WWW made up horribly ugly things such as Microsoft's RTF format, for example, will be quite unthinkable. Web applications are rarely anything more than a few simple widgets on pages with a submit button. The software development world has since then tried various approaches in handling web applications.

Static HTML is not so programmable, so we have ASP or JSP to intermix it with code to generate dynamic HTML. If you allow people to write sloppy code, they'll do it. I have seen a lot of code where JSP/ASP intermix with data accessing routines and business rules routines, resulting in hard to follow and maintain code. The solution for that of course, is the important Model-View-Controller pattern to separate presentation, logic, and data.
Ever since, people try to associate a JSP with a "controller" file. Ever since, people try to come up with a good way to handle the action attribute of each <form> tag.

This is where frameworks come in. You can write your own, of course, or employ a favorite well known framework. The most popular frameworks for Java are of course Struts and Spring. Both sounds like important foundational elements of your car. Hmm, perhaps the next framework may be named "tires" or even "engine".

Both frameworks work by adding a section in web.xml to reroute files with certain extension such as *.do to be handled by the framework servlet, and provide some configuration file to link the JSP and the controller classes together. The controller is responsible to do work and retrieve data, to be toss back to the JSP for "view" purpose. Each framework has its own hard-to-manage-by-hand XML configuration file.

Struts is action oriented. It treats each thing happening to your web page is an action: loading, saving, submit button clicked, etc. The newest buzz is being to able to use POJO (Plain Old Java Object). Ok, POJO is a wacky acronym. It comes with a full set of custom tag libraries.

Spring is not just MVC, have a lot more things, such as buzzword Aspect Oriented Programming. This seems to outshadow Struts and even EJB. The examples I've seen encourage overriding *.htm so that we don't show what technology we are using such as .asp, .jsp, or .do. It promotes itself with Hibernate: an attempt to add object orientation to good old relational database. That's ORM: object relational db management. But is ORM really a good thing? How do you freely perform your own query? I don't mind plain old JDBC. Spring encourages the JSTL tags.
Theoretically, the Spring IDE for Eclipse is supposed to make everything easy, but who do you go to when you see an install error?

Both frameworks offer validation routines that may take a while to get used to. Both requires XML configurations, and a learning curve, and programmer discipline to write good code. Document all over please, it is already hard to follow an easy sample program.

Wednesday, February 20, 2008

JSTL

In the beginning web pages are static, enter CGI/ASP/JSP or whatever server side program to insert logic to generate HTML.
In the beginning there was HTML, then the world wants to define their own tags. Enter XML.

How about XML intermixed with programming? You may have seen the pure ugliness of this in the form of XSL. But XML/XSL are data and translating data. Though ugly, but it hasn't yet mess with traditional programming. The crave for your own tags doesn't stop here. JSP allows you to create your own tags in tag library. If you let people create your own tags people WILL do it, and eventually becomes standardized.

The Java Standard Tag Library (JSTL) is like a tag-based
programming language! Note: This is hardly new, actually it has come out for several years. I run into it because it seems the industry is embracing it.
All the Spring Framework examples I see uses JSTL.

JSP already provides convenient insertion of Java code within HTML. JSTL merely makes programming harder by changing syntax.
<%=variable%> prints out a variable. Nice and intuitive.

Does the following JSTL equivalent makes it more convenient?
<c:out value="${variable}" />

Of course, in order for this to work you need to import the JSTL tag library.
Actually, this is equivalent to <%=pageContext.getAttribute("variable")%>)Look, variable also has no type associated with it, and I thought one advantage of Java is strongly typed.
No one needs the extra syntax. That $ reminds me the horror of BASIC and PERL.

But wait there is more, you can even do if statements and switch statements, even iterator loops, all with different syntax than regular JSP! Oh my, for conditions, you can even use lt, gt, ne, eq like good old Fortran!

The implementation of the taglib simply change it back to the java scriptlets. Why fuss with it?

See these links for details
http://www-128.ibm.com/developerworks/java/library/j-jstl0211.html

Java builds on the syntax of C and C++. A generation of programmers are used to its syntax, we don't need to add XML tags around them.
I already object to the new for loop of Java 5 (which looks like mathematicians's for every element in a set notation).
We don't need generics (templates) from C++ either. If you let people do templates, everything will be littered with templates! If you let people do their own tags, they will use it all over. It is already hard to track down JSP typos, a good IDE may help you detect what's wrong. But it will be much harder to track down the non-java tags in JSTL. I see it not making programming JSP any easier.

Tuesday, February 19, 2008

The comic author sucks in math

xkcd.com often provides amusing math/science related comics. Ok, though quality is not top notch but better than what I can do. I have it as a igoogle gadget so I get updates daily. The following comic intends to spark gender prejudice in math:



What the author does not remember is this: in standard math notation the integral sign NEVER appears by itself. It needs to answer "with respect to variable.". You know, dx, dy, etc. It seems like x is the variable here but it wasn't specified. So I have to say it is neither the boy or the girl sucks in math but the author himself. Ok "sucks" may be too harsh. How about "needs more work."?

Ok, on math prejudice, I have met some very smart female math students. If girls want to learn they can also be very accomplished mathematicians. It is just math not quite attractive enough for many of them to major in that's all. Look around a typical math classroom beyond the required calculus series: almost all guys. Look at a faculty bulletin board: almost all male. My take on education is this: if one is willing to learn and has the right resources, anyone can be an accomplished student. It just turns out that guys have more interest, that's all.

Friday, February 15, 2008

Another university shooting

We have seen enough shooting on campus. Last time it was a psychological disturbed person, this time it is a "normal" person without his medication at NIU. No motives. Nothing explains it. Just what kind of medication was he taking? Is someone suing that pharamaectical company about not warning: may cause shooting if patient stops taking this stuff.

Without a gun, it may only take a few guys to subdue even the craziest emotional disturbed kid even when the kid is without the medication. With a gun it is another story. So this guy was interested in sociology and criminal justice. Justice IS: we bring fair punishment to those who endangers the society. For instance, bank robbers get locked up in jail. We punish the evil doer AND keep him from hurting others. Toughest criminal justice question: what can we do to those who commit crazy crime THEN suicide? Ancient Chinese dark history recorded some people whipping the criminal's corpse to vent some form of punishment after death.

Americans really ought to think hard and seriously on gun control. It should be a high priority campaign issue. Politicians: TALK about it, tell me what you are going to do before you can earn my vote.

American soldiers often shoot innocent people at the warzones, while crazy people or evil criminals shoot our innocent people at supposedly safe places such as schools and shopping malls.

Monday, February 11, 2008

Amusing google news

I love google. Amazing search ability is just the beginning. I am sure everyone agrees that their map service is awesome. I especially love iGoogle. You can create your own page of your favorite portlets! That's what portal SHOULD be, unlike the wacky content management system I use here at work. News is great too. It pulls info from various newssite so I have my own customized newspaper.

Here is an amusing news entry I see today:



No, not the news item itself is amusing, but look at that first line of article! It talks about Javascript! Seasoned programmers know that this is the <noscript> tag. What people are still using browser without javascript? Ok, you can turn javascript off. Some people do amazing things with Javascript, combine that with DHTML and one can have some fairly sophiscated sites. Maintaining such code can be nightmaric though. Some people prefer no client side coding at all! Rather, people have libraries that generate complicated javascript routines, especially for AJAX. Suddenly the pendulum of preference swings back to thick client.

Monday, February 4, 2008

Mall shooting

Mall shooting is closer to home than ever! Tinley Park Mall shooting leaves 5 dead and 1 wounded! The evil doer is still on the run. What is the motive of shooting 5 ladies at Lane Bryant? I have never been to this mall. But this can happen to YOUR favorite shopping mall while you are shopping. Not too long ago there was a Omaha mall shooting. We see so many of these shootings that we become NUMB, like how you will ignore hear news about another suicide bomber in Baghedad.

But no, this time is close to home!

Besides the poor victims' families, just about everyone's life goes on.
News soon go back to cover the action of Omaba vs Hillary in their campaign trail as we approach Super Tuesday. Of course, the aftermath of the Super Bowl! (Why do we use Roman Numerals in naming the Super Bowls?)

When will gun control ever get enough attention?

I can almost hear "no, guns don't kill people, people kill people." "The founding father gave us the 2nd Amendment". You are not encouraging people bring a gun to a shopping mall for self-defense are you?

"No, the price has gone up"

So I bought a cup of coffee from the company's cafeteria by handing in 2 dollar bills. I expect at least a quarter back. I only get about 15 cents. "Is this a LARGE cup?" The cafeteria lady replied, "nope, the price has gone up!"

This isn't clearly labeled in the cafeteria! Plus, isn't it a bit outrageous to get a 16oz coffee for almost $2.00? It is more expensive than a GALLON of gasoline (before 9/11). If you think about it, coffee is more expensive than gasoline! Coffee drinkers should boycott expensive coffee by brewing at home.

How do we fight high coffee prices? Someone should open a dollar-a-cup gourmet coffee shop! There is still huge earning margins at a dollar a cup. But how do we compete giants such as Dunkin or Starbucks? There are MANY failed non mainstream coffee shops around here in downtown Chicago.

Before one can open a busines of earning a-dollar-a-cup coffee, one needs to spend huge amount of dollars in renovating a coffee shop, pay big dollars for advertising, and hire some people and make sure there is warning label "your coffee is hot" to prevent outrageous lawsuits that only happens in America. No wonder the coffee is 2 dollars a piece. So brewing your own coffee is probably the best option.

Object Obsession

Recently I talked to a colleague who considered switching jobs but he wasn't so successful at his interview. "Man, it was hard." "How so?"

"OO concept: What's the difference between aggregation and composition?"

Yikes I am stumped. Just when do these terms come to play in real life? I vaguedly remember these things in some academic materials. Big words, perhaps buzz words. Do these things actually help you write working, maintainable programs?

Both words suggest a "has-a" relationship, but what is the difference?

See this link for detailed discussion: http://faq.javaranch.com/view?AssociationVsAggregationVsComposition.

Composition describes object that compose of important parts you can't live without. Like a car is not a car anymore without an engine. Association is a weaker description, like a tree is still a tree without some branch.

"How do you test an EJB?"

We don't use EJBs all that much here at work. Code wise, EJB2 is quite messy. It is very hard to write that code without a code generator like Websphere. However mess it is, how do you test it? of course you deploy it and try running the methods within! Nope, not good answer. The answer people look for is of course JUnit, specifically JUnit EE. Even "Junit" is not good enough.

"Unit testing" is a buzzword. You write something and then you write what you expect in the unit test. For example, you write a function call add3, you supply inputs in your unit test, and you supply the expected output, like providing 1,2,4 and expect 4,6,7. Tedious AND boring additional work. What good is it if you write your own test? Better: somebody else writes your test case. Yes, the idea of unit test is to re-run everything, preferably automatically, so you make sure new code does not break old code. Some people go overboard, "test driven programming", in which you write tests first. Now that's a bit too much obsession with unit testing.

I've got some reviewing to do before going to my next buzzwords interview. Some of the newest buzz things are Ruby, Spring Framework, Hibernate and all that.

What employers should look for: problem solving skills and coding ethics. Great developers pick up things quickly, whatever it is. Coding ethics are writing maintainable, followable, efficient, documented code. One usually does not need elaborate OO designs such as aggregation vs composition. Rather, you need a MINIMAL model to describe what you really need, rather than over-engineering to get impossible-to-maintain spaghetti classes with all those unfollowable "factories" and stuff. Often true in programming (AND in life): simple is beautiful.