简体   繁体   English

Nette NEON 格式有什么用(与 JSON 相比)

[英]How is Nette NEON format useful (comparing to JSON)

When JSON came out, it came with a nice dedicated web-page.当 JSON 出现时,它带有一个很好的专用网页。 They summarized the ggrammar on a single page.他们在一页上总结了语法。 They explained how easy it is to use JSON (natively) in JS.他们解释了在 JS 中使用 JSON(本地)是多么容易。 Then they provided a miriad of libraries for other languages.然后他们为其他语言提供了大量的库。

Now NEON is available in PHP.现在 NEON 在 PHP 中可用。 I am new to PHP, but I lack to see it's usefulness (except it tries to be pretty, for the price of ambiguity and white-space problems).我是 PHP 的新手,但我看不到它的用处(除了它试图变得漂亮,以模糊和空白问题为代价)。

Is there any reason I shouldn't cut out all NEON stuff and replace it with simple JSON?有什么理由我不应该删掉所有 NEON 的东西并用简单的 JSON 替换它吗?

Neon is maybe more readable than json, but as you said there are some problems with white-space / tab. Neon 可能比 json 更具可读性,但是正如您所说,空白/制表符存在一些问题。 But many IDEs (NetBeans, PhpStorm...) support it, so you can use auto-format.但是许多 IDE(NetBeans、PhpStorm...)都支持它,因此您可以使用自动格式化。

I think you misunderstand some things.我想你误解了一些事情。

NEON is default configuration file for Nette framework , it's nothing like that will be replacing JSON in PHP for ever. NEON 是Nette 框架的默认配置文件,它不会永远取代 PHP 中的 JSON。

NEON is 100% capable of replacing JSON object, but it's mainly targeted for configuration files, which will be modified by people. NEON 100% 能够替换 JSON 对象,但它主要针对配置文件,这些文件会被人修改。 At same time it's a powerful alternative for YAML which is also great configuration file format for humans used for example in Symfony FW.同时,它是 YAML 的强大替代品,YAML 也是非常适合人类使用的配置文件格式,例如在 Symfony FW 中。

There are no problem with spaces/tabs in real at all, you just must use one of them - that's only strict not bad.实际上,空格/制表符完全没有问题,您只需要使用其中之一即可 - 这只是严格还不错。 Because good code starts with consistency.因为好的代码始于一致性。 There are plenty ways of doing things, but in one project, you should have things unified.做事的方法有很多,但在一个项目中,你应该把事情统一起来。

JSON is cross-platform compatible format which is surely has place in projects. JSON 是跨平台兼容格式,在项目中肯定占有一席之地。 Mostly in generated files.主要在生成的文件中。 But it's really clumsy and ugly for files which are directly changed by developer.但是对于开发人员直接更改的文件来说,它真的很笨拙和丑陋。 NEON/YAML do this thing 1000x better, and if you does not get it that value added to configuration files, then you probably doesn't work enough with configuration files. NEON/YAML 将这件事做得好 1000 倍,如果您没有将其添加到配置文件中,那么您可能对配置文件的工作不够。

In Nette, you can use configuration in many other file types - even in json.在 Nette 中,您可以在许多其他文件类型中使用配置——甚至在 json 中。 But if you new in PHP as you said, don't do it.但是,如果您像您所说的那样熟悉 PHP,请不要这样做。 Nette and Symfony FWs weren't use this formats for nothing. Nette 和 Symfony FW 并没有无缘无故地使用这种格式。 It is has added value.它具有附加值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM