Effective Coding on Unix

Home

Updated 2006-10-04

In this article, I will explain how I code on unix.

Use a unix Computer

Store your source code and compile it on a unix computer. It will be your development server. I recommend using a popular version of Linux: Gentoo, Debian, or Ubuntu. I don't think that Cygwin makes a good development platform.

Avoid sysadmin work. Use a computer that somebody else manages. If you're a university student then get a shell account on the university's system. If you're a UIC CS student then use oscar.cs.uic.edu.

Use PuTTY

If you already have a Linux workstation or a Mac with OS X then you can run ssh from a terminal to connect to your development server. On Windows, use the free SSH client, PuTTY. Follow these instructions to install it properly on Windows XP™:

  1. Go to the PuTTY Download page. Download the "Windows-style installer". At the time of this writing, it is called putty-0.58-installer.exe.
  2. Run the installer. Install with the default options. This puts the PuTTY files into C:\Program Files\PuTTY
  3. The pscp.exe program must appear on the path for it to be useful. Configure the PATH environment variable:
    1. Right-click on My Computer and choose Properties. The System Properties dialog box will appear.
    2. Click the Advanced tab.
    3. Click the Environment Variables button at the bottom. The Environment Variables dialog box will appear.
    4. Under System variables, scroll down and select Path.
    5. Click the Edit button. The Edit System Variable dialog box will appear.
    6. Click in the box labeled Variable value: and press the End button on your keyboard to go to the end of the text.
    7. Type ;C:\Program Files\PuTTY; at the end of the text. The semicolons are important!
    8. Click OK to save changes to the Path variable.
    9. Click OK to close the Environment Variables dialog box.
    10. Click OK to close the System Properties dialog box.
  4. Make a shortcut to your development server, oscar.cs.uic.edu:
    1. Open My Computer and navigate to C:\Program Files\PuTTY.
    2. Press Alt-F-W-S to open the Create Shortcut wizard.
    3. Type putty oscar.cs.uic.edu and hit Enter.
    4. Type oscar.cs.uic.edu as the name of the shortcut and hit Enter to finish creating the shortcut.
    5. Press Alt-F-I to add it to the Start Menu.

PuTTY comes with good default settings. Commands and settings are available by clicking the icon in the upper-left corner of the window, just left of the title bar. I like to increase the Font size and maximize the window.

You can get full-screen mode with ALT-Enter. This makes the PuTTY window take up the entire screen. It looks just like your computer is the development server. Turn on the ALT-Enter shortcut key like this:

To make your changes stick in the program, you need to save over PuTTY's default settings:

Use Tab-Completion

All decent unix shells can interpret the tab key to complete a partially typed filename. With tab-completion, one can manage files very effectively. It is much faster than using a using a mouse and graphical file manager.

Use Screen

Do all of your development with one terminal. Use screen to create virtual terminals and switch betwen them using the keyboard command. There is a huge advantage to keeping your hands on the keyboard all the time.

Use Emacs

Read Effective Emacs (local copy).

Customize your ~/.emacs file. I have incorporated most of the suggestions in Effective Emacs into my .emacs file.

Write a Good Makefile

Use the makefile to build, clean, and test. For interactive programs, add command line options that bypass the interactive prompts, so you can test your program without interacting with it. Make many tests: test1, test2, test, etc. Make tests that should succeed and others that should cause your program to report errors. Make clean should remove core, *.o, all temporary files created by tests, and the program's executable.

Learn to Read Manpages

They can be tough for an inexperienced person to understand. Read the entire manpage of every library function call that is used by your program. Also take a look at man pages listed in the SEE ALSO section. The manpage open(2) is for the open in section 2 of the manual. Read it with man 2 open. If your unix system views manpages with more then change it to less.

Keep Source Code Organized

Be organized. Don't mix source code and other files. Put test data files in a test/ subdirectory. What is suitable for the source code directory: c, cpp, h, makefile, readme, INSTALL, COPYING, any data files required by your program.

Use tar

tar czvf project.f.tar.gz project/

tar xzvf project.f.tar.gz

Keep backups of your source code directory: a, b, c, …, z.

Use pscp to copy the backups to your workstation

Prevent Programming Errors

TODO

Things to add to this tutorial:

Home


Copyright © 1999-2012 Michael Leonhard