Thoughts about feedback loop

Random thoughts, including three ways to execute edit-compile-test cycle.

Are you a risk taker? I try not to be. It’s not worth it. Why risk invested time, if it’s possible you lose it all. I have a rule. Don’t do anything you can’t verify. Or, don’t do anything without some kind of feedback loop. What am I talking about?

  • Don’t deliver to much to the customer. Without knowing he is satisfied 1/4 of the way.
  • Don’t check in more than one thing at a time to the version control system. (You like to know what edit it was that broke the build).
  • Don’t change to much to a source file, without compiling.

It’s like playing half-life on the hardest level. You save all the time. To ensure you don’t have to do it all again. 

And with LFE it’s also true. Error messages are sparse and some times no line number exist. The only way is to code with tests and keep the last edit in your head. This is actually good. Think about all the times you had to use long time memory. Long time memory takes long time to use. And small steps make you go into the zone faster.

If the feedback loop are so important, should we think about it? Yes. If you exercise it several times a day. It’s important to be as painless as possible. 

One important feedback loop is edit-compile-test cycle. Therefore, I have listed the ones I know. I think it’s wise to know them all, and then choose one.

  • Manual compile – f5
  • flymake-mode  (Emacs only)
  • auto_compile.sh (Linux only) 

Manual compile – f5
This is fun (the first three times you hit f5). Then it starts to itch a bit. Any way, some folks thinks it build character, some thinks it feels like a job. Sounds okej? Then f5 is the key for you.

To program your emacs environment to react to f5. Paste this into your dot emacs file.

(setq compilation-ask-about-save nil
      compilation-window-height 15)

(defun my-save-compile-and-test ()
  (interactive "")
  (save-buffer 0)
  (compile "make && make start"))

(global-set-key [f8] 'my-save-compile-and-test)

flymake-mode
I like flymake. Flymake compile your code in the background. You need to have two cores or more, if you don’t want it to effect your system latency. Put this in your dot emacs and M-x flymake-mode.

(global-set-key [f3] 'flymake-display-err-menu-for-current-line)
(global-set-key [f4] 'flymake-goto-next-error)

(when (load "flymake" t)
  (setq flymake-log-level 3)
  (add-hook 'find-file-hook 'flymake-find-file-hook)
  (add-to-list 'flymake-allowed-file-name-masks
	       '("\\.lfe\\'" flymake-simple-make-init)))

And this need to be in the Makefile.

check-syntax:
	@erl -noshell -pa ${LFE_EBIN} -eval 'code:load_file(lfe_comp).' -eval 'File=hd(init:get_plain_arguments()), try lfe_comp:file(File) of {error,X,AR} -> lists:foreach(fun(L)-> {Line,B,Error}=L, io:format("~s:~p: ~p ~p~n",[File,Line,B,Error]) end, X),halt(0) ; {ok,X,AR} -> halt(0); {X,Y,Z} ->  io:format("~p:~p:~p:",[X,Y,Z])  catch X:Y -> io:format("~p:1: Compiler crash ~p ~p ~n",[File,X,Y]), halt(0) end.' -extra ${MAIN}_flymake.lfe 2> err.out

(Sorry for the long line. Here is the Makefile)

auto_compile.sh
This only works on linux. You need a kernel older than 2.4.16. And inotify-tools installed.

sudo apt-get install inotify-tools

This script will start executing “make && make test” whenever you save a file, ending with lfe. Paste this into auto_compile.sh and start it in a terminal. (This tips I got from the erlang-mailinglist. Nice place to hang out.)

#!/bin/bash
clear
make clean && make start
echo

inotifywait -m -e close_write *.lfe | while read f; do
file=$(echo "$f" | cut -d' ' -f1)
    clear
    date
    make clean && make start
done

Screencast
A screencast showing flymake in action. (go to http://vimeo.com/1692160 for a full screen view)

That’s all. Please make a comment if I missed (or misspelled) something.

Published in: on September 7, 2008 at 10:54 am Comments (1)
Tags: ,

The URI to TrackBack this entry is: http://cadaro.wordpress.com/2008/09/07/lfe-tips/trackback/

RSS feed for comments on this post.

One Comment Leave a comment.

  1. Flymake is way cool. Thanks.


Leave a Comment