Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
elcannon
Jun 24, 2009
We have an API endpoint that returns a type that looks like: { public string Foo; public int Bar; public Dictionary<string,string> FooMetadata; } and it serializes and deserializes just fine with System.Text.Json. Looking at our swagger docs there is actually a valid JSON schema thing that forces an object into being a flat set of key -> value pairings:
{
"type": "object",
"additionalProperties": { "type": "string" }
}

In practice it allows clients to "tag" objects with metadata that they care about but doesn't fit anywhere in our schema. I guess if you had no access to any docs or schema definitions and pulled an object like:
{"Foo":"butt", "Bar":0, "FooMetadata": {"Yos":"pos"}}
from the API, there's nothing in the JSON that is explicitly saying that 'FooMetadata' is a Map that can contain arbitrary keys as opposed to a statically typed object that looks like { public string Yos; }. Having an array of objects with "Key" and "Value" fields serves as a hint that those keys shouldn't be baked into a type definition, but then allows for duplicate keys. It looks like there is a way to force uniqueness of array elements in JSON schema but at that point I would probably go the XSD route because this poo poo is awful.

Definitely not a huge fan of "everything is a map" typing which gets you this kind of javascript hotness:
var foo = [0,1,2];
foo["yos"] = "pos";

Adbot
ADBOT LOVES YOU

PIZZA.BAT
Nov 12, 2016


:cheers:


redleader posted:

xml (the superior data exchange format)
:hai:

redleader posted:

* maybe you can do something in an xsd to ensure a key only appears once idk

yeah you can

lotta people are scared of xsds though

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

DELETE CASCADE posted:

what is the point of json

Share Bear
Apr 27, 2004

human readable data interchange format for javascript op

the intent and the usage, as always, might diverge

xtal
Jan 9, 2011

by Fluffdaddy
Why did they use JSON is a good question, why did they use HTTP is just as good. Unless your target is a web browser and only their ergonomics matter, start your API with something like TCP and MsgPack or ProtoBuf and then add an HTTP JSON adapter on top for those plebs.

Share Bear
Apr 27, 2004

xtal posted:

Why did they use JSON is a good question, why did they use HTTP is just as good. Unless your target is a web browser and only their ergonomics matter, start your API with something like TCP and MsgPack or ProtoBuf and then add an HTTP JSON adapter on top for those plebs.

why not just use the (my language serialization) built in serialization, everyone should know how it works by now, it's obvious and simple, as opposed to json

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat
i love msgpack

Twerk from Home
Jan 17, 2009

This avatar brought to you by the 'save our dead gay forums' foundation.

xtal posted:

Why did they use JSON is a good question, why did they use HTTP is just as good. Unless your target is a web browser and only their ergonomics matter, start your API with something like TCP and MsgPack or ProtoBuf and then add an HTTP JSON adapter on top for those plebs.

What's the advantage of doing TCP and MsgPack over something like gRPC so that you don't have to implement your own streaming, sessions, metadata, all that stuff?

xtal
Jan 9, 2011

by Fluffdaddy

Twerk from Home posted:

What's the advantage of doing TCP and MsgPack over something like gRPC so that you don't have to implement your own streaming, sessions, metadata, all that stuff?

gRPC is pretty good actually, HTTP/2 fixes most of the issues you'd get with an HTTP API, but most of the time it still doesn't use other HTTP features like caching. So my gripe is with making extensions to a document serving protocol to make it work for other use cases, when it was unnecessary in those use cases to begin with.

Doom Mathematic
Sep 2, 2008

redleader posted:

xml (the superior data exchange format) doesn't really have any good way of serialising dictionaries. there are a few ways to xmlise a dict, but they all run into the same problem as that key-value list*. it's kind of amusing because they're using json, which does have good syntax for dictionaries, but they managed to gently caress it up anyway

* maybe you can do something in an xsd to ensure a key only appears once idk

Maybe the JSON API is directly derived from the XML API.

echinopsis
Apr 13, 2004

by Fluffdaddy
JSON from {friday : 13}

akadajet
Sep 14, 2003

echinopsis posted:

JSON from {"friday" : 13}

ftfy

