話しをしたいポイントは3つ。
- 条件分岐を避けましょう
- 一時変数の使い方に注意しましょう
- 状態の使い方に気を使いましょう
これを徹底することで、バグの入り込む余地を最小限に保つプログラミングをしましょう。
| function keys(t) | |
| local keylist = {} | |
| for k in pairs(t) do | |
| table.insert(keylist, k) | |
| end | |
| local i = 0 | |
| return function() | |
| i = i + 1 | |
| return keylist[i] | |
| end |
| #!/bin/sh | |
| IPTABLES=/sbin/iptables | |
| # 初期化 | |
| $IPTABLES -F | |
| # デフォルトルール(以降のルールにマッチしなかった場合に適用するルール)設定 | |
| $IPTABLES -P INPUT DROP # 受信はすべて破棄 | |
| $IPTABLES -P OUTPUT ACCEPT # 送信はすべて許可 |
| # /etc/init.d/dropbox | |
| ### BEGIN INIT INFO | |
| # Provides: dropbox | |
| # Required-Start: $network $syslog $remote_fs | |
| # Required-Stop: $network $syslog $remote_fs | |
| # Should-Start: $named $time | |
| # Should-Stop: $named $time | |
| # Default-Start: 2 3 4 5 | |
| # Default-Stop: 0 1 6 | |
| # Short-Description: Start and stop the dropbox daemon for debian/ubuntu |
| " Conque | |
| " http://www.vim.org/scripts/script.php?script_id=2771 | |
| " ~/.vim/after/ftplugin/conque_term.vim | |
| augroup MyConqueTerm | |
| autocmd! | |
| " start Insert mode on BufEnter | |
| autocmd BufEnter * | |
| \ if &l:filetype ==# 'conque_term' | |
| --- Configure 2010-09-30 14:41:41.000000000 +0900 | |
| +++ /tmp/configure.perl 2010-09-30 14:40:55.000000000 +0900 | |
| @@ -23388,6 +23388,14 @@ | |
| EOM | |
| rp="Press return or use a shell escape to edit config.sh:" | |
| + . UU/myread | |
| + nostick='' | |
| + case "$ans" in | |
| + '') ;; |
| #include <gtk/gtk.h> | |
| int | |
| main(int argc, char* argv[]) { | |
| gtk_init(&argc, &argv); | |
| GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| g_signal_connect(G_OBJECT(window), "delete-event", [] () { | |
| gtk_main_quit(); | |
| }, window); | |
| GtkWidget* button = gtk_button_new_with_label("click me"); |
| function cdup() { | |
| echo | |
| cd .. | |
| echo "=> $PWD" | |
| zle reset-prompt | |
| } | |
| function cdprev() { | |
| echo | |
| popd |