Naive Programming

I think that may always be the case, especially when the resulting program is a function of what I’m asked to do! I was instead considering how, give experience in mathematical reasoning and programming, one writes increasingly concise code.

Because of the intense usefulness of Maths in programming, I cannot grok my fellow students’ disapproval of the subject. One of the major ways my code has grown less naive is in the borrowing of mathematical concepts.

Naive:

// print the sum of numbers x through y.
int sum(int x, int y) {
  int s = 0;
  for (int i = x; i <= y; i++)
    s += i;

  return s;
}

Insightful:

// print the sum of numbers x through y.
int sum(int x, int y) {
  return y*(y+1)/2 - x*(x+1)/2; 
}

I cannot remember a time when a working insightful function has been worse then the naive equivalent. Even in my contrived example above the naive_sum() has inputs which would yield undefined output such as the case where y <= x while the insightful_sum() would degrade more gracefully.

In the naive style, we’d have to add conditionals to validate inputs that the maths would accept, meaning increased line count, reduced legibility, increased chance of errors, and increased nativity. The only advantage I can see to the naive style is the reduction in mathematically cluttered code.

FreeBSD on the Desktop: How much are we giving up?

I’ve been running FreeBSD for awhile now. Looking back at my posts, it appears that I hammed up my Slackware installation right around the turn of the new year so near abouts three-and-a-half months.

FreeBSD on the desktop, if you’ve experienced it, is a learning experience. So much that at times I feel like I’m being punished for not knowing everything about my system.

To clarify on my desktop history you should know that a few months ago I switched to xmonad for my window management from Fluxbox. I went from an already minimal window-manager to an an even more minimal window-manager.

I don’t want my desktop to do everything for me all the time. On the other side of the coin, I don’t want to have to do everything for it.

I was reminded of this disconnect when I fired up Fedora 16 on a machine at home (it was running FreeBSD but I was sick of compiling packages from ports. Yes, I know I can get packages in binary but I can’t understand how to keep my binary packages and ports in sync for cherry picking every other source.) Everything just worked together.

After installing emacs and copying my global .emacs.d/ things are just working. After a `yum install xmonad` I am able to login under xmonad. I see they’ve even included a .xmonad/ in my home.

The Fedora developers must have a picture in mind of how the system should be and it appears that all packages have been designed with this picture in mind.

I don’t know what this means for FreeBSD. The craftsmanship of the FreeBSD project never ceases to amaze me. I love just setting my variables in rc.conf. However, it seems to me that more work needs to be done to integrate binary and source versions.

Some ports build against the kernel source. Why is my /usr/src not updated by freebsd-update? (Update: yes, it can update /usr/src.)

If FreeBSD could solve the Package vs Ports dilemma, and if packagers provided more apparent defaults for settings then FreeBSD would be a very strong desktop. I’m sorry that everything I plug in isn’t automagically configured, but doing that is complex and what is convenient for me may be inconvenient for the masses.

In the coming days, I do see myself spending some time contemplating the differences in experiences. FreeBSD truly is the unknown giant.

Mp3’s and blog posts.

Word on the street is that Morningsiders would like to embed MP3 files in their posts.

This sounds like a cool idea, so I’ve sat down and see that WordPress can already do something like this:

brobob

Sounds good. How to do it?

Step 1, have a mp3 file. =) That’s easy.

Step 2, choose “Upload/insert” from the post screen.
The Upload/Insert icon

Step 3, choose your mp3. Enter some details about it and select enter into post.

Step 4, enjoy.

Helping a little, old (rich) lady

One day, on the drive home from work, I witnessed an elderly lady in battered clothes struggling. Her wheelie basket, piled with laundry, had gotten stuck. In an unexpected and unprecendented pang of empathy, I stopped and offered assistance. Delighted to have me after, apparently, struggling for some time I was quickly able to pop the stuck wheel out of its prison (the sewer grate).

Preparing to leave, she stops me. “Before you leave, I have a reward to offer!”

She has my attention now. “I can give you 1,000,000 dollars or I can give you thirty daily payments starting today of one penny. I shall double each subsequent payment.”

To be kind, I offer the “lower” payment of a penny. I don’t need any old ladies millions of dollars. She gives me a penny and departs.

Sitting back in my office, I stop and think about what I’ve done. I realize that each day she pays me (for all thirty of them) I can expect 2^{day-1} cents. Considering it further, I begin to understand that the miracle of a doubling scheme such as this is that every subsequent day I will receive exactly one more cent than all the previous days combined.

A few weeks later, it now takes a rather large dump truck to deliver the little copper coins. Wondering how many dollars this all amounts to I quickly scribble on a pad of paper: \frac{2^{30}}{100} = \$10,737,418.

Just something to remember when you see an elderly lady in need.

I killed my workstation…

I cannot believe it. ~120 days uptime on my Slackware13.1-AMD64 system. I decided I needed to re-arrange my office. It was time for a change. Well, everything was nearly in place. When I went to slide my (running) PC back I accidentally touched the power switch on the rear after warning myself not to.

Evidently, 120 days of running leaves a lot of the file system in cache. It would not boot past lilo and I was ready for a change here, too. Booting to a live CD I backed up my /home/ and BFU’d the machine to FreeBSD 8.1-RELEASE. Last I tried it was a year ago, I’m interested to see if it or I have changed.

Sound (sp/dif)?
# kldload sound
# kldload snd_hda
# sysctl hw.snd.default_unit=2