Saturday, March 25, 2006

Political Standing

Last week at my caucus meeting I met Cliff Lyon. Bob mentioned him earlier this week. We had an interesting conversation. He suggested that I start or join a more politically oriented blog (probably not going to happen). Cliff also said he was interested in how I converted from being a republican to being a democrat. I think I'll share...

The first key, is that my political party is not my religion. This moots the term "Conversion". I switched because I had 2 options. One party that has a platform I agree with, but doesn't follow it to the extent that I disagree with the actions of its members. Or, a party that I may disagree with sometimes that actually sticks to its platform. I also believe I am in a better position to be heard and to be able to do things to get meaningfully involved in a smaller party.

I guess the moral of what I have learned is that if fewer people made their party their religion we would have better competition. Besides, the democrats aren't exactly perfect. They nominated John Kerry of all people when they had a fully operational Howard Dean sitting around.

I would like to say one final thing about confusing politics and religion. It happened in Germany. Having a leader that claims to be a Christian, but who does not act like a Christian is very dangerous. Continuing to vote for them, even more so. People ignore too many things that are wrong when they believe someone is a Christian. Lets take warrantless wiretaps. It's pretty easy to establish that they happened. The trouble is that we have to follow the rule of law. Let this slide and it won't be such a big deal that other laws are broken. I can't stand TV shows and movies about what the president does because those often show the president as being above the law. Bad move...

So here I am, Shaun the democrat. Lets just hope that whoever I back I don't become Shaun the oppressed. I see it coming plain as day so lets stop voting for people who abuse power in any level of government.


Tuesday, March 21, 2006

Lambda Epiphany in C

Today I realized that C can get Lambda like behavior. I wrote the following code:

#include <stdio.h>

