Unix ReferenceYou will be working on our department GNU/Linux computers in lab and to do and turn in your work. If you took Comp 11 here at Tufts, you will already have some familiarity. It's a good idea to be familiar with basic Unix commands (Linux is kind of Unix operating system). You will need to create directories, navigate among directories, create, copy and remove files, compile files, etc. One good reference is
Working RemotelyYou can do all your work on the department lab machines, but if you want to work remotely on your own computer, you'll need a program that lets you interact with the department server (the same program you'll use in lab):
ssh(which stands for Secure SHell).
- For Windows, there are a couple choices:
- Download MobaXterm (you may want to go to Settings/Configuration and go to the terminal tab and uncheck “Backspace sends ^H”) or
- Download puTTY from
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html. The most comprehensive choice is the Installer option on that page. To make windows created on the server work, you will need something called X-windows forwarding. Installing
xmingworks. Note: to use X-windows,
xmingmust actually be running. So, start it with
XLaunchbefore you start your session in puTTY.
You'll use puTTY to connect to
homework.cs.tufts.edu(that's the “host name or IP address” you'll be asked about). You can save that so puTTY will connect to that host in the future without your having to type it. You'll want to go to Connection → SSH → X11 and check “Enable X11 Forwarding.” You can also go to Connection → Data and enter your CS login name in the Auto-Login Username field.*
*Thanks to Dalia Berkowitz and Tom Magerlein for the information on the menu selections!
- For GNU Linux/Unix: Open a terminal. On Macs, that's done
using Applications→Utilities→Terminal in the Finder. On a
GNU/Linux machine, you'll have to hunt around and there terminal
application is in different places depending on the distribution.
When you get a terminal, type
usernameis your CS department user name.
In fact, if you want to open up a separate window running emacs or kate, then you'll need to tell the server that it can open windows on your machine. This is almost the same as above:
ssh -X email@example.com
-Xtells homework it can use X-Windows, to communicate with your computer.
http://www.cppreference.com/a very good reference site.
http://www.cs.brown.edu/courses/cs123/resources/c++_mini_course.pdfis a good quick and dirty summary of C++.
http://www.cs.brown.edu/courses/cs123/docs/java_to_cpp.shtmlis a C++ tutorial for Java programmers.
- For you Java types, the Brown folks also have a C minicourse.
- Ben Blais recommends
http://www.cplusplus.com/for generall C++ information, documentation of standard library functions, and examples.
Comp 11 Review MaterialHere are notes on various topics from a previous version of Comp 11. If you are new to Tufts or C++, or if you're just a little rusty, please review these topics.
- More structs
- Design with data structures
- Object-oriented programming (classes) also include examples of separate compilation and linking.
- Linked structures (Note: The linked lists in these notes are done without classes, and they use a slightly different model than those we use in Comp 15. They are like lists in Lisp, Scheme, ML, Haskell, and Erlang. These lists still use the same basic structure, and they show how to do data abstraction without classes, which is how it's done in Comp 40.)
- It isn't quite the way I draw them, but you might want to look at Eric Roberts's guide to writing heap/stack diagrams.
GNU/Linux and EMACS
You might consider installing GNU/Linux on your computer. The Ubuntu distribution is popular, and I have successfully installed it on a laptop with relative ease. Running it in a VM is reasonable. Any flavor of Linux should work for most things, and, for that matter, most of our code (all?) will run under any Unix (such as MacOS, which uses a Unix system descended from BSD Unix).
Larry Greenfield wrote a useful Linux Users' Guide that contains an introduction to Unix/Linux, including documentation and examples of lots of Unix commands as well as introductions to emacs and vi.
Norman Matloff has also written Emacs: The Software Engineer's “Swiss Army Knife.” Larry Greenfield wrote a handy GNU Emacs reference card that you can carry around with you. There is also an XEmacs reference card. (Thanks to Karl Schults for sending this link.)
Formatting code in Emacs
You can set Emacs's indentation style to to various things. At
the moment, I'm using
linux style for C++. For an
idividual editing session, you can type
It will be easier still if you change the
C-c . linux
.emacsfile in your home directory to make this apply every time you edit a C file. If you don't have a
.emacsfile in your home directory, then just make it, and put this stuff in. Here is what I have in my
.emacsfile, and you should add this to your
.emacsfile right away:
This will set the indentation depth to 8 spaces, get curly braces to behave, and force emacs to use space characters rather than tab characters for indentation. The last bit is important if you want your code to look the same to other people (like graders!) who may not have the same tab settings you do.;; ;; Setting default styles for Java, C, and C++ ;; (setq c-default-style '((java-mode . "java") (c-mode . "linux") (c++-mode . "linux") (other . "gnu"))) (setq-default indent-tabs-mode nil) ;; Uses spaces rather than tabs ;; for indentation
When you are typing your code and you come to the end of a line,
C-j, rather than a return. If you do this, Emacs
indents the next line automatically according to the indentation
rules. Alternatively, hitting
Tab will indent the
current line according to the current rules. If you have edited a
function and ruined the indentation (or you fear you may have brace
or parenthesis problems), you can indent an entire block by placing
the curser over the opening curly brace of the block and typing
M-C-q. You can also select a region and then type
Search engines like Google have really changed debugging: it is very common now to cut and paste an error message one doesn't understand into a search engine and look it up that way. But that is not enough.
You will benefit by becoming familiar with a proper debugger.
Runtime error messages are generally uninformative, and
sometimes, a flood of print statements won't do the trick.
is the GNU debugger and has a line-oriented interface. It has a
GUI front end called
ddd, which has documentation
available via the web
and in a downloadable PDF document.
Here is a brief
lab with exercises for learning
Think of a debugger as a replacement for the interactive read-eval-print loop in interpreted environments that you may have used in languages like Python, ML, or Scheme.
Here are some notes on