Sunday Oct 08, 2006

I keep forgetting how closures work...

Language geek warning. I'm not going to explain closures here, I'm just going to mumble some thoughts aobut them. Read about them on Wikipedia. The short answer is that a closure is a code-block that you can pass around a pointer to. It lets you write your own replacement for for loops and while loops.

Every now and then I get interested in some language or other that has closures, and I have to figure out what they are again. It's a little bit like not being able to understand pointers in the C language until you can visualize the underlying Von Neumann Architecture underneath. There's no way to understand how closures work until you stop visualizing the traditional call stack architecture.

Since some people started discussing closures in Java recently, I figured I would try to remind myself how they work. My confusion always boils down to "What about global variables?" What happens when a closure access a global variable? I decided to go to my go-to source these days, Wikipedia. Paragraph 2 of the Implementation section says: A typical modern Scheme implementation allocates local variables that might be used by closures dynamically and stores all other local variables on the stack.

All of a sudden it made sense. If you want proper closures, you have to implement a garbage-collected runtime system, and use it for every local and global variable except for cases where the compiler can prove that certain variables cannot be accessed any closures.

So the short answer to my confusion is: You can't have closures in any language that has global variables in the sense that C and C++ have global variables. At least that's my latest understanding.

Wednesday Aug 02, 2006

Red Hat versus Ubuntu

An email alias that joined recently got this article forwarded to it: Why Red hat will go bust because of Ubuntu. It will be interesting to see how this plays out. I installed Ubuntu recently, and my first thought was "How un-Linux-like." It just worked out of the box.  The bottom up strategy described in the article is a philosophy that is basically ignored by most corporations.  When the sales and marketing guys get involved, nobody is quite willing to put their faith in the community to choose what's best. Or maybe they're not confident in their own ability to build the best product.  Whichever it is, it ties into the same strategy that Sun is following by Giving it away for free and making it up in volume.
About

Chris Quenelle

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today