Darren Provine at Rowan University


(Click here for text version.)

Helpful Hints

Work efficiently by looking for patterns.

A lot of what goes on in all of computer science, and this class is no exception, is looking for patterns. As an experiment for a few years, I gave out the exam questions in advance of the exams. I provided a list of 25 or 30 questions, and on exam day picked 7 or 8 of them to put on the test. (I reserved the right to (a) add one extra question, if I think of a good one, and (b) make small changes, like asking for the `5 biggest' on the test when the sample question asked for the `10 smallest'.)

One year, I got this e-mail about the sample questions:

It took me four days just to complete the exam, and now I have to memorize it, and I don't even know if my answers are right.

What I advised this student was that memorizing the answers to questions likely to be changed is a waste. Instead, what I intended was for students to look at the problems and notice what they had in common. For example, several questions were about the `find' program. It has some command flags which can be used to change how it acts and what it searches for. Instead of committing to memory five different ways to run `find', it would be much better to look at the answers, see what things they have in common, and commit to memory how the program is used.

This doesn't apply just to sample exam questions. The same principle applies to many other things as well. Commands generally follow a pattern:

    command_name  option_flags  argument_list

The option flags, while they are assigned with a bit of anarchy, usually have something to do with a keyword related to how they act. `rm' ReMoves files; to work Interactively, you use `-i'. `ls' LiSts files; to get a Long listing, you use `-l'. Even if you can't remember which flag you want, you can usually make a good guess or two, and then check the manual.

That brings me to the next hint:

The on-line manual is your friend. It knows more than you do.

I often get e-mail from students during the semester protesting that they can't figure something out, that it's impossible, or that we didn't cover something in class.

I often reply with a letter which says something like this:

See `man ls'.

or

See ls(1).

The latter syntax, `name' followed by a number in parentheses, means `information about name is in section number of the on-line manual'. So what you would do is see the entry in section number of the manual for topic name. So you would type `man 1 ls'. (Most things that you will be interested in are only in the manual in one place, so you generally don't have to specify which section you want.) If you are solving a problem, and you know you need the `ls' command, or the `date' command, but you can't figure out how to make it do what you want, read the manual. (This is often abbreviated `RTFM', which stands for `Read The Fantastic Manual'.)

The textbook is not just a portable supply of tissue paper.

In the `testimonials' section, I quote a student who had a problem with metacharacters in a file. He needed to get rid of them, and he knew that sed(1) could do something like what he wanted -- but he couldn't type in those characters on his keyboard. So how could type them on the command line? I referred him to page 123 of the textbook, section 5.3. (Note that this was the old book; we've since adopted a new one, so current students won't find matching page numbers.)

One semester I got mail from a student who asked how he could run the command `whoami' within quotes; his mail included the problem and asked a question:

sed -e 's/who_did_it/`whoami`/' version.info

How do I get the whoami to work as a command and not a string?

My reply:
Well, you could (a) pay more attention in class, or (b) read the paragraph that starts `Sometimes...' on page 181 of the book.
In general, we'll be working on material which is in the assigned readings. If you do the assigned readings in advance, you will likely find the lectures easier to follow and the problems easier to solve.

Also, you can use this hint in conjunction with the one about the manual. Log on to Elvis and type the commands in as they are described in the book. See if they work the way the book says they should. If not, look in the manual and see if says in there somewhere that this version of a program is somewhat different than the description in the book.


(US flag) This page's URI: http://elvis.rowan.edu/~kilroy/class/lab_tech/?hints
Last modified: Wednesday, 14 January 2004, 2:28:20pm