Table of Contents
回复内容:
Home Backend Development PHP Tutorial 请问这2种编写代码的风格有何区别?

请问这2种编写代码的风格有何区别?

Jun 06, 2016 pm 08:47 PM
c++ php python programmer

PHP代码:

<code><?php //写法1:有空格
header( "Content-type:text/html;charset=gbk" );
//写法2:没空格
header("Content-type:text/html;charset=gbk");
?>
</code>
Copy after login
Copy after login

记得之前在哪里看到过,推荐采用写法1,不知道为什么?

这个问题已被关闭,原因:

回复内容:

PHP代码:

<code><?php //写法1:有空格
header( "Content-type:text/html;charset=gbk" );
//写法2:没空格
header("Content-type:text/html;charset=gbk");
?>
</code>
Copy after login
Copy after login

记得之前在哪里看到过,推荐采用写法1,不知道为什么?

怎么看顺眼怎么写!

应该没区别,是为了好看吧..
比如说var=a;和var = a;是一样的,我喜欢后者也是为了好看

没区别
比如一个php函数
function fun1($str1, $str2){
}
两个参数中间用逗号隔开,但是为了好看,逗号后面会跟上一个空格

只不过文件大了2个字节而已

第一种写法应该是为了感官上更直接,不会因为代码太紧凑而读起来费劲。

找个编码规范, 按编码规范来

区别还是有的,加了空格,文件大小会变大。哈哈。 个人认为这个属于个人习惯吧,怎么顺眼怎么写。

举个明显点的例子。

<code>for(int i=0,j=0;i</code>
Copy after login

<code>for(int i = 0, j = 0; i </code>
Copy after login

哪个可读性好,很显而易见吧!

两种风格都是没有问题的,也就是说是符合规范的,

但是关键的一点是:

<code>要在代码里从始至终使用一种规范\风格,如果使用以上两种风格\规范混搭,那样的话既不美观,也不正确
</code>
Copy after login

没有区别。编码风格的问题不涉及语法,对编译器来说能认识就好,怎么写都行。但是代码写出来都是要人来看的,所以为了善待自己善待他人,要写清楚。不说其他编码风格,就说这里提到的排版,通过空格、换行、对齐,让代码按照其逻辑来组织(错落有致),对快速理解代码也是很有帮助的。还有很重要的一点是,整个代码整个项目的程序,其风格就应该一致!你写的和其他项目成员写的应该一致!到底是采用这种风格还是那种风格就反而没那么重要了。

zend studio 默认格式化就是第一种,不过平常更多的是第二中的规范,主要还是要看整体代码的规范统一即可!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Clair Obscur: Expedition 33 - How To Get Perfect Chroma Catalysts
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1677
14
PHP Tutorial
1278
29
C# Tutorial
1257
24
What is the significance of the session_start() function? What is the significance of the session_start() function? May 03, 2025 am 12:18 AM

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

Quantitative Exchange Ranking 2025 Top 10 Recommendations for Digital Currency Quantitative Trading APPs Quantitative Exchange Ranking 2025 Top 10 Recommendations for Digital Currency Quantitative Trading APPs Apr 30, 2025 pm 07:24 PM

The built-in quantization tools on the exchange include: 1. Binance: Provides Binance Futures quantitative module, low handling fees, and supports AI-assisted transactions. 2. OKX (Ouyi): Supports multi-account management and intelligent order routing, and provides institutional-level risk control. The independent quantitative strategy platforms include: 3. 3Commas: drag-and-drop strategy generator, suitable for multi-platform hedging arbitrage. 4. Quadency: Professional-level algorithm strategy library, supporting customized risk thresholds. 5. Pionex: Built-in 16 preset strategy, low transaction fee. Vertical domain tools include: 6. Cryptohopper: cloud-based quantitative platform, supporting 150 technical indicators. 7. Bitsgap:

How to use MySQL functions for data processing and calculation How to use MySQL functions for data processing and calculation Apr 29, 2025 pm 04:21 PM

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

Composer: The Package Manager for PHP Developers Composer: The Package Manager for PHP Developers May 02, 2025 am 12:23 AM

Composer is a dependency management tool for PHP, and manages project dependencies through composer.json file. 1) parse composer.json to obtain dependency information; 2) parse dependencies to form a dependency tree; 3) download and install dependencies from Packagist to the vendor directory; 4) generate composer.lock file to lock the dependency version to ensure team consistency and project maintainability.

C   and Performance: Where It Still Dominates C and Performance: Where It Still Dominates May 01, 2025 am 12:14 AM

C still dominates performance optimization because its low-level memory management and efficient execution capabilities make it indispensable in game development, financial transaction systems and embedded systems. Specifically, it is manifested as: 1) In game development, C's low-level memory management and efficient execution capabilities make it the preferred language for game engine development; 2) In financial transaction systems, C's performance advantages ensure extremely low latency and high throughput; 3) In embedded systems, C's low-level memory management and efficient execution capabilities make it very popular in resource-constrained environments.

How to configure the character set and collation rules of MySQL How to configure the character set and collation rules of MySQL Apr 29, 2025 pm 04:06 PM

Methods for configuring character sets and collations in MySQL include: 1. Setting the character sets and collations at the server level: SETNAMES'utf8'; SETCHARACTERSETutf8; SETCOLLATION_CONNECTION='utf8_general_ci'; 2. Create a database that uses specific character sets and collations: CREATEDATABASEexample_dbCHARACTERSETutf8COLLATEutf8_general_ci; 3. Specify character sets and collations when creating a table: CREATETABLEexample_table(idINT

How to rename a database in MySQL How to rename a database in MySQL Apr 29, 2025 pm 04:00 PM

Renaming a database in MySQL requires indirect methods. The steps are as follows: 1. Create a new database; 2. Use mysqldump to export the old database; 3. Import the data into the new database; 4. Delete the old database.

Composer's Purpose: Managing Project Dependencies in PHP Composer's Purpose: Managing Project Dependencies in PHP Apr 30, 2025 am 12:01 AM

We need Composer because it can effectively manage dependencies of PHP projects and avoid the hassle of version conflicts and manual library management. Composer declares dependencies through composer.json and uses composer.lock to ensure the version consistency, simplifying the dependency management process and improving project stability and development efficiency.

See all articles