• Gordon (unregistered) in reply to Anon

    !"".equals(someString)

    returns true if someString is not the empty string.

    I believe calling equals on a new instance of a string set to ""

    I guess

    !params.get(sub.getFieldName().toLowerCase()).getValue().trim().equals("")

    or something would be better as you would not have the new instance. LOL

  • hoodaticus (unregistered) in reply to boog
    boog:
    It's possible they may have started with something like this and as they ran into NullPointerExceptions or missing keys (probably in production), they added the rest of the code, leading to the monstrosity we see today. It's what some coders like to call "iterative development".
    That kind of crap pisses me off. Instead of understanding the root of the problem and tackling it there, slapping on bullshit code combinations until the exceptions go away. AKA monkeys typing at a keyboard will one day produce a complete work of Shakespeare.

    For the benefit of the ignorant (certainly not you, boog), that is not what iterative development is. Iterative means tackling a small fraction of the requirements at a time, getting the user satisfied, and then tackling more requirements until the guy paying the bills considers the project complete or runs out of money.

    CAPTCHA: yeah, right.

  • hoodaticus (unregistered) in reply to frits
    frits:
    Haven't any of you jerks heard of Conjuctive Normal Form? Sheesh...
    I always called that boolean math, but I only ever use it non-.Net languages, since M$ fucked the value of truth, and I refuse to encase everything in abs().

    This also makes my code very unmaintainable and confuses mortals, who in any case deserve to be punished for making me work outside of .NET in the first place.

  • b (unregistered)

    Unintentionally, I actually said "What the fuck" while reading this code abomination. :-(

  • John Muller (unregistered)

    I've written code like

    if ((x == x) == (x != x)) { // Do Something }

    and had the Do Something block run, so nothing is really surprising to me now.

  • Rado (unregistered) in reply to Anon

    [quote]

    Forgive my ignorance, but does the !"".equals() actually do anything useful?

    [quote]

    If I am correct it will check to see if the sub.getFieldName is not made of spaces (i.e. at least one non space character).

  • Danack (unregistered) in reply to Anon

    Forgive my ignorance, but does the !"".equals() actually do anything useful?

    It checks that the string is not an empty (zero length) string.

  • Maarten (unregistered) in reply to Anon
    Anon:
    Forgive my ignorance, but does the !"".equals(param) actually do anything useful?

    It returns false if param is an empty string.

    !param.equals("") is also possible, but it's a NullPointerException waiting to happen.

  • not-of-this-Earth (unregistered) in reply to Skilldrick
    Skilldrick:
    TRWTF is using spaces instead of tabs.
    Wrong. (good) Programmers use spaces instead of tabs. Try to google why.
  • Gautier (unregistered) in reply to Anon

    the !"".equals(MyStr) means "" not equals to MyStr

    You can also write : !String.IsNullOrEmpty(MyStr) or just MyStr!=""

    But I love the other way !! Think different :-P

  • Matt Westwood (unregistered) in reply to not-of-this-Earth
    not-of-this-Earth:
    Skilldrick:
    TRWTF is using spaces instead of tabs.
    Wrong. (good) Programmers use spaces instead of tabs. Try to google why.

    Matter of opinion. I prefer tabs to spaces, myself, for more reasons than I can be bothered to write at the moment.

  • (cs) in reply to not-of-this-Earth
    not-of-this-Earth:
    Skilldrick:
    TRWTF is using spaces instead of tabs.
    Wrong. (good) Programmers use spaces instead of tabs. Try to google why.
    As long as you're consistent with the rest of the code-base, it doesn't actually matter whether it is tabs or spaces. But for the love of all that's holy, be consistent.
  • zimbatm (unregistered) in reply to Anon
    Forgive my ignorance, but does the !"".equals() actually do anything useful?

    I think the ! inverses the boolean return value of "".equals()

  • David Mårtensson (unregistered) in reply to Anon

    Yes I do believe it does.

    The whole thing is a test to see if a certain parameter exists and is set to something other than empty string.

    The !"".equals is false if params.get(....).trim() is empty.

    Sure, there are many better ways to do this and much more easy to read, but as it said, its another way to do things :P

    :)

  • Eric de Redelijkheid (unregistered) in reply to Anon

    Forgive my ignorance, but does the !"".equals() actually do anything useful?[/quote]

    Check if a string is empty?

  • causa (unregistered) in reply to Anonymous
    Anon:
    Forgive my ignorance, but does the !"".equals() actually do anything useful?

    Guys, this question was answered on the first page with a textbook answer. Featuring a comment really highlights the fact that nobody bothers to read past the first 4 comments before they add their own...

    Anonymous:
    It will return "false" if the parameter passed into equals() is not an empty string. This is the retarded equivalent of doing ((param != null) && !param.equals("")). They've done !"".equals(param) because this means they don't have to null-check the parameter (instead they are calling equals on a new empty string and passing the param into that, so it doesn't matter if param is null).
  • MrC (unregistered) in reply to Anon

    Checking the param isn't blank from the look of it.

    captcha: genitus

  • (cs)

    Could it be the same person who wrote this little gem I saw in a piece of code:

    Convert.ToString( Convert.ToInt32((Decimal.Round(Decimal.Multiply(Decimal.Divide(dDays, iTotal), iWidth), 0))) + iLEFT - (Convert.ToInt32(Decimal.Round(Decimal.Divide(Decimal.Multiply(Decimal.Divide(1, iTotal), iWidth), 2), 0) + (rblDisplay.SelectedValue == "2" ? 23 : 0))) )

    Getting dizzy yet?

  • Skilldrick (unregistered) in reply to not-of-this-Earth
    not-of-this-Earth:
    Skilldrick:
    TRWTF is using spaces instead of tabs.
    Wrong. (good) Programmers use spaces instead of tabs. Try to google why.

    I totally agree - which is why I corrected my comment:

    Skilldrick:
    Skilldrick:
    TRWTF is using spaces instead of tabs.

    Of course, I meant "using tabs instead of spaces". :P

  • Spike (unregistered) in reply to Anon

    Is this an empty comment?

  • Steve (unregistered) in reply to not-of-this-Earth
    not-of-this-Earth:
    Skilldrick:
    TRWTF is using spaces instead of tabs.
    Wrong. (good) Programmers use spaces instead of tabs. Try to google why.
    It doesn't make the blindest bit of difference whether you use tabs or spaces - as long as you're CONSISTENT. Consistency is all that really matters here, as long as you pick a scheme and stick with it you can use whatever you damn well like. Once you're in the IDE it should be transparent anyway (since the IDE should be converting tabs to spaces or spaces to tabs depending on your chosen scheme). Personally I prefer spaces but there are obvious advantages to tabs (smaller file size for one - you only need one tab where you would use 4 spaces - now multiply that by at least every line in every code file - and you start to see a very real filesize improvement from using tabs over spaces).
  • TheNoob (unregistered) in reply to Anon

    !"".equals(params.get(sub.getFieldName().toLowerCase()).getValue().trim())

    is false when the Parameter params.get(sub.getFieldName().toLowerCase()) consists of white spaces an otherwise true, doesn't it?

    Same like !params.get(sub.getFieldName().toLowerCase()).getValue().trim().isEmpty()

  • (cs) in reply to TheNoob

    !"".equals(params.get(sub.getFieldName().toLowerCase()).getValue().trim())

    But why the toLowerCase()?

  • commoveo (unregistered) in reply to Steve
    Steve:
    one tab where you would use 4 spaces

    4 spaces? Heretic! 8 spaces is the natural order as teletypes, VT100s and matrix printers set a tab stop at every eighth position. So you can just cat a file to them.

  • JJoos (unregistered) in reply to Anon

    Yeah it basically is the same as x.equals(""), except that you won't get a NullReferenceException.

    You should use String.IsNullOrEmpty in .NET framework versions 2 and higher.

  • (cs) in reply to DOA
    DOA:
    I think the only solution is to wire pepper spray to certain people's keyboards and have it activate when Ctrl + C is pressed.

    What's wrong with terminating a process?

  • Mike (unregistered)

    !"".equals(params.get(sub.getFieldName().toLowerCase()).getValue().trim() That is a legitimate check that the value of the parameter is not empty. No really WTF here, except not creating temp variables for increased readability.

  • zzz (unregistered) in reply to xtremezone
    xtremezone:
    Code snippet:
    !"".equals((...).trim())
    This is why .NET has System.String.IsNullOrWhiteSpace.
    !string.IsNullOrWhiteSpace((...))

    org.apache.commons.lang.StringUtils.isEmpty(string);

  • (cs) in reply to hoodaticus
    hoodaticus:
    boog:
    It's possible they may have started with something like this and as they ran into NullPointerExceptions or missing keys (probably in production), they added the rest of the code, leading to the monstrosity we see today. It's what some coders like to call "iterative development".
    That kind of crap pisses me off. Instead of understanding the root of the problem and tackling it there, slapping on bullshit code combinations until the exceptions go away. AKA monkeys typing at a keyboard will one day produce a complete work of Shakespeare.
    My sentiments exactly.
    hoodaticus:
    For the benefit of the ignorant (certainly not you, boog), that is not what iterative development is. Iterative means tackling a small fraction of the requirements at a time, getting the user satisfied, and then tackling more requirements until the guy paying the bills considers the project complete or runs out of money.

    CAPTCHA: yeah, right.

    You are correct, but you'd be surprised how many developers are, as you say, ignorant. We need to stop such ignorant development teams from writing this kind of code. I say we round 'em all up and feed 'em all to a volcano. Only way to be sure.

  • -chris- (unregistered) in reply to Anon

    Writing:

     !"".equals()
    

    is identical to writing:

     !string.empty.equals()
    

    "" is just the literal equivalent of string.empty and they can be used interchangeably. It does look strange in the above example for sure!

  • Zomg (unregistered) in reply to Anon

    That whole line may just be the equivalent of a 'field not empty' check.

  • r4dD00d (unregistered) in reply to xtremezone
    xtremezone:
    Code snippet:
    !"".equals((...).trim())
    This is why .NET has System.String.IsNullOrWhiteSpace.
    !string.IsNullOrWhiteSpace((...))

    What does it do when string is null? Throw NPE?

  • _ (unregistered) in reply to Anon

    Forgive my ignorance, but does the !"".equals() actually do anything useful?

    It checks if the parameter is not an empty string. Although, it's a very weird and unreadable was to do so.

  • yername (unregistered) in reply to commoveo
    commoveo:
    Steve:
    one tab where you would use 4 spaces

    4 spaces? Heretic! 8 spaces is the natural order as teletypes, VT100s and matrix printers set a tab stop at every eighth position. So you can just cat a file to them.

    Exactly, but you also set sw=2 and sts=2 in your favourite editor..

    Then again, Steve probably uses VC6 IDE, which has the tab size of 4 spaces..

  • The other guy (unregistered) in reply to Anon
    Bob:
    Forgive my ignorance, but does the !"".equals() actually do anything useful?

    That and the bit before it do pretty much what string.IsNullOrWhitespace(params.get(sub.getFieldName().toLowerCase()).getValue()) does.

  • Anon (unregistered) in reply to r4dD00d

    No, it's literally !string.IsNullOrWhiteSpace(argumentAsString). See http://msdn.microsoft.com/en-us/library/system.string.isnullorwhitespace.aspx for details

  • ideo (unregistered) in reply to Anon
    Anon:
    No, it's figuratively !string.IsNullOrWhiteSpace(argumentAsString). See http://msdn.microsoft.com/en-us/library/system.string.isnullorwhitespace.aspx for details
    FTFY. lmao, not this again!
  • vlc (unregistered) in reply to Anon
    Anon:
    Forgive my ignorance, but does the !"".equals() actually do anything useful?

    Yes, it is equal to str != null && str.length > 0 :)

  • vlc (unregistered) in reply to vlc
    vlc:
    Anon:
    Forgive my ignorance, but does the !"".equals() actually do anything useful?

    Yes, it is equal to str != null && str.length > 0 :)

    Oops, it should be: str == null || str.length > 0. Which sucks anyway :D.

    Cheers.

  • Luiz Felipe (unregistered)

    What sucks with these new languages (java,c#,vb) is that string can have fucking nulls. in the past i only get format exception, now i have a language that i dont need to manage memory but gets fucking null reference exception. All of it to avoid throw away one or two more bytes per string, if it is initialized to String.Empty it will suck the same bytes from memory than a nil pointer.

  • Dylan (unregistered) in reply to Anon
    Anon:
    For readability:
    if (
    	params.containsKey(sub.getParentField().toLowerCase()) 
    	&& (
    		params.get(sub.getParentField().toLowerCase()).getValue().equalsIgnoreCase(sub.getReplaceOn()) 
    		|| (
    			"*".equalsIgnoreCase(sub.getReplaceOn()) 
    			&& params.get(sub.getFieldName().toLowerCase()) != null 
    			&& params.get(sub.getFieldName().toLowerCase()).getValue() != null 
    			&& !"".equals(params.get(sub.getFieldName().toLowerCase()).getValue().trim())
    		)
    	)
    	&& params.containsKey(sub.getFieldName().toLowerCase())
    ) {

    Forgive my ignorance, but does the !"".equals() actually do anything useful?

    I would venture a guess that !"".equals(someString), would return true if the string is not empty.

    I would also venture a guess that a function such as !someString.empty() also exists. or someString.length() > 0.

  • (cs) in reply to Luiz Felipe
    Luiz Felipe:
    What sucks with these new languages (java,c#,vb) is that string can have fucking nulls. in the past i only get format exception, now i have a language that i dont need to manage memory but gets fucking null reference exception. All of it to avoid throw away one or two more bytes per string, if it is initialized to String.Empty it will suck the same bytes from memory than a nil pointer.

    Please send me the name of the company where you work. I would like to offer them my services.

    frits Bug Assasin

  • steve (unregistered) in reply to Anon

    I should guess that the !"".equals() would check to see if the argument inside the parens for equals() is not equal to the empty string. So, if you get the parameter, and trim whitespace, and you have at least one character left in the string, this expression would return true.

  • Chris (unregistered) in reply to Anon

    The !"".equals(...) bit checks to see if the stuff inside the equals(..) is not an empty string.

    It does a string equality comparison between "" (an empty string) and the bit inside the (..). Looks funny but works.

    Cheers,

    Chris

  • Some Dude (unregistered) in reply to Anon

    Forgive my ignorance, but does the !"".equals() actually do anything useful?

    It checks if a string is not empty.

  • Skúli (unregistered) in reply to Anon

    It can. It is asking if some string is equal to ""

  • (cs) in reply to Dylan
    Dylan:
    Anon:
    Forgive my ignorance, but does the !"".equals() actually do anything useful?

    I would venture a guess that !"".equals(someString), would return true if the string is not empty.

    I would also venture a guess that a function such as !someString.empty() also exists. or someString.length() > 0.

    Ah, but !string.empty() is very different from !"".equals(string).

    !string.empty() returns true if the non-null string 'string' is not empty. !"".equals(string) returns true if string is not null and not empty.

    The strange-looking way that is recommended to do string comparison in Java is because a member variable might be null (and thus throw a NullPointerException if you try to invoke the empty() or length() methods on it), but a string constant (between double quotes) cannot be null.

  • (cs) in reply to Luiz Felipe
    Luiz Felipe:
    What sucks with these new languages (java,c#,vb) is that string can have fucking nulls. in the past i only get format exception, now i have a language that i dont need to manage memory but gets fucking null reference exception. All of it to avoid throw away one or two more bytes per string, if it is initialized to String.Empty it will suck the same bytes from memory than a nil pointer.
    Indeed, variable initialisation is highly overrated, as are type safety and exception processing.
  • (cs) in reply to Anon

    !"".equals(expression)

    is basically the same as

    expression != ""

  • ideo (unregistered) in reply to Luiz Felipe
    Luiz Felipe:
    What sucks with these new languages (java,c#,vb) is that string can have fucking nulls. in the past i only get format exception, now i have a language that i dont need to manage memory but gets fucking null reference exception. All of it to avoid throw away one or two more bytes per string, if it is initialized to String.Empty it will suck the same bytes from memory than a nil pointer.
    Jaime, is that you?

Leave a comment on “The Other If”

Log In or post as a guest

Replying to comment #:

« Return to Article