2012-09-11

Git with Vimdiff

One time view:

git difftool --tool=vimdiff --no-prompt <filename>

Always:

git config --global diff.tool vimdiff
git config --global merge.tool vimdiff

For Single Repository:

git config diff.tool vimdiff
git config merge.tool vimdiff

To avoid having Git prompt when launching Vimdiff:

git config --global difftool.prompt false
Standard

2012-09-07

Tcl: Hello World

File: hello.tcl
---------------
puts "Hello World!"

Run it with:

$ tclsh hello.tcl

Project Euler #1 in English:

Take the numbers from 1 upto but not including 1000 and for each number, if the number is divisible by 3 or 5 add it to a sum. Once every number has been looked up, print that sum.


Algorithms

I’ve been thinking about trying to use Lua as a algorithm description language instead of Python, there are a few things holding me back. One is that the end statements in Lua add a small but significant amount of space especially when I’m programming on paper.

I do wish that there was simple scripting language that was more Pascal like and supported Goto. Lua 5.2 has a goto statement, but it’s not widely available yet. Python does not support goto natively, but does use exceptions for control flow, which can work in a limit way for goto like constructs.

The main reason I want a version of GOTO is because I’ve been looking at Donald Knuth’s The Art of Computer Programming, and his descriptions of algorithms essentially use gotos rather than structured loops for control flow. I’d like to be able to translate his algorithms into code essentially as they are, before trying to rework them into structured form.

Practically, C has been the best language so far for doing immediate translations of Knuth’s algorithms that I’ve played with.

Standard

2012-09-6

Go: Hello World

Hello world program in Go:

File: hello.go
--------------
package main

import "fmt"

func main() {
    fmt.Println("Hello World!")
}

Run it with:

$ go run hello.go

Or compile it with:

$ go build hello.go

and run the executable as:

$ ./hello
Standard

2012-09-03

C: Hello World

Hello world program written in C

File: hello.c
-------------
#include <stdio.h>

int main() {
    puts("Hello World");
    return 0;
}

Run it by:

  1. Compile with $ gcc -o hello hello.c
  2. execute with $ ./hello
Standard

2012-09-02

Seven Languages

I’m considering trying to study something about one of the seven languages I mentioned each day. So if I switch languages each day, then I will be studying or learning something about each of those languages once a week.

I’m also thinking about taking each project Euler problem and trying to write up a solution to it in each language I am looking at that day.

So with this scheme, each day I would hopefully learn something new about one of these "favorite" languages, and each day I would have a little practice with a not entirely trivial coding expression.


Lua: Hello World

hello.lua:
----------

print("Hello World!")

That’s it, run it with

$ lua hello.lua
Standard

2012-08-31

Slow Typist

I’ve been thinking today about the fact that I’m such a slow/inaccurate typist.

I wonder if that’s what causes Vim to feel somewhat annoying to me. When I get trying to go fast in Vim, I find myself often making mistakes. Emacs slows me down a little bit and maybe that makes it a little more forgiving. Also, the lack of modal editing, means that I’m having to hit a key chord rather than banging a sequence of keys to do whatever I’m trying to do.

I type somewhere between 30 and 50 WPM when I’m trying, depending on how the typing program measures.

I guess the problem is more that I’m a fairly inaccurate typist, rather than just a slow one.

I have wondered if the fact that I’m slow should make Vim more attractive, because I can leverage it’s better commands for copying and duplication, however, the fact that I’m often inaccurate removes a lot of the benefit of using it, because even if it can overcome my slowness via copying, it can’t overcome my inaccuracy.

Keys Instead of Mouse

I’m trying at the moment (I don’t know how long it will last), to avoid using the mouse as much as possible for my general computing. I can basically do anything I need to at the command like via only keyboard. And since I’m using Xmonad as my window manager and Vimium is a browser plugin, I can do most of the non-windows GUI specific stuff fine without using my mouse.

About the only time I really need to reach for the mouse is when I pull up a Windows VM to use Windows specific programs, or when I’m using MonoDevelop, which is either not as keyboard friendly as the rest of my environment, or I haven’t taken the time to properly learn it’s particular shortcuts.

Vim vs Emacs Keybindings

One of the reasons I’m trying to figure out which version of keybindings to focus on, is that because I’m trying to be keyboard based, I would like to basically have to use only one set of keybindings to control the various programs I’m using.

However, it seems to be the case that the best keyboard driven apps or plugins, tend to focus on either Vim or Emacs keybindings and don’t do a great job of providing for the other style. So I may just have to be content to switch back and forth between those bindings depending on what program I’m using. Strangely enough, that doesn’t actually seem to cause me that much trouble, as long as I’m actually switching between different applications.

The other day I was editing code in Vim, and using the Erlang shell which uses Emacs style keybindings by default, and switching back and forth between them using Xmonad. I really didn’t have any trouble at all using the correct key scheme in the right place.

Emacs Backup File Junk

The other day I spent some time cleaning out cruft from my .emacs file. One of the things I took out at the time was the bit of code that makes Emacs put all the backup copies of files it edits into one directory rather than dropping them in the same directory as the file that is being edited.

As a result, Emacs is now a pain to use in situations like the blog generation where I invoke the editor as part of an automated build process. Now those backup files become part of the generated blog posts.

There are a few solutions:

  • Re-copy the code to cause Emacs to use a dedicated backup directory
  • Change the blog build process to ignore files that are Emacs backups.
  • Use Vim instead of Emacs

Currently I’m going with using Vim instead of Emacs for editing any file where auto-generated files could interfere with other build processes. I’m aware that is something like the height of laziness, but I don’t really want to deal with either of the other options right now, even if it just involves re-copying some code out of an old copy of the config file.

Vim Typing Tutor

I took the time today to track down an old blog article I’d remembered reading about using Vim as a typing tutor.

Vim comes with a diff facility that with a bit of ingenious prodding can do a reasonable job of checking whether you are accurately typing an example text.

Here’s the command from the blog post as a single line:

vimdiff -o <inputfile> /tmp/temp.txt "+exe 2 \"wincmd w\"" "+normal 1000i "  "+diffupdate" "+go 1" "+startinsert"

Combined with the commands wc to count the words / characters in the input file and the time command to find out how long you took to type the file, you can also get a reasonable estimate of your typing speed.

Standard