Archive for November 2006

Code commenting tool?

Dear lazy web,

I’ve been searching for a tool that lets me attach comments to text files. What I inted to use it for is commenting on code. The things I’d like to see in it are

  1. Keeping original text (i.e. the source) separate from the comments.
  2. A way to “export” the text and comments in a single document for sharing with others. It’d be ideal if the format was HTML.

It would be a nice-to-have if the tool aided in moving comments from one revision to the next.

When asking on a Debian mailing list it was suggested that a VCS would allow me to keep comments in the original text itself. While it would be doable I’d really like to have something that’s a little less bare-bones.

After hearing about the GPL3 drafting process I’m more and more thinking that a similar way of commenting on code, i.e. online using a browser, would be a good way of doing it. ([Here] is draft 2 of GLP3 with comments.)

So, does anyone out there now any tool like this, or will I be forced to write one myself?

Getting real with Haskell

Yesterday I decided to leave the relative safety of solving exercises in tutorials and instead try solving a small problem I had at work. I had pairs of times (points in time, like Wednesday November 8 01:17) and I needed the difference between them. Not a tricky problem by any stretch of the imagination, but I figured I had to start using Haskell at some point. I might as well make this that point.

I started out by playing around with System.Time and System.Locale in gchi. One thing that seemed missing was a function that took a String and tried to interpret it as a CalendarTime. After a mail to Haskell Cafe I discovered MissingH.

I found myself programming top-down, stubbing “sub functions” while trying to get the types of the current function right. It turns out I was “lucky” and there wasn’t many monads involved, but still I did run into some problems with mixing do notation and let, where, and case. In the end I split out those constructs and kept only the most basic syntactical constructs inside the do.

Here’s the end result, not the most functional piece of Haskell code ever seen, but it’s the first time I dip my toes in the sea of Haskell without a tutorial life-west.

module Main where

import System.Locale
import System.Time
import System.Environment
import MissingH.Time.ParseDate

diffAndToString :: CalendarTime -> CalendarTime -> String
diffAndToString s e = 
    let
        sC = toClockTime s
        eC = toClockTime e
        diff = normalizeTimeDiff $ diffClockTimes eC sC
    in
        formatTimeDiff defaultTimeLocale "%R" diff

calcDiff :: String -> String -> Either String String
calcDiff start end =
    let
        -- I had problems using %Y, so I'm using %C%y instead
        sT = parseCalendarTime defaultTimeLocale "%C%y%m%d-%H%M" start
        eT = parseCalendarTime defaultTimeLocale "%C%y%m%d-%H%M" end
    in
        case (sT, eT) of
        (Nothing, _) -> Left "start time"
        (_, Nothing) -> Left "end time"
        (Just s, Just e) -> Right $ diffAndToString s e

resultString :: String -> String -> String
resultString s e =
    let
        calculatedDiff = calcDiff s e
    in
        case calculatedDiff of
        (Left s) -> "Bad " ++ s
        (Right s) -> s

main :: IO ()
main = do
    args <- getArgs
    putStrLn $ resultString (args !! 0) (args !! 1)

Epilicious in Ubuntu Edgy Eft

It seems my Debian packages for Epilicious have worked in Ubuntu (Dapper Drake I suppose). This is purely accidental. It’s however a very nice accident :-) This lucky coincidence doesn’t hold for Edgy Eft.

If you are lucky then you can get my Epilicious packages to work on Edgy Eft by copying (or linking) the files to /usr/lib/epiphany/2.16/extension. No guarantees, and YMMV, of course.

Related news: I’ve just updated the package of the development edge version of Epilicious.