int main(void){
  int val = 4;
  int lambfunc(int innerval){
    return innerval+val;
  int i = 2;
  printf("lambfunc(%i) = %i\n",i,lambfunc(i));
  return 0;

It gave the following result:

lambfunc(2) = 6

The significance of this is that I was able to write a function in a function that made use of variables in the scope of the function. What was really cool is when I added the nestlamb() function:


int nestlamb(int fn(int)){
  int value = 6;
  return fn(value);

int main(void){
  int val = 4;
  int lambfunc(int innerval){
  return innerval+val;
  int i = 2;
  printf("lambfunc(%i) = %i\n",i,lambfunc(i));
  for(val = 0;val < 5; val++)
    printf("nestlamb(lambfunc) = %i\n",nestlamb(lambfunc));
  return 0;

What's really cool about this is that I have a function (main) that has a function in it (lambfunc) that uses variables in the local scope. When I go through the loop calling nestlamb() passing lambfunc I call it 5 times with val ranging from 0-4. nestlamb(lambfunc) returns values 6-10. This means that nestlamb uses the changing values in the scope of main. I managed to do this by passing the pointer to lambfunc instead of passing the return value from calling lambfunc(). This passed the pointer to the instance of lambfunc() that exists on the stack. Subtle difference with a powerful result.

Some things to remember when doing this:
  • lambfunc() must only be passed to other functions. Never return it!
  • C has static typing. This still isn't going to be as flexible as things like using (map (lambda) ...) in lisp.
  • You can't declare a lambda and use it in one expression. First you define it, then you use it.

All things considered, this is really cool. I'll be writing some very interesting code in the future. The ability to declare a function on the stack is very interesting to me.


Monday, March 20, 2006

Professional Piracy

Yesterday during the course of a political discussion I was told that I am a professional pirate. Perhaps I'm a little hazy on definitions, but I thought piracy involved stealing and getting gain and what not. If I'm a pirate then I need to find another line of work because piracy isn't paying off nearly as well as my day job.

What was implied when I was called a "Professional Pirate"? I believe it was a shot at open-source software. If you believe everything that comes out of SCO I guess that would make some sense.

This all came up because I shared my belief that Orrin Hatch is bad for copyright. Tighten copyright down to the point where nothing leaves copyright or make reverse engineering illegal and you will eventually stifle innovation.

Despite this tendency of copyright to become tighter and tighter there are people who want software to be free. They write software and release the source under a license that allows editing and redistribution of code. In fact with when released under the GPL providing your changes to source code is mandatory if you are distributing the software.

The point is it's good and legal to give something away that is yours. In fact, you are probably making use of open source software. The HTTP headers for this blog show that it is being served by an Apache Web Server (free software). If you're using Mac OS X to read this the base system is BSD UNIX based (BSD has its own open source software license). If you're using windows the IP networking code is derived from BSD UNIX and the API is specifically called BSD sockets. Being able to borrow the BSD sockets API from BSD UNIX and use it in other operating systems helped the development of interoperable systems. Because of the open source BSD license and industry standard APIs that are not defended by copyright I can write code that can be ported to many different systems. I can spend more time on my software and less time on writing compatibility layers. It's already hard enough to port without having to rewrite network code for every operating system.

What really bothers me about being called a Professional Pirate is that it is based on my use of software that is being contributed willingly by programmers and companies. IBM contributes to free software because they are a hardware vendor. With open source they can contribute to a server operating system with growing mind share in the market place. What happens when they do this? They can make sure it runs perfectly on their hardware and can make better promises about how well their hardware can run these systems.

This problem really comes down to two fundamental schools of thought. The first is "We (a company) must build what people want and be paid for it. We will protect it with copyright". This is right and fair and I will agree with it; that's what copyright is for. The second is "We (everyone) all need this. Let's all contribute to the common cause of building it, but keep it free by copyright protection." This is also right and fair.

Now for the real question: Why was this important enough for me to blog about?

Quite simply, it's because without open source software I would not be where I am today. I was able to install Linux on an old 486 with 16MB ram and a 240MB HDD. I was able to start learning on my own. I thought the Linux kernel was an interesting topic and all I had to do was download the source and start reading. Looking at real world grade code is highly educational. Using open source development tools like GCC also allowed me to become a better programmer.

I am where I am today because some information is free to those who look for it and some people are generous enough to give of their time to help others learn (online discussion groups) produce good software. Besides, Linux originated as a hobby project.


Friday, March 17, 2006


Today Christie asked me if I was going to write some more haiku. Since I've already done that I think I'll try something different...

To what end do I make a hack?
For which cause do I write?
Perhaps it is because I have a knack.
For this cause I think I might!

On my programs I do work.
In my code I do conceive,
to find my errors where they lurk.
Inspiration for this I do receive!

It is much fun to pass the time.
A new project to come forward!
Oft I work not for a dime,
The code complete my true reward.

Is not this time well spent?
Just a shame it pays not rent!

Ok, so it may not be the best sonnet around, but I think it's pretty good for 15 minutes.


Tuesday, March 14, 2006

Peer review has never been so tasty!

I was looking at last night and I found this cool little thing. Measuring the speed of light with chocolate chips. I think I need to give it a try, just to make sure I can get the same results. However, I think it would be best to replace the plate with a rice crispy treat substrate. That would make cleanup even easier.


Monday, March 13, 2006

I see parse trees!

I have a confession to make. I've been playing with scheme again. The trouble is that languages like Scheme and Lisp are just so interesting. My biggest problem is I'm not thinking like a compiler yet. I've been doing so much procedural programming that I'm not really ready to jump straight into generating parse trees.

To skip the code scroll down to "END CONCLUSIONS".

Take for instance a factorial function I just wrote:
(define (mfac num)
(if (= 1 num)
(* num (mfac (- num 1)))))

In C I could write this a couple of ways...
int mfac(int num){
return num == 1 ? num : num * mfac(num -1);
int mfac(int num){
if(num = 1)
return 1;
return mfac(num - 1);

Now these map pretty well. It's just doing other more procedural things that is harder. I'm just not thinking in parse trees well enough yet. Take the following:
char *str = "This is a string";
printf("After += 5 \"%s\"\n",str);
I can see that I need to use (let ((str "This is a string")) (print str))
The trouble is doing things like the pointer addition and the subsequent call to (print ...).

I get errors with the following:
(let ((x 2))
(print x)
(print (* x 2))

Update: I think I figured out why (let ...) wasn't working. I was using the "Advanced Student" language with DrScheme. I tried "Standard R5RS" and it started working. Oops... I even tried (let) with CLisp (Yes, I know Lisp and Scheme aren't the same) and it worked as expected there too.

C would look like this:
int x = 2;
printf("%i\n",x * 2);


It doesn't seem to want to work. There is something I don't understand yet. It's obvious. I'm getting close and it's more of a syntax thing than anything else. Suffice it to say this is one of the most fun/hardest programming languages I've ever tried to learn. The coding style I used when doing the first C implementation of mfac() above came to me after I started learning Scheme.

People look at me funny and wonder why it is that I can get excited about a language. I guess it's because it's taking everything I thought I knew and shifting it. I still write programs in the same languages; they just don't look the same to me anymore.


Friday, March 10, 2006

The internet and you

Have you ever stopped to think about just how much you use the internet? Since my last post I have moved and been living with reduced internet access.

Sound exciting?

I can assure you I've just found other ways of wasting my time. Usually involving other people or sleeping. Yeah, sleeping is good. I've gotten more good nights of sleep without using the internet than I have had in a while. The first key is that I'm not up until 12:30 or 1:00 reading sites like reddit. Granted, there is nothing wrong about those sites. It can just take a long time to read all of the interesting stuff that's out there in the world.

I hadn't really given much thought to how much time I was spending on the internet. As I think about it I feel like it fills the same void that TV fills for some people. Instead of talking about last night's episode of Survivor or whatever else people are watching these days I start or join conversations with things I read in links on reddit. Or, gasp, things I found linking from other people's blogs.

Now for the question I'm not sure I'm ready to honestly answer. Is this much better than sitting and watching TV? I am on a constant search for things that look interesting. I often forget to ask if I am contributing to the interesting things in the world.

what is the net impact of my life if all I do is read other people's material? I may be able to contribute to interesting dinner conversation, but what can I really do?

Starting this blog was partially meant to give me mental exercise. It's done pretty good in that regard. It helps me clear up what exactly I am thinking. It also provides a forum for people I know and people I don't know to respond to what I write. I've only ever been called a bad name one time.

Perhaps it's time to step up and do something more. Every so often I feel the urge to start another programming project. Though, the more time I spend programming the more realistic I get about what size of projects I can take on by myself. Maybe it's just time to manage my time better and spend my time better reading more literature and doing more in my life rather than reading web pages. Perhaps I'll even spend a little more time alone with my thoughts. This could be dangerous; it's a good way to end up with blog posts like this one.

All things considered I'm looking for some change. Let's see how I do.