Progressive JPEG
Feb 19, 2003

i think flatbuffers are ok

its a pain to work with if you want to frequently make piecemeal edits to existing ones but it's very fast if you don't need to do that very often

redleader
Aug 18, 2005

Engage according to operational parameters
serialization is a direct result of computers being able to communicate which, as we all know, is the work of the devil and has led to nothing but misery for the human race

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
adama was right

xtal
Jan 9, 2011

by Fluffdaddy

redleader posted:

serialization is a direct result of computers being able to communicate which, as we all know, is the work of the devil and has led to nothing but misery for the human race

When you think about it everything is serialized as 1s and 0s, so you're actually even more correct about it being terrible

Phobeste
Apr 9, 2006

never, like, count out Touchdown Tom, man

xtal posted:

When you think about it everything is serialized as 1s and 0s, so you're actually even more correct about it being terrible

and then it's serialized to weird little random voltages stuck in silicon or oddly magnetized areas of ferric ceramic or polymer or whatever. awful

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Doom Mathematic posted:

Maybe the JSON API is directly derived from the XML API.

if we're taking about the example from the aws sdk in the op, it's this

Soricidus
Oct 21, 2010
freedom-hating statist shill
honestly I wouldn’t care so much how aws represents things on the wire if their “high level” python sdk converted it to a more consumer-friendly form

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.

xtal posted:

When you think about it everything is serialized as 1s and 0s, so you're actually even more correct about it being terrible
#cancelclaudeshannon

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Soricidus posted:

honestly I wouldn’t care so much how aws represents things on the wire if their “high level” python sdk converted it to a more consumer-friendly form

botocore uses auto-generated models

so do all their other sdks except java iirc

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


the thing I'm working on right now does serialisation by generating instructions for a custom VM running on the server which then reproduce the encoded data when executed

this is used as a universal communication protocol for a dozen different server applications, each with their own special instruction sets

some of the encoded data also includes a lex/yacc custom language for filtering (because regexes are too pedestrian I guess), which is then transpiled into said instructions

none of this is the actually terrible part, that's where the instructions are added and removed to the data package in event callbacks from the GUI, which now I have to remove

someone really worked hard on that job retention

then again he doesn't work there anymore so who got the last laugh huh? well certainly not me

Private Speech fucked around with this message at 18:06 on Jul 29, 2020

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


there is also no documentation on those instruction sets outside of looking at the server source code, which has about one comment per thousand lines of code

though each server does have an enum listing its instructions (where position in said enum = instruction code), naturally this is not in any consistent file, but rather a random header with a quality name like tlssyn.h (actual name)

Private Speech fucked around with this message at 17:29 on Jul 29, 2020

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


each server instruction set has over 200 instructions, some with very clear names like HALF_OR (this is apparently a conditional jmp/goto instruction to break condition evaluation early, as in: "if (true || whatever)")

that is not to be confused with INT_OR and BYTE_OR, which do boolean arithmetic

I believe this qualifies for the thread on enough levels to warrant a multipost

e: albeit a lot of it can be excused by the code being going on 30 years old

anyway webdev is terrible and systems programming is so much better let me tell you, json more like failson, furthermore

Private Speech fucked around with this message at 18:07 on Jul 29, 2020

Soricidus
Oct 21, 2010
freedom-hating statist shill

Blinkz0rz posted:

botocore uses auto-generated models

so do all their other sdks except java iirc

I know. but that’s an implementation detail and they are leaking the poo poo out of it.

it’s loving amazon, they have plenty of resources to maintain some qol tweaks for really common and basic things like tag dictionaries.

but yeah it’s amazon so why am I even surprised they hold good design and user experience in open contempt

abraham linksys
Sep 6, 2010

:darksouls:
as a primarily-frontend dev i get kinda confused by all the serialization talk just b/c it seems like browser json is still faster in any benchmark

i've been messin around with multiplayer websocket games lately so i'm theoretically in the market for fast (de)serialization and smaller message sizes but as far as i can tell from googling, json is still the way to go. signalr supports messagepack but provides zero actual benchmark tools indicating anything about performance, which you'd really kinda hope for if they've bothered to add the option

