How to Approach Writing Code + Lvalues vs. Rvalues
Today I walked you through how to approach solving a larger problem in computer science. You have to break the program down into small parts, solve the small parts, and assemble them into a larger program. This is a skill in and of itself that is built over many years, so today I wanted to show you how I'd go about solving the homework assignment.
This homework was already decomposed somewhat by me in the comments, so I started with that. Then, when I got to the triply nested loop, I wrote the inner block first, tested the hell out of it, then wrote the wrapping loop, tested it, and so forth.
All along the way I was couting all the things. This is a habit you need to get into doing so you can see what your code is doing as it runs. (Or use a debugger, either way.) Many if not most of the questions I get on Discord are from students who haven't the foggiest notion of what their code is doing wrong or where it went wrong - if you get into the habit of logging what your code does, then you'll have a much better grasp on where it goes wrong, when it does go wrong. Which it will.
Then we talked about call by reference and call by value a little more, noting that only lvalues can be passed by reference. lvalues are things that can appear on the left (hence the l) side of an assignment operator. rvalues are things that can't appear on the left side.
x = 7 is okay, because x an lvalue. 7 = x is not okay, because 7 is an rvalue.
This is a bit of terminology that every CS person needs to learn, IMO, because compilers will use these terms in their error messages.
Other Videos By Bill Kerney
2021-09-22 | Ethics in Autonomous Vehicles |
2021-09-21 | Karnaugh Maps, Simplifying If Statements |
2021-09-21 | Destructible Meshes - Blueprint Interactions |
2021-09-20 | Ethical Systems II - Is/Ought + Virtue Ethics |
2021-09-18 | Digital Logic II |
2021-09-17 | Making Video Games Interactive + Blueprints Coding |
2021-09-17 | Doubly Nested Loops + Chars + Strings |
2021-09-17 | Ethical Theories I |
2021-09-17 | Introducing Colorslib |
2021-09-16 | Voronoi Relaxation / Lloyd's Algorithm |
2021-09-15 | How to Approach Writing Code + Lvalues vs. Rvalues |
2021-09-15 | Truth Tables II + Denying the Antecedent + Affirming the Consequent |
2021-09-14 | Under the Hood I + Lighting + Special Effects in UE4 |
2021-09-14 | Introducing Readlib |
2021-09-14 | C++ I/O and Digital Logic |
2021-09-13 | Function Overloading and Commenting Code |
2021-09-13 | Truth Tables - AND, OR, NOT |
2021-09-11 | Call by Reference |
2021-09-10 | Modus Ponens and Modus Tollens |
2021-09-10 | SVN, Voronoi |
2021-09-10 | GDC Talks, Landscape III, Material Functions |