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 revision | ||
programming_fundamentals_with_processing:ch03-places-to-put-things [2017/07/26 17:59] – [Good names] mithat | programming_fundamentals_with_processing:ch03-places-to-put-things [2017/07/26 18:06] (current) – mithat | ||
---|---|---|---|
Line 123: | Line 123: | ||
$x = \frac{{ - b \pm \sqrt {b^2 - 4ac} }}{{2a}}$ | $x = \frac{{ - b \pm \sqrt {b^2 - 4ac} }}{{2a}}$ | ||
- | However, most programming languages let you give variables long names--subject to certain rules. **TODO verify:** The rules in Processing say that an identifier must start with an upper or lowercase letter and then can be made up of any combination of upper or lowercase letters, numbers, and the underscore character. Note that spaces in identifiers are not allowed. | + | However, most programming languages let you give variables long names---subject to certain rules. **TODO verify:** The rules in Processing say that an identifier must start with an upper or lowercase letter and then can be made up of any combination of upper or lowercase letters, numbers, and the underscore character. Note that spaces in identifiers are not allowed. |
- | There is also a HolyList® of identifiers that Processing has reserved for its own use--so called **reserved words**. You cannot use reserved words for your own identifiers. For example, '' | + | There is also a HolyList® of identifiers that Processing has reserved for its own use---so called **reserved words**. You cannot use reserved words for your own identifiers. For example, '' |
Finally, Processing is a **case sensitive** language, meaning that the identifier '' | Finally, Processing is a **case sensitive** language, meaning that the identifier '' | ||
Line 158: | Line 158: | ||
</ | </ | ||
- | 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: |
<file java variables3c.pde> | <file java variables3c.pde> | ||
Line 184: | Line 184: | ||
int recHeight; | int recHeight; | ||
</ | </ | ||
- | are variable declarations--they announce to the Processing compiler that you plan to use variables with names '' | + | are variable declarations---they announce to the Processing compiler that you plan to use variables with names '' |
Most programming languages, including Processing, are **typed languages**. A typed language is one that differentiates between different types of data: an integer number is one type of data, a character such as ' | Most programming languages, including Processing, are **typed languages**. A typed language is one that differentiates between different types of data: an integer number is one type of data, a character such as ' | ||
Line 220: | Line 220: | ||
=== int === | === int === | ||
- | The '' | + | The '' |
<code java> | <code java> | ||
Line 265: | Line 265: | ||
=== double === | === double === | ||
- | The '' | + | The '' |
=== char === | === char === | ||
- | The '' | + | The '' |
<code java> | <code java> | ||
Line 313: | Line 313: | ||
- | ---- | + | <WRAP center round box 80%> |
=== Geek break: Why doesn' | === Geek break: Why doesn' | ||
Line 324: | 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 ===== | ||
Line 339: | Line 337: | ||
int foo = 66; | int foo = 66; | ||
</ | </ | ||
- | The above statement declares an integer variable named '' | + | The above statement declares an integer variable named '' |
- | If you try to access the value of a variable without initializing it or otherwise giving it a value, the Processing IDE will complain at you. This is because it is widely considered bad programming practice to rely on the default values given to variables by a language. The reason for this is that many languages do not specify //any// default values for variables--at least for some categories. In other words, the " | + | If you try to access the value of a variable without initializing it or otherwise giving it a value, the Processing IDE will complain at you. This is because it is widely considered bad programming practice to rely on the default values given to variables by a language. The reason for this is that many languages do not specify //any// default values for variables---at least for some categories. In other words, the " |
)) | )) | ||
Line 351: | Line 349: | ||
char firstInitial, | char firstInitial, | ||
</ | </ | ||
- | declare two variables--'' | + | declare two variables---'' |
You can even combine variable initialization and multiple declaration in the same statement: | You can even combine variable initialization and multiple declaration in the same statement: | ||
Line 360: | Line 358: | ||
==== Potential pitfalls ==== | ==== Potential pitfalls ==== | ||
- | Syntactic sugar can be a tricky thing. On the one hand, syntactic sugar makes it easier to write your programs--it increases **writability**. When done right, it also makes programs easier to read--it increases **readability**. However, when a language has too much syntactic sugar, then the number of ways to express the same idea increases to such a level that it ends up making it //harder// to read--because the reader has to know all the intricacies of all the different possible ways of doing things. | + | Syntactic sugar can be a tricky thing. On the one hand, syntactic sugar makes it easier to write your programs---it increases **writability**. When done right, it also makes programs easier to read--it increases **readability**. However, when a language has too much syntactic sugar, then the number of ways to express the same idea increases to such a level that it ends up making it //harder// to read--because the reader has to know all the intricacies of all the different possible ways of doing things. |
programming_fundamentals_with_processing/ch03-places-to-put-things.1501091962.txt.gz · Last modified: 2017/07/26 17:59 by mithat