GithubHelp home page GithubHelp logo

Comments (7)

 avatar commented on July 24, 2024

In my life coding, I always put a comment where a break would be that reads

// intentionally omitted break

I'd vote something like that.

Sent from my iPhone

On Nov 8, 2013, at 3:06 AM, Matthijs Hollemans [email protected] wrote:

How to format a switch statement?

How to point out that a case falls through?


Reply to this email directly or view it on GitHub.

from objective-c-style-guide.

gregheo avatar gregheo commented on July 24, 2024

@elephantronic I love the phrase "life coding"!

I go with a boring /* fallthrough */ myself. I agree, this should always been commented if you mean to leave out the break.

switch (foo) {
case 1:
  // stuff
  // *** fallthrough! ***
case 2:
  // moar stuff
  break;
default:
}

from objective-c-style-guide.

icanzilb avatar icanzilb commented on July 24, 2024

hm .. I think I have never in my life had a switch that lets cases fall through ... I find it confusing and easy to miss out on when debugging.

I have either completely overlapping cases:

case 1: case 2: case 5:
// stuff
break;

or

case 1:
//stuff 1
break;
case 2
//stuff 2
break;

etc.

from objective-c-style-guide.

hollance avatar hollance commented on July 24, 2024

I suggest we always include a default: case.

switch (condition) {
  case 1: {
    // ...
    break;
  }
  case 2: {
    // ...
    break;
  }
  default: {
    // ...
    break;
  }
}

I don't think the braces are necessary all the time, but definitely when a case contains more than one line.

from objective-c-style-guide.

funkyboy avatar funkyboy commented on July 24, 2024

More over: if you are switching on an enumeration default is not needed.

On Sat, Nov 9, 2013 at 10:15 AM, Matthijs Hollemans <
[email protected]> wrote:

I suggest we always include a default: case.

switch (condition) {
case 1: {
// ...
break;
}
case 2: {
// ...
break;
}
default: {
// ...
break;
}}

I don't think the braces are necessary all the time, but definitely when a
case contains more than one line.


Reply to this email directly or view it on GitHubhttps://github.com//issues/19#issuecomment-28123255
.

Cesare Rocchi
http://studiomagnolia.com

from objective-c-style-guide.

 avatar commented on July 24, 2024

If you are switching on an enumeration, it's recommended practice to not include a default case because the compiler cannot warn you for unhandled values.

Sent from my iPhone

On Nov 9, 2013, at 4:47 AM, Cesare [email protected] wrote:

More over: if you are switching on an enumeration default is not needed.

On Sat, Nov 9, 2013 at 10:15 AM, Matthijs Hollemans <
[email protected]> wrote:

I suggest we always include a default: case.

switch (condition) {
case 1: {
// ...
break;
}
case 2: {
// ...
break;
}
default: {
// ...
break;
}}

I don't think the braces are necessary all the time, but definitely when a
case contains more than one line.


Reply to this email directly or view it on GitHubhttps://github.com//issues/19#issuecomment-28123255
.

Cesare Rocchi
http://studiomagnolia.com

Reply to this email directly or view it on GitHub.

from objective-c-style-guide.

ndubbs avatar ndubbs commented on July 24, 2024

Could someone add this as a new section after "Enumerated Types," then send a pull request?

from objective-c-style-guide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.