ucd-username.wasm
I learned Go writing go-ucd which is nothing more than an embedded lookup table to convert Unicode characters to their English-language Unicode name. For example:
$> ./bin/ucd 🍦 SOFT ICE CREAM
Or:
$> ./bin/ucd 䍕 NET; WEB; NETWORK, NET FOR CATCHING RABBIT
Eventually, I wrote go-ucd-username
on top of go-ucd
to allow for meaningful "pretty"
URL-safe aliases for users with full Unicode usernames. For example:
./bin/ucd-username mr. 😁 mrgrinningfacewithsmilingeyes
For example, a user with the name Admiral
🍦
would have the pretty URL
/admiralsofticecream
rather than something like
/users/GSf653874tgsjBB7ZZqp0
. I still get a lot of blank stares when I tell people about
go-ucd-username
. You have to believe that the
semantics in URLs
are important and if you don't then I agree the whole thing is
a bit silly.
While it's true that an Internalized Resource Identifier (IRI) would allow you
to create an equivalent /Admiral%20🍦
URL it's still early days for IRIs meaning
browser support is uneven and there are a number of security concerns that
haven't been fully sorted yet.
The alternative is to strip out all the non-URL safe
characters from URLs which means if you have one user with the
name Bob
and another with the name Bob
🍦
and another still with the name
🍦 Bob
only one of them can have the pretty
URL /bob
.
go-ucd-username
side-steps all those issues and
allows for a better-than-nothing alternative. I make a point of using go-ucd-username
on any
website I run with user accounts. I don't expect many people
either know about it or benefit much from what it does but I like
the idea of accounting for tiny (but important) details like this.
There is nothing specific to the Go programming language
about go-ucd-username
. Go is very fast, has excellent Unicode support and allows you to create pre-compiled
binaries for a number of operating systems so you can write
tools that don't first require installing a bunch of other things
in order to start using them. Beyond that go-ucd-username
could be written in any modern programming language.
In the time since it was first written we've seen the
introduction of WebAssembly which the Mozilla
Developer Network describes as ...a way to run code written in
multiple languages on the web at near native speed, with client
apps running on the web
. One of those languages
is Go and the other day I wondered whether
go-ucd-username
would be a good way to kick the
tires and see how it all works.
Is it possible to call the ucd-username
functionality written in Go from JavaScript? Yes. Is it worth
downloading and executing a 6.3MB binary to do what could probably be
done in ~100 lines of native JavaScript? Probably
not. There are better
things to use WebAssembly for if only because the setup and
scaffolding required to do anything with it is a bit of a twisty
maze.
For example I spent the better part of 45 minutes trying to embed the exact same code that works just fine over here on this website but with no success:
https://aaronland.github.io/go-ucd-username/
I have no idea why it doesn't work because there's very little in the way of debugging and it fails with a different set of error conditions in Firefox than it does in Safari. But only on this website...
So, it's clearly all still wet paint
but it's good to
get a feel for what's possible.
This blog post is full of links.
#ucd-username-wasm