使用解释语言时的数据文件
假设我有一些数据,我想要几种类型。我认为最简单的例子可能是游戏中的图块:我会有草、岩石、树等,每个都有不同的值集。
我会立即继续创建一个文件并在运行时读入它,这样我就不必重新编译它来使用 C++ 之类的东西进行调整。但如果我使用 Python 或其他一些解释语言,那么必须以如下格式制作文件会有很多意义:
善良的草
颜色0xdfdfdf
走 真实
看到真实
而不是:
草类(瓷砖):
定义 init(自身):
我不记得如何初始化。家长
self.颜色 = 0xdfdfdf
如果不编译,第一个明显的好处就会丢失。
Say I have some data which I want several kinds of. I think the easiest example could be tiles in a game: I would have grass, rock, tree, etc. each with different sets of values.
I would immediately go ahead and make a file and read it in at runtime, so I wouldn't have to recompile it all for a tweak with something like C++. But if I was using Python, or some other intepreted language, would there be much point in having to make the file in a format like:
kind grass
colour 0xdfdfdf
walk
true
see true
Rather than:
class grass(tile):
def
init(self):
I can't remember how to init. parents
self.colour = 0xdfdfdf
The obvious benefit of the first is lost, when you don't compile.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
还有其他几个原因,尤其是非编码人员可能会更改配置,让我们让他们感到舒服。
对于不同的情况,您可能有许多不同的配置文件。如果您使用基于代码的方法,那么您将拥有为每个不同的配置实例复制的真实的、语法上更复杂的代码。我认为代码的多个副本是一件坏事。
此外,配置不必来自文件,它可能(例如)位于数据库中 - 在分布式系统中可能比文件更好。因此,分离代码和配置可以提供灵活性。
Several other reasons, not least that a non-coder may change config, let's make them comfortable.
You may have many different config files for different situations. If you use your code-based approach you have true, syntactically more complex, code replicated for each different config instance. I'd claim that multiple copies of code is a bad thing.
Furthermore, config need not come from a file, it might (for example) be in a database - in distributed systems that may be better than a file. Hence separating code and config can give flexibility.