The Environment Object Pattern in Go
Permalink
Jan 23, 2014
Programming, Golang

One of the things I've been really enjoying about Go is how easy testing is. The pervasive use of interfaces and composition-instead-of-inheritance synergize nicely for testing. But as I've expressed this online on reddit and Hacker News a couple of times, I've found that this does not seem to be a universally-shared opinion. Some have even commented on how hard it is to test in Go.

Since we are all obviously using the same language, the difference must lie in coding behavior. I've internalized a lot of testing methodology over the years, and I find some of the things work even better in Go that most other imperative languages. Let me share one of my core tricks today, which I will call the Environment Object pattern, and why Go makes it incrementally easier to use than other similar (imperative) environments.

Read the rest...


So you want to write a Monad tutorial in Not-Haskell...
Permalink
Jan 17, 2014
Programming, Haskell

There are a number of errors made in putative Monad tutorials in languages other than Haskell. Any implementation of monadic computations should be able to implement the equivalent of the following in Haskell:

minimal :: Bool -> [(Int, String)]
minimal b = do
    x <- if b then [1, 2] else [3, 4]
    if x `mod` 2 == 0
        then do
            y <- ["a", "b"]
            return (x, y)
        else do
            y <- ["y", "z"]
            return (x, y)

This should yield the local equivalent of:

Prelude> minimal True
[(1,"y"),(1,"z"),(2,"a"),(2,"b")]
Prelude> minimal False
[(3,"y"),(3,"z"),(4,"a"),(4,"b")]

At the risk of being offensive, you, ahhh... really ought to understand why that's the result too, without too much effort... or you really shouldn't be writing a Monad tutorial. Ahem.

In particular:

A common misconception is that you can implement this in Javascript or similar languages using "method chaining". I do not believe this is possible; for monadic computations to work in Javascript at all, you must be nesting functions within calls to bind within functions within calls to bind... basically, it's impossibly inconvenient to use monadic computations in Javascript, and a number of other languages. A mere implementation of method chaining is not "monadic", and libraries that use method chaining are not "monadic" (unless they really do implement the rest of what it takes to be a monad, but I've so far never seen one).

If you can translate the above code correctly, and obtain the correct result, I don't guarantee that you have a proper monadic computation, but if you've got a bind or a join function with the right type signatures, and you can do the above, you're probably at least on the right track. This is the approximately minimal example that a putative implementation of a monadic computation ought to be able to do.


Permalink
Jan 15, 2014
Programming
Scientists (and, in my experience, especially bioinformaticians) tend to make horrible, awful messes no matter how maintainable you think a language is. (You can hand them Inform 7 and it'll still end up looking like Fortran ate the csh manual and vomited all over an APL keyboard.)
-- chromatic on HN

Permalink
Dec 19, 2013
Programming, Golang

I've pushed two repos to GitHub with Go code:

Both libraries have 100% test coverage, and are golint and go vet clean.

There's more coming, but they're bigger than these. My supervisor tree library is nearly ready to go, but the requisite blog post explaining the design is still in progress. (It's big.) The library that implements Erlang-style mailboxes, including the ability to cluster together machines and send messages across the cluster the way Erlang does, is still in progress. (I have just barely started the clustering.) My current plan is to lock down and stabilize the system this is being written for in the single-server case, then implement this clustering.

I wouldn't mention it, except that Google does not seem inclined to index these without some form of external link. GitHub permits external indexing of the master branch of projects but I think perhaps their robots.txt forbids the scraping necessary to find unlinked projects. Hopefully this fixes that.


Computer Security Haiku

Gold in vault, target
Steel door closed, locked, key thrown away;
Thief laughs "There's no wall!"

Data stream flows, filling
Lake overflows; disaster!
Arbitrary code

Man trusts fellow Man,
fellow Man undeserving.
Script code injected.

Novice celebrates,
Output easy, just append strings!
Master needs new novice.

Dark secrets made, shared
Tells foe the password is lost...
Rubber hose finds it.

"Love", Alice tells Bob
In anger, Eve flips one bit
Now love's checksum fails

Small time differences,
like the blink of a blink, yet,
timing attacks still work.

Chick digs my profile,
sends regards in attachment.
Virus, still no love.

That plaintext password?
Easy, but when the press hears...
thought too hard to bear.

Address sign-up forms,
Security mindset sees
a way to spam foes.


I'm aware of the rule that haiku are supposed to have "season words", but I just couldn't jam them in there. "Arbitrary Javascript injection" is ten syllables already, for instance. It seemed better to not jam them in.


Past Posts ->

 

Site Links

 

RSS
All Posts

 

Blogroll