Software Carpentry
Introduction


Introduction


Self Assessment


The State of Play


Meeting Standards


The Grass Isn't That Much Greener


Hidden in Plain Sight


The Times They Are A-Changin'


This Course


Setting Up


A Note on Tool Choice


Contributing


Recommended Reading


Typographic Conventions


Summary


Exercises

Exercise 2.1:

What is the largest software project you have ever worked on? How well did it meet its original objectives? What is the most important thing you learned from it?

Exercise 2.2:

Write a point-form list of the programming tools you use on a regular basis. When and how did you learn each one? How proficient do you think you are with each? Compared to whom?

Exercise 2.3:

Suppose you have been given one week to write a program to translate old-style configuration files to a new syntax. Write a point-form description of how you would go about it.

Exercise 2.4:

Rewrite the following fragment of code to make it more readable. Don't worry about the fact that you don't know the language it's written in; feel free to use any functions or language features you're familiar with from other languages.

i = open('oldconfig.cnf', 'r');
ll = i.readlines();
for j in 0..len(ll) {
    if len(j) > 0 {
        if not defined(r) r = new list;
        r.append(j);
    }
}
sort(r);
print 'longest line is', r[0];

Exercise 2.5:

What are the errors in the function shown below? Don't worry about the lack of variable declarations: this language doesn't need them. Note that, like C and Java, this language uses 0 as the first index for lists.

# Calculate a running sum of a list of numbers.
# If the input values are [1, 2, 3], the final values are [1, 3, 6].

def running_sum(values) {
    i = 1;
    while (i < len(values)) {
        values[i] = values[i] + values[i-1];
    }
}

Exercise 2.6:

A sub-contractor in Euphoristan has just written a function that takes two lists of phone numbers (represented as strings), and returns all those in the first list that are not in the second. You only have a few minutes to test it before she goes off-line for the weekend; what are the first half-dozen test cases you would try?

Send comments