for (unsigned long i=0; i<N; ++i)
// do something
for (unsigned long i=0; i<N; ++i) {
// do some stuff
// do some more stuff
}
long
or unsigned long
for iteration unless you know you will need fewer possible values.SparseVector
). Function names should be lowercase underscored (e.g., pack_dense_vector_to_sparse
).for (const std::string & peptide : all_peptides)
.auto
if (1) typing is clear from context and (2) writing the type explicitly is cumbersome (e.g., when assigning a lambda function.fix_string
should instead be named replace_k_amino_acid_with_r_amino_acid
. Your code should be able to be read like a story:
class Girl:
def sleep_in_bed_from_bear(bear_name):
if bear_name == 'Papa':
result = 'too hard'
elif bear_name == 'Mama':
result = 'too soft'
elif bear_name == 'Baby':
result = 'just right'
else:
assert(False)
print(bear_name + "'s bed was " + result)
goldilocks = Girl()
for bed_for_which_bear in ['Papa', 'Mama', 'Baby']:
goldilocks.sleep_in_bed_from_bear(bed_for_which_bear)
// Find the argmin:
int min_index = -1;
double min_val = inf;
for (long i=0; i<N; ++i) {
double val = arr[i];
if (val < min_val) {
min_index = i;
min_val = val;
}
}
// Note: currently sorts to find the median;
// this will be slower than O(n) median-of-medians,
// but will not yet limit performance.
std::sort(vec.begin(), vec.end());
double median;
if (N % 2 == 1)
median = vec[N/2];
else
median = (vec[N/2-1] + vec[N/2]) / 2.;
// todo: replace this with an O(n log(n)) sort
sort_naive(vec);
// fixme: currently assumes N is odd:
median = vec[N/2];
2.
instead of 2.0
or 2
as the format to distinguish floating point types; however, when the magnitude is <1, use 0.7
rather than .7
.bit_reverse_naive_bitwise
, bit_reverse_bytewise_table
. This is because the user of this function gives primacy to the task at hand; the method for accomplishing it is less important than the problem it solves.std::map<std::string, std::vector<std::string> >
protein_to_peptides. Note the specific use of plurals: a value is pluralized only when multiple things go in or come out; a dictionary of one husband to one wife should not be named husbands_to_wives
if (lhs ==rhs)
should be replaced with if (lhs==rhs)
or if (lhs == rhs)
.import numpy as np
and import pylab as P
. Other libraries should be imported with thier names (e.g., import sympy
) or surgically using only the functions you need (e.g., from scipy.signal import fftconvole
).using namespace std;
BaseClassName::function_name()
instead of the implicit version this->function_name()
// one protein -> multiple peptides
std::unordered_map<std::string, std::vector<std::string> > protein_to_peptides;
// several proteins
std::vector<std::string> proteins_sharing_peptide;
// (protein,length) x several
std::vector<std::pair<std::string, unsigned> > protein_and_length_s
.
car_transmission
.SparseVector.cpp
should contain the definition for the class SparseVector
. A source file containing only function should be named with the function's name, which should be lowercase and with underscores for whitespace (e.g., sort_naive
). A source file containing multiple functions should be named descriptively with the theme of the functions in the file (e.g., bit_reversal
). Functions should not be in the same file if they are not thematic with one another. Figures included in paper subdirectories should be located in /doc/papers/paper-name/figures. If scripts are needed to build a particular figure, that should be included in a subdirectory, named /doc/papers/paper-name/figures/figure-description. Include a Makefile for each paper and in source code where necessary.valgrind --tool=memcheck --leak-check=yes --leak-check=full ./a.out
.valgrind --tool=callgrind ./a.out
and view the results with kcachegrind. Do not leave around temporary files output by callgrind; by default, the most recent file will be loaded by kcachegrind, and you may accidentally load an incorrect file.git add *
git reset <hash>
where <hash> is the hash of the latest commit without the undesired file. Then use git add
to add all the files you want to keep that were effected by the reset. In the commit message, make note that you are rewriting the commit history. Then use git push -f
to force an update. Finally, make sure you let everyone with write access to the repository know that the history has been rewritten and that they should reclone the repo (this prevents them from accidentally merging back in the unwanted binary file).----------------------------------------------