Lab 10 FAQ
General Recommendations | Debugging Advice | SocialNetwork class | InstaFace program
General Recommendations
- Ask yourself the questions that I/the student assistant asks you when you're stuck solving a problem.
- Test most methods (exception: __init__) right after you implement them. If you make mistakes, you're likely to repeat those mistakes in each subsequent method, meaning that you'll spend even more time debugging. Catch mistakes early to correct yourself.
- Test each class thoroughly before moving on to the next class so that you find problems early
- Comment your code! Commenting helps you remember _why_ you coded something the way you did.
- Think about what data you have access to and what data types they are. The most common issue is students forgetting a variable's data types and what you can do with that data type. Perhaps draw yourself a picture of the data, to remind yourself what you're dealing with, since the ideas are abstract. I also recommend naming your variables in ways that help you remember the data type to have less "cognitive strain". Refer to the APIs for the data structures (you should have handouts for all of the data structures).
- Look at previous examples/solutions/labs that solve similar problems to what you're facing. You have read files, you have formatted strings, you have used dictionaries (in class and in labs), you have written classes. Review the examples and remember what you did and why you did that.
Debugging Advice
- When you run into problems, print out variables or other information that may be useful to make sure that the variables have the values that you expect.
- Make sure you adhere to the data types expected for the parameters to methods--check the comments to confirm what should be passed into the method. For example, ids are strings. You can choose to make ids integers, but that will have a far-reaching effect on your code, so think about that choice carefully.
- Underscore or not? You will use an underscore when you defined the variable name or method to begin with an underscore. We will use underscores to name instance variables. Only our "helper methods"--methods that are only supposed to be used by that class--will be named with underscores.
- When do I use
self
? Useself
when you need to refer to the object that you're using--for example, if you want to call a method for the class that you're in or if you want to use an instance variable.
SocialNetwork
Reading in the People File. When you read in from a file, what does every line end with? How will that affect your code? Anything you should fix?
Reading in the Connections File.
We solved a similar problem in terms of reading in this
file format in class when we read in the file with the format
name year
on each line.
Exporting People. What is the format of the people file that you read in? That is what you want to write out in this method. Note that this method takes the filename, where as the helper method takes the file object.
InstaFace
Command-line Arguments. Look at the example code from the lab slides. You may want to copy the program into IDLE. To test the command-line arguments, you need to run the program from the terminal. The idea is to make testing the program easier with a variety of files used as inputs (without having to retype the filenames). I've done most of the hard work. Just read the comments for what you need to do.
Recommendations:
- When you're implementing the user interface for InstaFace, write
down the APIs for the
SocialNetwork
andPerson
classes or use, for example,help(Person)
so that you can refer to it.In CSCI209, we use the Java programming language, which makes it easier to use the API without these manual steps.
- The
code for the UI should be fairly straightforward because you're simply
leveraging the APIs of the classes that you already wrote. Do NOT
rewrite code that you already implemented in
the
SocialNetwork
orPerson
class.