Skip to content

Instantly share code, notes, and snippets.

BrianWill

Block or report user

Report or block BrianWill

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@BrianWill
BrianWill / csharp_generics.md
Last active May 30, 2019
C# generics for beginners
View csharp_generics.md

Generic Class

Consider a simple class:

class PetOwner {
    public Pet pet;
    
    public void SetPet(Pet p) {
        this.pet = p;
@BrianWill
BrianWill / mutli-threaded program structures.md
Last active Nov 15, 2018
Multi-threaded program structures
View mutli-threaded program structures.md

single-threaded structures

processing job

A processing job is a program that simply takes some input at the start, performs some kind of data transformation/generation, and returns output at the end. The simplest programs are generally processing jobs, but some processing jobs, like compilers, can be quite complicated. Nearly all programs in the early decades of computing were processing jobs.

The defining feature of a processing job is that the set of input is fixed before data transformation/generation begins. For the sake of efficiency, input may be read incrementally during transformation/generation, but only when it can be assumed that no external forces are mutating the input as it is read. Likewise, output data can be written incrementally during transformation/generation, but only when doing so doesn't affect any incrementally read input.

Functionally pure transformation/generation logic is usually easier to reason about, but mutation can be simpler when it side-steps bothersome and complicat

@BrianWill
BrianWill / tech_writing.md
Last active Sep 21, 2019
Rules for technical communication
View tech_writing.md

In a recent talk, Siobhan Gibson and Kerry Turner from Unity layed out three key qualities of good technical communication:

  • accurate
  • concise
  • clear

It's a good short list, but the inclusion of clear feels to me like begging the question: clarity is a product of multiple factors, including both accuracy and concision. To better define clarity, we should expand the list and define these factors:

accurate

View Go's := syntax is error-prone with multiple targets.md

Problem

The := syntax is error-prone when dealing with multiple targets and variables of enclosing scope:

// often a mistake:
var a int
{
  a, b := foo()    // creates a new 'a' in this scope instead of using 'a' of outer scope
}
@BrianWill
BrianWill / Go overview.md
Last active Jun 29, 2019
Go language overview for experienced programmers
View Go overview.md

The Go language for experienced programmers

Why use Go?

  • Like C, but with garbage collection, memory safety, and special mechanisms for concurrency
  • Pointers but no pointer arithmetic
  • No header files
  • Simple, clean syntax
  • Very fast native compilation (about as quick to edit code and restart as a dynamic language)
  • Easy-to-distribute executables
@BrianWill
BrianWill / Javascript - asynchronous code.md
Last active Aug 24, 2019
Using asynchronous API's using callbacks and Promises
View Javascript - asynchronous code.md

In most programming languages, most functions are synchronous: a call to the function does all of its business in the same thread of execution. For functions meant to retrieve data, this means the data can be returned by calls to the function.

For an asynchronous function, a call to the function triggers business in some other thread, and that business (usually) does not complete until after the call returns. An asynchronous function that retrieves data via another thread cannot directly return the data to the caller because the data is not necessarily ready by the time the function returns.

In a sense, asynchronous functions are infectious: if a function foo calls an asynchronous function to conclude its business, then foo itself is asynchronous. Once you rely upon an asynchronous function to do your work, you cannot somehow remove the asynchronicity.

callbacks

When the business initiated by an asynchronous function completes, we may want to run some code in response, so the code run

View understanding_git.md

Before getting into Git, let's establish a few ideas common to all version control systems:

Diffs between versions of a file

Given two versions of a file, we can find the diff(erence) between them, line-by-line. For example, given two versions of this file:

Version A:

Roses are red
Violets are green
@BrianWill
BrianWill / Javascript expressions, variables, arrays, and objects.md
Last active Aug 20, 2016
Javascript expressions, variables, arrays, and objects
View Javascript expressions, variables, arrays, and objects.md

Values and variables

A value is a piece of data. We have several data types in Javascript:

  • number
  • boolean
  • string
  • array
  • object
  • function
@BrianWill
BrianWill / Javascript functions.md
Last active Sep 21, 2016
Javascript functions
View Javascript functions.md

Named functions vs. anonymous functions

A function statement creates a new function and assigns that function to a variable of the given name:

// creates a new function and assigns it to the variable foo
function foo() {
    // do stuff here
}
View Clojure Reader and Evaluator.md

How Clojure Code Becomes a Running Program

Lisp, the original high-level language, introduced a long list of features common in languages today, including dynamic typing, interpretation, and garbage collection. The original Lisp language is long gone, but it had many imitators, which we call 'dialects' of Lisp. Clojure, introduced in 2007, is the first Lisp dialect to gain wide usage in three decades.

Though Lisp features have been co-opted by many other languages, what still distinguishes Lisp dialects from all other languages is how Lisp dialects translate source code into running programs. In non-Lisp languages, the code translation process has two primary steps:

  1. lexing (a.k.a. tokenization) and parsing
  2. code generation (compilation or interpretation)
You can’t perform that action at this time.