Format string to string
-
Just started working on some objective C code today and been giggling quite a bit. I thought I'd post this little gem.
NSString *dateCompletedTitle = [[NSString alloc] initWithFormat:@"%@", NSLocalizedString(@"PDFCompletedKey", @"")];
Creating a string to return a localized string that's formatted as a string by creating another string. Even better, the application only supports one language, English. And if you did localize it to support a number of languages, the translator would have no idea of what PDFCompletedKey was as there is no comment. Life's too short to refactor this project.
"You get that on the big jobs."
-
Just started working on some objective C code today and been giggling quite a bit. I thought I'd post this little gem.
NSString *dateCompletedTitle = [[NSString alloc] initWithFormat:@"%@", NSLocalizedString(@"PDFCompletedKey", @"")];
Creating a string to return a localized string that's formatted as a string by creating another string. Even better, the application only supports one language, English. And if you did localize it to support a number of languages, the translator would have no idea of what PDFCompletedKey was as there is no comment. Life's too short to refactor this project.
"You get that on the big jobs."
One of the gems I keep finding in a (former) coworker's code:
CString string;
string.Format(_T("some text"));CString::Format()
does 'C'printf()
style formatting. Why go through all that just to initialize a string to a constant value? :rolleyes: For the non-MFC folks in the audience:CString string(_T("some text"));
is the preferred way to do this.
Software Zen:
delete this;
-
Just started working on some objective C code today and been giggling quite a bit. I thought I'd post this little gem.
NSString *dateCompletedTitle = [[NSString alloc] initWithFormat:@"%@", NSLocalizedString(@"PDFCompletedKey", @"")];
Creating a string to return a localized string that's formatted as a string by creating another string. Even better, the application only supports one language, English. And if you did localize it to support a number of languages, the translator would have no idea of what PDFCompletedKey was as there is no comment. Life's too short to refactor this project.
"You get that on the big jobs."
There's a slight memory management issue at work here though. If using iOS ref counting (not ARC), the variable you're showing is retained, whereas the localized string answer would be autoreleased. So it's a fancy way of doing [NSLocalizedString(...) copy].
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood 'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
-
Just started working on some objective C code today and been giggling quite a bit. I thought I'd post this little gem.
NSString *dateCompletedTitle = [[NSString alloc] initWithFormat:@"%@", NSLocalizedString(@"PDFCompletedKey", @"")];
Creating a string to return a localized string that's formatted as a string by creating another string. Even better, the application only supports one language, English. And if you did localize it to support a number of languages, the translator would have no idea of what PDFCompletedKey was as there is no comment. Life's too short to refactor this project.
"You get that on the big jobs."
Honestly, no matter how bad or well written it is, all objective C code looks like a coding horror to me. But I suppose this looks worse then most.