monitor memory usage
To monitor the memory usage of long running applications, we can use top in batch mode.
Start the application in background, monitor the pid of interest at regular intervals. For example, the command below will run top on a single process, every 10 seconds, for a maximum of 1080 times (three hours).
% cat cmd.sh #! /bin/env zsh command of interest >& log.txt & PID=$! top -p $PID -b -n 1080 -d 10 >& top.txt &
The output from the command is redirected to log.txt and that from top is redirected to top.txt
If necessary, change the top command as needed. For example,
top -u raju -b -n 1080 -d 10 -c >& top.out &
will monitor all the processes from a user named 'raju'.
- R, octave, Matlab use a 1-based indexing scheme. i.e. the first element of a vector has an index of 1.
- Perl, C, C++ use a 0-based indexing scheme.
- Fortran 90 - arrays can start with an arbitrary index.
- Google style guides can be found at http://google-styleguide.googlecode.com/svn/trunk/ . In particular
|R||both **, ^ will work|
|C, C++||pow function in the math library|
For a comprehensive list, see https://en.wikipedia.org/wiki/Exponentiation#In_programming_languages
Tips on programming
- Do not focus on where the code is wrong, but only on why the code is wrong. Use asserts to enforce the assumptions about the algorithm. They are helpful in catching the logic errors and in documenting the code.
- Instead of calling the same function twice, create a variable to store the return value and reuse that. Variables are cheap compared to the time spent on evaluating a function.
- Make code as modular as possible
handling bugs from users
- http://mat.exon.name/notablog/computers/doityourself - A very nice article! Talks about how developers should approach bug reports. The gist is that, when a user reports bugs, do not expect them fix it for you. The onus to fix it is on the developer.
why short circuiting
Short-circuiting operators allow us to write boolean expressions such as "x ≠ NIL and x.f = y" without worrying about what happens when we try to evaluate x.f when x is NIL.
- Code reviews are not meant to find defects, they are meant to prevent them.