say you're making your new program (say, for example, a chessboard editor)
obviously you will need to save the chessboard as a file.
so you decide to support a few formats:
.fen (forsyth-edwards notation)
.pgn (portable game notation, the 1.e4 stuff)
.chs (a new format you wanna make)
so... how do you make a new file format?
some people, when confronted with a problem, say: "oh, i'll use regex." now they have two problems.
same principle.
some people, when confronted with making a new file format, say: "oh, i'll use plaintext." now they have an absurdly large, garbled format that needs a sprawling parser. a format they made themselves, to be exact.
"and then let's add a json edition and a schema validator." EXCUSE ME.
when you make a plaintext format without any constraints in mind, you end up with a format called chess_filefmt_beta_final_FINAL2.
and it ends up ugly to parse, ugly to use, ugly to edit, and then just the helper that makes you able to use it without a headache imports 20 modules, 4 packages, and is 5914 lines long.
and then you have the audacity to parse it with regex.
no. stop.
that's just how to make even more crappy formats in an endless loop of "refinement".
1
limit yourself. think what you actually need and what is useless.
in the .chs format all we need is a header and the 8x8 board.
2
pick the best way to store your data.
in the .chs format binary data works well.
maybe your format needs plaintext.
or maybe something else.
3
make the minimum usable version.
in the chess format we just store a 4 byte header (c h s \0) and then in each byte we pack two chess tiles. (6 pcs*2 players + empty = 13, fits in 4 bits neatly)
maybe your format is bigger, more detailed, or needs something completely different.
4
add versioning to the format
maybe leave a byte for version so you don't end up with a format called chess_filefmt_beta_final_FINAL2 or something.
have fun making cool formats. bye.
Top comments (0)