- 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
That thing is not using StringBuilder. What else is there to say?
Admin
That at least they're consistently clueless?
Admin
Ohhh, if you think manually building a JSON is bad I have news for you. About a year ago we had a meeting with a provider which was having an issue with the dates sent to their API, which was baffling to us because we used Newtonsoft.Json to serialize the requests so there should have been no issues whatsoever. Well, one of the devs shared his screen and they were manually parsing the JSON. Facepalm moment for everyone else in the meeting. I was so shocked I didn't even think of taking a screenshot. Still, I coudln't resist asking why they weren't using using some library to do the parsing and it turns out the original devs were gone and it was a case of "if it works..."
Admin
I really (dis)like the extra fun in accessing the dictionary as if stringly-typed, then inferring the type from the string before writing the JSON. Which means, both
true
and"True"
end up "serialized" astrue
.Knowing it's really a dictionary of
Object
s makes it even more ridiculous, given .NET and Java alike have plainly usable Run-Time Type Identification capabilities.Addendum 2025-10-09 09:17: Oh and of course, no escaping of any sort is done.
Admin
Yeah, yeah, all your comments are fine and necessary and glorious. I, however, am pissed off by the apparently global variable "time" being used as a parameter in the first assignment.
Admin
This post reminded me there's a guy at work who used to use VB.NET and string concatenation to generate XML files.
Since I was responsible for the Unity C# project that would consume those files I whipped up an XmlSerializer based class library project and provided him with the DLL to drop into his own project with simple to use serialize/deserialize methods.
I also encouraged him to lean C# but I'm not sure if he ever did. That wasn't the critical problem anyway.
Edit Admin
I think time is a regular member, initialized in the constructor. Considering that neither the legacy naming convention or m_ or the new with just an underscore were used, I'm pretty sure now that this code was written actually by a Java developer.
Addendum 2025-10-09 12:51: On a second glance, this code was for sure written by a Java developer because they used Equals instead of the operator which is generally more efficient and especially in the old days static operators which got inlined were always more efficient than the vcall.
Admin
Remy> ...I beg you, just get a library...
Never, /ever/, discount the possibility of a PHB insisting that third party libraries are not to be used because of licencing/copyright issues.
Edit Admin
There's a hidden danger in this. You know all those stories about people named "Null" who have problems with poorly-written software that chokes on their name? I suspect that at least one reason they have problems is that someone rolled their own XML "serializer" and didn't check for null strings.
In many implementations of whatever language, if you try to print a null string, you get the word "null" or some variation instead of a null access violation. So if you're happily making your XML by doing string formatting (ex: printf("<tag>%s</tag>", tagvalue) or equivalent), you get the word "null" in your XML.
I was on a project that was consuming XML from a public third-party database. Many string values in the XML were the literal "null". As in <tag>null</tag>.
My only recourse was to ignore anything with the value "null"...
Edit Admin
I had a case at work a while back where I was trying to check if a database entry had been overwritten to prevent a race condition. I had a date time stamp passed through from an application. But every time I tried to compare it to the entry in the DB it didn't mismatch. Turns out, the application, written in TypeScript, was concatenating the date time stamp when it turned it, and other values, into JSON.
Edit Admin
In addition to all the WTFs already mentioned, there's the WTF where we first append a comma and then check if the comma was needed in the first place, in which case we cut it out by taking a substring.
This code is just so delightfully wrong on every level. And it probably kind of works. Which is why I hate it.
Admin
What I hate most about this code is if you replace it to use the JsonSerializer it will probably break the application that consumes these files.
Edit Admin
What makes this even more WTF-y is that XML supports nulls for elements:
<tag xsi:nil="true"/>
. For attributes you're SOL, though. Well, I guess you could simply not output the attribute at all and hope the consuming code doesn't map those to empty strings.Admin
You laugh here, but I just yesterday converted similar JS code to use JSON library