A Compiler from Scratch
Compilers (generally) are made up of:
Read a file or input
Loop through the string (while there is input...)
iterate through a defined list of *tokens*; use regular expressions to account for every possible symbol.
With each successful read of a line of a string; remove that line from the file input.
The parser takes a list of tokens and parses each one into a tree.
The Code Generator
Recurses through the tree and generates code for another language accordingly
Statistics over git repositories
computing historical stats on a git repo.
iterate over revisionsusing
git revlist HEAD
awkis useful for pulling fields out of strings.
string interpolation is possible in bash:
echo "`my_func` `my_func2`"
set -eat the top of your file means if any command in the script fails, the whole script will abort. By default, if you don't do this, bash will continue.
You should "quote your variables":
good: grep "$file_pattern"
bad: grep $file_pattern
xargscan take multiple lines of input and turn them into arguments to another function.
echo '1 2 3' | xargs ls
Source Code History Integrity
What is history integrity?
How do we enfoce it?
Why do we care?
Mercurial is about having an immutable history.
Git is the opposite.
Whenever you re-write the history you are introducing commits that haven't been run against tests.
Conflicting Principles in OOP
Overview: There are many common principles of object oriented programming and thus they will at times conflict.
Processes and Jobs
This was a very useful screencast. It informed several new entries in my Unixº notes.
jobsshow running jobs.
fgbrings most recent job to the foreground.
fg %1brings job 1 to the foreground
ctrl +zin a shell will turn an active process into a job
bgallows a job to run in the background.
Tar, Fork & The Tarpipe
A (obsolete) way to copy a directory using tar:
(cd src && tar -c .) | (cd dst && tar -xp)
But the above is a useful way to teach you about unix commands.
The brackets are subshells.
This causes your shell to fork itself, isolating the cwd, variables, etc.
useful for doing something that will not pollute the top shell environment.
The subshells use
fork, which creates processes and returns a
Coupling & Abstraction
Sometimes you have to create your own API's to other libraries (an ORM, for example);
Spiking & Continuous Spiking
Spiking is when you write code without tests (in a TDD oriented approach) and once you figure out what you are doing, you (often) throw it out and then start again from a TDD approach.
What belongs in an active record model?
aim to thinly wrap what the database is doing.
if there is a lot of control flow, it might belong elsewhere.
be careful with active record callbacks (before_create, after_create, etc.)