Show newer

@aescling @wallhackio “shake it out” is a florence + the machine song which is better

@wallhackio @aescling well javascript doesn’t have any native concept of object type so in order to transform JS you have to first identify the type of every object and then call the methods associated with that type

“identify the type of object” can be trivial in the case where every object has a `type` property, but that’s still boilerplate you have to write and most real-world JSON is not this verbose

the end result of all this is that most code for processing JSON is incredibly bespoke

in XML on the other hand, the type of things is obvious (it's the node name), so you can just use a generic recursive descent mechanism with type-specific transforms, and you don’t have to write the first part because that’s XSLT

example JSON:

{ "type": "example"
, "items":
[ { "type": "item"
, "value": 1 }
, { "type": "item"
, "value": 2 } ] }

example XML:

<example>
<items>
<item value="1"/>
<item value="2"/>
</items>
</example>

desired result:

<p>Here are my items: {1}, {2}.</p>

XSLT conversion:

<x:template match="example">
<p>
<x:text>Here are my items: </x:text>
<x:for-each select="items/*"/>
<x:if test="position()!=1">
<x:text>, </x:text>
</x:if>
<x:apply-templates select="."/>
</x:for-each>
<x:text>.</x:text>
</p>
</x:template>
<x:template match="item">
<x:text>{</x:text>
<x:value-of select="@value"/>
<x:text>}</x:text>
</x:template>

conversion from JSON left as an exercise

suppose a new item type is added. with XML/XSLT, this just necessitates adding a single new template to handle it. how much does the code need to change to accommodate this with JSON?

@wallhackio @aescling there are thing which are very easy to do on s-expressions or in XML which are a pain in the ass to do with JSON and those things are basically all of the nature “convert this structure into that structure”

strong argument for just deserializing into a lisp, transforming, and serializing back, and that makes one wonder why you aren’t just using a lisp as your structure to begin with

@wallhackio @aescling JSON is best used for closed APIs with known parameters, where a tight binding exists between the three schemas (see <en.wikipedia.org/wiki/Three-sc>)

when these things diverge JSON becomes less and less desirable

@wallhackio @aescling tree based structures are for cowards both JSON and XML are bad for data

XML is better for markup

@wallhackio @aescling JSDOM is extremely heavyweight and you’re unlikely to find a reasonably featureful replacement

if you don’t need the full DOM and just need simple parsing or whatever, there are probably options

a fire emblem game i’ve never played before? with a bunch of mechanics i’m not familiar with? sure i’ll put it on the hardest difficulty. why not

fire emblem is just a puzzle game for people who like bow lesbians

@coriander i’m like “spiderman doesn’t believe in cops he’s just a teenager”

superheroes who hand criminals over to the cops because they trust in the criminal justice system

versus

superheroes who hand criminals over to the cops like “it’s your problem now, suckers”

@aschmitz so like i could teach someone how to write good ruby code, which is a nice thing to learn and helpful to folks, but it’s not where my true power lies

Show older
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.