MrMoo
Sep 14, 2000

MsgPack is a little better in a browser due to faster transit times, going protobufs or similar are all a fair bit slower still. I did see a benchmark list something else faster, but probably bogus testing per typical for webdev. MsgPack has been super guilty on that front too.

I basically wrote frontend and backend to support both, then testing how each ran. MsgPack faired better. I only bothered because a JSON C++ library supported it relatively transparently.

MrMoo fucked around with this message at 19:16 on Jul 29, 2020

Soricidus
Oct 21, 2010
freedom-hating statist shill
I guess it’s like js as a whole. if everyone does things badly enough, companies have to pour resources into mitigating that, whereas the things that were not terrible to begin with don’t see anything like the same kind of effort.

CRIP EATIN BREAD
Jun 24, 2002

Hey stop worrying bout my acting bitch, and worry about your WACK ass music. In the mean time... Eat a hot bowl of Dicks! Ice T



Soiled Meat

Blinkz0rz posted:

botocore uses auto-generated models

so do all their other sdks except java iirc

the java SDK uses autogenerated models as well. you can even get the generator source code and run it yourself.

https://github.com/aws/aws-sdk-java-v2/tree/master/codegen

here's the maven plugin code: https://github.com/aws/aws-sdk-java-v2/tree/master/codegen-maven-plugin

echinopsis
Apr 13, 2004

by Fluffdaddy
ok so I've only just started fuckng around in javascript and I came across this situation that really fuckin baffled me and only now do I know why

I was multiplying a variable by 1.1 and the program was running as expected

I changed the number to 2, and it would halt and talk about an undefined object

and it really stumped me for a while, and so I put a ; after the 2, and it executed...

ok.. so I removed the ; and yep it fails to execute again. changed back to 1.1 and it worked regardless of the semicolon


fuckin stupid

echinopsis
Apr 13, 2004

by Fluffdaddy
code:
Another example based on rule 4:

(() => {
  return
  {
    color: 'white'
  }
})()
You’d expect the return value of this immediately-invoked function to be an object that contains the color property, but it’s not.
Instead, it’s undefined, because JavaScript inserts a semicolon after return.

Instead you should put the opening bracket right after return:

(() => {
  return {
    color: 'white'
  }
})()
is this true? how is this tolerated

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

it’s tolerated because semicolons are boring

PIZZA.BAT
Nov 12, 2016


:cheers:


ah another member to the ‘javascript is a steaming pile of garbage’ club. i’ll update the massive tome

jesus WEP
Oct 17, 2004


get used to putting a semicolon at the end of each statement, it’s good practice for if you migrate to an actually useable language

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


jesus WEP posted:

get used to putting a semicolon at the end of each statement, it’s good practice for if you migrate to an actually useable language

that's not what the problem in the last post is though - he doesn't want to end the statement there, but js puts an implicit comma there anyway

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

javascript is.... bad?!

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS
sometimes whitespace matters?????

jesus WEP
Oct 17, 2004


Private Speech posted:

that's not what the problem in the last post is though - he doesn't want to end the statement there, but js puts an implicit comma there anyway
oh right yeah i get it now, thanks

champagne posting
Apr 5, 2006

YOU ARE A BRAIN
IN A BUNKER

Blinkz0rz posted:

sometimes whitespace matters?????

don't be daft

Adbot
ADBOT LOVES YOU

Private Speech
Mar 30, 2011

I HAVE EVEN MORE WORTHLESS BEANIE BABIES IN MY COLLECTION THAN I HAVE WORTHLESS POSTS IN THE BEANIE BABY THREAD YET I STILL HAVE THE TEMERITY TO CRITICIZE OTHERS' COLLECTIONS

IF YOU SEE ME TALKING ABOUT BEANIE BABIES, PLEASE TELL ME TO

EAT. SHIT.


how do people feel about #pragma once?

there's this GCC dev laying out a decent case for why it's bad

on a personal level I don't use it for more complex projects, and both cppcoreguidelines and Google C++ guidelines don't recommend it either, with broadly the same reasoning

stackoverflow and reddit have a lot of people agitating hard for it though

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply