05.01.2013 Views

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Syntax Coloring<br />

As you type, Xcode analyzes the syntax of your code and automatically colors the text based on<br />

what it represents. While the colors can be set to your personal preference, by default, keywords<br />

are pink, macros are brown, comments are green, numerical constants are blue, and string constants<br />

are red.<br />

Since your code remains black, the colors help it stand out. It also helps you keep your<br />

strings and comments properly closed. If, for example, you forget to type a closing quotation<br />

mark, the bright pink color of your code will both indicate that something’s wrong and give you<br />

an immediate idea of where the problem is.<br />

Automatic Formatting<br />

While whitespace remains optional in most languages, no programmer I’ve ever met would consider<br />

forgoing it. Xcode will automatically indent your code, and if you like, will even insert<br />

closing braces for you. Aside from keeping your code tidy and preventing premature wear on<br />

your Tab key, automatic formatting is another trick to help you notice mistakes early. Forgetting<br />

a brace or bracket will cause subsequent lines to format improperly.<br />

Autocompletion<br />

Terseness is the enemy of readability, but descriptive variable and function names take longer to<br />

type, cramping a coder’s mind and hands. Autocompletion combines the best of both worlds.<br />

Typing just a few letters can produce descriptive, readable code. Autocompletion further saves<br />

time by inserting replaceable argument tokens in method names. Typing Cmd+/ will highlight the<br />

next token.<br />

Again, this convenience also prevents errors. Assuming you pick the correct completion, the<br />

expanded text will always be correct, while typing out the entire name by hand is prone to<br />

human error. It’s a good habit to always activate autocompletion, even when you’ve typed something<br />

out, just to make sure you didn’t make a mistake.<br />

The autocompletion suggestions list can be activated by pressing Esc. From Xcode’s preference<br />

window, you can also choose to have autocompletion occur automatically if you pause<br />

while typing. Since that could quickly become annoying, the length of the pause is also customizable.<br />

Code Scoping<br />

Xcode 3 introduces a ribbon bar that runs alongside the main code editing window. The ribbon<br />

shows varying shades of gray depending on the scope of the code beside it. This gives a quick<br />

visual check that all your braces and brackets are properly balanced. If you need a little extra<br />

indication, hovering your cursor above the ribbon will extend its shading to the code itself,<br />

giving an exact indication of scope.<br />

Code Folding<br />

CHAPTER 25 MAC <strong>OS</strong> X DEVELOPMENT: THE TOOLS 467<br />

Xcode 3 also introduces code folding, which collapses a given scope in the editor. For example, a<br />

long if statement that doesn’t apply to what you’re trying to do can be collapsed into a single<br />

line. Similarly, functions and sections can be collapsed. The collapsing is syntax aware, and if<br />

you use the line numbering bar, the appropriate numbers will be skipped so you don’t lose your<br />

place.<br />

To fold your code, click the ribbon bar. When code is folded, a disclosure triangle will<br />

appear in the ribbon bar. Clicking this disclosure triangle will unfold that section of code.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!