Phillip Pearson - web + electronics notes

tech notes and web hackery from a new zealander who was vaguely useful on the web back in 2002 (see: python community server, the blogging ecosystem, the new zealand coffee review, the internet topic exchange).

2002-12-20

Creative Commons and open source

Matt Croydon: "What kind of effect are the new Creative Commons licenses going to have on open source software?"

IMHO the GPL is "attribution + share alike", and the BSD/MIT licenses are "attribution". They're just somewhat better understood for software. Any combination of "attribution" and "share alike" should be GPL-compatible.

Technorati

Forgetting for a moment that it's sort of a competitor to my own Blogging Ecosystem project, Technorati is pretty cool. I just found loads of interesting things linking back to me on my cosmos page. Thanks to Dave Sifry for a great service.

I wonder what the quality of the 'new inbound link' RSS feeds is like. It would certainly be worth $10/year for something like that. My comment monitor has made keeping track of my own blogs much much easier -- this one would also help me keep track of other people's blogs.

Alternatively, I could spend an afternoon and hack up an equivalent feature for the ecosystem. Decisions, decisions :-)

I'm inclined to just shell out the cash. There's only room for so much duplication in this world!

BTW (in response to one of the aforementioned newly-found links) - Matt: thanks for the mention. Last time I checked, it cost a little over NZ$2000 to get to the USA, which is about US$1000. (Also, the value of money is different: salaries in the USA are 3-4X higher than in NZ; a highly-paid executive here might get NZ$120K, i.e. US$60K). So I guess I won't be going :-)
... more like this: [, ]

Not for use in the real world

Sometimes it seems that C++ was designed as some sort of academic exercise, to make C look object-oriented and flexible, but that the people implementing it never actually thought about how it would be used in the real world.

MSVC not supporting local functions, for example. Why doesn't it? GCC handles them just fine.

Here's another shocker. If you define a private class, you can't use it as a template argument. Why not? What technical reason is stopping the compiler writer from being able to do this sort of thing? Aren't private classes just public classes with long munged names like Foo::Bar::Baz?
... more like this: [, ]

Wow

A reverse debugger (jwz calls it a 'palindrome debugger') has already been written. Wow.

The idea here is that the debugger traces everything a program does, building a history of all memory accesses, and then you can walk backwards from a crash to see what events led up to it. Great for bugs that only pop up after the app's been running for some time, and difficult to reproduce bugs.

Unfortunately, it looks like the project died due to lack of appreciation :(

C++ trickery: returning multiple values by turning functions into objects

Something that's always annoyed me about C++ is that you can only return a single value from a function, and that it's such a pain in the ass to have to go and create an object just to hold a value that hasn't been well-defined yet.

In Python, you can say stuff like:

def foo(bar):
    return 1, 2, 3, munge(bar), ['a', 'b']

j, k, l, m, n = foo('asdf')


foo() returns a tuple (an immutable list) containing five items. The first three are integers, the fourth is whatever munge(bar) returns, and the fifth is a list. Being able to do this sort of thing is great. The icing on the cake, however, is being able to unpack them at the other end. In Python, given, say, a 3-element list 'mylist', you can say:

a, b, c = mylist

... and now a, b and c will contain the values in mylist. The above example of calling foo unpacks all the return codes into j, k, l, m, and n.

Yesterday, it occurred to me that it's possible to do a similar thing in C++ by turning a function with multiple returns into an object. The function body becomes the constructor of the object, and all the values it returns become public member variables. For example, the Python function above and its caller might become something like this:

class foo
{
public:
    int j, k, l;
    string m;
    list n;
    foo(string bar)
    {
        j = 1;
        k = 2;
        l = 3;
        m = munge(bar);
        n.push_back('a');
        n.push_back('b');
    }
};

foo ret("asdf");


Now, all the returned values can be accessed by looking at ret.j, etc.

A disadvantage here is that this won't work with methods, only standalone functions. C++ doesn't seem to let objects access their surrounding scope - the following doesn't seem to work for me:

class foo
{
public:
    int a;
    class bar
    {
    public:
        bar()
        {
            printf("bar(): a == %d\n", a);
        }
    };
};

... more like this: [, ]