How to Approach Writing Code + Lvalues vs. Rvalues

Channel:
Subscribers:
2,640
Published on ● Video Link: https://www.youtube.com/watch?v=czfXf1kmtVQ



Category:
Guide
Duration: 1:18:55
171 views
1


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.







Tags:
csci 40
lvalue
rvalue
decomposing software
writing code