Programming thread

While we're on the topic of recursion, who wants to rate my json to xml converter? :)
Answer the age-old question: is this NIGGERLICIOUS, or DIVINE INTELECT?
This doesn't work. You can't just remove all whitespace from the JSON, whitespace inside a string is data that has to be preserved. I'd rethink the whole whitespace-removing thing, as long as you have to keep track of whether you're in a string or not (including watching out for escaped end quotes), you might as well go all the way and just ignore whitespace "live" during parsing when you're keeping track of all that stuff anyway.

Why are you fseeking around with file pointers? I think it'd be better to just read the input file (or at least the chunk of it you're currently working on) into memory and use actual pointers.

Also:
C:
FILE* new_json = fopen("./temp.json", "w");
// ...
fclose(new_json);
// ...
FILE* json = fopen("./temp.json", "r");
I get what you're going for, but it's your temp file, if you don't want to write to it anymore just don't write to it.

EDIT: one other thing, the JSON definition of "whitespace" isn't exactly the same as the isspace definition either.
By default, isspace counts \f and \v as whitespace, but JSON doesn't.

https://en.cppreference.com/w/cpp/string/byte/isspace
https://www.rfc-editor.org/rfc/rfc8259.txt

(EDIT 2: also, having functions called "array" and "string" is probably asking for trouble if you ever plan to bring C++ into the mix and someone using's the std namespace.. I don't know what "wins" in clashes like that and I refuse to find out)
 
Last edited:
I prefer to write them in an "algebraic" style, like so: 0x2D <= c && c <= 0x39
Please don't do this.
I'd write this as c >= '-' && c <= '9'.

I think it'd be better to just read the input file (or at least the chunk of it you're currently working on) into memory and use actual pointers.
Yes, or mmap it.
 
  • Like
Reactions: UERISIMILITUDO
Rusty's code is preferable because ' ' is clear wrt meaning, 0x20 requires more domain-specific knowledge to interpret, even if they are equivalent. I guess it's arguable that not using 0x20 makes the integer ordering less clear, but that should be inferable from the bounds.
No I meant why not order the comparisons like in a math textbook? It's more readable that way.
 
Why are you fseeking around with file pointers? I think it'd be better to just read the input file (or at least the chunk of it you're currently working on) into memory and use actual pointers.
Because it isn't necessary

EDIT 2: also, having functions called "array" and "string" is probably asking for trouble if you ever plan to bring C++ into the mix
I don't
 
Hello kiwi faaarmer saaar.

Where is best online resource to begin c++.

I want to build my own engine because godot is for kaffirs.

Thank you dearly saar. Also please dm googel pleh card code pls saar. Do not redeem it. I will do that for you.
 
Hello kiwi faaarmer saaar.

Where is best online resource to begin c++.

I want to build my own engine because godot is for kaffirs.

Thank you dearly saar. Also please dm googel pleh card code pls saar. Do not redeem it. I will do that for you.
 
Hello kiwi faaarmer saaar.

Where is best online resource to begin c++.

I want to build my own engine because godot is for kaffirs.

Thank you dearly saar. Also please dm googel pleh card code pls saar. Do not redeem it. I will do that for you.
I don't know your experience but ChiliTomatoNoodle on YouTube has a shitload of really good C++ playlists. He has beginner/intermediate/advanced game programming, 3D DirectX, "game engine infrastructure", etc.
 
  • Like
Reactions: Hall of Cost Payer
No I meant why not order the comparisons like in a math textbook? It's more readable that way.
Because it's not idiomatic, i.e. nobody else does it.

Because it isn't necessary
fseek leads to a syscall, and syscalls are slow. mmap is the way to get the best performance out of this sort of thing.
 
  • Informative
Reactions: Nitro!
  • Thunk-Provoking
Reactions: ADHD Mate
fseek leads to a syscall, and syscalls are slow. mmap is the way to get the best performance out of this sort of thing.
I didn't say it would do nothing, I said it wasn't necessary. A handful of milliseconds isn't going to break the bank on a CLI tool for changing one filetype to another.
 
Hello kiwi faaarmer saaar.

Where is best online resource to begin c++.

I want to build my own engine because godot is for kaffirs.

Thank you dearly saar. Also please dm googel pleh card code pls saar. Do not redeem it. I will do that for you.
I'll bite on this niggerlicious bait, https://learnopengl.com/ will teach you about the graphical end of a 3d game engine.
 
Back