Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Matching braces always line up vertically in the same column as their construct.
- example:
- void foo()
- {
- while (bar > 0)
- {
- System.out.println();
- bar--;
- }
- if (oatmeal == tasty)
- {
- System.out.println("Oatmeal is good and good for you");
- }
- else if (oatmeal == yak)
- {
- System.out.println("Oatmeal tastes like sawdust");
- }
- else
- {
- System.out.println("tell me pleeze what iz dis 'oatmeal'");
- }
- switch (suckFactor)
- {
- case 1:
- System.out.println("This sucks");
- break;
- case 2:
- System.out.println("This really sucks");
- break;
- case 3:
- System.out.println("This seriously sucks");
- break;
- default:
- System.out.println("whatever");
- break;
- }
- }
- All if, while and for statements must use braces even if they control just one statement.
- Reasoning: Consistency is easier to read. Plus, less editing is involved if lines of code are added or removed.
- if (superHero == theTick) System.out.println("Spoon!"); // NO!
- if (superHero == theTick)
- System.out.println("Spoon!"); // NO!
- if (superHero == theTick) {
- System.out.println("Spoon!");
- } // NO!
- if (superHero == theTick)
- {
- System.out.println("Spoon!");
- } // YES!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement