Quoting property names in JavaScript

JavaScript is relatively lax when it comes to valid object syntax. Property names can be quoted or unquoted in most circumstances. These two examples are identical.

 

I’ve noticed recently that I’ve developed my own quoting style at some point that seems to be rather uncommon so I decided to finally share it and why I’ve come to use it. I’m sure I’m not the first, nor will I be the last to come up with this system but it’s probably worth a blogpost anyway.

A lot of the time in my job I find myself having to work with JavaScript objects derived from JSON (or JSON Schema). Functions consume them, or construct them, and output a modified version of them based on user input. These objects have very strict rules over what properties they can have, but certain property keys are user configurable (In JSON Schema, these are ‘additional properties’.

NB: By user input here I mean any input into your function. It could be user input, or it could be input from an external component that interfaces with your functions in some manner.
 

Consider the following example JSON Schema where quoted property names are never used.

The same example, but this time with every property name is quoted

 

Now tell me. At a glance is it obvious which property names are open to manipulation by the user, rather than being a schema-defined name from the schema (in this case JSON Schema)? At a glance, what is the type of the somethingElse property under filed?

Contrast that with the following example, where I quote fields as I would under my system.

 

To me it makes it much clearer which properties the user chose, and also makes it easier to visually navigate eg if this is in a test file and I need to update a particular fields type to reflect new behavior, because syntax highlighting now colors them differently.

This example happened to be an instance of JSON Schema, but I feel this technique works equally well for any object where the user can control the structure of the object, as opposed to just the content. Every object your code is working with will have some structure to it.

More generally I guess I’d phrase this as quoting significant property names, or ‘Significant Quoting’ as opposed to always quoting or never quoting.

Obviously there’s a couple of drawbacks in representing objects this way in test files. JavaScript quoting rules are somewhat complex, and so mandating a property name be quoted or not sometimes has to depend on the name itself rather than the source of the property name. The other drawback is that there is no linting rule I’m aware of to enforce this. Which, as an advocate of automated rule enforcement and correction, bugs me. A linting system to enforce this could probably be devised with enough investment and time defining typescript style rules or annotations for the objects you work with.

Despite those drawbacks though, I really do feel that in code and especially in test files, this quoting system can make it much easier and quicker to comprehend the structure and navigate down a complex object.

Questions on the Bethesda reselling drama

For context the drama I’m referring to is described over in this polygon article. It’s been updated a couple of times since original publication so you may not have read the most recent version.

A brief summary however is that a firm that’s been hired by Bethesda demanded that a third-party amazon seller take down their listing for a still-sealed game that they no longer wanted and had listed as being ‘new’. The reasoning given by the firm is that they are an unauthorised seller, and thus it comes without a [manufacturer] warranty (I assume this is because the warranty only applies when bought through an authorised retailer). This, they claim, creates a material difference which means that first-sale doctrine (remembering we’re talking about the US here) does not apply. Notably they are not, as far as we can tell, going after products listed as ‘used’. Presumably because if it’s listed as used that makes clear that any manufacturer warranty likely wouldn’t apply.

Now with the background set this raises some interesting (to me) questions.

Is new an accurate description of the product in this case?

Does it being listed as new imply that it comes with a manufacturer warranty?

Should a manufacturer warranty be able to be limited to just purchases through an authorised seller; bearing in mind in this case it’s unopened unused software and thus should be in factory-perfect condition.

Let’s imagine this wasn’t a marketplace order (which afaik is never the default shown seller, but instead a formal business who can be the default seller).

Would a consumer know it’s an unauthorised seller? As it was listed on amazon, amazon might default to showing this seller depending on their Algorithms, when a consumer searches for the game. The only indication would be they ‘sold by’ tagline.

What about if this merchant uses Fulfilled by Amazon, so the seller ships goods to an amazon warehouse and then when it sells it ships from an amazon warehouse (which means Prime delivery /shipping fees for the consumer)? This seems straightforward until you remember than Amazon will commingle inventory from different sellers, including their own.

(Slight segue: what this means is that if Amazon, Seller A and Seller B all sell Widget X; Amazon will put their own inventory and inventory shipped to them by Seller A and Seller B all in the same bins. When you buy Widget X ‘sold by Seller A Shipped by Amazon’; you might get the Widget X that Seller A shipped in to amazon, or one that Seller B shipped in, or even one Amazon themselves directly received. Sellers can opt-out of commingling like this – but it involves paying amazon more money)

In this commingled case someone may have bought a copy ‘sold by Amazon’ and that will be printed on their receipt, and presumably entitled to the manufacturer warranty with Amazon being an authorised seller… but they might actually receive a copy stocked into an amazon warehouse by an unauthorised seller (who, for instance, may have bought their copies in bulk in a sale, and then listed them once the sale ended at a small markup on the sale price below the current non-sale price). Does this matter? Does it even make sense when commingling is involved to have a concept of ‘authorised sellers’?

I ask these questions because the discussion around this seems to be getting caught up in the implications for selling used copies – which is, to me, a much less interesting discussion given that this case is specifically around something being sold as ‘new’.

The hollow cuboid

An image of the Enclosure sculpture

Enclosure – Paul de Monchaux. The inspiration for this piece

The structure appeared one day.

You might expect that no one paid much attention to it, that they believed it to just be another art installation in a city park.

But people noticed. It wasn’t an art installation. At least, not one sanctioned by the local administration. Not the national one for that matter. And the international bodies didn’t concern themselves with art. Usually….

The first person to see it in the early hours of the morning on their bike to work noticed The Quieting.

Approaching the frame, they realised they could no longer hear the sound of their bike on the path. The sound of the wind in the leaves. But they were running late to take over their shift and so onwards they peddled, putting it out of their mind. Or trying to.

As news spread of The Quieting the military was mobilised. You could hear them coming with their loud rattling Jeeps… so long as you weren’t in The Zone.

They came with their devices and their guns – not being sure what to make of it. Enquiries were being made to determine where it came from.

The first thing their devices told them was that The Quieting was absolute and, apparently, passive. It wasn’t like noise cancelling headphones – emitting a sound that just cancels out other sounds. There was no sound. None. It was as if the air was perfectly still, held in place. Except, of course, it wasn’t. You could still feel the wind.

Enquiries came back with no information. No one knew where it came from or why it was there.

And then the military scientists had another result come back that resulted in the cordon being widened.

They simply walked through it. They didn’t do this immediately naturally. They’d tested with microphones, speakers, cameras, sensors of all kinds and nothing had happened. But when the junior scientist walked into it they simply vanished.

Everybody was shocked. You would have heard a yell from the soldiers. Screams from the observers. Except for The Quieting.

It took a minute or two in all the panic for the soldiers and people at the cordon to notice… but where the cordon was previously outside of The Quiet Zone, it was now silent. The Quieting had reacted.

Military rushed to widen the cordon again, but really there was little need – the public had fled after seeing the soldier disappear.

Day after day, week upon week, this continued. Experiments that, while consistent and repeatable, refused to make sense. And slowly The Quiet Zone expanded as more experiments triggered its apparent defences.

Eventually the size of The Quiet Zone, and the refusal of The Quieting to yield to science lead to weapons being used. It was attacked with jackhammers, drills and power tools of all kinds. Each caused a reaction from The Quieting.

The public was scared. The Government was powerless despite the assistance of international bodies.

One by one countries, governments, fell. With The Quieting becoming ever more aggressive the political ramifications were felt the world over.

And when The Quieting was complete, when The Quiet Zone was global, what happened? Something spoke. Not out loud, for no longer was there sound anywhere. But something spoke into the minds of everyone.

‘You are ready’

On being trans

I’ve been on HRT for two years now, and I feel a need to write. So here’s some small insight into my feelings.

Sometimes I feel great. I put in the effort for appearances. I can almost believe I look good.

Sometimes I feel crap. As though no matter how much effort I put in cannot repair how I was made. Cannot make me appear female.

Sometimes I pass. I get addressed correctly. Whether as a genuine pass, or just a well meaning Stranger.

Sometimes I completely fail. Getting ‘sir’ed. Getting ‘he’ed. Those send me down.

Even the best and worse days can turn on a dime depending on how I get addressed.

And yet I don’t want to draw attention to myself by making a fuss. Especially to people who likely won’t see me again – coffee shop baristas, restaurant waiters etc. Yes I’ve been sir’ed in a Costa before. I don’t blame the workers. But it does cause a dip.

Sometimes I’m ok with how my body appears. Sometimes I really really am not. Some days I wake up and think I can pull an outfit off. Some days I wake up and just want to get rid of certain parts by any means necessary.

Sometimes people are genuinely nice. Smiling or whatever when we pass in the street. Other times they stare. Or kids laugh.

Kids can be the best or the worst. They don’t have the awareness of how to hold their tongues. Divide internal thoughts from external speech. This is very much a double-edged sword.

I need to work on my voice. But doing so solo means listening back to recordings to make sure I’m up in the right range. It’s a rare day that I can stomach doing that. It’s improved after the speech therapy I had a while back… but it’s not quite there yet. It’s still got a fair chunk of resonance even when trying to speak from the mouth.

My body hair is a nightmare. It always has been. My facial hair is better after the funding for some hair removal sessions. But it’s still not great. I need to look in to funding. But that means actually confronting the problem.

A lot of my issues – working on voice, keeping body/facial hair under control stem from what I call the pain of action. Doing something about it is a painful thing – the act of face shaving, the act of voice training – is a constant reminder that if all was right I wouldn’t have to go through this. The pain of inaction, of doing nothing, however is different because by not doing something about it it in some ways makes it easier to ignore… or atleast not actively think about. It’s a defence mechanism, however self-defeating it is. By not taking action you don’t have to actively think about, actively concentrate on the problem. It’s just there as a consistent background noise that to some extent you can tune out.

Referendum

I’ve been meaning to write a post on the EU Referendum we’re having. But well… we’re now on the eve of the refendum. This time tomorrow the polls will be closed and it will be done, for better or worse. I suspect most people who know me know how I’m going to be voting.

I was going to write a post explaining why I’m voting the way I am…. but it’s… frankly… pointless, and I jsut can’t see the point. I’m not going to change anyones opinion by writing, all it will serve to do is frustrate me. This entire campaign period has been full of negativity, misinformation, half-truths and sometimes outright lies. And that’s not to mention hyperbole.

And that’s…. all I can bring myself to write.

On Passion

I make no secret on my various internet accounts, including this blog, that I’m passionate about various causes. From freedom of speech, to the right to privacy. From the naturalists cause – that the human body is nothing to be ashamed or offended by – to believing that social equality is still decades away. From the need for us to tackle our climate emissions now, to the need for global laws for our global internet age.

But with all those causes I find myself asking why aren’t I doing more. I sit at my computer writing, liking, retweeting, reblogging the occasional articles or petitions. Probably once a week or less if I’m honest. This is so called ‘clicktivism’. But aside from a small donation to Open Rights Group each month, what am I actually doing?

I’m not really contributing to any of those causes. The minuscule amount of online activities I do for these really isn’t reflecting my passion for these areas. Why?

I’m not exactly short of time. My evenings and weekends are my own, and the latter of those certainly provides enough time for me to volunteer for an organisation that deals with one or more of these issues. Yet I find myself…. Devoid of passion when it comes to doing anything about these.

A common criticism of my generation, and even more so the up and coming generations, is that we’re lazy. We aren’t engaged in politics or political causes. We will hit a button to sign a petition, but we don’t actually do anything. And I can’t help but feel that this is true for me. Clicking a button is cheap. But actually syatematically campaigning for an issue. That’s expensive, long, hard and with the same guarantee of success as click-signing an e-petition. That is to say, effectively 0.

I am generation lazy. I am also passionate.

I want to scream from the rooftops about the causes I believe in. I also don’t want to leave the comfort of the Internet.

Passion, for my generation, means expressing ourselves on the Internet. Where our potential reach is very large. But our average reach is in our own little filter bubble.

But then… When our only political choice comes once in five years, between two parties where neither represent the views I hold…. What other choice do we have?

Changes have been made. Welcome back!

Welcome back!

I hope you all like the new domain, please excuse the scaffolding and things whilst we all get settled in here. Hopefully the semi-regular blogs can begin again soon.

And yes, this is my new name. Everywhere. I think I’ve blasted everywhere I can now. It’s nice to finally have it properly public.

Radio Silence and changes

There’s been radio silence on here for quite a while now. There’s a reason for that….

Changes are coming.

If all goes to plan, check back on Tuesday night to meet the new website (that will look very similar to the old one). And hopefully I can resume my semi-regular blogging like I had in 2013

I think my caching problem is fixed

A post will follow shortly (hopefully) outlining the pain I went through to get it working again.

 

(And yes, this does serve as a test post for the changes I just battled with)

EDIT: Turns out it isn’t yet. Will keep trying.

EDIT 2: Only problem left seems to be invalidating the main page cache on posting / editing posts. It automatically expires fine though.

EDIT 3: Debug might be helpful?

Suddenly posts from months ago

So you may have noticed that there are suddenly three new posts since March, none of which are from now.

The short answer is caching fail.

For whatever reason the caching plugin I was using didn’t expire its caches when I published posts. So although navigating directly to the post itself worked (if you followed my Twitter or Facebook links to the exact post), it wouldn’t show up on the main feed, nor presumably in RSS.

So to those of you who rely on RSS for keeping up to date, welcome back! At least you only have three posts to catch up on though!

*Will manually verify that caching is working properly when I post this post*