ChartsOrg / ChartsOrg/Charts

Brackets formatting

Open
#3,279 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Our (undocumented) style guide for brackets is to write the opening bracket on a new line like so:
```
func myFunction()
{
// Draw stuff
}
```
This is fine until we get into trailing closure syntax. How are we supposed to write it? We have options
```
// 1
myFunctionWithTrailingClosure { arg 1, arg2 in
// Do stuff
}

// 2
myFunctionWithTrailingClosure
{ arg 1, arg2 in
// Do stuff
}

// 3
myFunctionWithTrailingClosure
{
arg 1, arg2 in
// Do stuff
}
```

Option 1 is the only way I have ever seen this written and is the only clear way to write trailing closures, but it goes against our code style. I am strongly against the opening bracket on a new line because while it does make method and type declarations slight easier to read by forcing a new line, it makes chaining (`if-elseif-elseif`...) much more difficult to identify and read. There needs to be a final decision made on this.

Given most of the library was written using Swift, but without taking advantage of many Swift features I'd argue that the opening bracket on a new line comes from more crowded languages (e.g. C, Java), without consideration for Swift's cleaner syntax. As a result, we should move to the more standard (as seen throughout the Swift stdlib and foundation libraries, the Swift book, many popular iOS websites such as [RayWenderlich](https://www.raywenderlich.com), all of Apple's sample code, and even autocomplete) style of
```
func myFunction() {
// Draw stuff
}
```

Contributor guide

Open the contributing guide

Research direction

The issue names no repository files or tests. Start by reviewing the existing Swift style in the library alongside the Swift standard library, Foundation, the Swift book, and the cited Apple sample code. Done means reaching a final decision on brace placement for declarations and trailing closures, then recording the agreed convention and its scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
developer-experience
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.