Tuesday, April 25, 2023

USB-C and the plague of grackles

Everyone knows "universal" USB-C cables are a hot mess -- different power and data speed ratings, charge-only cables, Thunderbolt or DisplayPort over USB-C, wave after wave of logo grawlix.
But at least we knew that the problem of which way do we plug it in was solved. USB-C cables were bidirectional and flippable, no sweat. Right?
Last week I bought a couple of USB-C cables:
Two USB-C cables with tags.
The tag says:
If you hook up a USB-C 2.0 peripheral to this USB-C3.2 extension cable and it doesn't work as you expected, flip the connector over and try once more. It happens as a result of the compatibility issue of USB-C protocols and you need to connect a USB-C 2.0 peripheral to a USB-C 3.2 port in a specific direction.
(The other cable has the same tag, except it's "...to this USB-C 3.1 extension cable" rather than "3.2".)
I twooted that photo and man, did people have a lot to say about it.

To be clear, these aren't regular USB-C cables. These are extension cables -- that is, male-to-female. That's where the trouble starts.
I suppose I should explain how I record-scratched here. It's simple enough: I use an iMac. The iMac has no front ports. Plugging my USB security key into the back of an iMac is a pain in the, um, backside. My USB keyboard has side ports, but they're recessed in such a way that the security key can't be used with them.
Fine, I said, I'll just buy this nice USB-C multiport hub and solve my problem. So I did. But the hub's built-in cable is six inches long! With my iMac up on a stand (I'm tall), its ports are seven inches above the desk.
This is not an acceptable solution.

(Yes, my computer stand is a Red Hat Linux reference manual. RH 5.2 if you must know. "My Mac runs on Linux!" is now a 25-year-old joke, and nobody's laughed once.)
So, long cable story short, I need a USB extension cable.
(Or I could buy the hub I've got, but with a 12" cable instead of a 6" cable. That would be in spec! But Belkin doesn't offer that option.)

The first thing I learn is that there's no such thing as a USB-C extension cable. The standard doesn't allow for it.
Or at least I think that's true? Several people in the Mastodon thread told me it was true. But of course I found that out after buying two of them! There's scads of extensions and adapters and gender-changers on the market. I have no problem believing that they're all dodgy, but how dodgy? Shrug.
I realize that we're years past the point of "just make the wires longer". Cables are micro-hubs these days; they have to negotiate all those power and data options with the host computer. I appreciate that they don't burst into flame, I really do.
Still, those warning tags are gibberish. Nobody cares about the difference between USB-C 2 and USB-C 3.1 and USB-C 3.2. People want to plug things in and they work. Once you say "You have to flip the cable in this specific situation," it doesn't matter what the situation is or how dodgy the connectors are. People just learn that USB-C sometimes doesn't work until you flip the cable, which means we're going to spend the rest of our lives unplugging and flipping cables to see if that fixes the problem.
However, TLDR, if you don't own a male-to-female USB-C cable you can skip this entire post. The "regular" male-to-male cables have no polarity issues. I think.
By the way, the warning was absolutely true. I plugged in the extension cable, and then I shoved my security key in the other end, and nothing happened. I pulled out the key and flipped it over, and that fixed the problem. My soul died that day, on schedule.

When I did the original twoot, I twitted EU regulators for mandating USB-C connectors.
Cause: EU regulators move to force everybody to standardize on USB-C.
Effect: USB-C starts to lose the features that made it minimally acceptable in the first place.
That was a joke. There is no cause-effect relationship. But this does underscore the basic annoyance of legislating technical standards, which is that legislation can't keep up with the technology. The standard can barely keep up with the technology! Look at this mess!
The ostensible point of the EU regulation is to simplify the confusion of chargers and cables and ports, but USB-C is a confusion of chargers and cables and ports. It's never going to be anything else -- unless USB-D sorts it out, but now there will never be a USB-D. All future USB specs will be called "USB-C". This is not a benefit.
But I feel like mandating a technical standard isn't just an error; it's a category error.
People think "Oh, a technical standard is a set of rules, and governments can make rules." But this is wrong! I've been involved with a lot of technical standards. Okay, standards about IF virtual machines, which are not very important in this big old world. But I know how the process runs.
A technical standard is an agreement about how to divvy up the bug reports. That's all it is! I plug in the stupid security key, and it doesn't work, so whose fault is that? The key's fault, the cable's fault, the iMac's fault, my fault? Whose responsibility is it to fix the problem? That's as far as the spec takes you.
If you think that a spec is a set of rules, then you have to respond to my dilemma by saying "That cable is against the law." Which is patently silly, but in fact several people said that to me!
I believe (I'm pretty sure) that the cable is a violation of the spec. Not because the manufacturer is incompetent, though. You can't make a male-to-female USB-C cable that works in all situations, because the agreements on How This Works are messy and full of compromises and they started with the idea that nobody would do this.
But people want these cables anyway! The spec can't make them not! Well, here we are with another compromise. Hey, the cable works in most situations. It's just this USB-C 2.0 compatibility blah blah corner case.

Oh, sure, there are lots of technical standards which are subject to government regulation. The wiring of electrical outlets -- buckets of legal requirements. Why? Because the bug reports go "My sister stuck a paper clip in the electrical outlet and fried herself like a pickle." This bug report is a wrongful death lawsuit! Of course the government is involved.
(I once did catch my sister sticking a paper clip in the electrical outlet. I think she was seven. Sorry, M__. I remember thinking "She's not dead, so that must be the cold side" very quickly before I yanked it out and shouted "No!" It was the cold side.)
Anyway, I suppose there could be a lawsuit over USB-C extension cables that you have to flip over to work right, but it won't be a very interesting one.
If I tried to recharge my phone through this extension cable, it might go really badly. That's where the micro-hub power-rate negotiation comes into play. Flames, headlines, interesting lawsuit, etc. I plan to not find out.

Oh, right, the grackles? Just an image. You see a spec as an infallible stone tablet handed down by the authorities. I see it as a flock of grackles flapping around screaming at each other. If everything is okay, they all settle down and peck at seeds and bugs in some kind of neighborly order. If not, they'll have to work it out.
A flock of grackles is called a "plague", but that's not their fault.

Saturday, April 1, 2023

Hadean Lands source code

I said I'd do it, so here it is: the complete source code for Hadean Lands. Also, as a bonus, the test scripts I used while developing the game.
Do I need to say "spoiler warning"? I figure most readers of this blog have already played Hadean Lands, but if you're arriving late, then, you know -- spoilers. The code makes everything apparent. The test scripts constitute a walkthrough, too.
Note that I've formatted the source code for browsing, not compiling. It's a pain in the butt to compile (requires a very old version of Inform 7) and I'm not looking for patches or bug fixes. This is purely to satisfy people's curiosity. I've used my usual game source license: The game, story, and prose belong to me. You're welcome to make use of the programming concepts or the Inform code if that's helpful to you.

This is a contribution to IF Source Code Amnesty Day. Join in! Dig up your old IF game code and post it on Github or the IF Archive or wherever. Doesn't matter how janky or hacky or poorly formatted it is. (That's the "amnesty" part.) Future scholars may be interested.
In particular, if you wrote a room of Cragne Manor, drop me a line. I can add the source code to the Cragne source collection.
(This collection is an unofficial effort among Cragnites who want to participate. Ryan and Jenni aren't asking, and I haven't solicited any source code from them. It's just between you and me.)