Software Carpentry
Software Carpentry
Introductory
Hands on
Interactive
Summary
Regular Expressions
Make
Version Control
Python
Unix Shell
About Shell
File system
Manipulating Files
rm deletes files
File Permissions
Redirection
Jobs
Backgrounding a program
Control-Z and bg
fg foregrounds a program
ps lists processes
References
Regular Expressions
Programming Languages
Inbuilt: Perl, Ruby, Javascript etc.
As library: C, C++, Java, Php, Python etc.
Lot more:
Configuring Apache Web Server
Syntax Highlighting in editors
Even Google Search (well... not really. Just code search)
Basics
Example Applications
Editor: Vim
Programming: Perl
Metacharacters
| alternation
H|h matches h or H
() grouping
H|hello matches H or hello
(H|h)ello matches Hello or hello
Character Classes
\r matches a return
\t matches a tab
\w matches a word
\W matches a non-word
\s matches a whitespace
\S matches a non-whitespace
\d matches a digit
Quantifiers
? matches 0 or 1 time
Substitutions
Modifiers
References
Build Tools
Building a Project
file1.c
file2.c
file3.c
file4.c
file1.o
file2.o
file3.o
file4.o
library1.so
main.c
main.o
program
library2.so
Make
Other uses
Any set of tasks with dependency graphs
Automated testing
Building documentation
Even booting an operating system!
Writing Makefiles
hello: hello.o
gcc hello.o -o hello
hello.o: hello.c
gcc hello.c -c -o
hello.o
clean:
rm -f hello.o hello
Using Make
$ make
$ make clean
Basics
Target
Prerequisites
hello: hello.o
gcc hello.o -o hello
hello.o: hello.c
gcc hello.c -c -o
hello.o
clean:
rm -f hello.o hello
Commands
Rules
Bigger Project
hello: main.o filel.o file2.o
gcc main.o file1.o file2.o -o hello
main.o: main.c file1.h file2.h
gcc main.c -c -o main.o
file1.o: file1.c file1.h
gcc file1.c -c -o file1.o
file2.o: file2.c file2.h
gcc file2.c -c -o file2.o
clean:
rm -f hello main.o file1.o file2.o
Improving: Step 1
hello: main.o filel.o file2.o
gcc $^ -o $@
mail.o: file1.h file2.h
main.o: main.c
gcc $^ -c -o $@
file1.o: file1.h
file1.o: file1.c
gcc $^ -c -o $@
file2.o: file2.h
file2.o: file2.c
gcc $^ -c -o $@
clean:
rm -f hello main.o file1.o file2.o
Improving: Step 2
hello: main.o filel.o file2.o
gcc $^ -o $@
mail.o: file1.h file2.h
file1.o: file1.h
file2.o: file2.h
%.o: %.c
gcc $^ -c -o $@
clean:
rm -f hello main.o file1.o file2.o
Improving: Step 3
TARGET = hello
OBJECTS = main.o file1.o file2.o
main.o: file1.h file2.h
file1.o: file1.h
file2.o: file2.h
$(TARGET): $(OBJECTS)
gcc $^ -o $@
%.o: %.c
gcc $< -c -o $@
clean:
rm -f $(TARGET) $(OBJECTS)
Improving: Step 4
TARGET = hello
OBJECTS = main.o file1.o file2.o
main.o: file1.h file2.h
file1.o: file1.h
file2.o: file2.h
$(TARGET): $(OBJECTS)
gcc $^ -o $@
$(OBJECTS): %.o: %.c
gcc $< -c -o $@
clean:
rm -f $(TARGET) $(OBJECTS)
Phony Targets
Try this:
$ touch clean
$ make clean
.PHONY: clean
Improving: Step 5
TARGET = hello
OBJECTS = main.o file1.o file2.o
main.o: file1.h file2.h
file1.o: file1.h
file2.o: file2.h
$(TARGET): $(OBJECTS)
gcc $^ -o $@
$(OBJECTS): %.o: %.c
gcc $< -c -o $@
.PHONY: clean
clean:
rm -f $(TARGET) $(OBJECTS)
Autoconf
M4
Automake
Libtool
References
Version Control
Why?
Release management
Work as a group
Revisions
Initial Version
Added feature 1
Added feature 2
Fixed bug 1
Latest version
Release Management
Initial Version
Added feature 1
Fixed bug 1
Added feature 2
Version 1.1
Fixed bug 1
Version 2.0
Work as a Group
Initial Version
Added feature 1
B's Feature
A's Feature
Merge
Latest Version
Identify Regressions
Bug free version
Bug introduced
Personal Changes
Free Software Project
on the Internet
Version 1.0
Version 2.0
My research work
Idea 1
Version 3.0
Idea 2
Version 4.0
Idea 3
Basic configuration:
$ git config --global user.name "Your Name Comes Here"
$ git config --global user.email [email protected]
Creating a repository:
$ git init
Editing
Reviewing Changes
Current status
$ git status
History of changes
$ git log
Exchanging Patches
Patch file
Applying a patch
$ patch -p1 < my_feature.patch
Better ways
Tagging
Creating a tag
$ git tag VERSION_1
Deleting a tag
$ git tag -d VERSION_1
Rebasing
Bisecting
Stashing changes
Graphical Tools
References
Git: http://git-scm.com
Python
Why Python?
Yet powerful
Rapid development
Object oriented
Cross platform
Hello, World!
$ python
>>> print "Hello, World!"
Hello, World!
>>>
Python as Calculator
>>> 2+2
4
>>> (50-5*6)/4
5
Variables
>>> a = 2
>>> b = 3
>>> print a * b
6
Strings
>>> hello = "Hello"
>>> world = "World"
>>> print hello
Hello
>>> print world
World
>>> print hello + world
HelloWorld
>>> print hello + ", " + world + "!"
Hello, World!
Lists
>>> a = ['spam', 'eggs', 100, 1234]
>>> a
['spam', 'eggs', 100, 1234]
>>> a[0]
'spam'
>>> a[3]
1234
>>> a[-2]
100
>>> a[1:-1]
['eggs', 100]
>>> a[2] = a[2] + 23
>>> a
['spam', 'eggs', 123, 1234]
More on Lists
>>> a = [66.25, 333, 333, 1, 1234.5]
>>> print a.count(333), a.count(66.25), a.count('x')
2 1 0
>>> a.insert(2, -1)
>>> a.append(333)
>>> a
[66.25, 333, -1, 333, 1, 1234.5, 333]
>>> a.index(333)
1
>>> a.remove(333)
>>> a
[66.25, -1, 333, 1, 1234.5, 333]
>>> a.reverse()
>>> a
[333, 1234.5, 1, 333, -1, 66.25]
>>> a.sort()
>>> a
[-1, 1, 66.25, 333, 333, 1234.5]
More on Lists
>>> mat = [
...
[1, 2, 3],
...
[4, 5, 6],
...
[7, 8, 9],
...
]
Tuples
>>> t = 12345, 54321, 'hello!'
>>> t[0]
12345
>>> t
(12345, 54321, 'hello!')
>>> # Tuples may be nested:
... u = t, (1, 2, 3, 4, 5)
>>> u
((12345, 54321, 'hello!'), (1, 2, 3, 4, 5))
>>> t = 12345, 54321, 'hello!'
>>> x, y, z = t
Dictionaries
>>> tel = {'jack': 4098, 'sape': 4139}
>>> tel['guido'] = 4127
>>> tel
{'sape': 4139, 'guido': 4127, 'jack': 4098}
>>> tel['jack']
4098
>>> del tel['sape']
>>> tel['irv'] = 4127
>>> tel
{'guido': 4127, 'irv': 4127, 'jack': 4098}
>>> tel.keys()
['guido', 'irv', 'jack']
>>> 'guido' in tel
True
If .. else
>>> x = int(raw_input("Please enter an int: "))
Please enter an integer: 42
>>> if x < 0:
...
x = 0
...
print 'Negative changed to zero'
... elif x == 0:
...
print 'Zero'
... elif x == 1:
...
print 'Single'
... else:
...
print 'More'
For
>>> # Measure some strings:
... a = ['cat', 'window', 'defenestrate']
>>> for x in a:
...
print x, len(x)
...
cat 3
window 6
defenestrate 12
For
>>>
[0,
>>>
>>>
...
range(10)
1, 2, 3, 4, 5, 6, 7, 8, 9]
a = ['Mary', 'had', 'a', 'little', 'lamb']
for i in range(len(a)):
print i, a[i]
Break
>>> for i in range(10):
...
if i > 5:
...
break
...
print i
...
0
1
2
3
4
5
Continue
>>> for i in range(10):
...
if i == 5:
...
continue
...
print i
...
0
1
2
3
4
6
7
8
9
Comments
>>>
>>>
...
...
Functions
>>>
...
...
...
...
...
...
>>>
...
0 1
def fib(n):
# print Fibonacci series
"""Print a Fibonacci series up to n."""
a, b = 0, 1
while a < n:
print a,
a, b = b, a+b
# Now call the function we just defined:
fib(1000)
1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
References
Thank you