Branching Paths
"You submitted a pull request."
Indika was, in fact, reviewing the comments she'd gotten on that very same pull request, when her boss, Bill, walked up behind her. What she didn't understand is why Bill said it like it was an accusation.
"Yes?" she replied.
"Okay, well, we don't do that here. You're new, so I'll let it slide, but please review the developer guide."
Well, Indika had reviewed the developer guide, or at least thought she had. As it turned out, there was the official, company wide developer guide. That's the one she'd read. But Bill maintained his own, for his team. He hadn't ever told her about it, but apparently assumed she'd have the oracular blessings of Apollo and find it by herself.
It had this to say:
Branching is prohibited. Merging is a time wasting activity and goes against CI principles. Only use git to commit, push, and pull.
And rebase, presumably, if everyone was just committing on the main branch?
Indika asked one of her co-workers, Elise, over coffee: "Is this real?"
"Yeah," Elise said. "I'm not sure how he found out about your PR, I don't think anybody added him to the review. I mean, why would they?"
"Oh, I sent him the link," Indika said. "Just a whole, 'I'm new here, look at me doing the work!' type heads up."
"Oh yeah, definitely don't do that."
"So we do use PRs?"
Elise nodded. "Of course we do. We're not crazy. We just make sure Bill never finds out."
That seemed like a terrible way to work, but Indika went along with it, at least for a few weeks. Then an opportunity presented itself; she and Bill bumped into each other in the kitchenette grabbing coffee, and nobody else was around. At this point, Indika had already submitted a number of PRs without Bill knowing.
"Bill, I've been meaning to ask, what's your rationale for prohibiting branching?"
Bill loved being asked that question. "Well, well, it comes from twenty years of experience. What exactly does a branch get you?"
"A distinct history of changes that can be maintained and eventually merged in once a large unit of work has been done without disrupting other work that might be in flight?"
"Another point of conflict! A chance for the code you're working on to get stale. A chance to fall behind the rest of the team. Now, for a large open source team, with a lot of collaborators, a branch might make sense. I'm skeptical, but I can at least understand it. But for our internal team? It's just developers seeing a new toy and going, 'oh, shiny!'"
Indika sipped her coffee and went back to her desk. She was fortunate to have a window nearby, and looked at the squirrels playing in the branches of the tree.
[Advertisement] Plan Your .NET 9 Migration with ConfidenceYour journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!
CodeSOD: Public Private Partnership
Eric O was trawling through an API for handling concurrency, and found this little mismatch between the comment and the definition:
/// <summary> /// private Status, because while this object needs to be able to set the status, consumers should only be able to check it, lest everything break. /// </summary> public StatusType Status { get { return _status; } set { if (value != _status) { RaisePropertyChanged("Status"); } } }It's very important we make this property private, lest clients abuse it, and unleash dragons, chaos, and other potential horrors. Given that this happens inside of a concurrency API, I can only imagine what could go wrong when you mess this up. So sure, the comment makes sense.
The definition on the other hand, doesn't agree.
In practice, it's probably fine to do it this way, and at least the comment will show up in the documentation. If a consumer of the API misbehaves, they'll at least see that the docs suggest this is private.
The joke, of course, is the idea that the users of the API are going to read the docs, or care that one of the public methods suggests that it should be private.
.comment { border: none; } [Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.The Crossroads
-Leila
For a while I was stunned, staring at the email in front of me. I’d just told my boss I was quitting, refusing a promotion into my recently-deceased mentor Aggie’s shoes. Now, the new head of Human Resources wanted to see me.
Me? A Tech Support drone with one foot out the door? Well, she didn’t know that yet, did she?
Something in me feared where this might lead. But, Leila had stuck her neck out to rescue me from CEO Gibbs. She seemed like she cared about making things better. I decided to hear her out. Figured I owed her that much before I blew outta there for good in two weeks.
I had way too many hours to kill. Between whittling down my overstuffed inbox and resuming casework, it should’ve been easy to distract myself, but I couldn't focus on a single thing. I’d just done what had once seemed impossible. My brain wasn’t letting go of that any time soon.
Megan and Reynaldo also handed in their resignations. I got their messages confirming as much. We met up for lunch at a nearby restaurant and celebrated, but I was distracted. Amid the smiles and positive energy, the meeting with Leila was all I could think about. Should I mention it? I decided not to, not until I knew more.
I dreaded the afternoon slog now more than ever, but somehow, it slogged. When the clock’s hands finally crawled to 3:30, I threw on my coat and hat and darted out for one last smoke break. Then, it was time for C-Town.
Consumed with nervous energy, I shunned the elevator to race up the stairs floor by floor. Figured I’d burn off some stress, which could only help with whatever came next. Also figured I’d have a minute to recover in the vast executive lobby before finding my way to her office. Instead, I found Leila standing right there, every bit as polished as our surroundings. She faced me with surprise. “Hello.”
I tried to speak, laugh, something. Instead, I doubled over, coughing and gasping for air that felt all too thin up in nosebleed territory. While recovering, I couldn’t help but notice the gleaming tile beneath my feet, contrasting against my work shoes encrusted with sidewalk salt. Such details seldom crossed my mind, but the sort of people who worked up there lived and died for such details. Face flush, I cleared my throat one more time and righted myself, looking her way. “’Scuse me.”
“That was a long way up,” Leila remarked, gesturing behind herself. “I thought we could visit the observation deck. Would you like something to eat or drink first?”
Truth be told, I was already dying for another smoke. “No, that’s all right.”
“Follow me.”
She led the way through massive, quiet corridors to a small room with glass walls and ceiling. At this height, all one could see outside was a thick lead wall of fog. Leila strayed up to the far wall, a jewel against the void, and glanced back over her shoulder with chagrin. “I’m sorry, the view’s not very good today.”
“I dunno, I kinda like it.” Something about foggy weather had always intrigued me. With the normal world gone, it seemed like anything could happen.
She beckoned me closer with one hand. I strayed up next to her right side, staring out at the shrouded view.
“I understand you and Agatha Shaw were close,” Leila began quietly. “You have my deepest condolences.”
A two-ton anvil crashed onto my nerves. My fists clenched up at my sides. I worked so hard to hold back the flash-flood of grief that I couldn’t string words together. I only trusted myself to nod.
She glanced my way, hesitating. “Would it be better if we rescheduled?”
“I’m here,” I forced out. “Whatever you have to say, say it.”
She nodded. “First: while you were out of the office, I asked Francis Bronson to hand in his resignation.”
I drew a blank on the name, and blinked her way in confusion.
“The manager who nearly destroyed a printer with his hair dryer,” Leila explained, “after I’d just made a company-wide push for everyone to respect our office equipment.”
“Oh. Hothead!” My nickname for the guy. I’d worked that case a few weeks ago, but it felt more like years. Hothead worked in HR—at least, he had. After disarming him, I’d sent Leila an email, appealing for help against someone who clearly shouldn’t have been managing a supply cabinet, much less human beings. Well, she’d delivered. A warm note of satisfaction offered me a welcome lift out of grief. “Thanks. Really.”
Leila smiled. “We make a good team, I think. Which brings me to the other thing I wanted to discuss. Something new.”
My gaze fastened onto hers with a mix of intrigue and dread.
“You and I both know how badly this place needs to change. Let’s work together and actually fix things. I want to create a Change Management team and make you Team Lead.”
I was speechless, caught completely off-guard.
“The first thing we’d do is attack our company-wide leadership problem. Audits, surveys, hearings … eventually, a reorg. Along with simplifying the corporate structure, we’ll get rid of all the—Hothead, you called him? All the other Hotheads.”
“The biggest hothead is sitting at the top of the whole rotten pyramid,” I blurted. “He ain’t budging. He ain’t signing off on this, either!”
Leila was unfazed. “I think we could frame everything in a way that makes Mr. Gibbs like it. After all, we’re reducing payroll. We’re better positioning ourselves in a tough economic time. Worst-case, we could always use the three magic words: Google Did It.” She smirked.
I couldn’t help smirking back. Then I remembered what I’d done just a few hours earlier. “But I’m outta here. I quit! Put in my notice this morning!”
Leila nodded calmly. “Do you have a new position lined up somewhere else?”
“No. I'm going freelance with friends.”
“Friends who are leaving the company along with you?”
I nodded.
She paused for thought. “If you were to lead my Change Management team instead, you’d be able to recruit internally for your team. Whoever you think would be the most helpful. You’d set the agenda for whatever’s most important to address so that other good people don’t feel like they have to get away from here. All of this would mean a promotion to Director, with a salary and benefits to go with. And if you need more bereavement time, I could arrange an indefinite leave of absence until you feel ready to come back.”
The breath died in my throat. Had I suffered a stroke? I must’ve had a stroke. No, she really said it. She was on the level. I could change things. I could hire my friends to help me do it. A raise, full bennies, working with her every day?
Only a fool would refuse. And yet, my gut ached at the idea.
I stood there, frozen and mute, until I remembered something in my trench coat pocket: RD, the rubber duck I’d miraculously rescued from Aggie’s former office. I reached into my pocket and seized him in my fist.
RD? Aggie? I thought. Whoever’s listening. It all sounds amazing. I know she means it. But … it’s another trap, isn’t it? Staying in this joint for any reason means betraying myself. Betraying everything.
“Listen,” I finally said, “I’m flattered you even offered, but it ain’t right for me. Don’t give up on your idea! I’ve got friends here with ideas of their own for changing things. 32-hour work weeks. The end of free overtime. A union. I’ll send ’em your way. Offer them a spot on your team.”
Leila sighed. “A union would be an especially tough sell to Mr. Gibbs, but that really is a case where Google Did It. We might scare him so much with that idea that everything else would seem harmless in comparison.” She faced me with a sad smile. “A shame that we’re losing you. I was starting to learn some interesting things about printers.”
I’d miss her, too. And yet, I was feeling surprisingly great about my refusal.
“Make sure you file for unemployment,” she said. “We won’t stand in your way.”
I offered my hand. “Thanks for everything, Leila. Whenever it is they kick you outta here for good, come find me.”
She shook, sad smile persisting. “Maybe I will.”
I told Megan and Reynaldo about the new Change Management team. Made sure they knew the offer was on the table in case they preferred that over jumping ship. Both were quick to say no. Like me, they were too excited about our plans to stop now.
For the next couple of weeks, there was still plenty of work to be done: transferring my open tickets to other support reps and all that. But there was barely any time for it. Coworker after coworker stopped by my cube to express their surprise and wish me well in whatever came next.
“You’ll never be problem-free,” one of them advised me. “Go looking for the problems you want to have.”
I felt happier, freer, more determined than I had in ages. It was the conviction of knowing I’d stuck to my guns to do the right thing for myself.
Sanjay also jumped ship to join us. And there was one last surprise that came in the form of a phone call. The name on my work phone’s caller ID was DRACORA, P. So-called “Dracula!” Having a fairer opinion of her than most, I picked up without any sense of dread.
So-called “Dracula!” She hadn’t been so bad at all. Surprised, I picked up in a hurry.
“I’m so sad to hear you’re leaving!” she said. “What kind of freelance work are you doing?”
“All sorts of IT projects,” I replied. “Maybe some consulting on the side.”
“I have a friend who needs help setting up a website for her business. Is that something you could help her with?”
My eyes flew wide open in shock. “Sure!”
“I’ll put you in touch with one another.”
“That’d be swell. Thanks!”
We exchanged contact info. She promised to keep pointing friends our way whenever she could.
On my last day, I sent my personal contact information to my coworkers. I reminded them of Leila’s offer and urged them to keep me posted on their different causes. Then my friends and I walked out of a building that no longer had a hold over any of us.
It felt pretty damn swell.
Our accountant helped us incorporate RD IT Solutions. Only close friends knew it stood for “rubber duck.” The company covered medical and other relevant expenses for everyone. There was no hierarchy. Everyone had equal financial stakes and an equal say in company decisions.
After decades of being an expert at what I did, I was back at square one, learning the ropes. So much of what we had to learn for our business could only be learned through failure. Still, it felt rewarding to challenge my brain in new ways. The new gig let me wear lots of hats, from tech support to coding to business admin.
With no more regular paychecks, we had to tighten down our finances to what was critically important. We worked remotely at whatever times worked best for us, with the occasional meet-up at a public place or someone’s home. We all knew that any one of us having some kind of trouble could count on the rest of the group to help out as best as they could.
Megan quit smoking again. I cut way back myself. Wasn’t trying to, I just haven’t felt the need as much. Also stopped having those nightmares. It no longer feels like I’m living just for time off and weekends. I don’t spend my Sunday nights dreading Monday.
Dracula really did introduce us to our first client. It’s crazy what the universe puts out there when you go looking for it.
We met up remotely for our first client meeting to discuss requirements and expectations. When the topic of deliverables came up, our client scrunched her nose and interrupted Megan mid-sentence. “I don’t trust email! I’d rather you fax me the files.”
We were building a website for her.
“You mean, the source files?” Megan soldiered on bravely.
“Just fax me the codes,” the client said. “My nephew can re-type them into the Internet.”
She provided a fax number, fully expecting us to print out several hundred lines of code to send over. After deploying our first stab at a website that met her requirements, we did just that, mostly out of curiosity.
A few days later, she called us in a huff, saying her website looked like random letters. Her nephew had typed the code into Facebook.
FIN
Error'd: Time Wounds All Heels
Looked to the past for some time-traveling entries to round out a themed post. They're 25% fresh.
Robert apparently got a notification of a planned past delivery. It could be just a case of two systems that don't report different time zones, but even so, that's a wtf. Says he: "I just received an email from OnePlus this morning letting me know they have updated the planned delivery date for my order to Yesterday. I guess the delivery driver is going to time travel to get there on time since it still hasn't arrived. "
Kinkster Ypsilon Omega was really turned on by a time-traveling hottie who posted a photo an hour before joining. "(Heavily redacted screenshot.) Either Fetlife (a kink community website) is very welcoming to time travelers, or allows new members to upload their profile picture. Because time handling code surely never fails..."
ERIC P. shared a photo from 2023. "My 2008 Ford has suddenly time-warped 1024 weeks into the past. GPS date roll-over bug. No updated firmware available. No way to set the calendar manually. No way to turn off the date display."
Marc Würth "... just added a new RSS feed to my Netvibes dashboard (great tool otherwise, by the way). While it was still fetching the feed, it showed these peculiar crawling stats. Once fully loaded, it showed sane info, though." I'm curious about the specificity of 261 years.
Quite recently, an anonymous slightly flexed "Not only did I receive two parcels prior to the Roman conquest of Britain, but the date calculation for the combined notification has then failed and returned the Unix epoch." For those who missed the flex, dig Wikipedia: "Wardian London is considered to be the most expensive residential development in East London." I guess they can afford professional time travelers.
A More Civilized Age
Greta (previously) sends us more updates from her "Ancient Development Environment".
An important task an IDE must do is report build errors to its users. Arguably, that's one of the most important parts. I wouldn't know, I insist on building from the CLI all the time, because IDEs confuse and frighten me. I recognize I'm the weird one here, who is more comfortable in GDB than in a GUI debugger, but this isn't about me, it's about the IDE Greta is using.
It needs to display an error. Why does it need to display an error? Well, Greta hasn't figured that out yet. The error I'm about to show you doesn't really explain what happened or why or give any hint as to what needs to be done to fix it. To make matters more confusing, it doesn't happen consistently, so simply re-running the build could potentially fix it.
None of that is why we're here, though. What makes this a WTF is how the error is displayed:
Greta shares her bullet points about what she hates about this:
- It's a popup that happens arbitrarily during build, under unknown conditions
- It says nothing about what went wrong, or indeed if anything went wrong
- It's in a non-user-legible XHTML format. It shows the markup of this XHTML rather than it being rendered.
- It arguably shows the XHTML markup in the worst way possible: in a tree view (?!) with one row per source line
- The markup isn't even well-formed. I'll let you count the reasons why.
- The control used is from some sort of legacy windowing toolkit that doesn't support text anti-aliasing.
- The first button on the upper-left, "Get latest C++ Builder Direct headlines from the Internet", does nothing.
I'd honestly forgotten about the era when the Internet was still kinda novel so every application had a "push a button and go to our web page, and this somehow definitely won't just break when we change our URL structure in the future."
Greta adds:
For all of the hatred I harbour for this, the second button ("Information about C++ Builder Direct") brings up the following powerful dose of 90s nostalgia, so I can't stay mad:
CodeSOD: Connection State
Frederick A sends us a bit of null checking code, and offers us a better solution.
class ConferenceService { /// <summary> /// Checks if conference is active /// </summary> public bool IsCalling() { try { return m_ConnectionService.Core.State.IsWebRTCConnected; } catch { return false; } } }This is for a web conferencing tool, which uses WebRTC to set up connections between clients in the chat. This function checks if the chat is active by checking a IsWebRTCConnected flag. But as you can see in this code, that flag is on a long chain of objects, some of which may not exist when this function is called. Thus, we wrap the whole thing up in a try/catch. If anything throws an exception, we know we can just return false. It's probably fine.
The obvious and easy fix, which Frederick proposes, is to use the C# coalescing operator: ?. m_ConnectionService?.Core?.State?.IsWebRTCConnected ?? false would solve this problem just fine.
That said, I wouldn't say that's a true fix. We're talking about a state machine here, though admittedly with two states under discussion (connected/disconnected), though there are probably more not being checked here. This information should be managed via a state machine, not via boolean flags stuffed deep in an object chain. The fix isn't a WTF, but it definitely hints at a better way to manage all of this. Now, my solution likely requires a lot more modification and code changes than what we have here, so I'm not suggesting anyone go off and rewrite this from scratch just to have a cleaner way of managing state. But folks definitely should think more carefully about how they manage state.
.comment { border: none; }CodeSOD: Always Take the Option
Frequent submitter Capybara James sends us this simple snippet, which highlights that even when you have the lovely convenience of Optional types, you can use them wrong.
if (StringUtils.hasLength(dto.getAssetModelUUID()) // Other conditions ) { return Optional.ofNullable(dto); }We access the getAssetModelUUID member of dto, and if it's a non-empty string, we can then return a nullable of this thing that's definitely not null in the first place.
Okay, in the scheme of things, that's not that bad. All we're really doing is just not using the syntactic sugar that automatically boxes your dto into a nullable type. On it's own, it's not bad, just ugly. But like all things, it doesn't exist on its own. It exists inside of a giant pile of code where this pattern is used all the time. Even functions which don't return nullable types box (and unbox) the type. Optional is scattered through the code like a magic ward against null reference exceptions.
Does it help? No, not really, the code is buggy and error prone. Will it ever get fixed? Probably not in this lifetime.
Lose Some Padding
Flat-file style databases were designed to fit the constraints of the systems they were running on. You specify your schema in terms of "how many characters in a file we use to store this data", meaning something like this: JOHN SMITH 12343rd StAnytown PA12345 is read in my knowing that the first name field is 8 characters wide, the last name field is 8 characters wide, the street number is 4 digits, and so on.
It's also a terrible schema, and woe to anyone with a long name. But many a mainframe had a similar schema.
Now, let's think about maintenance here. What happens when we also want to store a middle initial? We've created for ourselves a problem. Somehow, I have to insert a character into every row, which basically means making a new table with a new schema, copying every record out of it and updating it to use the new schema. I can't just ALTER TABLE like an RDBMS. And worse, every piece of software that touches the table also needs to be updated. On a large legacy system, a simple task like "add a field to our database" could take weeks of developer time, and depending on the software, be a high risk operation.
Which is why the smart developer, when working with flat files, includes padding. Maybe my schema for an address record looks more like this: JOHN SMITH 12343rd StAnytown PA12345 . That's 16 characters of padding at the end of the file. Now somebody says that I need to store a middle initial, I can just shrink the padding by one and add a middle initial field, like so: JOHN SMITH 12343rd StAnytown PA12345Q
Is this elegant? No. But it works. I haven't changed the length of the row at all, so I don't need to move data around. Software modules only need to be updated if they care about what's in the middle initial field; if they're out of date, they just think there's a "Q" in the padding, and don't care.
In real-world applications, instead of putting all the padding at the end, you'd usually put the padding in a few spots in the middle of the table. Any time you need a new column, you just steal a few characters from padding. Sure, someday you'll run out of padding, or at least out of padding blocks big enough for your new field, and then you'll have to do the hard work of shuffling data around. But in practice, you can get very far without that happening.
Which brings us to Brenda's adventure. Her team supports an IBM mainframe storing data in VSAM flat files. In other words, they've been doing the sort of thing I just talked about for many, many years.
Of course, in the modern era, you can't just leave your data sitting in an mainframe. Even if the mainframe is the source of truth, you want to be able to report on it and connect it with your other data systems. You need to, somehow, get the data into a modern RDBMS.
So the company hired a bunch of developers to write an extract-transform-load process, which pulls the data out of the mainframe. The mainframe team handed them a "copybook" for the flat file, which described the structure, and the ETL devs went to work.
And maybe those ETL devs didn't understand the importance of padding. Maybe they just missed the padding. Whatever it was, there were several places where the data was structured like SOME_USEFUL_FIELD PADDING PADDING PADDING SOME_OTHER_FIELD, and they opted to split it like so: SOME_USEFUL_FIELD PADDING PAD, DING PADDING SOME_OTHER_FIELD.
When they released this process, it was fine. The padding characters got stripped before displaying, so the users never saw them. They were stored in the database, though, so when someone tried to reconstruct the data in a way that was compatible with the flat files, you could just concatenate the columns together and get a valid result.
It was fine- until it wasn't. The ETL devs, bless their hearts, only tested against the production mainframe. And why not, they were doing read only operations, what's the harm? Had they tested against the development mainframe, they would have seen new features in flight, features which consumed some of that padding, and realized that they should have paid closer attention to the copybook.
But instead, the test cases all passed. The software was, as far as the project managers and ETL developers could tell, working perfectly. So it was accepted, released to production, and running for a few weeks before the mainframe released its features. Those features then ruined all the beautiful reports with extraneous data.
And since the ETL devs were on contract, any request to have them rework it under the original contract was met with a stern "Works as designed". Instead of paying the contractors to come back and rework the system, the mainframe devs instead were tasked with finding different padding fields they could use, padding fields which wouldn't end up ruining any reports management liked to see.
Error'd: I Believe In Lingonberries
I've never been a huge fan of their furniture but I will happily demolish a plate of meatballs.
Jan agrees "My loyalty to this Swedish megastore is immeasurable."
"Choosing Concert Seats is Surprisingly Hard" for jeffphi who explains "While I have mixed feelings about indulging in nostalgia tours, I was curious to see seating options for this Rick Springfield concert. Turns out I *still* have questions!"
"Would you like to undo this unspecified problem?" richard H. rants "This came out of nowhere while composing an email. (I think I had just hit 'enter' to move to the next line.) Does anyone at Microsoft read these error dialogs before they ship it? Anyone? Is anyone at Microsoft forced to endure their own software?"
An anonymous fan of extinct charismatic megafauna complains "This is %{insult}"
Finally, and most seriously, merely pseudonymous WeaponizedFun has just highlighted for us that a true secret is something only one person knows. "Apparently, when OnSolve says "PROTECT YOUR USERNAME - NEVER give your username to anyone," this includes them not telling me what it is." See, if they told you, it wouldn't be a secret anymore.
[Advertisement] Plan Your .NET 9 Migration with Confidence
Your journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!
CodeSOD: Negative Days
Killian Brendel was looking through the .NET source code, and found this comment on the TimeSpan struct.
// TimeSpan represents a duration of time. A TimeSpan can be negative // or positive. // // TimeSpan is internally represented as a number of milliseconds. While // this maps well into units of time such as hours and days, any // periods longer than that aren't representable in a nice fashion. // For instance, a month can be between 28 and 31 days, while a year // can contain 365 or 364 days. A decade can have between 1 and 3 leapyears, // depending on when you map the TimeSpan into the calendar. This is why // we do not provide Years() or Months().Okay, a TimeSpan represents a duration of time. Makes sense. It can be negative or positive. Sure. It's a number of milliseconds. Okay, yeah. Other units of time get hard to represent that way, because months could have 28-31 days. Sure, yeah. I'm with you. And a year could contain 365 or 364 days, and a decade could have between 1 and 3 leapyears.
Wait, go back one. How long can a year be? I know negative leap seconds are going to be an issue, but negative leap days are gonna be way worse.
In the scheme of things, this isn't much more than a fat-finger typo. It doesn't impact the behavior of the class, which is why it's been sitting there since the initial commit, twelve years ago. The TimeSpan class itself hasn't been touched in that time, which also isn't much of a surprise, since it's really just a wrapper around a number of milliseconds. More complex date arithmetic, like AddMonths or AddYears is handled in the various date-time related objects.
So, is this a true WTF? Well, probably not. But it's interesting. Actually, the whole class is kind of interesting, as you can spot deprecated default constructors, as well as compile-time hooks for handling support for older versions of .NET including Silverlight, a technology that hasn't received an update since 2019, hasn't been supported in major browsers since 2015, and officially left support in 2021.
.comment { border: none; }Representative Line: Something Wonderful
Today, we look at a "representative comment" from Mark W. This particular comment appears on a function:
/// <summary> /// Does something wonderful. /// </summary>Well, I'm glad it's wonderful, but are we talking "Christmas magic" wonderful? Or sarcastically droll "Oh, how wonderful for you." wonderful? Tone doesn't get conveyed in text very well, so you've really got to be precise with your wording if you want us to get it.
Mark writes:
This comment is not really a 'representative' line; it exists in an otherwise very well written 100k+ line codebase.
Maybe it's not representative of the codebase as a whole, but it clearly represents this section of the codebase wonderfully.
.comment { border: none; }CodeSOD: Convert Back, Way Back
Windows Presentation Foundation, the XML-based UI framework for Windows, has its own "fun" quirks. One of its core ideas is that controls can be data-bound: that text box is linked to a numeric field in your model class. Type a different number, and the model automagically updates.
That's fine for what it is, but of course you're going to need to give it some instructions on how to do those kinds of conversions for your own custom types. And that's where the IValueConverter interface comes in.
You can write a class which implements that interface, which can then Convert and ConvertBack. Which, as a note, I hate that naming convention; which way is "back"? Well, that's controlled via an annotation. This is some of Microsoft's sample code, from their docs:
[ValueConversion(typeof(Color), typeof(SolidColorBrush))] public class ColorBrushConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { Color color = (Color)value; return new SolidColorBrush(color); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return null; } }I don't particularly like this API, but again, it is what it is. This converts a color into a brush, and returns a null when we try and convert back, because that's not a valid operation.
Which brings us to Fredrika's submission. You see, there is a problem with this approach. If you bind a text box to a double? field, everything is fine and handled automatically- except the built-in converter doesn't turn empty strings into nulls. So one of her co-workers wrote this:
public class StringToDoubleConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { double? parsed = value as double?; return parsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { string parsed = value as string; if (parsed == string.Empty) return null; return parsed; } }Convert doesn't do anything. ConvertBack takes the string from our text box, checks if it's empty, and if it is, returns null.
Now, you'll notice something about the code here: when it Converts, it casts value as double? and when it ConvertBacks, it casts value as string. So that's where it's reaching out to the .NET Framework's built-in conversion functions.
I'm not entirely sure where to point to for the WTF, and some of that may be because I've had the good fortune to never have to use WPF. I don't like WPF's approach, but the developer behind this code isn't helping matters. Certainly naming variables parsed isn't clarifying matters.
I don't have a nice bow to put on this one. I just don't like any of this. I don't like the converter API. I don't like this implementation of it. I don't like trying to treat empty text boxes as null values, which I'm sure is correct here, but boy howdy do I suspect there'll be problems in the future.
The Hard Goodbye
One minute, you’re fine. The next, you’re doubled over with tears spilling down your face while an aching black hole in your heart threatens to drag you into oblivion.
Grief’s funny like that.
Aggie Shaw, my old friend and mentor, had died of a sudden illness at home. She’d lived alone. Who found her? How? I didn’t know and never would. There was so much I’d never gotten a chance to tell her. She would’ve listened to me vent the frustrations and resentments I’d been burying over the years for sanity’s sake. She would’ve known what to do.
God, I missed her.
As if that weren’t bad enough, the brass expected Tech Support to go right back to business as usual. Maybe the rest of them wanted to bury their heads in casework. I didn’t. Between this, the horrible winter commute, and the promotion I’d never asked for, going back to the office felt impossible.
My boss wouldn’t let me use sick time. He really should’ve; the grief had hit me like a goddamn truck. Good thing the start of the new year a while back had refreshed my stack of paid time off. I started burning it from both ends.
When I wasn’t flat on my back or nursing a migraine, I was stumbling around my tiny apartment with half a brain cell, attending to the bare minimum of survival. Eat this. Drink that. Where’d I leave my smokes? In the rare times I could think, my thoughts were plagued with darkness. I didn’t know if I’d ever make it out of that mess.
Then, Megan called.
It was nearing noon that day. I was lying in bed, peering out my window at a dull gray sky and falling snow. I’d let everything else dump to voicemail, but when she rang, I answered with the urgency of a drowning victim grabbing a buoy.
“Hey,” she greeted, her voice subdued. “I heard about what happened. I’m really sorry.”
There was so much tumbling through my head, but none of it wanted to tumble out. “Thanks,” I managed.
“How are you?”
“Lousy.”
“Wanna meet up somewhere that isn’t work?” she asked. “The Apex Tower has a big indoor courtyard. I eat lunch there sometimes. If we go around 10 in the morning, we’d probably have it to ourselves.”
Something in me leapt at the offer. “I’d like that. Tomorrow?” I would still be on vacation-in-name-only.
“Sure,” Megan replied. “See you then!”
I had something to look forward to. Part of my emotional burden lifted right then and there.
It was a little easier to get out of bed the next morning. I took the bus to an unfamiliar spot of downtown, crossed a slush-covered plaza, and entered a skyscraper. The warm ground-floor courtyard boasted marble floors and immense windows for walls. Potted trees and flowers lined the perimeter. Huh, I’d forgotten those even existed.
Megan was already seated at a metal table flanked by two chairs. When she spotted me, she jumped to her feet and waved, a knowing and sympathetic look on her face. She waited until I reached the chair across from her to say, “You look like you could use a hug.”
I froze with surprise, one hand on my hat in the process of removing it. A hug? My puzzled brain tried to figure out just when I’d been hugged last. I had no idea. My body wasn’t waiting around for an answer. It was already turning toward her, arms raised.
Megan silently walked into my embrace and hugged back firmly.
Tears spilled down my face. My heart ached. And yet, another part of my invisible burden suddenly lifted. Something in me had been dying for this, for my pain to be seen.
“Thanks,” I muttered.
We parted. While I doffed my coat and hat, Megan returned to her chair, sitting back down across from me. “Whatever you need to get off your chest, go for it,” she offered.
I sat myself down, sniffled, blotted my eyes on my sleeve, then glanced high and low to confirm something I already knew: we were alone in that big empty joint. Still, I hesitated. At first, I wasn’t even sure I remembered how to string words together to form a sentence. But then it started gushing out of me like a busted water main. “You ever hear of rubber-duck debugging?”
Megan blinked. “No.”
Surprising. Most developers had, but she was fresh out of college. “A programmer came up with it way-back-when,” I explained. “Whenever you’re coding something and get real stuck on a bug or error, you find yourself a rubber duck. Go line by line in your code and explain to the duck, out loud, what you want the code to do. Eventually, you and the duck will find the point where your intentions and reality don’t match up.”
She smiled. “I like that.”
“Aggie had a rubber duck in her cube she called RD,” I continued. “Whenever she was stuck with a support issue or even a personal problem, didn’t know where to go next, she’d tell RD about it. He’d help her figure out what to do or ask next.
“When I first got hired, Aggie showed me the ropes. She always said, the best way to troubleshoot is to be the duck yourself. Get people, or hardware, or software to explain what they’re trying to do. You’ll figure out how to proceed.
“Some people are so upset at the problem that they take it out on the nearest target: the support rep who comes to help. Aggie could charm even the angriest people into cooperating with her. She was the best. She was the best, and all she got for her trouble was more work. Now that she’s no longer of any use to them, they’ve swept her under the rug. They want me to replace her!”
Megan’s eyes went wide.
“I’m no damn manager! I told my boss where to stick it. I’m riding out my PTO, and then hell if I know what’s next. I can’t go back there, I’d just be dying in place. And for what? So the bum at the top of the food chain can have a third yacht?” I leaned toward Megan, my gaze pleading with hers. “Look, I ain’t afraid of death. I’m afraid of dying before I’ve lived. I don’t want my only contribution to the world to be reimaging laptops and rescuing old printers. I can’t do it anymore. Can’t sit around complaining, either, I gotta do something! I gotta get the hell outta that joint!”
There it was: out in the open again, no longer whispered but shouted from the core of my being. Leaving was the right call for me. I felt it in my bones.
Megan held eye contact, blinking a few times. “I remember you saying you wanted to leave. If you did, what would you do?”
I’d never really let myself play with my little pipe dream. “I dunno exactly. But I’ve bought myself time to think it over. There are options, like going freelance.”
She blinked again. “Freelance tech support?”
“I majored in Computer Science back in school,” I said.
Her eyes went wide again. “Really?”
“Haven’t flexed those muscles in a while, but I could. Or I could get into something totally different. And you could come with.” Well aware of how unhappy she was at that joint, I sat up straighter in my chair. “We could start our own IT group. No bosses. Everyone an equal partner with an equal say in how things are run. And we could rope in anyone else who wants to come with!”
Megan seemed intrigued at first, but then sobered. “What about bills? Rent? Everything?”
“We could pool our resources and look out for each other,” I said. “That’d give us some time to get our feet under us.”
Her expression turned strained. “Aren’t you scared?”
“You bet I’m scared!” I glanced down at the table. “When I first got outta school, the idea of spending the whole rest of my life at a full-time job terrified me. But it seemed like everyone around me was fine with it. I thought I was the problem. Bit my lip, put my head down … for 20 years.” I glanced back up at her pleadingly. “Has it gotten any better? No. I’ve just gotten used to it. Another 20 years, and I won’t be any good for anything else. That’s if I make it that long! Aggie didn’t. Look, there’s no right or wrong answer, just what’s right for you. Listen to your gut. If you don’t like where you’re at, I’m living proof that staying the course is the wrong move. Leaving is risky … but so’s staying put, you know. The next round of layoffs could be right around the corner. You might get stuck babysitting that scheduling algorithm you were telling me about.”
Megan listened intently to my rant. Finally, she nodded. “You’re right. I’m not happy where I am, and it won’t get any better. Time to try something different.”
Still mired in grief, I had at least gained a new sense of purpose to keep me afloat in the storm. Megan went back to work like nothing had happened. With my remaining time off from work, I did some research into our options. Hunting around online turned up a highly-rated accountant who walked me through the bare-minimum corporate setup, the taxes and bookkeeping and all that. We both tracked down advice online from other freelancers who’d been where we were now. And we put out feelers among our coworkers. Our questions struck some nerves, but also stirred considerable interest. Reynaldo was in; we had ourselves a network guy. Sanjay, a backend developer, was a maybe who wanted more time to think it over.
There were plenty who wanted to join us badly, but couldn’t swing it due to debt, insurance, things like that. I urged them to think about one thing they could improve at work, one cause they could get behind. Whatever it was, I told them to start making it happen, one step at a time.
As my PTO bled away, I found myself half-exhilarated, half-scared outta my wits.
Finally, it was time to go back. That first morning seemed like any other, but with my secret purpose in mind, I sat on the bus and walked the bone-chilling streets with a secret strength hardening my spine. When the old joint appeared ahead of me, more foe than friend, I felt relief knowing our remaining time together was short.
Tech Support seemed no different; everyone was quietly minding their own business. I’d had plenty of time to think about what I’d do on the first day. My plan involved skipping my cube and heading straight to Aggie’s old office. After my talk with Megan, I’d decided to go looking for something. I had a snowball’s chance in hell of finding it, but something in me insisted on trying.
As I walked up to the closed front door, the first thing I noticed was my name, not hers, standing out in fresh, gleaming gold letters against the frosted glass. Pushing past revulsion, I grasped the doorknob and turned it.
The door gave way to darkness. I flipped the light switch with my other hand and found an empty desk, gutted shelves, bare walls. Looked like someone had come through with a giant trash can and thrown out whatever wasn’t bolted down. My revulsion intensified, but hey, at least I wasn’t trespassing. I shut the door to “my” office behind me and slowly approached the desk.
There was nothing to be found out in the open, not even a stray paperclip. I sat down hard in her old chair, reeling for a minute. Then I searched the desk drawers in front of me: first the bank on the left, then the right. Empty. I pulled out the drawer just under the desk—and there he was, swimming between a few stray pencils: a rubber duck about 3 inches tall. RD in the flesh.
It was as if Aggie had put him there for me to find. I couldn’t believe it. My spirits soared in a way they hadn’t for ages.
Just as I slipped the duck into my trench coat pocket, the door to her—my—office swung open again, making me freeze. There stood Bill, my boss.
“I saw the lights on in here.” A smug smile spread over his face. “I knew you’d be back. Bet it feels great, knowing you’re done babysitting all those morons and their computer equipment!”
Was that it? Twenty-odd years of my life boiled down into one cynical statement? No, there was more to it than that. For every bizarre war story, there were tales of grateful people helped, challenging problems solved. It hadn't been all bad. But it was over, just not the way Bill thought.
An electric mix of nerves and resolve jolted me to my feet. “I told you to find someone else, and I meant it. This is my two-week notice.”
I left Bill agape in that threshold and hurried back to my old cube, where my company-assigned laptop, docking station, and phone still resided. I hung up my coat, sank into my old chair, and booted up the machine. I had such a mountain of email in my inbox that I didn’t even want to look at it, but there was one message at the top that I absolutely couldn’t pry my eyes away from:
I moved some things around on my calendar. 4:00 PM today is open. Please come to the executive floor.
-Leila
To be continued ...
Error'd: The Song that Never Ends?
"Watch to the end", the scammers demand. In today's episode of Error'd, the end is a long time coming. But at least it's amusing. In the meantime, Amazon irked and/or terrified thousands of their customers last week by mailing out ridiculously inflated bills. It's been covered extensively elsewhere but why should we miss all the fun?
It was Willy who worried "Amazon prices seem to have crept up this month, finance are going to have something to say"
Dave A. is on the horns of a dilemma. "Is it optional or required? Make up your mind, TAP! I'm TAPping my fingers waiting for you to decide."
"This rating is through the roof!" exclaims a regular who wants to be Anonymous today. "We're done with linear rating scales. Now you can have 5 stars on both X and Y axes. Also, given this is for a company that cleans roofs, we can make a joke this rating is out of the roof, and out of the <div> as well. In case you're interested and in case you want take a screenshot yourself: https://mijndakschoon.nl/" It's real; I checked.
Richard H. found a flubstituted email. "Quickbooks here reminding me that I failed to pay invoice number "{{rand_invoice}" Or this might be a scam/phishing email. Hard to tell." I'll bet {{money}} on scam.
B.J. H. is usually quite concise. Usually. "If this is ALL NORMAL I'm worried what will happen in an emergency"
[Advertisement] Plan Your .NET 9 Migration with Confidence
Your journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!
Classic WTF: My Many Girlfriends
In the long ago, wild-west days of the late 90s, there was an expectation that managers would put up with a certain degree of eccentricity from their software developers. The IT and software boom was still new, people didn't quite know what worked and what didn't, the "nerds had conquered the Earth" and managers just had to roll with this reality. So when Barry D gave the okay to hire Sten, who came with glowing recommendations from his previous employers, Barry and his team were ready to deal with eccentricities.
Of course, on the first day, building services came to Barry with some concerns about Sten's requests for his workspace. No natural light. No ventilation ducts that couldn't be closed. And then the co-workers who had interacted with Sten expressed their concerns.
During the hiring process, Sten had come off as a bit odd, but this seemed unusual. So Barry descended the stairs into the basement, to find Sten's office, hidden between a janitorial closet and the breaker box for the building. Barry knocked on the door.
"Sten awaits you. Enter."
Barry entered, and found Sten precariously perched on an office chair, removing several of the fluorescent bulbs from the ceiling fixture. The already dark space was downright cave-like with Sten's twilight lighting arrangement. "He welcomes you," Sten said.
"Uh, yeah, hi. I'm Barry, I'm working on the Netware 3.x portion of the product, and Carl just wanted me to check in. Everything okay?
"This is acceptable to Sten," Sten said, gesturing at the dim office as he descended from the chair. Sten's watched beeped on the hour, and Sten carefully placed the fluorescent bulb off to the side, in a stack of similarly removed bulbs, and then went to his desk. In rapid succession, he popped open a few pill containers- 5000mg of vitamin C, a handful of herbal and homeopathic pills- and gulped them down. He then washed the pills down with a tea that smelled like a mixture of kombucha and a dead raccoon buried in a dumpster.
"He is pleased to meet you," Sten said, with a friendly nod. Barry blinked, trying to track the conversation. "And he is pleased with it, and has made great progress on building it. You will like his things, yes?"
"Uh… yes?"
"He is pleased, and I hope you can go to him and tell him that he is pleased with this, and set his mind at ease about Sten."
So it went with Sten. He strictly referred to himself in the third person. He frequently spoke in sentences with nothing but pronouns, and frequently reused the same pronoun to refer to different people. The vagueness was confounding, but Sten's skill was in Netware 2.x- a rare and difficult set of skills to find. So long as the code was clear, everything would be fine.
Everything was not fine. While Sten's code didn't have the empty vagueness of unclear pronouns, it also didn't have the clarity of meaningful variable names. Every variable and every method name was given a female first name. "Each of these is named for one of Sten's girlfriends." Given the number of names required, it was improbable that these were real girlfriends, but Sten gave no hint about this being fiction.
There was some consistency about the names. Instead of i, j, and k loop variables, you had Ingrid, Jane, and Katy. Zaria seemed to be only used as a parameter to methods. Karla seemed to be a temporary variable to hold intermediate results. None of these conventions were documented, obviously, and getting Sten to explain them was an exercise in confusion.
It led to some entertaining code reviews. "Michelle here talks to Nancy about Francine, and then Ingrid goes through Francine's purse to find Stacy." This described a method (Michelle) which called another method (Nancy), passing an array (Francine). Nancy iterates across the array (using Ingrid), to find a specific entry in the array (Stacy).
Sten lasted a few weeks at the job. It wasn't a very successful period of time for anyone. Peculiarities aside, the final straw wasn't the odd personal habits or the strange coding conventions- Sten just couldn't produce working code quickly enough to keep up with the rest of the team. Sten had to be let go.
A few weeks later, Barry got a call from a hiring manager at Initrode. Sten had applied, and they were checking the reference. "Yes, Sten worked here," Barry confirmed. After a moment's thought, he added, "I suggest that you bring him in for a second interview, and have him walk you through some code that he's written."
A few weeks after that, Barry got a gift basket from the manager at Initrode.
Thanks for the tip
Sten did not get hired at Initrode.
[Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.Classic WTF: Server Room Fans and More Fun
"It's that time of year again," Robert Rossegger wrote, "you know, when the underpowered air conditioner just can't cope with the non-winter weather? Fortunately, we have a solution for that... and all we need to do is just keep an extra eye on people walking near the (completely ajar) server room door."
"For as long as anyone can remember," Mike E wrote, "the fax machine in one particular office was a bit spotty whenever it was wet out. After having the telco test the lines from the DMARC to the office, I replaced the hardware, looked for water leaks all along the run, and found precisely nothing. The telco disavowed all responsibility, so the best solution I could offer was to tell the users affected by this to look out the window and, if raining, go to another fax machine."
"One day, we had the telco out adding a T1 and they had the cap off of the vault where our cables come in to the building. Being curious by nature, I wandered over when nobody was around and wound up taking this picture. After emailing same to the district manager of the telco, suddenly we had the truck out for an extra day (accompanied by one very sullen technician) and the fax machine worked perfectly from then on."
"I found this when I came back in to work after some time off," writes Sam Nicholson, "that drive is actually earmarked for 'off-site backup'. Also, this is what passes for a server rack at this particular software company. Yes, it's made of wood."
"Some people use 'proper electrical wiring'," writes Mike, "others use 'extension cords'. We, on the other hand, apparently do this."
"I was staying at a hotel in Manhattan and somehow took a wrong turn and wound up in the stairwell," wrote Dan, "not only is all their equipment in a public place (without even a door), it's mostly hanging from cables in several places."
"I spotted this in China," writes Matt, "This poor switch was bolted to a column in the middle of some metal shop about 4m above ground. There were many more curious things, but I decided to keep a low profile and stop taking pictures."
CodeSOD: Classic WTF: Fork and Log
A few years back, Adam C. was brought in to help with some performance problems that appeared while load testing a VXML Platform. The project was already well behind and they couldn't figure out why the system kept falling over under a very slight load. To make matters worse, Adam had absolutely no prior knowledge of the system or its software other than Wikipedia’s definition of what VXML is.
A veteran to these sorts of situations, Adam grabbed a coffee, a donut, and then started picking through the application logs to get a feel for what the system is doing and where something might be going wrong.
Looking in /var/log/messages, he was pleased to find with several days’ worth of messages, but over and over again, the same entry popped up:
Exception encountered writing error log."Seriously, who logs an error that they can't log an error? ...and is that even possible?" Adam wondered aloud after seeing the same senseless message for what he figured to be the hundredth time.
Frustrated, and hoping to learn what ludicrous conditions might precipitate a log to contain such a message, Adam dug into the source and hit paydirt in the form of this wonderful nugget of code:
public void error(String logID, String errStr) { StringBuffer errLogCmd = new StringBuffer("/usr/bin/logger -p "); try { Runtime rt = Runtime.getRuntime(); errLogCmd.append(errlogFacility); errLogCmd.append(" -t "); errLogCmd.append(logID); errLogCmd.append(" "); errLogCmd.append(errStr); rt.exec(errLogCmd.toString()); } catch (Exception ele) { System.out.println("Exception encountered writing error log." + ele.getMessage()); } } As he mentally parsed his way through the code, Adam could feel his breakfast tickling up from the back of his throat in reaction to the number of WTF’s he found himself facing.He couldn’t decide what about the implementation was worse - forking off an external process to log something, the fact that log4j could have been used to send stuff to syslog (which the project used elsewhere), or that since the program's output was already piped to /usr/bin/log, just doing a System.out.println() would have been equivalent to this code.
As it turned out, this wasn’t the root cause behind the performance problems, but needless to say, that code got junked rather quickly and he moved on to looking for the next performance bottleneck.
[Advertisement] Plan Your .NET 9 Migration with ConfidenceYour journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!
CodeSOD: Classic WTF: The Table Selector
"In my native language of German," writes Christian, "the word quellcode is a pretty direct translation of 'source code'."
"Unfortunately, bad code seems to cross language barriers - as does that famous three-letter explicit adjective. But occasionally I’ll find a piece of quellcode that deserves its own special, localized expletive: quäl-kot. When I stumbled across this interface in our quellcode, quäl-kot was the first thing that came to my mind."
public interface ITableSelector { string selectTable1(); string selectTable2(); string selectTable3(); string selectTable4a(); string selectTable4b(); string selectTable5(); string selectTable6(); string selectTable7a(); string selectTable7b(); string selectTable8(); string selectTable9a(); string selectTable9b(); string selectTable10(); string selectTable11(); string selectTable12(); string selectTable13(); string selectTable14a(); string selectTable14b(); string selectTable14c(); string selectTable14d(); string selectTable15(); string selectTable16(); string selectTable17(); string selectTable18(); string selectTable19(); string selectTable20(); string selectTable21a(); string selectTable21b(); string selectTable22(); string selectTable23(); string selectTable24(); string selectTable25(); string selectTable26(); string selectTable27(); string selectTable28(); string selectTable29(); string selectTable30(); string selectTable31(); } [Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.Error'd: Princess Pricing
Sam suggests this Error'd indicates "Disney+ preparing the ground for usage-based billing." I'm intrigued by the idea that Disney might charge by the minute, but I suspect the reality is far more mundane.
Silly prices at online shopping sites don't usually make it through the gauntlet here, but I'm making an exception for the math, as Rob H. points out "it ain't mathin'."
and Harrison suggests a novel kind of discounting math "I went to the supermarket later at night for some beers, and had a snoop around the yellow sticker items for anything I might need or could freeze. This bakery item was priced in reverse, Was: 0.00, Now 1.99, discounted by negative infinity percent, and infinity is even printed upside down somehow."
We've got a mojibake from dragoncoder047: "Was browsing through the widget options on my iPhone home screen and found that Game Center had decided to do this. Mind you, my iPhone was, and always had been, set to English."
Finally a combination of typical time travel and package tracker shenanigans, not explained by time zone hijinks. Evelyn notes "Apparently the package was registered in July, on its way during January, and then got back to July."
CodeSOD: Wait Longer
Karen was maintaining some specification tests that were flaky. Not extremely flaky, but three or four times out of a thousand, the tests would just fail. The tests were complicated, and some of the operations were timing sensitive, so it wasn't precisely surprising- but the problem was that they were actually generous with their timing windows. The unit tests passed consistently, it was only these functional, specification-based tests that failed.
So, for example, there were sections in the tests where they wanted to wait at least 2ms. Since the code and tests were in TypeScript, they used the setTimeout function, which per standard JavaScript documentation warns that it may wait longer. But again, Karen was fine with longer.
Unfortunately for Karen, the documentation for NodeJS is less specific, as it makes no guarantees about when the timeout function gets invoked. This means that it can fire the timeout before the time has elapsed.
After many, many hours of debugging, that was exactly the situation that Karen found herself in. Which is why her very simple wait function went from:
export const wait = (ms:number) => new Promise((complete) => setTimeout(complete, ms));To the much more awkward:
export const wait = (ms: number) { const target = performance.now() + ms; return new Promise((complete) => { const checkReady = () => { if (performance.now() > target) { complete(); } else { setTimeout(checkReady, 1); } } setTimeout(checkReady, 1); }); }This version of the function checks the time every millisecond, and only completes the operation if we've waited at least as long as our target duration. This ensures that the timeout never fires too soon and it fixes the janky tests. But it's also terrible. Terrible that it exists. Terrible that this is the best solution. Terrible that our functional tests need to be so time sensitive. And terrible that the Node runtime actually breaks the one consistent scheduling guarantee that pretty much every other scheduler does: that it'll wait at least as long as you asked, but might wait much longer.
At best, we can say, "at least it's only testing code."
[Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.