今天写代码的时候,用了下面的大括号,结果被老大说我不规范了,知乎大神都是怎么使用大括号的
我这样写:
<span class="x">public function test(){</span> <span class="x"> return;</span> <span class="x">}</span>
回复内容:
编码规范这玩意,没有什么对错,在团队里听老大的就对了。 是不规范,那是每个公司都有自己公司代码规范,虽然我也喜欢金字塔规范,但是你得按照公司来啊。老兄,就这点事情你还要来提个问题。那我想问你,如果这里说是你的规范,然道你还回去和你老大理论? java是你那种风格,C、C++很多你老大那种风格,我也喜欢你老大那种风格的,我觉得这种风格代码范围更直观 随便,主要看代码规范前置的话,方便注释掉条件语句来测试运行块
后置的话,主要省掉一个空行。
-----
参考其他答案,我觉得
方法、类这些可以用后置,因为不大可能注释掉方法头或者类头
条件控制(if、while之类)可以用前置 有图慎入,,,
=============
这是JAVA:


用的都是快捷键格式化,对称爽吗?
不就是习惯了某个IDE的style嘛!
难道人家编辑器的默认样式不规范?
一家之言而已。
哼,,,
就酱,,, 我对你们老大也是呵呵了,一开始我们就规定:不规定细节,在乎这个还不如多给手底下的兄弟们一些赞扬。 来写 tcl 吧,包您满意,必须按您的写法,左花括号在行尾 我喜欢第一种 {
} 关于大括号的对齐问题业界并没有统一的要求,除了少数IDE(比如visaul studio)会自动将代码格式化为你们老大要求的格式外;更多的IDE并不会限制大括号的格式。 大学时学.net的时候,我也曾尝试改变自己的习惯写成你们老大要求的格式,但后来觉得多占一行反而让代码可读性降低了,于是便放弃了。
@毕兆尚 回答里说的好,如果你们老大只是口头要求你而不是制定了成文的规范,那么你应该和老大沟通沟通让他制定完善成文的规范,而不是拍脑瓜子说别人的代码不规范。毕竟代码规范的存在目的在于减少团队合作中的混乱减少维护成本,但如果作为技术管理者,仅仅是以拍脑瓜的形式要求别人按自己的习惯来写代码,那效果适得其反。
当然,如果公司有成文规定要求这么写,那么你就需要花点心思去熟悉一下并遵守公司的编码规范才好 让我想起了我在写算法题的时候经常用xxx(){
//code...
}
因为个人觉得这样不占地方(一己之见),比较简洁。
但是我也尝试过很多次xxx()
{
}
个人比较喜欢上面的。其实是因为第二个要写完整个一行xxx(){}后(个人习惯),
需要往前倒推2个backspace.......(其实我很懒)。
但是如果团队有规范,或者说一起编程的同学同事他们看不惯(处女座请原谅),我也会按照他的方法写,毕竟报大神大腿就不能任性了。
re答主: 如果老大并不强求你怎么写,你就按照习惯就好啦,毕竟一个括号老大应该不 至于太苛刻。 如果真的是项目组规范了一下,最好还是规范着来。毕竟大家 都能看的顺手也能提高项目效率吧。

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

Key players in HTTP cache headers include Cache-Control, ETag, and Last-Modified. 1.Cache-Control is used to control caching policies. Example: Cache-Control:max-age=3600,public. 2. ETag verifies resource changes through unique identifiers, example: ETag: "686897696a7c876b7e". 3.Last-Modified indicates the resource's last modification time, example: Last-Modified:Wed,21Oct201507:28:00GMT.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.