Our new Indie Games subforum is now open for business in G&T. Go and check it out, you might land a code for a free game. If you're developing an indie game and want to post about it, follow these directions. If you don't, he'll break your legs! Hahaha! Seriously though.
Our rules have been updated and given their own forum. Go and look at them! They are nice, and there may be new ones that you didn't know about! Hooray for rules! Hooray for The System! Hooray for Conforming!

[Programming] Quote trees are version control for the thread

1646567697085

Posts

  • 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.
    ironsizide
  • bowenbowen ayyyyyyyy 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

    Warning: I am a programmer/sysop. IANAL/IANAD, seek actual advice from certified people in their respective fields if you are actually in need of it.
  • 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.

    Battle.net: Spawnbroker#1471
    Dehumanizedbowenecco the dolphinMvrckthatassemblyguyironsizide
  • admanbadmanb the bored genie Seattle, WARegistered User regular
    JSON is love. JSON is life.

    bowenSpawnbrokerecco the dolphinEchoSporkAndrewDelzhandsyndalisMvrckurahonkythatassemblyguyironsizide
  • 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.

    Battle.net: Spawnbroker#1471
  • 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.
    bowenEchomightyjongyoadmanbMvrckschussironsizide
  • EchoEcho Staring is caring Moderator mod
    edited March 20
    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
    Steam wishlist
    Casual wrote: »
    a man reaches a certain age when he can no longer be part of groups with "wang" in the title
  • 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.

    ecco the dolphin
  • EchoEcho Staring is caring Moderator mod
    Yeah, plenty of apps accept C-style comments in their not-actually-JSON-now config formats.

    Steam wishlist
    Casual wrote: »
    a man reaches a certain age when he can no longer be part of groups with "wang" in the title
    bowen
  • bowenbowen ayyyyyyyy Registered User regular
    you can always just add a comment key or something too

    I guess

    Warning: I am a programmer/sysop. IANAL/IANAD, seek actual advice from certified people in their respective fields if you are actually in need of it.
  • 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.

  • bowenbowen ayyyyyyyy Registered User regular
    lol yaml trying to be relevant still

    Warning: I am a programmer/sysop. IANAL/IANAD, seek actual advice from certified people in their respective fields if you are actually in need of it.
    urahonky
  • jaziekjaziek 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
  • 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.

  • ecco the dolphinecco the dolphin Registered User regular
    edited March 20
    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.
    Echo
  • OghulkOghulk Be Humble Sit DownRegistered 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

    天上龙肉,地上驴肉
    bowen
  • [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.

  • bowenbowen ayyyyyyyy 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?

    Warning: I am a programmer/sysop. IANAL/IANAD, seek actual advice from certified people in their respective fields if you are actually in need of it.
  • bowenbowen ayyyyyyyy Registered User regular
    also the 2015 certification is shitting on everyone that isn't Epic

    Warning: I am a programmer/sysop. IANAL/IANAD, seek actual advice from certified people in their respective fields if you are actually in need of it.
    [Michael]
  • OghulkOghulk Be Humble Sit DownRegistered 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...

    天上龙肉,地上驴肉
    bowenEcho
  • gavindelgavindel You were sent from my sight When your heart grew darker than your nightRegistered 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.

    Looking for magical girls? Try: http://rpg.drivethrustuff.com/product/144223/Sparks
    Maybe more interested in morally dubious shapeshifters and stealing from gods? Try:
    Signature.jpg

    ecco the dolphinschuss
  • 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...)

    Tofystedeth
  • bowenbowen ayyyyyyyy 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

    Warning: I am a programmer/sysop. IANAL/IANAD, seek actual advice from certified people in their respective fields if you are actually in need of it.
    schuss
  • [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

    bowen
  • 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.

  • 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
    Play D&D 4e? :: Check out Orokos and upload your Character Builder sheet! :: Orokos Dice Roller
    The PhalLounge :: Chat board for Critical Failures IRC! :: #CriticalFailures and #mafia on irc.slashnet.org
    bowenCarpyEcho
  • DelzhandDelzhand Registered User regular
    edited March 21
    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
    Final Fantasy XIV: Heavensward - November Elspeth (Sargatanas)
    JacobyMvrckkime
  • admanbadmanb the bored genie 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.

  • EchoEcho Staring is caring Moderator 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.

    Steam wishlist
    Casual wrote: »
    a man reaches a certain age when he can no longer be part of groups with "wang" in the title
    bowen
  • 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.
    ecco the dolphin
  • iTunesIsEviliTunesIsEvil Registered User regular
    edited March 21
    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
  • bowenbowen ayyyyyyyy Registered User regular
    newtonsoft.json is what you want to use for .NET

    Warning: I am a programmer/sysop. IANAL/IANAD, seek actual advice from certified people in their respective fields if you are actually in need of it.
    EchodjmitchellaDehumanizedecco the dolphinadmanbthatassemblyguy
  • KakodaimonosKakodaimonos Registered 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; } }
    
    

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

    Battle.net: Spawnbroker#1471
    Echo
  • SpawnbrokerSpawnbroker Registered User regular
    edited March 21
    Geth roll 1d20

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

    1d20 19 [1d20=19]

    Spawnbroker on
    Battle.net: Spawnbroker#1471
    CampyRendadmanb
  • OrcaOrca Registered 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!

    evilthecat wrote: »
    "Bioware I want to suck on your teets of gamingness".

    The 2012 issue of Fornax. | Steam and Origin: Espressosaurus
  • DelzhandDelzhand Registered User regular
    "Oh god, why does this work" is somehow more frustrating than "Oh god, why doesn't this work".

    Final Fantasy XIV: Heavensward - November Elspeth (Sargatanas)
    MvrckInfidelTofystedeth
  • KakodaimonosKakodaimonos Registered 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.

  • OrcaOrca Registered 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.

    evilthecat wrote: »
    "Bioware I want to suck on your teets of gamingness".

    The 2012 issue of Fornax. | Steam and Origin: Espressosaurus
  • KakodaimonosKakodaimonos Registered User regular
    That was the function. :)

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

Sign In or Register to comment.