• King (unregistered)

    Replace apolacyptically with apocalyptically?

  • (nodebb)

    And seem to leave double spaces.....

  • (nodebb)

    Raises the question, if there IS a legitimate corner case where this method may be necessary. Like YYYYYY or similar with mixing month numbers an month names. I mean, I es to stretch a bit to think of a use case for even “April(04)”, never mind “April04” or 201818, 182018, ... But the edge cases exist. Given that they shouldn’t normally by necessary I wouldn’t be surprised if, i’m the weird case where they actually become necessary, they aren’t supported without such a pattern.

  • (nodebb)

    Also: Likely cause of that line: “We need the date without separator, we need it yesterday, and god forbid the untested code fails in production.” Under such constraints slapping a .replace onto the code may be the reasonable choice I guess. So this particular WTF makes me think... Of expletives mostly.

  • Laserbrain (unregistered)

    Further more it only works for locales where the date separator is a "/" character. The "/" itself in the format string is a format specifier (since it's not wrapped in '-characters) that means "Date separator" and converted to match the current system. It could for instance become a "-" or "."... (See https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings, search for "The date separator".)

  • my name is missing (unregistered)

    Caesar had this problem, his IDE's failed to format March.

  • Karl (unregistered) in reply to R3D3

    Good guess but this was brand-new code

  • Hal (unregistered) in reply to Laserbrain

    Which might indicate this isn't a WTF at all . It might be desired behavior, maybe '/' inst allowed for some target like URL or filename, or is used as some kind of field separator down stream but '.' and '-' might be allowed so in cases where '/' is the date separator and only in the cases, they want to remove them. That is certainly the kind of reasoning that deserves a comment through if that is the case.

  • Pedro (unregistered)

    @nodebb That is not required. For instance, if you want to get 06Jun (Month number+month name), you can use an empty divider:

    DateTime.ToString("MM''MMM");

    Those are 2 single-quotes inside (empty char).

  • Pedro (unregistered) in reply to Pedro
    DateTime.Now.ToString("MM''MMM");

    DateTime.Now, of course.

  • (nodebb) in reply to Pedro

    Now I am curious how the API produces “April'04” :)

  • Foo AKA Fooo (unregistered) in reply to my name is missing

    A too brutal comment!

  • (nodebb) in reply to Hal

    Which might indicate this isn't a WTF at all

    Unless the desired outcome is "use no separator unless the current culture uses something other than '/'", then this is a WTF. The users may all be in the same country and never change their internationalization settings, but then this will simply be a WTF that no one notices. Bad code that works is still bad code. Bad programmers that produce results are still bad programmers.

  • Appalled (unregistered)

    I'm missing something. Why not skip the entire mess with DateTime.Now.ToString("ddMMyyyy"). I've done that many times although usually for client-side sorting purposes like "yyyyMMDD". I've been retired too long and don't remember syntax perfectly (doesn't dd mean no leading zero), but I would ALWAYS use the pattern that includes a leading 0 in days and month. Not having that 0 leads to giant problems and I would fight with Users to the bitter end to retain it.

  • Merus (unregistered)

    My favourite bit is how it's a formattedID

    I mean, you might get away with it, but let's hope you don't need two of whatever it's an ID for on the same day

  • Barf4Eva (unregistered) in reply to Jaime

    While true that bad programmers that produce results are bad programmers... I've seen good programmers that produce bad results. I've seen bad programmers produce good results.

    Not sure I care too much in regards to this little code snippet if the rest of the code did as intended and worked fine. Especially if it were an application providing some sort of complex service, I'm going to overlook their bad programming and instead try to understand their ability to produce the good result.

  • Sole Purpose Of Visit (unregistered)

    Well, personally, I would regard TRWTF as a library whose ToString() method is actually a Format() method, complete with magic characters representing each particle in the date object. (Which is a botched inheritance from the Unix/Linux/Posix DateTime(), which at least had the merit of being pretty ubiquitous.)

    If your deliberate intent as a library writer is to throw a soupcon of cognitive dissonance into the mix, it's hardly surprising that things like this are the outcome.

  • Naomi (unregistered) in reply to Sole Purpose Of Visit

    Overloading toString like that is hardly uncommon. I can understand why someone might not care for it, but it's a matter of taste, which is never a WTF. :/

  • (nodebb)

    I'm going to overlook their bad programming and instead try to understand their ability to produce the good result.

    This is TRWTF.

    One of the reasons our industry is in such bad shape is because we keep ignoring our craft. Programmers suck because we're OK with sucky programmers. We do this in the fact of mountains of evidence (mostly security nowadays) that bad programming is causing us real problems.

    The development team lead and management are there to make sure we're "doing things right". QA and the customer will make sure we're producing good results. If the internal team loses sight of craft, none of the other teams will pick up the slack.

  • (nodebb) in reply to Sole Purpose Of Visit

    Well, personally, I would regard TRWTF as a library whose ToString() method is actually a Format() method

    Fair enough. In .Net, ToString() will always exists, but you had better check the documentation to figure out whether it does anything useful (protip: it usually doesn't). That's not a whole lot better than a parallel universe where object didn't have ToString() and you had to check the documentation to see how to string format something.

    I guess the original .Net team hoped that most classes would override ToString() with a reasonable implementation and you could just call ToString() on anything and usually be pleased with the result.

  • WTFGuy (unregistered)

    Enough of these languages look enough alike with a small enough sample that it'd be nice if WTF staff could explicitly tell us the language involved. Lots of people are assuming C#, and I agree the syntax is valid C#.

    But that doesn't necessarily mean it's not also valid Java or whatever. IANA enough of a Java dev to know for sure. Just the other day we had a back and forth about C vs C++.

    Once we're not sure which language it truly is, we're no longer able to make detailed comments like Laserbrain did. Maybe she's spot on and maybe he's way off base. We just don't know.

    I'll continue with the assumption it really is C#.

    As to the workmanship itself, overall the .Replace(...) tells me the dev doesn't know the API; he/she only knows examples of API use. They know what .ToString("dd/mm/yyyy") returns in their locale. And they know how to get from that result to the one they want. But they have no clue about all the details of which format specifiers do what in their API. And they may also be 100% ignorant of locales. I'm actually a little surprised they had the creativity to insert spaces surrounding the slashes.

    I also have to agree w Merus. The biggest WTF is the fact the result is stored in a var named formattedID. Unless perhaps the next few lines we don't see append some other info (e.g. a serial number) onto the (non-sortable) date part to arrive at the final formattedID value.

  • Naomi (unregistered) in reply to WTFGuy

    The easiest way to distinguish Java and C# is their convention around initial capitals. By convention, Java reserves initial capitals for class names (aside from constants written in ALL_CAPS); C# also capitalizes the first letter of member names. And for better or for worse, Java doesn't have an equivalent to C#'s properties, so .Now could only ever be a member variable or an inner class.

    Also, it's not relevant here, but Microsoft decided to use Hungarian notation on their interfaces for some reason, so if you ever see IList or IFormatProvider or what have you, it's C#; in Java those would be List and FormatProvider. And lastly, C# aliases String to string and encourages you to use the latter, while Java's content to just have Strings.

    Of course, these are only conventions... and you know how readily code that ends up here adheres to conventions, but it's still a fairly reliable set of heuristics.

  • Naomi (unregistered)

    (And I know I'm opening a can of worms here, but as a culture, can we please get over our aversion to the generic they? It's both simpler and more inclusive, and I've yet to hear a compelling reason not to use it.)

  • Pedro (unregistered) in reply to R3D3

    https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

    "MMMM'MM" => September'09 (in september) "MMMM'YY" => April'20

  • MiserableOldGit (unregistered)

    Isn't this just someone receiving a shitty date format in their inbound data and stripping it to allow it to cast to something that a datetime variable will accept, in whatever language they have to use?

    I know we should sanitise everything, but if you are just getting a fixed bit of crappily formatted data from a known source that really is wasting time and effort.

  • (nodebb) in reply to Sole Purpose Of Visit

    The naming isn't the problem. TRWTF is object class having virtual ToString method, because just like with Equals, 99% of classes don't have a meaningful, defined string representation. It ends up being used as debug string getter in most cases and actual string converter in very few cases, like integer and DateTime.

  • Erin (unregistered) in reply to Jaime

    To be fair, any scenario where you're using ddmmyyyy format is already quite likely to be failing culture rules. yyyymmdd makes sense for sorting regardless of culture but ddmmyyyy is generally a Euro-centric format. The US is mmddyyyy and most other places are either yyyymmdd or just wouldn't ever write a date in a purely numeric format at all.

Leave a comment on “Separate Replacements”

Log In or post as a guest

Replying to comment #:

« Return to Article