-
Notifications
You must be signed in to change notification settings - Fork 23
Stage 0: Adjusted from feedback #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Adrianamm
wants to merge
5
commits into
frcsoftware:main
Choose a base branch
from
Adrianamm:jayfeedback-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
efd6c7e
Added feedback for stage 0
Adrianamm c39b26e
Merge branch 'main' into jayfeedback-2
zachwaffle4 2c75093
Merge branch 'main' into jayfeedback-2
zachwaffle4 891fe66
Apply batched suggestions from code review
Adrianamm c33e101
updated with feedback
Adrianamm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,41 +9,31 @@ codeRegionSources: | |
|
|
||
| ## Syntax | ||
|
|
||
| As you start programming, you might make a mistake or make a typo. | ||
| When that happens, your code will have a red line under it. | ||
| This is because Java has rules called syntax. | ||
| Syntax is a set of rules that have to be followed so that the computer can understand and run your code. | ||
| It’s important to pay attention to the syntax! | ||
| If your code has a red line under it, first check whether the syntax is correct. | ||
| This can be done by researching online or by comparing your code with examples. | ||
|
|
||
| You can also learn what’s wrong with your code when you put the cursor over the section of the code with the red line and read what the error message is. | ||
| Error messages will not tell you exactly what's wrong with your code. | ||
| If you’re unsure on what the error message means, you can look it up to get additional context. | ||
|
|
||
| <Slides> | ||
|  An example of a syntax error (note the squiggly line) | ||
|
|
||
|  An example of a syntax error popup | ||
|
|
||
| </Slides> | ||
| Syntax is the basic set of rules that all programs in a language must follow. | ||
|
Adrianamm marked this conversation as resolved.
|
||
| Java's syntax is very specific, there are different rules for how certain lines of code are written. | ||
| Syntax errors are the most common sorts of errors. | ||
| Whenever the syntax is mentioned, pay attention closely. | ||
|
|
||
| ## Variables | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #240 "This could use more emphasis! Examples of bad variable names vs good. There's probably a good code snippet showing why good variable names are important" |
||
|
|
||
| Variables are containers that are used to store information in a program. | ||
| This could be a variable that holds the temperature or a variable that holds the speed of the motor. | ||
|
|
||
| Variable declarations have the following syntax: | ||
| To make a variable, there are 5 parts: | ||
|
|
||
| {/* rli:ignore */} | ||
| 1. Data type | ||
| 2. Name of the variable | ||
| 3. Equals sign | ||
| 4. Value | ||
| 5. Semi-colon | ||
|
|
||
| ```java | ||
| Datatype name = value; | ||
| ``` | ||
| ### Data Types | ||
|
|
||
| Data types refer to the type of value that our variable has. | ||
| It helps tell our program more information about our variables such as what type of information it holds and how it can be used. | ||
|
Adrianamm marked this conversation as resolved.
Outdated
|
||
| Data types can include numbers, characters, or a string of words. | ||
| Unlike many programming languages like Python, in Java, you must specify the type of every variable. | ||
|
Adrianamm marked this conversation as resolved.
Outdated
|
||
| This makes your programs more reliable, because the compiler will prevent you from using the wrong type with an error. | ||
|
|
||
| Some example data types that are commonly used in FRC programming are: | ||
|
|
||
| - int: Integer numbers that are positive or negative. | ||
|
|
@@ -56,16 +46,22 @@ Some example data types that are commonly used in FRC programming are: | |
| - String: Holds a sequence of characters. | ||
| Denoted by double quotes ("). | ||
| Example: “Hello World” | ||
| - char: Holds a single character. | ||
| Denoted by single quotes ('). | ||
| Example: 'A' | ||
|
|
||
| The name of your variable can be almost anything you want, but it should be easy to read and make sense to others who may be reading your code. | ||
| One major exception is spaces, which are forbidden in variable names. | ||
| Instead, you should write variables in what's known as camel case (`frontLeftDrive`). | ||
| Upper snake case (`FRONT_LEFT_DRIVE`) should be used instead for constants, which we will learn about later in the course. | ||
| Variable names can have numbers at any point except for the first character. | ||
| (`motor2` is a valid name, `2motor` is not). | ||
| <Aside type="note"> | ||
|
Adrianamm marked this conversation as resolved.
|
||
| When creating a String, make sure the S is capitalized! `string robotName = | ||
| "Plunk"` will throw an error but `String robotName = "Plunk"` will not. | ||
| </Aside> | ||
|
|
||
| ### Name | ||
|
|
||
| In Java, variable names may only be letters, numbers and underscores `_`, and variable names cannot start with numbers. | ||
|
Adrianamm marked this conversation as resolved.
Outdated
|
||
| The name of the variable can be whatever you want, however, we recommend making them descriptive and easy to read. | ||
| This will make it much easier for you to understand your own code and for others to help you. | ||
|
|
||
| One common variable naming style is camel case, where each word is capitalized except the first. | ||
| For example, `frontLeftDrive`, `currentTemperature`, and `targetPosition` are all camel case. | ||
| Another common variable naming style is upper snake case, where each word is capitalized and an underscore is used in between each word. | ||
| For example: `BACK_LEFT_DRIVE`, and `GEAR_RATIO` are in upper snake case. | ||
|
|
||
| <Aside type="note"> | ||
| Java is a case-sensitive programming language! | ||
|
|
@@ -75,14 +71,16 @@ Even though it’s spelled the same, if your variable name is MotorID then you t | |
|
|
||
| </Aside> | ||
|
|
||
| ### Semi-colons | ||
|
|
||
| In Java, semi-colons `;` are similar to a period in a sentence. | ||
| It is what tells the compiler when a statement ends. | ||
| Semi-colons are used commonly in programming and aren’t only for creating variables. | ||
| We will see more examples of this later in the course. | ||
| This makes having a semi-colon at the end of your code important. | ||
|
Adrianamm marked this conversation as resolved.
Outdated
|
||
| In most cases, not having a semi-colon will cause an error. | ||
|
Adrianamm marked this conversation as resolved.
Outdated
|
||
|
|
||
| In FRC, variables can be used to hold information about the robot and its different mechanisms. | ||
| The example below shows 3 variables that were used for a climber mechanism, `CLIMBER_ID` is an integer that holds the motor controller ID number which is 51. | ||
| `UP_POSITION` is a double that holds the value -33.5 and `DOWN_POSITION` is a double that holds the value 0. | ||
| ### Example | ||
|
|
||
| Taking what we learned, the following are four variables that each use a different data type. | ||
|
|
||
| ```java #variables | ||
|
|
||
|
|
@@ -105,8 +103,9 @@ A print statement in Java looks like: | |
|
|
||
| ``` | ||
|
|
||
| What the print statement does is take information inside the parentheses, in the previous example, it’s “hello!”, and prints it out to the terminal screen. | ||
| When using a print statement, the text that we want to print out goes inside the parentheses and is in quotes. | ||
| The print statement takes information inside the parentheses, in the previous example, it’s “hello!”, and prints it out to the terminal screen. | ||
|
Adrianamm marked this conversation as resolved.
Outdated
|
||
| When using a print statement, you have to surround a string with quotes, to indicate that you want to work with that text literally. | ||
|
Adrianamm marked this conversation as resolved.
Outdated
|
||
| A print statement without the quotes will cause an error because the compiler will look for a variable by the name instead of printing. | ||
|
Adrianamm marked this conversation as resolved.
Outdated
|
||
| However, if we are printing out the value of a variable, then we do not need quotes, as shown below. | ||
|
|
||
| ```java #printVariable | ||
|
|
@@ -117,6 +116,9 @@ However, if we are printing out the value of a variable, then we do not need quo | |
|
|
||
| When programming, we use comments to write notes that explain what the code does. | ||
| This helps make the code more readable for others because if they are unsure of what your code does, they can read your comments. | ||
| Writing comments can also help you! | ||
| By leaving comments that explain what code does, it can be helpful when trying to understand what your code does and it can be helpful for debugging. | ||
|
Adrianamm marked this conversation as resolved.
Outdated
|
||
|
|
||
| Comments are ignored by the compiler, which also means that you can use comments to prevent code from running. | ||
| In Java, there are two types of comments: single-line comments and multi-line comments. | ||
|
|
||
|
|
@@ -148,6 +150,24 @@ For example, this is a comment with two lines of text. | |
|
|
||
| ``` | ||
|
|
||
| ### Writing Comments | ||
|
|
||
| It's best to use comments to explain what the code is trying to do with words, rather then just restating the code. | ||
| For example, this is a useful comment because it explains what the purpose is and how it accomplishes the task. | ||
|
|
||
| ```java #goodComment | ||
|
|
||
| ``` | ||
|
|
||
| This is not a useful comment because it doesn't tell the reader what the purpose of the code is. | ||
| It just restates the code. | ||
|
|
||
| ```java #badComment | ||
|
|
||
| ``` | ||
|
|
||
| There's no need to use comments for every line of code, but if something might be confusing to someone else later (or even yourself), leave a comment! | ||
|
|
||
| ## Java Fundamentals Exercise | ||
|
|
||
| <Aside type="exercise">WIP</Aside> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.