Wednesday, November 24, 2004

A bad code from Ted Husted?

This source code is listed on Ted's site. I found this code when I was searching for a trick for automatic token checking in a Struts application. Although this is just a simple example, but it sure has bad coding practices that shouldn't be followed by newbie programmer (note that I am a newbie too).

// Check for missing token
forward = mapping.findForward("getToken");
if ((null!=forward) && (!isTokenValid(request))) {
// Post token error message
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.token"));
saveErrors(request,errors);
return (forward);
}
if (null!=forward) {
// reset to guard against duplicate request
resetToken(request);
}

The first code's flaw is, the code doesn't use single return style method.
The second is, there is double variable checking, while a single if-else block could achieve the same goal.

I rewrite above code become this :

// Check for missing token
forward = mapping.findForward("getToken");
if (null!=forward) {
// reset to guard against duplicate request
resetToken(request);
if(!isTokenValid(request)){
// Post token error message
ActionErrors errors = new ActionErrors();
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.token"));
saveErrors(request,errors);
}
}

Hey, where are the return statement?
It's removed from the code since we actually didn't need to escape at that time. A better approach should be using a boolean variable that indicate whether the token is valid or not.

permaLink() | postComments() | read4Comments()

Good design!
[url=http://vwlzugjn.com/dxbv/pvuz.html]My homepage[/url] | [url=http://ruujazjc.com/sywj/mzzg.html]Cool site[/url]

By Anonymous Anonymous, at 12:30 AM  

Good design!
My homepage | Please visit

By Anonymous Anonymous, at 12:30 AM  

Great work!
http://vwlzugjn.com/dxbv/pvuz.html | http://pkapgijf.com/avwa/aflb.html

By Anonymous Anonymous, at 12:30 AM  

Watiti.com
Join me and my circle of friends at http://www.watiti.com, an online social networking community that connects people from all over the world.

Meet new people, share photos, create or attend events, post free classifieds, send free e-cards, listen music, read blogs, upload videos, be part of a club, chat rooms, forum and much more!

See you around! Bring all your friends too!

Watiti.com

By Anonymous Anonymous, at 5:59 PM  

Monday, November 22, 2004

API for Friendster/Multiply/Hi5

Another invitation mail just arrive in mailbox. It's from hi5.
When it comes like this, it just a matter of time when an software (like
Gaim)/API (like BloggerAPI)/webservices that can bridging (built on a layer above these 'social net websites') sites like friendster/multiply/hi5/etc come, so anyone just need to have a single account.

Has someone started an SF project for this one? If it hasn't, u s'd start a new one :)

(Well, I wonder that Google will create one too. GNet? googlefriends? :p)

permaLink() |

Xbeans

I've found another xml library that has power on its simplicity. This lib has a really different idea about how to build xml-based application using a chained transformer (xbean). I like this approach, while the other lib seems to be full-bloated with all-future-xml-feature-that-yet-ready-to-use.

It's Xbeans. And it's a real JavaBean (oops... I mean, it is a visual component/can be configured using IDE :)

permaLink() |

Cat Stevens said

- If you want to sing out, sing out, and if you want to be free, be free, cause there's a million ways to be, you know that there are. -

watashi

My Photo
Name: Monang Setyawan
Location: Jakarta, Indonesia

I'm nothing

likes...

anime, games, Java, watching movies, operating illegal software and music downloads, playing the guitar, reading, football, cats

dislikes...

pineapples, snakes, Bush, Bill Gates, hypocrites

valuable primates

MartinFowler JamesGosling RickardOberg GradyBooch JasonHunter SteveJobs CedricBeust BruceTate HaniSulaiman DionAlmaer BruceEckel CarlosWhoever CameronPurdy GrahamGlass BillBurke GavinKing MarcFleury RichardStallman JamesStrachan ErikHatcher CraigMcClanahan MonsonHaefel GuidoVanRossum JimWaldo Joel Spolsky JackShirazi EricRaymond HeinzKabutz

archives

10/2004
11/2004
01/2005
02/2005
03/2005
04/2005
07/2005
09/2005
11/2005
12/2005
01/2006
02/2006
01/2007
09/2007
10/2007
12/2007

other people

Mr. Good Indonesian
We Hate Indonesia
Zul van Delft

donation provided by

Java-Tips

links

My Wiki
TSS
/.

behind the scene

I like grey because it reminds me of the colour of my brain. My brain conjures up funny or useless thoughts to be ranted in this blog/journal.

Let them speak



This horrible page has been visited for times

theWrittenOne
-Yet Another Useless Blog- Random thought, Java, and anything