首先来看一个crash日志。如下:
State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?
There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.
Here I present a composable pattern for pure state machiness with effects,
import Foundation | |
public class Storage { | |
fileprivate init() { } | |
enum Directory { | |
// Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the <Application_Home>/Documents directory and will be automatically backed up by iCloud. | |
case documents | |
0x0000 | Ericsson Technology Licensing | |
---|---|---|
0x0001 | Nokia Mobile Phones | |
0x0002 | Intel Corp. | |
0x0003 | IBM Corp. | |
0x0004 | Toshiba Corp. | |
0x0005 | 3Com | |
0x0006 | Microsoft | |
0x0007 | Lucent | |
0x0008 | Motorola | |
0x0009 | Infineon Technologies AG |
cd $path | |
DATE=`date -v-6d +"%Y-%m-%d"` | |
AUTHOR=`git config user.name` | |
LOG=`git log --branches --pretty=format:"\n%ad: %s" --date=short --after=$DATE --author="$AUTHOR"` | |
CHANGES=`git log --branches --date=short --after=$DATE --author="$AUTHOR" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "本周贡献代码: +%s行, -%s行, 总行数: %s\n", add, subs, loc }' -` | |
WEEKSTART=`date -v"monday" +"%-m月%d"` | |
TODAY=`date +"%-m月%d"` | |
REPORT="【周报】$WEEKSTART ~ $TODAY \n\n$CHANGES\n$LOG\n" |