• Destroy all Software

Filed under:

A Compiler from Scratchcompiler

Overview

Compilers (generally) are made up of:

  • Lexers (tokenizer)

  • Parsers

  • Code generator

The Tokenizer

  • 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

  • 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 repositoriesunixgit

  • computing historical stats on a git repo.

  • iterate over revisions using revlist: git revlist HEAD

  • commands learned:

    • git ls-tree

    • awk is useful for pulling fields out of strings.

    • string interpolation is possible in bash: echo "`my_func` `my_func2`"

    • set -e at 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

    • xargs can take multiple lines of input and turn them into arguments to another function.

echo '1
2
3' | xargs ls

Source Code History Integritygit

  • Overview:

    • 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 Jobsunix

This was a very useful screencast. It informed several new entries in my Unixº notes.

  • jobs show running jobs.

  • fg brings most recent job to the foreground.

  • fg %1 brings job 1 to the foreground

  • ctrl +z in a shell will turn an active process into a job

  • bg allows 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 process id.

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.)