一个文件有多少行PHP代码太多了? [英] How many lines of PHP code is too many for one file?

查看:350
本文介绍了一个文件有多少行PHP代码太多了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个PHP文件,它执行2个mysql数据库调用,其余的脚本是if语句,例如file_exists和其他简单变量。到目前为止,我在这个文件中有大约2000行代码。

I'm creating a PHP file that does 2 mysql database calls and the rest of the script is if statements for things like file_exists and other simple variables. I have about 2000 lines of code in this file so far.

如果语句为真,最好包含一个单独的文件;或者直接在if语句中直接输入代码?

Is it better practice to include a separate file if a statement is true; or simply type the code directly in the if statement itself?

它们是PHP应该遵守的单个文件的最大代码行数吗?

Is their a maximum number of lines of code for a single file that should be adhered to with PHP?

推荐答案

我想说不应该有任何与你的php文件中的行数相关的性能问题,它可以像你需要。

I would say there should not be any performance issue related to the number of lines in your php files, it can be as big as you need.

现在,对于模式和最佳实践,我会说你必须自己判断,我看到许多组织良好的文件有几千行和一个很多实际上很小而且难以阅读的文件。
我的建议是:

Now, for the patterns and best practices, I would say that you have to judge by yourself, I saw many well organized files of several thousand lines and a lot of actually small and difficult to read files. My advise would be:


  • 判断源代码的可读性,总是把它整理好。

  • 如果你的文件兼具两者,那么在某种程度上进行逻辑分离是很重要的:大量数据库访问,写入,修改,html渲染,ajax等等。你可能想要分离事物或使用面向对象的方法。

  • 始终在逻辑分离和代码之间搜索平衡。它不应该是杂乱的,也不应该是很多10行文件

这篇关于一个文件有多少行PHP代码太多了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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