Syntax convention for Functions/Method carriage spacing

I would like to know if there is meant to be one or two spaced below a Function/Method when created:

e.g.

func shouldItBeThisWay() {

let choice1: Bool = false
}

or

func thisWay() {

let choice2: Bool = false
}

the second spacing will not be shown here thanks to the way the auto-formatting works, but the "thisWay() function has two carriage spaces

It might seem odd to have two, but at times with immediate For Loops it can be easier to read. I was just unsure if there were specific Swift guidelines on this?

I’m having trouble understanding your question.

You can put text into code voice with ASCII’s single `grave accents`.

And you can put whole sections into code voice with three of them:

```

let this = be.code()

```

If you do that it will respect your spacing, and we will be better able to see what you are trying to ask.

Sorry, like this:

func shouldItBeThisWay() {

let choice1: Bool = false
}

or

func thisWay() {


let choice2: Bool = false
}

For me it's readability, but for other more experienced coders it might mean life and death.

Like your other question, it makes no syntactic difference.

Most style guides would recommend indenting the body of the function:

func mostCommonRecommendation() {
    doStuff()
}

But there is almost no agreement on how much vertical space should go where. (Though multiple empty lines in a row is somewhat rare.) I stick empty lines into my code roughly the same as I put paragraph breaks into my prose. They sort of group logically related things, but there isn’t a precise rule and it is somewhat dependent on the context. Some developers think like movers, wanting to have the most possible fit on the screen at a time, disliking “wasted” space. Others think more like composers, making very careful use of the void to frame the content. This one is really up to you to decide for yourself.

1 Like

Useful apologies, I'll consider myself a composer.

I didn't realise that I didn't indent, I take that for granted in Xcode, thanks for pointing that out.

Terms of Service

Privacy Policy

Cookie Policy