Do not compare Strings
-
So today we stumble on this bug during QA where either an Android app or the iOS one would work. The problem: a value in our central configuration server.
So, if the value was 5 iOS/Web crash. If the value was PRD Android crash. Take into account that the iOS app is the reference one and Android should follow it.
When asked to the Android guy to change this logic on the app his response left me stunned:
Me: it's an easy change. It's harder to do elsewhere and I want consistency.
Dev: I can't. In Android you can't compare strings.
Dev: well, you can
Dev: but you shouldn't
Me: ... change the code.And this guys has been developing this app for at least a year.
I'm afraid of what I'm going to find tomorrow.
-
AHAHA.
==
vs.equals()
strikes again, in a way you wouldn't expect!
-
Dev: In Android you can't compare strings.
-
AHAHA.
==
vs.equals()
strikes again, in a way you wouldn't expect!I confess, I also have been guilty of using
if(str == "")
instead of
if(string.IsNullOrEmpty(str))
in C# (for about one day, though, until the first version bit me in the ass due to the string being actually Null and not merely empty...)
I blame Javascript.
-
-
-
I confess, I also have been guilty of using
if(str == "")
I just know that tomorrow I'll find that.
-
-
Dev: I can't. In Android you can't compare strings
How did he get past the interview stage?
-
How did he get past the interview stage?Someone obviously used the wrong comparison method when parsing his list of skills :p
-
How did he get past the interview stage?
It's more how he's had this thought, and his own brain hasn't gone "No, that can't be right".
Not even for long enough to open Google.
-
Oh well, he's an outside developer in a low level consulting firm that my company uses for cheap grunt work... That's another WTF on its own and probably the reason this project is in the sorry state it's after almost two years. It's the perfect example of a project destined to fail but since another future big project depends on this one, I was dragged into to try to finish it.
-
So, if the value was 5 iOS/Web crash. If the value was PRD Android crash. Take into account that the iOS app is the reference one and Android should follow it
I'm sorry, I did not get past this. Should dev change Android so that it too crashes if value is 5?
-
-
What possible value could hold both "5" and "PR[o]D[uction]" at different times?
Clearly the solution is to change the value on the server to be PR5.
-
Ah.
5
is a number,"PRD"
is a string.They cannot be compared.
-
So, if the value was 5 iOS/Web crash. If the value was PRD Android crash.
I'm assuming that it's 5 in a string. But still... what variable can hold both of those at different times
-
A quantum variable?
-
-
I'm assuming that it's 5 in a string. But still... what variable can hold both of those at different times
The answer is: any variable can hold both of those at different times.
at the same time is another story.
-
JavaScript arbitrarily deciding to cast shit around without asking you?
Filed under: Ok, to be fair, it would cast it the other way around
-
That's why I end up writing stuff like
if(+b > +a) { /*stuff*/ }
Because Javascript!
(Or more specifically, because"10" < "2"
)
-
Or, actual code I had when pulling data from JSON:
{ ... phoneNumber = jsonObj.phoneNumber + "", ... }
Because who needs those leading 0s?
-
Because who needs those leading 0s?
Well, the last thing we'd want is for the phone numbers to be interpreted as octal constants...
-
Android should use the "PRD" string (or "STG", "QA", "DEV") and not an integer.
-
Well, the last thing we'd want is for the phone numbers to be interpreted as octal constants...
Or be confused with positive numbers...
-
Android should use the "PRD" string (or "STG", "QA", "DEV") and not an integer.
Well then; in that case it works as expected. IOS crashes on '5', and android crashes on its equivalent "PRD".
-
You can contact me on 7.515e10
-
-
In my last job, we dealt with electronic copies of itemised phone bills. At least once a month we'd get an exchange like this from the client:
We loaded a CSV bill in, but the dialled numbers look like 1.12345e+10
ย
Please confirm you are downloading the file, then loading it in without any modifications
ย
Yes, we have not touched the file.
ย
Your file contains the dialled numbers in 1.12345e10 format. The file I just downloaded from the portal is in the format 01123456789. Are you sure you didn't open it in Excel and save it?
ย
We did that, but we didn't modify it
-
And apparently my phone number is going to change every time that link registers a new click...
-
I thought you did that on purpose
-
Nope - didn't even occur to me...
-
Your file contains the dialled numbers in 1.12345e10 format. The file I just downloaded from the portal is in the format 01123456789. Are you sure you didn't open it in Excel and save it?
We did that, but we didn't modify it
I have a specific 3rd party company that I have to deal with that does this EVERY FUCKING TIME. I've had to explain to no less than THREE people at their moron company and beg them not to touch their fucking CSV file with Excel before they send it, and they do it again and again until I just give up and QA their shit once it hits the automated production process where they won't be touching it before I can.
-
You can specify to Excel not to fuck up columns when you import from CSV, can't you?
(I mean: I can; you you probably can; you your client, maybe not so much..)
-
If you actually had Excel open and are truly importing a CSV, you can get choices on column types. If you (which they do) have .csv mapped straight to Excel and are just double-click opening it, the only way I know of is to put a single quote in front of the value so Excel reads it as text instead. But I don't want that, because that would fuck up the automated process.
-
How about giving the file an extension like .txt instead?
-
That ought to be enough to prevent them opening it in Excel, for sure...
-
I'm afraid they'd find a way to fuck it up even worse. It already doesn't actually adhere to CSV format, even if you didn't open it in Excel. Just that opening it in Excel destroys some of the data irretrievably.
-
beg them not to touch their fucking CSV file with Excel before they send it
Having watched the process through screen sharing, it seems that a common thing is getting the file through email and not knowing any way to save it other than double clicking the attachment and choosing save as once it's opened. They don't see this as changing it with Excel because all they're doing is saving the attachment
-
I confess, I also have been guilty of using
if(str == "")
instead of
if(string.IsNullOrEmpty(str))
in C# (for about one day, though, until the first version bit me in the ass due to the string being actually Null and not merely empty...)
I blame Javascript.I really don't understand what kind of culture could ever induce someone to consider null, and the empty string, to be the same.
Under what circumstances could a string be either null or empty, with both of these meaning the same thing?
Is this like that thing with Java collections, where people would write e.g. a
Collection<User> findUsersBySurname(String surname)
that returns null if no users are found, instead of an empty collection?
-
I really don't understand what kind of culture could ever induce someone to consider null, and the empty string, to be the same.
-
adhere to CSV format
Hahahaha. Real-world CSV is a family of related pseudo-formats.
-
- People opening CSVs with excel just to check if they are ok and then save them
- Excel's CSV handling where it changes god knows what to fuck up the csv. Even if you start a new document put some basic text in it and save it as CSV it is just fucked. On a positive note: if I'm remembering correctly starting from Excel 2010 there was improvement. The CSVs didn't contain 10000s of empty lines anymore.
- CSV as a import/export format. 9 out 10 it isn't even actual comma separated but | ; tab or whatever.
-
When it's ; delimited, there's a good bet it's from a locale where commas are used as decimal separators, for even more fun when Excel decides that 1,50 = 1500.00
-
That is why
Real-world CSV is a family of related pseudo-formats
leads to
CSV as a import/export format
-
Why not solve all these problems by picking a separation character no-one will ever think of?
I bring you JSV - Japan Separated Values
Example:
Value 1๐พValue 2๐พValue 3
Of course, TRWTF is that Japan has its own emoji, and other countries don't
-
-
What about \0 separated values? Isn't the point of the null character as a string terminator?
-
๐ฌ๐ง
Yes, there are flags, but the silhouette is a separate emoji
@Jaloopa said:What about \0 separated values? Isn't the point of the null character as a string terminator?
Given how many security issues have been caused by bad\0
handling, do you really want to use it for data exchange?