As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
Options

[Programming] Kafkaesque rabbits in the queue at the pub

16465676970100

Posts

  • Options
    ecco the dolphinecco the dolphin Registered User regular
    Oghulk wrote: »
    Someone explain the purpose of JSON to me. Like I get it's a convenient way to store object metadata, but it's also kind of a hassle to navigate at times?

    I like it don't get me wrong, it just seems kinda silly if you don't know the keys for the data and have to sift through everything.

    But that argument can be applied to all forms of data formats. Given a binary blob, if you don't know the format/encoding, then good luck extracting any data from it.

    Given an XML document, you'd navigate the DOM tree if you didn't know which nodes to look for.

    JSON, at least, is human readable as bowen points out, and also relatively easy to parse by most/all languages. It's also expressive enough that it can be self documenting in a lot of cases - a human can probably figure out what well named fields mean without needing to consult a reference manual.

    XML might come close, but it's a pain to parse and generate compliant documents for.

    Penny Arcade Developers at PADev.net.
  • Options
    bowenbowen How you doin'? Registered User regular
    https://raw.githubusercontent.com/chb/sample_ccdas/master/HL7 Samples/CCD.sample.xml

    an example of ugly XML code that is an industry standard for some reason

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    SpawnbrokerSpawnbroker Registered User regular
    JSON is used a lot because it's relatively easy to parse, and it's especially easy for JavaScript to parse it, since its name is literally "JavaScript Object Notation." Since it's so easy for JavaScript to use it, it's kind of become a standard for web services to return it, and a ton of serializers have been written for other languages like C# to work with it.

    It's also kind of easy to read, and it's nice to have a standard instead of everyone using proprietary data formats.

    Steam: Spawnbroker
  • Options
    admanbadmanb unionize your workplace Seattle, WARegistered User regular
    JSON is love. JSON is life.

  • Options
    SpawnbrokerSpawnbroker Registered User regular
    We're actually having an issue at work right now where a ton of our web services are written in WCF and don't return data in JSON....except we've been heavily moving toward JavaScript in recent months.

    So now all the developers want to be using JavaScript, but we wrote all of our older APIs in a SOAP, non-RESTful way and we're all annoyed at everything all the time. And none of the managers want to kick off the project of rewriting our entire API because that will take a long time.

    Steam: Spawnbroker
  • Options
    ecco the dolphinecco the dolphin Registered User regular
    If we're not in a performance critical loop, I also appreciate JSON's ability to implicitly handle compatibility between versions. What's that? New field? Just add it in.

    Existing parsers who don't know about the new field will ignore it.

    Compared to a binary format where I'm constantly checking the size of the structure to make sure I've got all of it, or only some of it, flags to see what's valid, maybe tags if it's a stream of some kind - oh, what's that? Data alignment and implicit data padding is different between 32-bit and 64-bit versions because someone forgot about this? Yaaay.

    I really enjoy JSON. Especially in config files.

    Penny Arcade Developers at PADev.net.
  • Options
    EchoEcho ski-bap ba-dapModerator mod
    edited March 2017
    I once wrote a CSS to PList converter just so I wouldn't have to write a ton of XML by hand and could just make a TextMate-style theme with a simple CSS file.

    Why CSS isn't an actual theme format is a mystery. TextMate et al uses the same style of "class" selectors to pick a scope it applies to.

    Echo on
  • Options
    djmitchelladjmitchella Registered User regular
    JSON needs comments so badly, though -- not for interchange between apps, that's fine, but for config files written in json, it is a big pain that we can't annotate them for later.

  • Options
    EchoEcho ski-bap ba-dapModerator mod
    Yeah, plenty of apps accept C-style comments in their not-actually-JSON-now config formats.

  • Options
    bowenbowen How you doin'? Registered User regular
    you can always just add a comment key or something too

    I guess

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    zeenyzeeny Registered User regular
    Especially in config files.

    Naaaaah. Yaml is by far the best for configuration and it's great that most config loading tools nowadays support it.

  • Options
    bowenbowen How you doin'? Registered User regular
    lol yaml trying to be relevant still

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    jaziekjaziek Bad at everything And mad about it.Registered User regular
    JSON is used a lot because it's relatively easy to parse, and it's especially easy for JavaScript to parse it, since its name is literally "JavaScript Object Notation." Since it's so easy for JavaScript to use it, it's kind of become a standard for web services to return it, and a ton of serializers have been written for other languages like C# to work with it.

    It's also kind of easy to read, and it's nice to have a standard instead of everyone using proprietary data formats.

    but of course the serialisation libraries for other languages don't actually work in exactly the same way as for javascript itself, so you end up having to write a bunch of stuff to handle your particular case anyway.

    Steam ||| SC2 - Jaziek.377 on EU & NA. ||| Twitch Stream
  • Options
    zeenyzeeny Registered User regular
    bowen wrote: »
    lol yaml trying to be relevant still

    I'd say it's more relevant than ever, if only because Ansible provides by far the best provisioning experience.

  • Options
    ecco the dolphinecco the dolphin Registered User regular
    edited March 2017
    Ecco Bitch Redux

    If you're going to create a logging/progress update mechanism, it would be a really good idea to have a queue or something, because progress updates can arrive rather fast. Bonus marks if, because you're worried about memory consumption, you put a reasonable max size on the queue and provide feedback on when messages are dropped.

    Don't just say "Only one update can be processed at once, and I won't tell you when it's finished being processed/added to the log", and then "A new progress update will overwrite the update that's being processed, and there'll be no feedback indicating that this has occurred."

    Edit: oh my god. If it's going to be accessed by multiple threads, make it thread safe please. Oh god.

    Edit 2: gdsghvcszgjuhrfvhhjhfdcbjjggdrthhvcxdhjbhh fdgjhb gyffbjiddf argghhhhhhhh

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • Options
    OghulkOghulk Tinychat Janitor TinychatRegistered User regular
    bowen wrote: »
    https://raw.githubusercontent.com/chb/sample_ccdas/master/HL7 Samples/CCD.sample.xml

    an example of ugly XML code that is an industry standard for some reason

    Ok yeah I definitely get it now

    Thanks! Was just a question for my own sake

  • Options
    [Michael][Michael] Registered User regular
    bowen wrote: »
    https://raw.githubusercontent.com/chb/sample_ccdas/master/HL7 Samples/CCD.sample.xml

    an example of ugly XML code that is an industry standard for some reason

    About as ugly as the XSLT XML needed to convert a CCD's XML to a human-readable format. Thanks, MU.

  • Options
    bowenbowen How you doin'? Registered User regular
    [Michael] wrote: »
    bowen wrote: »
    https://raw.githubusercontent.com/chb/sample_ccdas/master/HL7 Samples/CCD.sample.xml

    an example of ugly XML code that is an industry standard for some reason

    About as ugly as the XSLT XML needed to convert a CCD's XML to a human-readable format. Thanks, MU.

    oh my god

    you too?

    what XSLT are you guys using, custom written?

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    bowenbowen How you doin'? Registered User regular
    also the 2015 certification is shitting on everyone that isn't Epic

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    OghulkOghulk Tinychat Janitor TinychatRegistered User regular
    Yeah jesus I got home and decided to do some more digging

    I can't imagine growing up in an age where data wasn't in JSON now

    JSON is just so...beautiful...

  • Options
    gavindelgavindel The reason all your software is brokenRegistered User regular
    Little does this thread know that I use my unlimited insider access to the big MS to selectively fail your installs -- especially the ones that were supposed to be easy overnight batch jobs! MWU HA HA HA HA.

    Book - Royal road - Free! Seraphim === TTRPG - Wuxia - Free! Seln Alora
  • Options
    dporowskidporowski Registered User regular
    Oghulk wrote: »
    Yeah jesus I got home and decided to do some more digging

    I can't imagine growing up in an age where data wasn't in JSON now

    JSON is just so...beautiful...

    It CAN be. Very often it's about as readable as that XML up there a few posts, because "we can just put EVERYTHING in!!!" is a thing many developers say to themselves. (Not that I think that XML is all that bad...)

  • Options
    bowenbowen How you doin'? Registered User regular
    even the worst jsons aren't anywhere near as bad as the worst xmls

    especially since people can't decide between attributes and child elements, so they do both in the same god damned document

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    [Michael][Michael] Registered User regular
    bowen wrote: »
    [Michael] wrote: »
    bowen wrote: »
    https://raw.githubusercontent.com/chb/sample_ccdas/master/HL7 Samples/CCD.sample.xml

    an example of ugly XML code that is an industry standard for some reason

    About as ugly as the XSLT XML needed to convert a CCD's XML to a human-readable format. Thanks, MU.

    oh my god

    you too?

    what XSLT are you guys using, custom written?

    I wasn't actually here when it was originally written, but I think it started with baseline CCDA and CCR XSLTs, modified as needed, since apparently every EHR has to have their own dialect. They're about 2000 lines each, but there are longer ones out there! Like https://github.com/lantanagroup/stylesheets/blob/master/Stylesheets/CDA/dist/cda-combined-web.xsl

  • Options
    dporowskidporowski Registered User regular
    bowen wrote: »
    even the worst jsons aren't anywhere near as bad as the worst xmls

    especially since people can't decide between attributes and child elements, so they do both in the same god damned document

    If people are given the choice between two things, they will inevitably decide "por que no los dos" and make the worst of all worlds.

  • Options
    InfidelInfidel Heretic Registered User regular
    Maybe it's because I'm a developer, but I can read JSON much easier because of explicit braces and brackets and following those.

    XML has indentation and that's about it. The extra noise from closing tags and not having lists stand out make it much harder to read imo.

    And since really only developers look at this shit...

    OrokosPA.png
  • Options
    DelzhandDelzhand Hard to miss. Registered User regular
    edited March 2017
    admanb wrote: »
    JSON is love. JSON is life.

    my only problem with json is that it's strict about commas in lists

    other than that, I'd be happy writing REST services that return JSON all day erry day

    "Hey I need the three closest stores and their inventory"
    "Okay here"
    "Great, I'm going to take these and-"
    "Buddy, I don't give a fuck what you're doing with that data."

    Delzhand on
  • Options
    admanbadmanb unionize your workplace Seattle, WARegistered User regular
    Delzhand wrote: »
    admanb wrote: »
    JSON is love. JSON is life.

    my only problem with json is that it's strict about commas in lists

    You actually reminded me that JSON's strictness about double quotes vs. single quotes around strings cost me a solid day of work one time.

  • Options
    EchoEcho ski-bap ba-dapModerator mod
    New jorb, day 2: home with a cold. :rotate:

    At least it's still the setup phase so it's not like I'm expected to produce results yet.

  • Options
    Alistair HuttonAlistair Hutton Dr EdinburghRegistered User regular
    Worst Json is definitely better by a long, long shot than worst XML. Worst XML is the absolute worst.

    But best XML can be utterly gorgeous. Attributes can bring a succinctness to a document that Json can't match.

    And, obviously, when it comes to a genuine documents rather than just object serialisation then XML is the winner winner.

    I have a thoughtful and infrequently updated blog about games http://whatithinkaboutwhenithinkaboutgames.wordpress.com/

    I made a game, it has penguins in it. It's pay what you like on Gumroad.

    Currently Ebaying Nothing at all but I might do in the future.
  • Options
    iTunesIsEviliTunesIsEvil Cornfield? Cornfield.Registered User regular
    edited March 2017
    Simple XML is fine, it's garbage like bowen linked above that's a problem. Also, while I'm at it: fuuuuuuuck XML namespaces. Either I'm a goddamn moron (certainly an option) or namespaces are the biggest pain in the dick when it comes to dealing with XML in C#.

    I've not yet really gotten to play much with JSON. It hasn't come up at work, and I've not done any personal projects with it yet.

    Does C# have a native JSON parser yet? (to Google I go)

    [ed] Apparently .NET 4.5 added a full-on System.Json namespace.

    [ed Mk 2] Apparently that's for Silverlight. Humbug.

    iTunesIsEvil on
  • Options
    bowenbowen How you doin'? Registered User regular
    newtonsoft.json is what you want to use for .NET

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • Options
    KakodaimonosKakodaimonos Code fondler Helping the 1% get richerRegistered User regular
    Implicit casting is gonna getcha. I think I need to have a chat with the devs about it again.

    Cause one of these is right, the other, not so much.
            public ulong SequenceNumber { get { return (ulong)((seqNum8 << 56) | (seqNum7 << 48) | (seqNum6 << 40) | (seqNum5 << 32) | (seqNum4 << 24) | (seqNum3 << 16) | (seqNum2 << 8) | seqNum1); } }
    
            public ulong SequenceNumber { get { return ((ulong)seqNum8 << 56) | ((ulong)seqNum7 << 48) | ((ulong)seqNum6 << 40) | ((ulong)seqNum5 << 32) | ((ulong)seqNum4 << 24) | ((ulong)seqNum3 << 16) | ((ulong)seqNum2 << 8) | (ulong)seqNum1; } }
    
    

  • Options
    SpawnbrokerSpawnbroker Registered User regular
    Both of those look wrong to me, I think I lost 1d20 sanity points just looking at that.

    Steam: Spawnbroker
  • Options
    SpawnbrokerSpawnbroker Registered User regular
    edited March 2017
    Geth roll 1d20

    Edit: Fuck me, look what your code has done!

    1d20 19 [1d20=19]

    Spawnbroker on
    Steam: Spawnbroker
  • Options
    OrcaOrca Also known as Espressosaurus WrexRegistered User regular
    Implicit casting is gonna getcha. I think I need to have a chat with the devs about it again.

    Cause one of these is right, the other, not so much.
            public ulong SequenceNumber { get { return (ulong)((seqNum8 << 56) | (seqNum7 << 48) | (seqNum6 << 40) | (seqNum5 << 32) | (seqNum4 << 24) | (seqNum3 << 16) | (seqNum2 << 8) | seqNum1); } }
    
            public ulong SequenceNumber { get { return ((ulong)seqNum8 << 56) | ((ulong)seqNum7 << 48) | ((ulong)seqNum6 << 40) | ((ulong)seqNum5 << 32) | ((ulong)seqNum4 << 24) | ((ulong)seqNum3 << 16) | ((ulong)seqNum2 << 8) | (ulong)seqNum1; } }
    
    

    Forget the implicit cast, that code is flat out wrong! Or it should be!

  • Options
    DelzhandDelzhand Hard to miss. Registered User regular
    "Oh god, why does this work" is somehow more frustrating than "Oh god, why doesn't this work".

  • Options
    KakodaimonosKakodaimonos Code fondler Helping the 1% get richerRegistered User regular
    I'll explain what's going on. @ecco the dolphin can also correct me if I'm not quite right in my explanation. And These are all coming out of a packed binary byte structure (where everything is just a sequence of bytes). So we pull the bytes out into a struct and then we need to pull the actual data out. (This data is also in network byte ordering and since we're on a Windows OS, we need to reverse the byte ordering).

    I'll start with an unsigned short.

    So it'd be something like this:
    
    public ushort count { get { return (ushort)((count2 << 8) | count1); } }
    
    

    A short is 2 bytes long. So lets say we get two fields in the structure, byte2 and byte1 and they both represent an unsigned short.

    So a ushort is 2 bytes long. Or 16 bits long. And each byte is 8 bits long.

    So what we can do is take the high order byte - count2 and push that into an unsigned short and just push it up to the most significant 8 bits. That's what the left shit by 8 is doing. We're taking a byte (8 bits long) and pushing it into a ushort and moving it left by 8 bits. So if count2 is 11111111 then count is now 11111111 00000000.

    So now we need the low bit. So we take the second byte and add that in using the bitwise or '|' . So if count1 is 00110011, then count is now 11111111 00110011

    The ulong code is just working with a 64-bit long and 8 bytes. And the issue was if we didn't cast the intermediate results to an unsigned value, we'd overflow and then have incorrect values.

  • Options
    OrcaOrca Also known as Espressosaurus WrexRegistered User regular
    I'll explain what's going on. @ecco the dolphin can also correct me if I'm not quite right in my explanation. And These are all coming out of a packed binary byte structure (where everything is just a sequence of bytes). So we pull the bytes out into a struct and then we need to pull the actual data out. (This data is also in network byte ordering and since we're on a Windows OS, we need to reverse the byte ordering).

    I'll start with an unsigned short.

    So it'd be something like this:
    
    public ushort count { get { return (ushort)((count2 << 8) | count1); } }
    
    

    A short is 2 bytes long. So lets say we get two fields in the structure, byte2 and byte1 and they both represent an unsigned short.

    So a ushort is 2 bytes long. Or 16 bits long. And each byte is 8 bits long.

    So what we can do is take the high order byte - count2 and push that into an unsigned short and just push it up to the most significant 8 bits. That's what the left shit by 8 is doing. We're taking a byte (8 bits long) and pushing it into a ushort and moving it left by 8 bits. So if count2 is 11111111 then count is now 11111111 00000000.

    So now we need the low bit. So we take the second byte and add that in using the bitwise or '|' . So if count1 is 00110011, then count is now 11111111 00110011

    The ulong code is just working with a 64-bit long and 8 bytes. And the issue was if we didn't cast the intermediate results to an unsigned value, we'd overflow and then have incorrect values.

    That kind of bit shifting and masking should all be hidden behind functions that generalize those kinds of actions for you. Ideally templated so all masks, shifts, etc. and created at compile time for you. It should be as simple as something akin to x = read<field>().

    Constructing all of it by hand is a recipe for the sorts of problems you just ran into.

    Source: embedded programmer, 1/2 of what I do is reading/writing into packed data fields, and I never have to shift a damn thing myself unless I need to expand the read/write functions for a new capability.

  • Options
    KakodaimonosKakodaimonos Code fondler Helping the 1% get richerRegistered User regular
    That was the function. :)

    The annoying ones are the feeds that decide to do a ulong with only 6 bytes.

This discussion has been closed.