programming_fundamentals_with_processing:ch03-places-to-put-things
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
programming_fundamentals_with_processing:ch03-places-to-put-things [2017/07/26 17:53] – [Math versus programming] mithat | programming_fundamentals_with_processing:ch03-places-to-put-things [2017/07/26 18:02] – [Processing's composite types] mithat | ||
---|---|---|---|
Line 72: | Line 72: | ||
One way we can learn the value of a variable is to output it to the console as in the code below: | One way we can learn the value of a variable is to output it to the console as in the code below: | ||
- | **program '' | + | <file java variables2.pde> |
- | + | ||
- | <code java> | + | |
void setup () { | void setup () { | ||
int a; | int a; | ||
Line 85: | Line 83: | ||
println(a); | println(a); | ||
} | } | ||
- | </code> | + | </file> |
or, if you like, | or, if you like, | ||
- | **program '' | + | <file java variables2a.pde> |
- | + | ||
- | <code java> | + | |
void setup () { | void setup () { | ||
int a; | int a; | ||
Line 103: | Line 99: | ||
println(a); | println(a); | ||
} | } | ||
- | </code> | + | </file> |
You can also use variables in places where Processing expects literal constants. Here's an example: | You can also use variables in places where Processing expects literal constants. Here's an example: | ||
- | **program '' | + | <file java variables3.pde> |
- | + | ||
- | <code java> | + | |
void setup () { | void setup () { | ||
int a; | int a; | ||
Line 118: | Line 112: | ||
rect(0, 0, a, b); | rect(0, 0, a, b); | ||
} | } | ||
- | </code> | + | </file> |
This will draw a rectangle whose upper left corner is at the origin of the canvas, whose width is the value of '' | This will draw a rectangle whose upper left corner is at the origin of the canvas, whose width is the value of '' | ||
Line 139: | Line 133: | ||
Knowing these rules, we could rewrite '' | Knowing these rules, we could rewrite '' | ||
- | **program '' | + | <file java variables3a.pde> |
- | + | ||
- | <code java> | + | |
void setup () { | void setup () { | ||
int var_one; | int var_one; | ||
Line 151: | Line 143: | ||
rect(0, 0, var_two, var_one); | rect(0, 0, var_two, var_one); | ||
} | } | ||
- | </code> | + | </file> |
or, | or, | ||
- | **program '' | + | <file java variables3b.pde> |
- | + | ||
- | <code java> | + | |
void setup () { | void setup () { | ||
int rec_width; | int rec_width; | ||
Line 166: | Line 156: | ||
rect(0, 0, rec_width, rec_height); | rect(0, 0, rec_width, rec_height); | ||
} | } | ||
- | </code> | + | </file> |
The only difference in the the three versions of the program is the names we have given to the variables; the programs are functionally identical. However, of the three versions a lot of programmers would probably prefer '' | The only difference in the the three versions of the program is the names we have given to the variables; the programs are functionally identical. However, of the three versions a lot of programmers would probably prefer '' | ||
Closely related to this are **coding conventions**--mutually agreed upon standard practices for writing code. Coding conventions are not rules; rather they are standard practices that have emerged over time and/or have been agreed upon ahead of time by a team of programmers. A common coding convention for variable names in Processing is to use CamelCase (i.e., capitalizing the first letter of adjacent words) with the first letter of the first word in lower case. Rewriting the example we have been working with so far using the CamelCase convention would yield: | Closely related to this are **coding conventions**--mutually agreed upon standard practices for writing code. Coding conventions are not rules; rather they are standard practices that have emerged over time and/or have been agreed upon ahead of time by a team of programmers. A common coding convention for variable names in Processing is to use CamelCase (i.e., capitalizing the first letter of adjacent words) with the first letter of the first word in lower case. Rewriting the example we have been working with so far using the CamelCase convention would yield: | ||
- | **program '' | + | <file java variables3c.pde> |
- | + | ||
- | <code java> | + | |
void setup () { | void setup () { | ||
int recWidth; | int recWidth; | ||
Line 183: | Line 172: | ||
rect(0, 0, recWidth, recHeight); | rect(0, 0, recWidth, recHeight); | ||
} | } | ||
- | </code> | + | </file> |
- | An alternative convention (used in program '' | + | |
+ | An alternative convention (used in program '' | ||
===== Data types ===== | ===== Data types ===== | ||
Line 323: | Line 313: | ||
- | ---- | + | <WRAP center round box 80%> |
=== Geek break: Why doesn' | === Geek break: Why doesn' | ||
Line 334: | Line 323: | ||
These might seem like small issues when you are just starting programming, | These might seem like small issues when you are just starting programming, | ||
+ | </ | ||
- | |||
- | ---- | ||
===== Syntactic sugar ===== | ===== Syntactic sugar ===== |
programming_fundamentals_with_processing/ch03-places-to-put-things.txt · Last modified: 2017/07/26 18:06 by mithat