Skip to content

Instantly share code, notes, and snippets.

@BrianWill
BrianWill / csharp_generics.md
Last active December 3, 2021 22:50
C# generics for beginners

Generic Class

Consider a simple class:

class PetOwner {
    public Pet pet;
    
    public void SetPet(Pet p) {
        this.pet = p;
@BrianWill
BrianWill / tech_writing.md
Last active October 6, 2024 06:44
Rules for technical communication

The 4 C's of good technical communication:

concise

Concision not only saves the audience time, it cuts out distracting verbiage and helps avoid burying key information in a sea of boiler plate.

Audiences very often revisit sources, and concision makes it easier to relocate particular bits of information.

Smaller pieces are easier to rearrange, and so in practice, the more concise, the more authors are likely to work out an ideal structure.

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 June 29, 2024 17:39
Go language overview for experienced programmers

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 April 26, 2024 08:11
Using asynchronous API's using callbacks and Promises

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

@BrianWill
BrianWill / understanding_git.md
Last active May 9, 2017 22:44
Understanding Git

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 August 20, 2016 19:02
Javascript expressions, variables, arrays, and objects

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 September 21, 2016 20:05
Javascript functions

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
}

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)

Writing Functionally Pure Code

Is all my code going to be pure?

Nope. No program can be composed 100% of pure code because every program must do I/O work, which is inherently stateful. Most programs also need to carry around some amount of internal state, to one degree or another. The goal of functional programming, then, is to maximize the proportion of pure code to impure code in your program.

Pure vs. Impure

What does it mean for data and code to be pure? The short answer is that pure things are immutable, but this is not quite accurate: all pure things are immutable, but not all immutable things are pure. Pure things are not only unmodifiable but also definitional.