|
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. 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) 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 :) |
|
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 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 other people
Mr. Good Indonesian donation provided by links 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 |