It's hard to write unit tests that are worth the costs our employers pay for them. I'll share two mostly-made-up diagrams then use them to justify writing code as data transformation.
There are four types of code:
**Diagram 1: Types of Code**
// Test for Architecture 1 | |
fetch = spy().andMockWith(function (args) { | |
// pattern matching and pretend games | |
}) | |
assertSpyStuff | |
assertMoreSpyStuff | |
assertMoreSpyStuff |
// Test for Architecture 2 | |
assert.deepEqual( | |
buildRequest(x, y, z), | |
expectedRequest | |
) | |
assert.deepEqual( | |
parseResponse(response), | |
expectedParsedResponse |
MobX observable | Rx Observable | |
---|---|---|
has to do with things changing | yes | yes |
"reactive" | yes | yes |
MobX observable | Rx Observable | |
---|---|---|
common use case | facilitating updating a UI when data changes | composing frequently-updated data from multiple sources and/or implementing a lot of timing logic |
better name is | "sneaky KVO" | "composable streams" |
very similar to | reactive data in Meteor and Vue | Node streams if Node streams were always in object mode and had things like through2 and multipipe built in |
implementation in JS requires |
nnoremap <leader><space> :noh<return> | |
nnoremap <leader><leader> :b#<CR> | |
nnoremap <leader>S :source ~/.vimrc<CR> | |
nnoremap <leader>g :e ~/.vimrc<CR> | |
nnoremap <right> <C-w>10> | |
nnoremap <left> <C-w>10< | |
nnoremap <leader>1 :bp<Cr> | |
nnoremap <leader>2 :bp<Cr> | |
nnoremap <leader>] @: |
:tnoremap <Esc> <C-\><C-n> | |
:tnoremap jj <C-\><C-n> | |
:tnoremap <C-w><C-w> <C-\><C-n><C-w><C-w> | |
:source ~/.vimrc | |
au TermOpen * setlocal nonumber norelativenumber | |
:nnoremap <leader>e <C-w><C-w>pa | |
Plugin 'tpope/vim-surround' | |
Plugin 'tpope/vim-commentary' |
class A { | |
#foo; | |
#bar; | |
method() { | |
class B { | |
#foo; | |
methodNested(a) { | |
a.#foo; // error: shadowed | |
a.#bar; // OK | |
} |
Three error cases for private name semantic errors:
(1) and (2) are special cases of (3)
Confusing note on terminology: in the semantics, '#foo' is the description for a private name, what a Muggle would call a "spelling" and a philosophyer would call an "orthography." From a semantic point of view, the private name itself (
#foo
) is unforgeable and cannot be written down, even thought it's clear exactly where the private name node in the syntax is.
Rough algorithm for generating the most accurate error message for leftHandSide.#foo
:
const main = () => { | |
const x = 2 | |
const y = 3 | |
;[1, 2, 3].forEach(v => { | |
console.log(v, y) | |
}) | |
console.log(x, y) | |
} |