6 ms·
As much as it seems to be recommended against (by... authors of serialistion protocols?) I am a strong believer in just using simple structures (and unions if n
by userbinator 10y ago
As much as it seems to be recommended against (by... authors of serialistion protocols?) I am a strong believer in just using simple structures (and unions if necessary) directly --- all these serialisation abstractions appear to have been invented at a time when machines varied far more widely in their characteristics such as endianness, alignment, word size, integer representation, and even byte size. Now that your platform is almost certainly going to be x86 or ARM, it makes little sense to add a layer of (sometimes substantial) complexity in essentially attempting to accommodate flexibility that won't be needed. I can see the necessity if e.g. you need to communicate with a 36-bit 1's complement mainframe, but otherwise it's just bloat.
Along the same sentiment, I'm not a fan of APIs using JSON and/or XML or some other overly-flexible textual encoding. Simple binary encodings, TLV-ish if necessary, are the best.
I was never really convinced by the "human readable" argument for textual encodings either --- you just need to get used to it, then you can read and write the bytes in a hexdump as easily as you can English. In fact I'd prefer working with hexdumps to XML. But unfortunately there's now a whole generation of developers who can't even count to 2 in binary and don't know what a hex editor is...
- erikb 10y agoIt sounds reasonable at first. But I'm very happy that we have a lot of stuff supporting very rare edge cases. Maybe it's just bad luck, but at work I often run into edge cases and I'm very happy if it is at least partly supported.
- lovich 10y agoI mean hell, why try and abstract out anything. We should go back to programming in binary, or at most assembly. We have a whole generation of developers who can't do either
- userbinator 10y agoI'm not saying all abstractions are bad. The problem is adding abstractions when they're not actually needed, which increases complexity instead of reducing it.
- protomyth 10y agoI can see "human readable" for system config files since that can save your bacon in an emergency (editable in a text editor), but I'm really at a loss when we are talking about a serialization protocol or app config files. I want efficiency and minimal parsing code, which makes it problematic to throw in human concerns.
- jimmaswell 10y agoWhy would you want human editable for system configs but not app configs?
- protomyth 10y agoI can probably have a program running to edit the app config file, but if I cannot edit the system config file in a text editor (particularly if it gets bad enough I'm booting in single user mode) I am really hosed.
- etjossem 10y agoRapid mocking and testing.
- jnordwick 10y ago> attempting to accommodate flexibility that won't be needed This sums up my issue with the current fashion in software development.
- evgen 10y agoUntil you actually do need the flexibility and then you are hosed. People who design protocols with some degree of flexibility have usually learned this lesson the hard way. To quote Kennedy quoting Chesterton: don't take down a fence until you know why it was put up.
- EdiX 10y agoPlease don't do this. It may sound reasonable at first but 'simple structures' don't define strings, variable length ints nor any kind of list type. Eventually you'll need some of that and your protocol will become a mess of implicit padding and implicit stride rules, where every list is handled in a different way. Not to mention all the deserialization security holes you are going to have. If you don't believe me take a look at X11.
- etjossem 10y ago> you just need to get used to it, then you can read and write the bytes in a hexdump as easily as you can English. In fact I'd prefer working with hexdumps to XML. But unfortunately there's now a whole generation of developers who can't even count to 2 in binary and don't know what a hex editor is... Man, when I read this, all I can think is "real programmers don't eat quiche." [1] We will continue to see more abstraction in our tools. By and large, the changes we've seen so far have made us more productive as programmers. You should try quiche sometime. You might like it. http://web.mit.edu/humor/Computers/real.programmers http://web.mit.edu/humor/Computers/real.programmers
- galacticpony 10y agoMany languages in use today don't even have a (first class) concept of unions or structures, at least not in the sense that you are talking about. If you're talking about about "bloat" those contexts, you might want to start somewhere else...
- phlakaton 10y agoSo long as you're willing to document exactly how your compiler packs those structs into memory, and your bytestream, go for it. But don't come crying to me when you upgrade compiler versions or switch compilers or add fields to your struct and the rules change on you. I'm going to hold you to your earlier requirements.