[ / / / / / / / / / / / / / ] [ dir / 8teen / animu / ausneets / leftpol / loomis / rolo / sonyeon / strek ][Options][ watchlist ]

/prog/ - Programming

Programming board
You can now write text to your AI-generated image at https://aiproto.com It is currently free to use for Proto members.
Name
Email
Subject
Comment *
File
Select/drop/paste files here
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Expand all images

File (hide): 497f0148664890c⋯.png (782.51 KB, 710x600, 71:60, Smug Kitty.png) (h) (u)

[–]

854c0b (1) No.4934[Watch Thread][Show All Posts]

Hey guys I've been wanting to learn about file formats for some time. Mainly interested because of vidya programming. Basically I want to learn how to properly structure data in text files for the purpose of saving/loading game data for any kind of scenario. I've not been able to find any information, nothing I search up brings me the results that I'm looking for. I've been just winging it this whole time, thinking there must be some kind of standard for this stuff. Please send help, thanks.

a1bcc8 (2) No.4941>>4945

There's a straight answer to this question, but I'm not going to spoonfeed you. That would deprive you of valuable learning!

Instead, I want yout to read "The Art of Computer Programming" by ESR. It has, I think, a whole chapter on what you're asking, but the whole book is great. It talks not about exact specifications for you to follow religiously (that's for pajeets, who can't be trusted to make decisions) but rather in terms of how you should think about software design, so that you can define the standard, so to say.


a1bcc8 (2) No.4942>>4945

*UNIX Programming, not "computer programming".


b7588d (2) No.4945

>>4941

>>4942

Thanks Anon-kun, trust me the last thing I want to be is a shitcoder.

>Unix

Got anything that isn't just for Unix though?


dc7499 (2) No.4948>>4952

There are many different ways to do it, with many pros and cons:

1. Writing data as text, and reading it in as text

+ Simple, usually easy to do

+ Just works

+ Easy to edit by hand

+ Generally quick to parse

- Breaks very easily, brittle

- Quickly gets unwieldy

- Large file size

- Very difficult to extend and scale

2. Just write it out as binary data, read it in in the same order

most of the same pros and cons as above, except

+ Small file size

+ The quickest parsing possible

- Difficult to edit by hand

- Can break when used on a different computer (endianness)

3. Dump it out as a simple text format that uses a library (like JSON)

+ Usually very fast

+ Easy to work with

+ Easy to understand

+ Easy to edit by hand

- Lack of schema and flexibility of format can make things painful

- Editing by hand is usually easy, but it's also easy to break (by, for instance, forgetting a comma)

4. Dump it out and read it in as a schema format (like Protocol Buffers or Capn Proto)

+ Incredibly fast

+ Very easy interface

+ Schema enforcement

+ Backwards-compatible for easy scaling

- Not hand-editable

- Can be difficult to figure out what has gone wrong when something goes wrong

5. Use something like SQLite as an application file format, and operate on the file as a database

+ Very fast (usually at least as fast as a binary format)

+ Don't have to load into memory while working

+ Can use SQL to work on the data, including features like JOINs and views

+ Easy to make backwards compatible

+ Easy to edit file using sqlite3 command

+ Transactions

- Schema can be hard to understand

- Can be easy to ruin data if you don't know what you're doing

- If you don't know SQL already, it can be a hell of a learning curve

- Have to either adopt an ORM or shuffle data between database and application manually

6. Some combination of the above, but zipped into an archive.

+ Combined advantages of the above

+ Ability to work with files like a filesystem

- Combined weaknesses of the above

- Much more complexity

- Usually have to have some sort of standard manifest or metadata file to index what is in the archive at hand, as well as possible version information.

Those are the big ones. I don't do any of the first two unless I need a file with only one or two fields total. The last three all have their strengths and weaknesses, so you'd want to choose something for your situation. There are other solutions, but most of them involve just creating something that fits into one of the latter 4 categories (like creating an extensible text or binary format of your own).

And you're wrong about there being some kind of standard. There are a lot of tools that can help you, but as far as "standards" go, everybody does their own thing.

* Libreoffice does 6 (odf is a zipped pile of XMLs)

* GNUCash does 3 or 5, depending on settings (XML or SQLite)

* Microsoft's document format these days (docx) is also a zipped pile of XMLs

* transmission uses 3 (JSON for its config and temp files)

It's just down to what works best for your situation at hand. I'd suggest experimenting with and using them all, so you can have the best judgment when choosing any specific one in the future.


b7588d (2) No.4952>>4953

>>4948

Thanks for the effort post. What about using XML for data files?


dc7499 (2) No.4953

>>4952

It works, but it's easiest if you do it as part of some serialization framework. Managing XML by hand is often a pain in the ass and way more verbose than other formats. Most everything that XML does, JSON does in a way that's easier to work with, read, and maintain.




[Return][Go to top][Catalog][Screencap][Nerve Center][Cancer][Update] ( Scroll to new posts) ( Auto) 5
6 replies | 0 images | 4 UIDs | Page ???
[Post a Reply]
[ / / / / / / / / / / / / / ] [ dir / 8teen / animu / ausneets / leftpol / loomis / rolo / sonyeon / strek ][ watchlist ]