Profile cover photo
Profile photo
Ralph Corderoy
2,220 followers -
Programmer of the Unix school
Programmer of the Unix school

2,220 followers
About
Ralph's posts

Post has attachment
Python’s NaN-handling catches people out, as it does in many languages.

    >>> def nan(): return float('nan')
    ...
    >>> n = nan()
    >>> n == n, n == nan(), [n] == [n], [n] == [nan()]
    (False, False, True, False)
    >>> {n: 0, n: 1, nan(): 2, nan(): 3}
    {nan: 1, nan: 2, nan: 3}

IEEE 754 decided NaN would never be seen as equal to itself. Bertrand Meyer¹, creator of the Eiffel programming language² with its design by contract³, argues the IEEE 754 got it wrong and the opposite is more useful, less unexpected, and “least damaging to time-honored assumptions embedded in mathematics”.

1.  https://en.wikipedia.org/wiki/Bertrand_Meyer 2.  https://en.wikipedia.org/wiki/Eiffel_%28programming_language%29 3.  https://en.wikipedia.org/wiki/Design_by_contract

Post has attachment
The Tragedy of the Commons is a well-known theory but I only knew what I’d gleaned from en.wikipedia.org/wiki/The_tragedy_of_the_commons, and suspect I’m not alone. +Tim Harford’s excellent Do You Believe in Sharing? added some interesting snippets, e.g. TotC says “freedom to breed is intolerable”, and contrasts its author’s views against those of Lin Ostrom who had studied long-lasting commons that hadn’t unavoidably descended into ruination. It’s a great read over a five-minute break with your favourite beverage.

Post has shared content
Using an int to track indentation and print itself as the indent when its String() method is called. play.golang.org/p/uY6SW71jjS is a longer example showing a bit more behaviour.
Stumbled on this Go code I wrote ages ago. It's an interesting use of the String method. (To see it in action, visit http://play.golang.org/p/MX7eFmtHh_)


// tab indents itself when printed.
type tab int

func (t tab) String() string {
  n := int(t)
  if n > len(tabs) {
    n = len(tabs)
  }
  return tabs[0:n]
}

Post has attachment
Python library Twisted has been around a long time, “an event-driven networking engine”. +Guido van Rossum recently learnt and explained some more of its internals as research for Tulip, his reboot of asynchronous I/O for Python. I thought it a "fun" read, highlighting how complex some of this stuff can get, not just for the implementer but for the user that has to comprehend the behaviour, especially when debugging.

Post has shared content
Written in Go, etcd is a distributed locking manager for small amounts of data, e.g. configuration, with handling of node failures. Similar to Google's Chubby, research.google.com/archive/chubby.html, or Apache's Zookeeper. It's just released version 0.1.0. Brandon explains more in the comments of his post.
etcd is a distributed key value store we have been working on for CoreOS. It is like Zookeeper but uses REST APIs and is written in Go. Excited to get this first release shipped!

A distributed configuration service is a primitive we are building into CoreOS. Every application stack builds something like this eventually we want there to be an easy default.

Post has shared content
Googler +Josh Haberman, works on BigQuery, has come up with a considered couple of issues with Go's design that's blocking him from using it. I thought there might be learned voices here that can better persuade him, perhaps from long experience, than my comment on his post.
I just can't get over my discomfort at Go's take on interfaces. In Go you don't explicitly declare that your type implements an interface, you just pass your type to a function expecting the interface and the Go compiler checks that you have method signatures that match the interface.

This lack of an explicit "implements" statement just bugs me so much. Interfaces can have really subtle semantics; without an explicit "implements" declaration it's unclear what (if any) interface and associated semantics you are promising to implement.

For example, I can easily declare two interfaces (I haven't written any real Go, so sorry if I get the details of this wrong):

type Writable1 interface {
  // Returns the number of bytes successfully written,
  // or "0" or on error or EOF.
  Write(data []byte) int
}

type Writable2 interface {
  // Returns the number of bytes successfully written,
  // or "-1" on error or EOF.
  Write(data []byte) int
}

Now there is no type that can implement both interfaces correctly, but any type that attempts to implement one will also (inadvertently) implement the other, and the Go compiler will be happy to let this happen.

Also, if the interface changes the compiler won't warn you about subclasses that need changing unless you compile the code that tries to use that type by its interface.

I really think explicit is better than implicit when it comes to "implements" declarations. This is a big stumbling block for me ever wanting to use Go.

Post has shared content
groupcache is implemented in Go and, I thought, sufficiently interesting to warrant its own post.
groupcache: Memcached alternative/replacement from its original author

+Brad Fitzpatrick has just given a talk at OSCON 2013 on downloads from Google’s dl.google.com: talks.golang.org/2013/oscon-dl.slide. Its old C++ code was replaced with an all-round better Go implementation.

groupcache is part of that and is now available. It has coordinated cache filling, so on a cache-miss the herd doesn’t thunder. Unlike Memcached, a key’s value is immutable, so no increment, etc. This allows groupcache to replicate sought-after items to processes other than the authoritative source, avoiding a bottleneck of CPU or NIC for very popular items.

#memcached #golang

Post has attachment
groupcache: Memcached alternative/replacement from its original author

+Brad Fitzpatrick has just given a talk at OSCON 2013 on downloads from Google’s dl.google.com: talks.golang.org/2013/oscon-dl.slide. Its old C++ code was replaced with an all-round better Go implementation.

groupcache is part of that and is now available. It has coordinated cache filling, so on a cache-miss the herd doesn’t thunder. Unlike Memcached, a key’s value is immutable, so no increment, etc. This allows groupcache to replicate sought-after items to processes other than the authoritative source, avoiding a bottleneck of CPU or NIC for very popular items.

#memcached #golang

Post has attachment
Cycle-counted bit-banging of video and audio

Heartened by the comments on Jeff Dean’s post, plus.google.com/118227548810368513262/posts/EMzp9NVV6QJ, showing that the skill of low-level optimisation is still valued, I thought I’d dig out Linus Åkesson’s 2011 blog post about his “Bit banger”.

It’s not uncommon to bit-bang audio these days, or even a video signal. Linus does both, and in a very constrained environment. He’s using a 1.6MHz Atmel ATtiny15 microcontroller that has room for a maximum of 512 instructions. RAM’s a bit tight too; 32 bytes. Though “RAM” is a bit of a stretch, those bytes are more accurately described as the register file.

Linus doesn’t shirk from giving detail so I’ll stop re-telling it here, but do look out for his assembly extract. It’s in two columns, video bit-banging instructions are on the left, audio on the right. They have to be interleaved because of the timing constraints. :-)

If Go matches my understanding of its ancestors, a select where more than one case can proceed will pick one pseudo-randomly. Is this true, and is it still true in the Playground? I'm suspecting it's effectively nobbled there, perhaps as a side effect of the PRNG always having the same seed.
Wait while more posts are being loaded