Garbage Burrito

Topic

Author Topic
Rheaghen-za
rheaghen

Coding Tips!

08 09, 2006 @ 09:07AM

how many times have you done this

if( request.getParameter("foo")!= null && request.getParameter("foo").equals("bar") ) {
doStuff();
}

this is WAY easier

if("bar".equals(request.getParameter("foo")) ) {
doStuff();
}

you can call methods on a "String Literal" in Java
including the null safe .equals() method!

Comments

Author Comments
Picture1
Ben Kittrell
08 09, 2006 @ 11:35AM

For some reason thats always made me cringe.

Rheaghen-za
rheaghen
08 09, 2006 @ 12:12PM

Kinda like Goatse makes you cringe? it was kinda like puttin the horse before the carrage for me until I accepted it. I think you just need some humble pie. I know it's unusual, but it's more efficient and totaly Kosher. if your not too freaked out.. try it, I promise it won't make Gaping Orafices appear in your apps.

this just goes to show humans are creatures of habbit. the next time you feel your self cringing without seeing Goatse(Microsoft), think to your self, I could be eliminating a Real innovation here(Linux/Mac). The good news is that you only need to try it(Linux/Mac) once =). When you discover that something(Microsoft) is a waste of time, you are free abandon it. Something is whispering microsoft in my ear. anyway, rember to be strong minded(Linux/Mac). Don't fall into failure(windows) just because it's familiar.

remember "String Literals" are objects too. those fun friendly people at sun made this a possibility for a reason. =)

Ryan's Random Thought:
Object woman = new Woman();
see... women are objects!
please feel free to hate me =)

Picture1
Ben Kittrell
08 09, 2006 @ 12:52PM

Actually I'll just stick with


if language == 'ruby'
 kickAss
end

Danger
08 18, 2006 @ 10:02AM

do stuff if "bar".eql? params[:foo]

Oh yeah baby...

Picture1
Ben Kittrell
08 18, 2006 @ 10:40AM

Danger, do you use the eql? method, or are you being sarcastic?

Rheaghen-za
rheaghen
08 18, 2006 @ 09:00PM

yeah ben.. because its a good coding practice. lol

Picture1
Ben Kittrell
08 18, 2006 @ 10:20PM

That's Ruby not Java ;)

Rheaghen-za
rheaghen
08 21, 2006 @ 05:33AM

calling an comparitor function from a string literal is a technique, not a language.

Picture1
Ben Kittrell
08 21, 2006 @ 06:44AM

It's a technique, *in Java*. In Ruby eql? and == are the same thing. You don't get a null/nil pointer if you use ==. Most scripting languages do not use == for identity comparison like Java.

I was just curious to know if Danger uses .eql? out of preference, or if he was just comparing to Java.

Pages: 1 2 >

powered by : Doodlekit Online Free Website Builder : developed by : Doodlebit™ Website Company