## Profile

Ralph Corderoy
Lived in London, England
2,331 followers|92,555 views

## Stream

### Ralph Corderoy

Shared publicly  -

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﻿
Let me start, dear reader of this blog, by probing your view of equality, and also of assignment. Two questions: Is a value x always equal to itself? (For the seasoned programmers in the audience: I am talking about a value, as in mathematics, not an expression, as in programming, ...
1

I guess if not-a-number is compared with not-a-number using a numerical comparision then it makes sense for that to be false in some way.﻿

### Ralph Corderoy

Tips and tricks  -

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]
}﻿
8

### Ralph Corderoy

Discussion  -

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.﻿
etcd is ready for its first release! We just marked v0.1.0 and uploaded binaries for Linux and OSX. These are the major features in this release: Simple: curl'able user facing API (HTTP+JSON); Secure: optional SSL client cert authentication; Fast: benchmarked 1000s of writes/s per instance ...
29
3

, Yes, Brandon answered what some of the differences were between Doozer and etcd on his post.﻿

### Ralph Corderoy

Show and tell  -

groupcache is implemented in Go and, I thought, sufficiently interesting to warrant its own post.

groupcache: Memcached alternative/replacement from its original author

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﻿
11
5

### Ralph Corderoy

Shared publicly  -

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. :-)﻿
Lines 0-479 displine: add r6, r10 ; t0 out PORTB, r2 ; t1 adc r7, r11 ; t2 mov r17, r22 ; t3 sbrc r24, 7 ; t4 eor r17, r23 ; t5 out PORTB, r17 ; t6 add r4, r8 ; t7 adc r5, r9 ; t8 brcc 1f ; t9 neg r12 ; t10 1: lsl r20 ; t11 rol r21 ; t12 brvc 1f ; t13 subi r20, 0xfe ; t14 1: in r16, ...
1

### Ralph Corderoy

Shared publicly  -

That’s a ‘path parameter’, defined in http://tools.ietf.org/html/rfc2396#section-3.3 but the superseding RFC 3986 doesn’t make them a formal part of a path. Even so, some web servers strip them out when traversing the path allowing us to add our own commentary to a URL.

That URL above goes to my posts. My boundless vanity would probably prefer the About page but if you open https://plus.google.com/115649437518703495227;Ralph-Corderoy/about you’ll see About is underlined in the navigation but the browser’s location is showing /posts and that’s what’s being displayed. Poor G+ has got a bit confused.

(In case it’s not obvious from the tongue-in-cheek nature of this post, I don’t serious intend anyone to do this. I just thought it an amusing little corner of URLs and shone a little light on it. If I were Google I’d stop ignoring path parameters on G+ quite quickly so your pride will take a fall when they become ‘404 Not found’.)﻿
1
In his circles
356 people
Have him in circles
2,331 people

### Ralph Corderoy

Shared publicly  -

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. ’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.﻿
3
1

, Thanks for letting me know; that's Wordpress for you. ;-) I expect Wolfe will sort it soon. And welcome to G+!﻿

### Ralph Corderoy

Discussion  -

Python library Twisted has been around a long time, “an event-driven networking engine”.  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.﻿
Instantly connect to what's most important to you. Follow your friends, experts, favorite celebrities, and breaking news.
11
4

Gosh, I hate async programming.﻿

### Ralph Corderoy

Discussion  -

Googler , 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.﻿
7
1

I think that  have a very valid point. Everyone answer the concern: "accidentally implementing an interface will cause a bug". A bigger concern is "not declaring implemented interfaces explicitly hamper readability".

If you look at the go/ast package for example, you'll find a "standard" type hierarchy for where "If is a statement" is implemented by having If struct implementing an annotation-only interface.

This indeed makes it harder to read, and harder to understand.

What really bothers me about 's approach for evaluating programming languages, is the methodology of deciding against a language because it has a single bad feature.

People worked successfully with far worse languages, with tools and methodology to mitigate their shortcoming. IMHO the mere features of the language does not correlate to a productivity boost.

Go features a first class standard library, with a clean API. Go put emphasize on top notch developer tools (which other language implemented a profiler so early, and added standard to the GDB). I personally couldn't care less if some detail is wrong in the language design.﻿

### Ralph Corderoy

Shared publicly  -

groupcache: Memcached alternative/replacement from its original author

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﻿
4
7

I'm hoping this improvement spreads further so googlecode.com stops returning 404 for HEAD until a little while after a GET for the same URL has primed its cache. It then works, returning 200, at least for a while. Been like this for a few years now. :-) code.google.com/p/support/issues/detail?id=660﻿

### Ralph Corderoy

Discussion  -

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.﻿
1

Cheers . Caching accepted, I can get a select to pick randomly by tweaking the magic value. Seeing about 50/50 between the two channels. http://play.golang.org/p/7Qylg4RF1w﻿

### Ralph Corderoy

Shared publicly  -

An interesting post by showing the internal structure of your id_rsa or id_dsa private SSH keys. He then shows how to switch a passphrase-protected private key from un-stretched MD5 to stretched-with-PBKDF2 using HMAC-SHA1, triple-DES encrypted. Or, in English, it makes brute-force attacks on the passphrase of a stolen private key more difficult. To switch is essentially one openssl(1) command.﻿
Improving the security of your SSH private key files. Ever wondered how those key files in ~/.ssh actually work? How secure are they actually? As you probably do too, I use ssh many times every single day — every git fetch and git push , every deploy, every login to a server.
5
2
People
In his circles
356 people
Have him in circles
2,331 people
Work
Occupation
Consulting programmer
Basic Information
Gender
Male
Story
Tagline
Programmer of the Unix school
Introduction
Unix/C programmer for over twenty years, lots of programming/assembly languages over that time, nowadays C, Python, and ARM.  Performance, problem-solving, and bit-twiddling are particular interests.
Places
Previously
London, England - West Sussex, England - Hampshire, England - Dorset, England - Versailles, France