记录PHP代码 - 是否影响性能? [英] Documenting PHP Code - does it hurt performance?

查看:113
本文介绍了记录PHP代码 - 是否影响性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能相信任何人通常都会反对文档和评论,但是在PHP中这样做的最佳实践(和实践)是什么?



在JavaScript中,您可以记录代码,然后运行最小化器来生成代码的生产版本以供使用。在PHP中怎么样,额外的文本行影响性能?你应该把你的文件保存在另一个文件中(我想象可能对API和框架很重要,但会减慢开发速度)?



编辑:



我的逻辑是,这将需要更长的时间,因为文件大小更长,并为解析器添加更多的工作(尽管可以忽略不计)。假设你有1000行代码和500行注释,那么你应该放一个总结的版本,然后直接转到实际的文档页面?

解决方案

使用PHP(如ASP.NET),代码可以在服务器上编译,生成的HTML被发送到客户端。

$ b $ PHP源代码被即时编译为可以由PHP引擎执行的内部格式。为了加快执行时间,并且每次访问网页时都不需要编译PHP源代码,PHP脚本也可以使用PHP编译器以可执行格式部署。


来源



在此过程中,意见被忽略,在诉讼中不起作用。它们不会减慢编译器的速度,因此不会影响性能。



您应该对代码进行注释(如果适用),并使用源代码保留注释。否则有更大的机会,他们会失去代码的步伐,然后比无用的更糟。


I can't believe anyone would normally object to documentation and comments, but whats the best practice (and practical) for doing so in PHP?

In JavaScript, you can document your code and then run a minimizer to produce a production version of your code for use. What about in PHP, does the extra lines of text affect performance? Should you keep your documents in another file (which I imagine might be important for API's and frameworks but would slow down your development)?

Edit:

My logic was that it would necessarily take longer because the file size is longer and add more work (though possible negligible) for the parser to sort out. Say you had 1000 lines of code and 500 lines of comments, should you put a summarized version instead and then direct to actual documentation page?

解决方案

With PHP (like ASP.NET) the code can be compiled on the server and HTML generated to be sent down the wire to the client.

PHP source code is compiled on-the-fly to an internal format that can be executed by the PHP engine. In order to speed up execution time and not have to compile the PHP source code every time the webpage is accessed, PHP scripts can also be deployed in executable format using a PHP compiler.

Source

During this process the comments are ignored and play no further part in proceedings. They don't slow down the compiler and hence don't affect performance.

You should comment your code (where appropriate) and keep the comments with the source code. Otherwise there's an even greater chance that they'll get out of step with the code and then worse than useless.

这篇关于记录PHP代码 - 是否影响性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