Answer the question
In order to leave comments, you need to log in
What is the best way to organize reading and writing files in different formats?
Hello!
I have a small question about the optimal ways to organize reading / writing files in different formats. To begin with, I will give the methods with which I deal: There is some editor program. The data it works with is divided into different structures (there can be from five to a thousand different ones).
Method one - tailor
All data transformations are performed directly inside the read/write functions (arrays of structures are sorted directly and internal values are converted to the target format. The structures themselves do not have any additional transformation functions). As a result, the functions of "footcloths" are obtained. My colleague thinks that this way is "not scalable", preferring the second way. I believe that this method has the advantage of the convenience of adding support for new formats by simply writing a similar "footcloth" for the new format. Also, the main advantage of this method is the visibility of the process of reading / writing a file in the specified format and it is very easy to draw up a detailed specification of the file format, focusing on only one main footcloth.
Method two - recursive
Unlike the first method, all transformations are performed directly in the data structures themselves, and the main footcloths only call these functions for each structure during the enumeration. On the one hand, this method has the advantage of the convenience of adding new parameters to each structure without having to additionally get into the basic read / write footcloth. But if you support many different and incompatible file formats, you will need to add additional read / write functions to each structure. If the task is to add support for a new file format in the presence of thousands of different structures, you will have to add a read / write function to each of them. The advantages of the approach are relevant only in the case of a single supported file format and in the case that the format is used in a small number of programs.
I'm interested in other people's opinions on this.
Answer the question
In order to leave comments, you need to log in
The tailoring method is good when the output is a simple structure file. For example, standard interprogram exchange files like HTML, PNG...
Recursive is more convenient for internal storage format, when you need to serialize everything that is in the program in a suitable form, and even support old versions of this serialization.
We are using Flatbuffers . :)
Documentation is present.
This thing also supports data versioning, subject to certain conditions.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question