I doth whip mine hair to the aft and to the fore.
46 stories
·
1 follower

Silly Hats Only

1 Comment
comic: 

This tactic did *intensely* amplify the surprise factor.

Read the whole story
Share this story
Delete
1 public comment
Groxx
59 days ago
reply
Taking surprise parties to the next level
Silicon Valley, CA

Moore's Hierarchy of Needs

1 Comment and 2 Shares
comic: 

We moved so many times for awhile... moving sucks :(

Read the whole story
denubis
80 days ago
reply
Sydney, Australia
Share this story
Delete
1 public comment
Groxx
79 days ago
reply
it me
Silicon Valley, CA

I want off Mr. Golang's Wild Ride

1 Comment
My honeymoon with the Go language is extremely over. This article is going to have a different tone from what I've been posting the past year - it's a proper rant. And I always feel bad writing those, because, inevitably, it discusses things a lot of people have been working very hard on. In spite of that, here we are. Having invested thousands of hours into the language, and implemented several critical (to my employer) pieces of infrastructure with it, I wish I hadn't.
Read the whole story
Share this story
Delete
1 public comment
Groxx
92 days ago
reply
I cannot possibly agree more. Go is a weird sort of drunken living nightmare if you try to do anything carefully.
Silicon Valley, CA

๐ŸŒŸ๐ŸŒŸ๐ŸŒŸNew comic!๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ

1 Comment


๐ŸŒŸ๐ŸŒŸ๐ŸŒŸNew comic!๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ

Read the whole story
Share this story
Delete
1 public comment
Groxx
97 days ago
reply
So accurate, it's beyond our ability to measure.
Silicon Valley, CA

Need a Magic Constant? Choose Something Obscure

1 Comment

We all have various constants in our code, whether they are integers for use with startActivityForResult(), strings for Logcat tags, and so forth. Most of these are internal to our code and do not affect others.

Sometimes, though, we have an API that we expose that others might call, where certain parameters are up to the callerโ€ฆ except for some magic constants. For example, you might have a key/value data store, where you want to reserve some keys for your internal use, but others can stuff whatever they want into that data store using their own choices of keys. Those reserved keys are magic constants.

(IMHO, try to avoid such APIs, keeping your internal data separate so there is no chance of a key collisionโ€ฆ but sometimes this API structure is unavoidable)

So, the caller of your API can choose any value for their keys, except certain magic constants. In that case:

  • Practice defensive programming and validate that a caller-supplied key is not one of your magic constants,

  • Document what the magic constants are, and

  • Choose obscure values

When it comes to NotificationChannel, we got two out of the three.

NotificationChannel has a DEFAULT_CHANNEL_ID constant. This is a magic constant, as you cannot use it as the ID of your own channel. If you try, you get a somewhat cryptic stack trace. But, that stack trace is because of the defensive programming, so thatโ€™s good. And the magic constant is documented, at least to an extent.

However, the value of DEFAULT_CHANNEL_ID is "miscellaneous".

Thatโ€™s a reasonably common English word, one that somebody might well choose without noticing that it is not an eligible value.

Particularly with strings, you have a near-infinite space to choose magic constants from. So, it is easy to choose a magic constant that is unlikely to collide with any value that others might choose:

  • Use a UUID

  • Use a passphrase generated by diceware

  • Use a series of digits from a random number generator

  • And so on

Even if memory use is a consideration, it would be better to choose a random six-digit number than to use a common word. There are lots of obscure values that we could use that are shorter than "miscellaneous".

After all, neither the compiler nor the OS really cares about the actual value. Your own code does not care about the individual characters inside of the magic constant. It just needs to know that it can look up things using that magic constant and get what it expects.

Magic constants are part of your API and they need to be designed along with the rest of the API. Itโ€™s just that whereas normally you want things to be human-readable, this is one case where you do not. Or, at the very least, choose a less-common human-readable word, such as "axolotl".

(NOTE: no actual axolotls were harmed in the creation of this blog post)

Read the whole story
Share this story
Delete
1 public comment
Groxx
319 days ago
reply
even better:
misc-[uuid]

human friendly and collision-"impossible".

I've done this before - it's handy. You can probably guess at the meaning, and you can search *the whole internet* for that UUID and get only relevant results. I'm not sure if there's any downside, aside from an insignificant increase in binary/log size.
Silicon Valley, CA

meCUP

1 Comment

 

meCUP.jpg

..Right?



Read the whole story
Share this story
Delete
1 public comment
Groxx
491 days ago
reply
Bluetooth audio is as much of a nightmare as USB-C audio. Noooo thank you.
Silicon Valley, CA
Next Page of Stories