Deef's Net

Home of all things Deef

Programming Efficiently

Since the summer of 2004, I've started thinking about how I can work most effectively. Part of the impetus for this was through attending OSCON 2004, and particularly the talks given there by Damian Conway. He and his talks are really indescribable -- they have to be witnessed to be believed. [Editor's Note: Several attempts at describing them have been deleted from this paragraph.]

On the last day of the conference, he gave a talk entitled Sufficiently Advanced Technologies that was particularly thought provoking. Here's the description:

In module design, interface is everything. Going one step beyond this dictum, Damian demonstrates and explains several practical applications of Clarke's Law ("Any sufficiently advanced technology is indistinguishable from magic") by presenting a series of useful [Perl] modules whose interface is...nothing.

The most immediate result of my trying to apply what I learned from this talk is the DBIx::SimpleQuery module. I'm not nearly the mad scientist that Damian Conway is, but I did bring the interface down to a single command, which has made my programming life wonderfully easier.

I've also been thinking lately about ways to reduce the amount of typing I have to do in general, whether for programming, or just in the shell. I've typed "/usr/local/apache/bin/apachectl graceful" far more times than I care to count.

Here are some of the things that I've come up with, or that I've found from others and have incorporated into my own practices:

  • ~/.bashrc

    # Set the title of the terminal window, for easy browsing through a
    # list (I tend to have a lot of PuTTY windows running, for instance).
    function title () {
        export PROMPT_COMMAND="echo -ne \"\\033]0;$@\\007\""
    }
    
    # Instead of typing "psql my_database my_user", I can just type
    # "psql".  I'm accessing the same database the vast majority of the
    # time anyway, but the defaults aren't correct for me.
    #
    # Passwords can be stored in ~/.pgpass if you're in a secure
    # environment.  I tend not to be in secure environments, so I avoid
    # this file and just type my password every time.
    export PGDATABASE="my_database"
    export PGUSER="my_user"
    export PGHOST="my_server"
    

  • ~/.emacs

    ; In PuTTY, right-click is paste.  In Win32 Emacs, right-click is
    ; copy.  This is not a good combination.  I'm more accustomed to
    ; PuTTY's behavior, so change Emacs to match
    (global-set-key [mouse-3] 'mouse-yank-at-click) 
    
    ; Shortcuts to commonly used commands
    (define-key global-map "\e[11~" 'cperl-perldoc-at-point) ; F1
    (define-key global-map "\e[15~" 'insert-mason-template)  ; F5
    (define-key global-map "\e[20~" 'sql-mode)               ; F9
    (define-key global-map "\e[21~" 'tmm-menubar)            ; F10
    (define-key global-map "\e[23~" 'html-mode)              ; F11
    (define-key global-map "\e[24~" 'perl-mode)              ; F12
    
    ; I'm trying out cperl-mode instead of perl-mode
    (defalias 'perl-mode 'cperl-mode)
    (eval-after-load "cperl-mode"
      (setq cperl-indent-level 4))
    
    ; .mc is my naming convention for Mason Component files.
    (add-to-list 'auto-mode-alist '("\\.mc\\'" . perl-mode))
    ; .t for Perl test files.
    (add-to-list 'auto-mode-alist '("\\.t\\'" . perl-mode))
    

  • /~.inputrc
    # F9: Edit httpd.conf
    "\e[20~": "su -c \"emacs -nw /usr/local/apache/conf/httpd.conf\"\n"
    # F10: Test Apache Config
    "\e[21~": "su -c \"/usr/local/apache/bin/apachectl configtest\"\n"
    # F11: Restart Apache Nicely
    "\e[23~": "su -c \"/usr/local/apache/bin/apachectl graceful\"\n"
    # F12: Look at the error log
    "\e[24~": "tail -n 200 -f /usr/local/apache/logs/error_log\n"
    

© 2000-2008, Stephen Simms. All Rights Reserved.