- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
!"".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
Admin
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.
Admin
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.
Admin
Unintentionally, I actually said "What the fuck" while reading this code abomination. :-(
Admin
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.
Admin
[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).
Admin
Forgive my ignorance, but does the !"".equals() actually do anything useful?
It checks that the string is not an empty (zero length) string.
Admin
It returns false if param is an empty string.
!param.equals("") is also possible, but it's a NullPointerException waiting to happen.
Admin
Admin
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
Admin
Matter of opinion. I prefer tabs to spaces, myself, for more reasons than I can be bothered to write at the moment.
Admin
Admin
I think the ! inverses the boolean return value of "".equals()
Admin
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
:)
Admin
Forgive my ignorance, but does the !"".equals() actually do anything useful?[/quote]
Check if a string is empty?
Admin
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...
Admin
Checking the param isn't blank from the look of it.
captcha: genitus
Admin
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?
Admin
I totally agree - which is why I corrected my comment:
Admin
Is this an empty comment?
Admin
Admin
!"".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()
Admin
!"".equals(params.get(sub.getFieldName().toLowerCase()).getValue().trim())
But why the toLowerCase()?
Admin
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.
Admin
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.
Admin
What's wrong with terminating a process?
Admin
!"".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.
Admin
org.apache.commons.lang.StringUtils.isEmpty(string);
Admin
Admin
Writing:
is identical to writing:
"" is just the literal equivalent of string.empty and they can be used interchangeably. It does look strange in the above example for sure!
Admin
That whole line may just be the equivalent of a 'field not empty' check.
Admin
What does it do when string is null? Throw NPE?
Admin
It checks if the parameter is not an empty string. Although, it's a very weird and unreadable was to do so.
Admin
Then again, Steve probably uses VC6 IDE, which has the tab size of 4 spaces..
Admin
That and the bit before it do pretty much what string.IsNullOrWhitespace(params.get(sub.getFieldName().toLowerCase()).getValue()) does.
Admin
No, it's literally !string.IsNullOrWhiteSpace(argumentAsString). See http://msdn.microsoft.com/en-us/library/system.string.isnullorwhitespace.aspx for details
Admin
Admin
Yes, it is equal to str != null && str.length > 0 :)
Admin
Oops, it should be: str == null || str.length > 0. Which sucks anyway :D.
Cheers.
Admin
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.
Admin
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.
Admin
Please send me the name of the company where you work. I would like to offer them my services.
frits Bug Assasin
Admin
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.
Admin
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
Admin
It checks if a string is not empty.
Admin
It can. It is asking if some string is equal to ""
Admin
!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.
Admin
Admin
!"".equals(expression)
is basically the same as
expression != ""
Admin