- How will code style be graded?
Here are some guidelines:
- Complex pieces of code should be documented in comments so that they become easier for the reader to understand—but don't overdo it with comments for trivial things.
- Common, general-purpose functionality should be decomposed into helper functions to avoid repeated code—don't overdo this either, e.g. by making it difficult to understand the flow of execution.
- Code should use consistent naming conventions and not contain commented-out code or vestiges of debugging.
- Please check the return values of all functions in which an error could occur, and handle these errors gracefully. Throwing an exception is one graceful way to handle an unrecoverable error.
- Avoid memory errors and leaks, egregious performance issues (e.g. allocating large amounts of memory for no reason) or unnecessarily complex approaches (e.g. a complicated data structure that is only marginally more efficient than something much simpler, or something available in the C++ standard library).
- You can check your code for memory leaks, invalid accesses, and undefined behavior by compiling with
cmake .. -DCMAKE_BUILD_TYPE=RelASanand then
make checkor running any of the individual apps.
- Before submitting each assignment, please run
make format(to standardize the formatting), and make sure to remove any dummy code or comments that were included with the starter code.
- How much of my grade will come from style and to the quality of my writeup?
- How do I run an individual test?
- Can I add include lines in the header files?
- Why does 'make check' fail even though it's in the Sponge README?
- What's the procedure if I want to use some of my late days?
- How do I use
$ git clone [bundle name] [unbundled name].
cdinto the unbundled directory.
$ git logand verify that you see the commits you expect to.
- Copy the commit hash of the starter code commit.
$ git diff [hash]to make sure they see all changes you want to submit.
- How do I debug?
gdb(on the VM,
sudo apt-get install gdb).
gdbon the executable corresponding to the test you want to debug (from the
ls teststo see the executables). e.g. from the build directory:
- The output of the test failure will show you the part of the test that failed. To set a breakpoint at that part of the test, break on the line in the test file where the test harness for that part is created. The test files are in
sponge/build/tests). e.g. if you're failing the
break 83(i.e. where the
write-pop2-endtest harness is created).
- You can set breakpoints on your functions using the function names, as usual.
Grading breakdown for labs: 15% style, 10% writeup, 75% functionality.
ctest -R '^test_name$'
Short Answer: This is a typo in our documentation. You should run
make check_lab0, not
Long Answer: The make target,
check, runs the entire sponge test suite. The full test suite requires a shell script,
tun.sh, which you won't get until a later lab. The make target
check_lab0 will just test lab0. You should be able to run it with the lab0 starter code (although it will return an error until you've completed the lab!).
To use a late day, please email the staff list (email@example.com) by the lab deadline, letting us know if you are using late days. With weekly labs, the CAs want to be able to get feedback to you quickly. As such, we will start grading as soon as the deadline passes, and want to avoid redundantly grading submissions that weren't intended to be final.
Here are some links to resources to learn Git.
Brief summary: Git commits store a snapshot of the current state of your code. For instance, say you break a feature that you know used to work, but aren't sure which code caused it to break. If you made a commit after getting that feature working, you can checkout that commit to see what things looked like in the good old days when it worked. So, make a commit every time you get something working! To make a commit:
First, git add the files you've changed - you must add before every commit. e.g.
git add ../libsponge/byte_stream.*
Then, commit with a message describing the state of the code. e.g.
git commit -m "All tests pass except many_writes times out."
You can see which files you modified by running
git status. To really understand the state of a Git repository, the command-line
tig tool, or the graphical
gitk tool, can be very helpful.
A handy shortcut to commit all modified files is
git commit -am "[message]".
git push - when you're ready to submit, you'll use git bundle instead to package your commits.
Sanity check: If you want to verify that you have submitted exactly the files you intended to, you may find the following useful.
First, once you've committed, run
git status. You should see a message saying
nothing to commit, working tree clean. If you have uncommitted changes, you'll see this instead:
Changes not staged for commit:.
Second, after you've copied your git bundle to rice, and logged into rice:
gdb is a great tool for debugging the labs! Check out the CS107 guide if you need a refresher.
gdb to debug a test:
- We don't recommend modifying any files in the
libsponge/utildirectory, since messing up the sponge library will make debugging difficult.
- If a test is timing out, but you want to check if it passes without the timeout, run the test executable individually, which won't enforce the timeout. e.g. from the build directory:
gdbmay help debug timeouts. While running the test in
gdb, if it appears to hang (meaning it may be executing a slow portion of code), ctrl-C and backtrace to pause and see which code was executing.
- What should the behaviour of my program be if the caller tries to peek or pop with a
lengreater than what is available?
We don't have any preference on the behavior if the caller tries to peek or pop more than is available in the stream, as long as you behave reasonably and don't crash in that situation. If you want to peek/pop the maximum available, that is fine with us. If you want to throw an exception (either for an overlength peek or an overlength pop), that is also fine with us.
- How fast should my code be? Here's a reasonable rule of thumb: if any of your tests are taking longer than 2 seconds, it's probably good to keep exploring other ways of representing the ByteStream. This lab doesn't require any sophisticated data structures, but it might still take some trial-and-error to find a reasonable approach. Sometimes "big-O" analysis can be misleading about the performance of real programs—the constant factors can matter a lot!