问题描述
我是软件开发的新手。现在,我正计划设计一个小型但有用的软件,以帮助人们背诵和复习英语单词。
I'm new to software development. Now, I'm planning to design a small but useful software to help people recite and review the English words.
作为Linux的长期用户,我发现面向用户的应用程序可以节省用户配置的方式多种多样,例如XML,纯文本,SQLite等。当我成为开发人员时,我认为最重要的事情是选择某种适当的方法。
As a long-time linux user, I found that user-oriented applications save user configuration in various ways, like XML, plain text, SQLite, etc. When I become a developer, the most important thing I suppose, is to choose some proper approach.
所以这里是我的问题是,大多数应用程序如何保存其数据?更具体地说,能否请您列出一些常用的数据存储方法?上面的数据是指可帮助应用程序记住事物并在下次启动时返回到先前状态的数据(也许这就是配置文件的全部内容)。顺便说一句,我很好奇纯文本样式的配置,它看起来像这样:
So here is my question, how do most applications preserve their data? More specifically, could you please list some sort of commonly used methods of storing data? The data above refers to the one which helps the application remember the thing and get back to the previous state when it starts up next time (Maybe that's what a configuration file all about). BTW, I'm curious about the plain text style configuration, it looks like this:
property2 = value2
property2 = value2
...
我想知道程序员应该如何使用正则表达式来实现整个方案,或者有第三方库可以调用,或者它们只是编写代码直接对其进行解析?
I wonder how the programmers implement the whole scheme, should they use regex ,or there're 3rd-party libraries to invoke, or they just write code to parse it directly?
对于我的小项目,它有两种持久性数据,一种用于用户友好的配置,另一个用作存储带有相关信息的英语单词的数据库。
As for my little project, it has two kinds of persistent data, one for user-friendly configuration, the other serves as a database which stores English words with related information.
感谢您的耐心等待! :)
Thanks in advance for your patience! :)
推荐答案
这实际上取决于数据的形式,数据的近似大小,性能要求以及设施来预处理或后处理数据,等等。
It really depends upon the form of the data, the approximate size of the data, the performance requirements, the facility to pre- or post- process the data, etc.
此外,您可能希望(或不希望)将数据保留为某种文本格式。文本格式(包括XML,,,...)是因为它可移植并且易于开发人员查看。此外,您还可以使用用于源代码的工具(例如 git
之类的版本控制系统)对其进行管理。缺点是,它需要占用更多的磁盘空间,并且需要花费更多的时间来解析&生成它(但是XML,JSON,YAML格式有许多支持它们的库)。而且文本数据很难直接访问:您基本上需要阅读所有数据才能使用它。
Also, you may want (or not) to keep your data in some textual format. The main advantage of textual formats (including XML, JSON, YAML, ...) is that it is portable and easy to look at by the developer. Also, you can manage it with tools for source code (e.g. version control systems like git
). The disadvantage is that it takes more space on disk, and it takes more time to parse & generate it (however, XML, JSON, YAML formats have numerous libraries supporting them). And textual data is hard to access directly: you basically need to read all of it to use it.
您也可以将这个问题视为或问题。您可以考虑使用XDR,ASN1或您自己的格式,或使用之类的库。您可能对采用二进制但可移植的格式感兴趣(例如,该文件在具有其他处理器,字节序和字长的系统上可读)。
You could also consider that problem as a serialization or persistency issue. You could consider using formats like XDR, ASN1, or your own, or libraries like s11n. You may be interested in having a binary but portable format (e.g. the file would be readable on a system with some other processor, endianness, and word size).
如果将您的数据视为配置数据(程序将读取而不是写入),使其呈文本形式,并具有表达注释的方式:系统管理员将非常乐意在配置文件中添加注释,程序应对此添加注释
If you think of your data as a configuration data (which would be read, not written, by your program), make it textual and have a way to express comments: the sysadmin will be very happy to add comments in configuration files, which your program should ignore.
如果您有大量的数据需要快速访问和更新,则最好使用二进制格式(类似于RAM内部的格式)。在这种情况下,请考虑转储和恢复生产(消耗)一些文本内容的工具。
If you have a big lot of data which should be accessed and updated quickly, a binary format (similar to what is inside RAM) may be preferable. In that case, think of a dump & restore facility producing (& consuming) some textual thing.
您还可以根据,其使用的算法类似于。
You may also think in terms of application checkpointing which use algorithms similar to those for garbage collection.
一个问题是您的数据的价值是什么...如果您认为即使应用程序在不断发展,它也应该保留下来(新版本,新功能)。记录好数据格式。
A question is what is the value of your data... If you believe it should stay even while your application is evolving (new versions, new features) think hard about that. Document well the format of the data.
这篇关于大多数应用程序如何保存其数据? (不谈论网络应用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!