Swift should have a syntax for classes that doesn't require indentation

Originator:brent
Number:rdar://17285095 Date Originated:12-Jun-2014 04:22 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode6-Beta (6A215l)
Classification:Enhancement Reproducible:Always
 
Summary:
A typical Swift file will probably consist of a single class, struct, enum, or extension, along with function definitions and related types. The current syntax for all of these types have the entire definition wrapped in curly brackets. That means that, except for about five lines at the top of the file and one at the bottom, every line in the file is indented at least one tab stop.

This wastes horizontal space in an already wordy framework, and it just plain looks funny. There should be an alternate syntax for definitions of classes and other types which implicitly means “for the rest of this file”, and which does not require indentation.

Steps to Reproduce:
1. Create a Swift file.
2. Put a large class in it.
3. Read it.

Expected Results:
Top-level items in the class, like method or property definitions, are against the left margin of the file.

Actual Results:
Top-level items are indented one tab stop.

Notes:
This was a nice feature of Objective-C, but it’s not the only language that worked this way. Perl is another example, and Perl 6 kept that feature even as it added an alternate block-style syntax too. Even C++ implementation files don’t demand you indent all the method definitions.

Possible syntaxes for this include:

class Foo (followed by a newline, with no “{“ before the next keyword)
begin class Foo
class Foo: (with no class names forthcoming) / class Foo: Base:
class Foo ->

You know the grammar better than I do, though, so you’re in a better position to choose.

It would be an error to have two of these top-level type declarations in one file.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!