Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Format string to string

Format string to string

Scheduled Pinned Locked Moved The Weird and The Wonderful
rubycode-review
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RobCroll
    wrote on last edited by
    #1

    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."

    G J S 3 Replies Last reply
    0
    • R RobCroll

      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."

      G Offline
      G Offline
      Gary Wheeler
      wrote on last edited by
      #2

      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;

      1 Reply Last reply
      0
      • R RobCroll

        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."

        J Offline
        J Offline
        Julien Villers
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • R RobCroll

          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."

          S Offline
          S Offline
          scotchfaster
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups