cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcus Crafter <craft...@fztig938.bank.dresdner.net>
Subject Re: Coding style question: backwards null checks
Date Fri, 07 Mar 2003 17:53:54 GMT
On Fri, Mar 07, 2003 at 12:44:04PM -0500, Tony Collen wrote:
> 
> Likewise, I've seen something like this in code... can't remember if it's
> anywhere in Cocoon:
> 
> if ( "something".equals(stringToCompare) {
>    ...
> }
> 
> IMO it seems more straightforward and easier to read if it's:
> 
> if ( stringToCompare.equals("something") ) {
>    ...
> }
> 
> Is this just a matter of style as well?  The first way seems goofy if you
> ask me.

	It's style but also beneficial because:
	
		if ("something".equals(stringToCompare)) { ... }
	
	works even when 'stringToCompare' is null, where:
	
		if (stringToCompare.equals("something")) { ... }
	
	would throw an NPE. The first one saves a leading null check.
	
	Cheers,
	
	Marcus


-- 
        .....
     ,,$$$$$$$$$,      Marcus Crafter
    ;$'      '$$$$:    Computer Systems Engineer
    $:         $$$$:   ManageSoft GmbH
     $       o_)$$$:   82-84 Mainzer Landstrasse
     ;$,    _/\ &&:'   60327 Frankfurt Germany
       '     /( &&&
           \_&&&&'
          &&&&.
    &&&&&&&:

Mime
View raw message