- 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
Replace apolacyptically with apocalyptically?
Admin
And seem to leave double spaces.....
Admin
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.
Admin
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.
Admin
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".)
Admin
Caesar had this problem, his IDE's failed to format March.
Admin
Good guess but this was brand-new code
Admin
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.
Admin
@nodebb That is not required. For instance, if you want to get 06Jun (Month number+month name), you can use an empty divider:
Those are 2 single-quotes inside (empty char).
Admin
DateTime.Now, of course.
Admin
Now I am curious how the API produces “April'04” :)
Admin
A too brutal comment!
Admin
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.
Admin
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.
Admin
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
Admin
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.
Admin
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.
Admin
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. :/Admin
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.
Admin
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.
Admin
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.
Admin
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
orIFormatProvider
or what have you, it's C#; in Java those would beList
andFormatProvider
. And lastly, C# aliasesString
tostring
and encourages you to use the latter, while Java's content to just haveString
s.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.
Admin
(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.)
Admin
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
Admin
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.
Admin
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.
Admin
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.