Skip to content

Instantly share code, notes, and snippets.

View RocketPuppy's full-sized avatar

Daniel Wilson-Thomas RocketPuppy

View GitHub Profile
import { todoReducer, deleteTodo } from '../src';
import { assert } from 'chai';
describe('when the todo exists alone', () => {
const theTodo = { text: 'foo' };
const state = [theTodo];
it('removes the todo', () => {
const newState = todoReducer(state, deleteTodo('foo'));
function deleteTodo(text) {
return {
type: DELETE_TODO,
payload: {
text
}
};
}
const initialState = []
function deleteTodo(text) {
return {
type: DELETE_TODO,
text: text
};
}
const initialState = []
function todoReducer(state = initialState, action) {
# My NixOS channel is behind the regular nix pkgs channel, so I didn't have go 1.6 or node 5 available in <nix_pkgs>
nix-build default.nix --arg go '(import <custom_pkgs> {}).go_1_6' --arg goPackages '(import <custom_pkgs> {}).go16Packages' --arg nodejs '(import <custom_pkgs> {}).nodejs-5_x'
nix-env -i -f default.nix --arg go '(import <custom_pkgs> {}).go_1_6' --arg goPackages '(import <custom_pkgs> {}).go16Packages' --arg nodejs '(import <custom_pkgs> {}).nodejs-5_x'
{ goPackages, fetchFromGitHub }:
with goPackages; rec {
errors = buildGoPackage rec {
rev = "a41850380601eeb43f4350f7d17c6bbd8944aaf8";
name = "errors-${rev}";
goPackagePath = "github.com/go-errors/errors";
src = fetchFromGitHub {
inherit rev;
owner = "go-errors";
repo = "errors";
{ stdenv, go, goPackages, git, curl, cacert, cowsay, jq,
openssl, nodejs, python, fetchFromGitHub }:
stdenv.mkDerivation rec {
rev = "v5.1.6";
name = "heroku-cli-${rev}";
buildInputs = [
cacert go nodejs curl git python cowsay jq openssl
goPackages.osext goPackages.binarydist goPackages.merry
goPackages.speakeasy goPackages.netrc goPackages.golock
{ stdenv ? (import <nixpkgs> {}).stdenv,
go ? (import <nixpkgs> {}).go_1_6,
goPackages ? (import <nixpkgs> {}).go16Packages,
git ? (import <nixpkgs> {}).git,
curl ? (import <nixpkgs> {}).curl,
cacert ? (import <nixpkgs> {}).cacert,
cowsay ? (import <nixpkgs> {}).cowsay,
jq ? (import <nixpkgs> {}).jq,
openssl ? (import <nixpkgs> {}).openssl,
nodejs ? (import <nixpkgs> {}).nodejs_5_x,

As developers it seems like we're in a land of plenty when it comes to code quality tools. There are many options, some more controversial than others. One such option I'd like to talk about today is the use of ESLint in Javascript with the consistent-return rule.

When you enable the consistent-return rule in ESLint the tool will automatically check that all code paths in a function either explicitly return a value or don't return a value. In functions that branch one might forget to return a value in one of the branches, and the consistent-return rule will warn you when that happens.

~$ irb
irb(main):001:0> FOO = 'baz'
=> "baz"
irb(main):002:0> FOO = 'bar'
(irb):2: warning: already initialized constant FOO
(irb):1: warning: previous definition of FOO was here
=> "bar"
irb(main):003:0> FOO
=> "bar"
irb(main):004:0> FOO.upcase

Math and Programming

Functions

In algebra functions are a way to map from one set of objects (the domain) to another set of objects (the codomain). In traditional imperative programs functions are a way to sequence operations to achieve a desired state. In some sense traditional imperative programs encourage reasoning about implementation details. Instead if we think about our functions in the same sense as in algebra, as mappings from some set to another, the implementation becomes almost incidental. Traditional imperative programming doesn't encourage this sort of thinking. It's a style of thinking that encourages reasoning about behavior over implementation. While there can be differences between implementations of the same function, the differences between implementations are almost always performance related and do not alter the domain and codomain.

Knowing the domain and codomain gives us information about how a function behaves in isolation. It clearly identifies potential edge cases, usually th