04.04.2013 Views

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Since the getBreed() method would return the name of a breed, you call the method as<br />

part of an assignment statement so that the returned named will get assigned to the variable<br />

breedName. I’ll be covering OOP in much more detail in Chapter 8.<br />

Naming conventions<br />

Perhaps you noticed that a bunch of the fictitious names I used in the examples were combinations<br />

of multiple words—for example, sleepWellAtNight() <strong>and</strong> getBreed(). This is<br />

referred to as camelback notation. It is common to use it in case-sensitive environments.<br />

By capitalizing the initial character of the multiple words, you can read them more easily.<br />

Notice that the initial letter of the first word isn’t capitalized. Camelback notation is not<br />

required, but highly recommended. However, there are some required naming rules.<br />

Legal names can only contain letters, underscores, numbers, <strong>and</strong> the dollar sign. The initial<br />

character must be a letter, underscore, or dollar sign—not a number. I recommend only<br />

using a letter as your initial character. Following the initial letter, it’s fine to use numbers.<br />

It’s also strongly suggested that you use names that are descriptive. For example, which is<br />

easier to underst<strong>and</strong>: getAge() or abdi()?<br />

The names you define are called identifiers. Based on the preceding rules, here are some<br />

legal identifiers:<br />

String myBall<br />

float speed<br />

int ballCount<br />

float theBallSpeed<br />

boolean YouCanActuallyMakeYourVariableNamesAsLongAsYouLike<br />

String BALL_MANUFACTURER<br />

Here are some illegal ones. Can you tell why?<br />

String Ball 1<br />

int 100bjs<br />

float -weight<br />

int myBall#<br />

The reasons are as follows: Ball 1 is illegal because of the space in the identifier; 100bjs<br />

is illegal because you can’t begin an identifier with a number; <strong>and</strong> -weight <strong>and</strong> myBall#<br />

are illegal because both use illegal characters: - <strong>and</strong> #, respectively.<br />

CODE GRAMMAR 101<br />

63<br />

3

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

Saved successfully!

Ooh no, something went wrong!