Swift-style-guide: The semicolons can help to improve the Xcode's performance

Created on 16 Nov 2017  ·  6Comments  ·  Source: raywenderlich/swift-style-guide

EN:
With out semicolons, the xcode will waste too much CPU in loading/indexing/analyzing the Swift code and grammar,
and this lead the Xcode to crash/no-response more frequently.
So, without semicolons is not a good choice for coding in Swift.
中文:
没有分号的话,Xcode 将消耗更多的CPU资源来处理加载、索引、分析 Swift 代码和语法,由此而导致的问题就是,Xcode 将会更频繁的崩溃/无响应。
所以在 Swift 中,不使用分号并不是一个好的选择。

More:
笔者在使用Swift 开发的过程中,在没有使用分号时,每天 Xcode 平均崩溃 10 次以上,非常影响开发效率。
The xcode crash or no-response more than 10 times everyday, when I coding Swift without semicolons.

All 6 comments

Source or benchmarks proving this?

The wider Swift community — see nearly any popular Swift open source library — doesn’t use semicolons.

Further, Apple has intentionally moved away from C-style programming practices... such as removing C-style for loops, ++ operator, etc.

I wouldn’t be surprised if semicolons too are even removed in a future version of the language.

For these reasons, even if there is a slight performance benefit at compile time, I’m personally strongly against this change.

let obj = NSObject()  
// Type `if` here, you can not find the `if` statement in the completion suggestions list.
// But if add a semicolon to the previous line or write a blank line between the previous line, the `if` statement completion suggestion will be in the list.

This simple example means: the xcode may wast CPU to process the grammar, but with a wrong result.

And I found that most crashes of the xcode appears at rebuilding the grammar after editing a statement.

I would direct this bug to Apple instead. I haven't used semicolons since the dinosaurs roamed the earth (Objective-C days) and don't recognize the problem you are describing.

We need some benchmark and to raise this bug to Apple (will do it ASAP and post the RDAR #, please dupe it), but if true and if Apple did not or could not have a fix before say Swift 5 or 6 not reverting to use more semi colons would be a sign of software zealotry rather than a productivity loss you would hardly be able to explain at any professional meeting.

Thanks for bringing this up. I reported the code completion issue as https://bugs.swift.org/browse/SR-6454

Hopefully it can be fixed in Swift 4.1. Apple is leading an effort to create a totally new tooling framework libSyntax written in all Swift! It is open source too so you can get involved.

If you have other concrete cases where autocomplete breaks down, I think it would be useful to hear about.

Tooling issues aside, semicolons and extra punctuation add to cognitive load and don't do anything for clarity which is the original motivation for their removal as a requirement. See Dave Abrahams eulogy to semi-colons in the Advanced Swift from WWDC 2014 talk.

Unless there is a huge sea change in the Swift community, semicolons aren't coming back. For that reason I am closing this issue. However, by all means, do report bugs that you find. It helps the whole community go forward! 😄

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aramezk picture aramezk  ·  9Comments

WingYn picture WingYn  ·  15Comments

icanzilb picture icanzilb  ·  6Comments

samkim102 picture samkim102  ·  6Comments

gokselkoksal picture gokselkoksal  ·  9Comments