this post was submitted on 30 Jun 2024
552 points (98.1% liked)

Programmer Humor

19149 readers
1219 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 

Meme transcription:

Panel 1: Bilbo Baggins ponders, “After all… why should I care about the difference between int and String?

Panel 2: Bilbo Baggins is revealed to be an API developer. He continues, “JSON is always String, anyways…”

you are viewing a single comment's thread
view the rest of the comments
[–] ooterness@lemmy.world 18 points 2 months ago (4 children)
[–] 0x0@programming.dev 9 points 2 months ago (3 children)

If there are no humans in the loop, sure, like for data transfer. But for, e.g., configuration files, i'd prefer a text-based solution instead of a binary one, JSON is a nice fit.

[–] MonkderDritte@feddit.de 9 points 2 months ago* (last edited 2 months ago) (1 children)

What, no! Use TOML or something for config files.

[–] 0x0@programming.dev 6 points 2 months ago

TOML

Interesting... me likes it.

[–] Michal@programming.dev 1 points 2 months ago (4 children)

Yaml is more human readable/editable, and it's a superset of json!

[–] bob_lemon 2 points 2 months ago

Yaml is just arcane bullshit to actually write as a human. Nor is it intuitively clear how yaml serializes.

[–] bitfucker@programming.dev 2 points 2 months ago

Until someone cannot tell the difference between tab and space when configuring or you miss one indentation. Seriously, whoever thinks indentation should have semantic meaning for computers should burn in hell. Indentation is for us, humans, not computers. You can write a JSON with or without indentation if you want. Also, use JSON5 to have comments and other good stuff for a config file.

[–] JackbyDev@programming.dev 1 points 2 months ago

It's entirely disingenuous because who the hell is throwing JSON into YAML without converting it? Oh wow, I changed the file extension and it still works. I'm so glad we changed to YAML!

[–] Aux@lemmy.world 1 points 2 months ago

Yaml is cancer.

[–] frezik@midwest.social 1 points 2 months ago (1 children)

What I'd like for a configuration language is a parser that can handle in-place editing while maintaining whitespace, comments, etc. That way, automatic updates don't clobber stuff the user put there, or (alternatively) have sections of ### AUTOMATIC GENERATION DO NOT CHANGE###.

You need a parser that handles changes on its own while maintaining an internal representation. Something like XML DOM (though not necessarily that exact API). There's a handful out there, but they're not widespread, and not on every language.

[–] bitfucker@programming.dev 1 points 2 months ago (1 children)
[–] frezik@midwest.social 2 points 2 months ago (1 children)

Is a very good idea providing much needed fixes to the JSON spec, but isn't really what I'm getting at. Handling automatic updates in place is a software issue, and could be done on the older spec.

[–] bitfucker@programming.dev 2 points 2 months ago (1 children)

Hmm, maybe I am missing the point. What exactly do you mean by handling automatic updates in place? Like, the program that requires and parses the config file is watching for changes to the config file?

[–] frezik@midwest.social 2 points 2 months ago* (last edited 2 months ago) (1 children)

As an example, Klipper (for running 3d printers) can update its configuration file directly when doing certain automatic calibration processes. The z-offset for between a BLtouch bed sensor and the head, for example. If you were to save it, you might end up with something like this:

[bltouch]
z_offset: 3.020
...
#*# <---------------------- SAVE_CONFIG ---------------------->
#*# DO NOT EDIT THIS BLOCK OR BELOW. The contents are auto-generated.
#*#
[bltouch]
z_offset: 2.950

Thus overriding the value that had been set before, but now you have two entries for the same thing. (IIRC, Klipper does comment out the original value, as well.)

What I'd want is an interface where you can modify in place without these silly save blocks. For example:

let conf = get_config()
conf.set( 'bltouch.z_offset', 2.950 )
conf.add_comment_after( 'bltouch.z_offset', 'Automatically generated' )
conf.save_config()

Since we're declaratively telling the library what to modify, it can maintain the AST of the original with whitespace and comments. Only the new value changes when it's written out again, with a comment for that specific line.

Binary config formats, like the Windows Registry, almost have to use an interface like this. It's their one advantage over text file configs, but it doesn't have to be. We're just too lazy to bother.

[–] bitfucker@programming.dev 2 points 2 months ago (1 children)

Ahh, then the modification must be done on the AST level not the in-memory representation since anyway you do it, you must retain the original.

[–] bleistift2@sopuli.xyz 3 points 2 months ago

Hell, no. If I wanted to save bytes, I’d use a binary format, or just fucking zip the JSON. Looking at a request-response pair and quickly understanding the transferred data is invaluable.

[–] themusicman@lemmy.world 3 points 2 months ago

If you're moving away from text formats, might as well use a proper serialisation tool like protobuf...

[–] wtfrank@feddit.uk -1 points 2 months ago (1 children)
[–] JackbyDev@programming.dev 1 points 2 months ago (1 children)

For the love of all things pure, holy, and just, please do not use YAML in your APIs...

[–] wtfrank@feddit.uk 1 points 2 months ago (1 children)

Fine, and if you don't use json in your API because of the deficiency highlighted in the meme, what format do you use in your API?

[–] JackbyDev@programming.dev 1 points 2 months ago

I use JSON. I have used Avro for things in Kafka but I'm not sure the benefits outweigh the negatives. Avro is much more complicated than people think and most folks don't really have a strong desire to learn how it should be used and do stuff incorrectly. Everybody knows JSON and it works with everything though. (Example: so many people just hear that Avro schemas can be backwards compatible but have zero idea that you still need the schema that wrote the message even if you want to read it into a newer one.)

Interestingly, I take the meme as saying a dev is using the wrong types in their serialization format (using strings to store integers) which was my biggest problem with Avro. Mostly from people not using logical types or preferring to use ISO 8601 datetime strings instead of the built-in timestamp-millis type.