Clocks that Run Backwards (and other innovations)

July 18th, 2010

Michael Hartl is spearheading a campaign for a cause that is near and dear to my heart. He wants to fix the fact that we are living with a suboptimal choice for the value of π:

http://tauday.com/

About a year ago I did a hunt on the web to see if anyone besides me had campaigned for changing the value of the fundamental circular constant we use to 2π. At that time, I only found the essay Michael cites: “π is wrong” by Bob Palais, which was published in 2001:

http://www.math.utah.edu/~palais/pi.html

Bob notes that the reactions he got ranged from “obviously” to “you’re nuts”. I’m personally in the “obviously” camp. Especially because in 1995 I gave an informal talk at my university called Clocks that Run Backwards (and other Innovations). In it, I suggested several foundational changes which would eliminate “accidental complexity” that I felt was burdening early education. Changing the circular constant was one of my big pushes.

I am almost 100% certain that other Quixotic-types must have espoused the idea before I ever thought of it. But I seem to be the earliest we know about (so far) who was crazy enough to treat it like an important topic in public—while sober, even. And I can call witnesses! :) In fact, one guy who came to the talk wrote my argument in response to a math question on an exam he didn’t know the answer to. He argued that he didn’t have to answer it due to religious objections to the choice of the value of pi. I think the TA gave him 0.628 points for the answer.

(Note: On another question on that test for which this fellow did not prepare, he wrote “6*O, where O is defined to be 1/6 of the answer to question 21″—or something to that effect. I don’t want any of the blame for that idea, though!)

Michael and Bob have made the arguments, and expanded upon them with more formal justification than I ever have. So rather than repeat that here, I’ll lay out how my proposal differed…as well as a few other things I talked about.

Read the rest of this entry »

When should one use const_cast<>, anyway?

June 12th, 2010

I saw a question on StackOverflow asking about why one would use const_cast. Because I’ve thought about that question lately I glossed over that they were asking specifically about applications of casting away volatile…which I didn’t even know you could use const_cast to do!

So I learned something. But I thought the answer I wrote to why you would use const_cast at all was pretty decent, so I was going to leave it there. But then I decided it was too off topic so I’d move it here.


The most common use of const_cast I’ve seen (with const) is this scenario:

  • You’re calling a library that has something like a printFoo(Foo* fooPointer) function, which clearly requires a non-const Foo.
  • There’s good reason to be “sure” this function doesn’t modify the Foo, but you’re unable to change the prototype or the source to express that knowledge for some reason.
  • Your code has made an effort to only use Foo* in contexts where writability is needed and const Foo* in all other contexts.

…that means that as a stopgap measure, you’ll have to const_cast in order to cross this divide and call the routine.

OTOH, the most legitimate use I know of is in subsystems that own objects in a non-const sense, yet have cases where they hand back const pointers to callers. The subsystem natively has more privileges on those objects, so if a caller passes one of those const pointers back it can “upgrade” the privileges.

Sure, the subsystem could store a useless map from non-const pointers to const ones…but const_cast is more time and space efficient:

const SubsystemObject* Subsystem::getReadOnlyObjectById(int id) {
     SubsystemObject* subsystemObject = getObjectCore(id);
 
#ifdef WORLD_WITHOUT_CONST_CAST
     constMap[subsystemObject] = subsystemObject;
#endif
 
     return subsystemObject;
}
 
void Subsystem::someMethod(const SubsystemObject* constSubsystemObject) {
     SubsystemObject* subsystemObject;
 
#ifdef WORLD_WITHOUT_CONST_CAST
     subsystemObject = constMap[constSubsystemObject];
#else
     subsystemObject = const_cast<SubsystemObject*>(constSubsystemObject);
#endif
 
     doSomethingNeedingNonConstAccess(subsystemObject);
}

Where the printf() Rubber Meets the Road

March 14th, 2010

After ignoring StackOverflow for a while, I decided to check up on it a bit lately. Someone asked a question that’s one of those kind of fundamental curiosity issues that I enjoy explaining. He said:

I always thought that functions like printf() are in the last step defined using inline assembly. That deep into stdio.h is buried some asm code that actually tells CPU what to do. Something like in dos, first mov beginning of the string to some memory location or register and than call some int. But since x64 version of Visual Studio doesn’t support inline assembler at all, it made me think that there are really no assembler-defined functions in C/C++. So, please, how is for example printf() defined in C/C++ without using assembler code? What actually executes the right software interrupt?

Obviously the answer is going to depend on the implementation. Yet I thought that with the open-sourced GNU C Library, it would be pretty straightforward to show how most of it is in C but it bottoms out at syscall. But it really was quite a maze to connect all the dots without doing any hand-waving! So I found that my explanation just kept growing until it was so long that a blog entry was a more fitting format.

So read on, fearless explorers, as we dig into the complicated answer to a seemingly simple question…

Read the rest of this entry »

BIL 2010 PARTICIPANTS - WELCOME

February 13th, 2010

Today I attended the fantastic event BIL. It is an “un-conference”, and was originally conceived as populist way of crashing/synergizing with the event known as TED.

(Though TED is awesome at spreading great ideas across the web, the speakers are by invite-only…and uninvited people must pay thousands of dollars to attend!!)

The incomparable organizer Todd Huffman gave me a minute to make an announcement after the talks had finished. I said something along these lines:

Hi there. My name is Brian. I love open source, and started a web site to support it called hostilefork.com. I also love Wikipedia—and I love events like BIL. So if you are doing something awesome and write me, I’ll do my best to offer any insights I can to help. My time is yours.

ALSO… I have an extra ten of these drinking glasses that need to find happy homes. As an added incentive, for each glass that is adopted I will donate $10 to BIL. So if you want to talk to someone technical–who will make time for you and your great idea, at no charge–find me and adopt a glass.

I hope to help you, but if for nothing else, do it for BIL!!

Yet while I and the other final announcers were speaking, the enthusiastic attendees were voluntarily packing up chairs. After all, we had to make our deadline for exiting the venue!! But I don’t think hardly anyone could hear me, and I think “something about open source and a glass” is about the gist of what anyone got out of what I said. :)

Thus only four glasses were claimed by the time we left the pavilion for lunch. But as lunch was wrapping up and I was about to hand Todd the $40 and head on home… people began to express curiosity about what was up with the glasses. Suddenly they were in demand, and the tenth was even contested over who would get it! I’m glad that the result is that every glass found a home, and I could give $100 to a wonderful cause that I supported wholeheartedly all the way back to when I attended the first BIL two years ago!

SO IF YOU GOT A GLASS: My hope is that you will keep it, and some night you will be enjoying a drink and be reminded that “The Fork” humbly offers his time and insights free-of-charge to the very sort of good people who think BIL is important!!! (I want not only good ideas to flow, but also that we all be vigilant in ensuring there isn’t an ever-increasing barrier to participation in that flow…)

MY PROJECTS: I know my WordPress theme is the default and lame, but if you look over in the right hand column you’ll see I’ve tried to make pages for my various open source projects. The one I’m most excited about is BlackHighlighter, which I’d like to develop further. (I’m especially interested in changing the balance of power in communications between people with little influence who send messages to those who get a lot of messages…and my goal is to employ BlackHighlighter to the communications between the electorate and Congressional representatives.)

I’M OPEN TO YOUR IDEAS AND CRITIQUE: This site is still in its formative stages, and it’s only one of my projects. But I did manage to get #1 Google rank for “hostile fork” and “hostilefork” and that makes me happy. (Because I want to STOP hostile forks, see my about page for more on my wish that open source developers push toward synergy, as if they were a company even though they are not!)

I invite you to talk with me about anything you’re working on. Leave a comment and I’ll write you back, or write me on Gmail… or follow me on Twitter.


I’d like to give thanks again to Todd, and to all the speakers and participants who gave their time the last two days. As much as I respect institutions and gatekeepers of clarity in knowledge, *someone* has to stand up and be the arXiv to the ACM… the Wikipedia to the Citizendium… the BIL to the TED!!


The Story behind the Glasses

These were a batch of 10 that had been in storage and difficult to give away, because the printer had screwed up in applying the third color (the white in the eyes):

I’d thought many times of just tossing them into the recycling, as they didn’t meet spec. But BIL has revolutionary thinkers—who share stories like beer bottles being presciently designed as interlocking bricks to build houses! How could I be throwing out these perfectly functioning highball glasses?

Once my carpool arrived in Long Beach, I ponied up the paltry (not to mention purely optional) suggested BIL donation of $20. Then I noticed there was exactly $100 left in my wallet, and ten glasses in my backpack. An idea formed:

What if I suggested that I would donate $10 to BIL for each glass that people would agree to give a safe and happy home? I mean, why not? I could use a dry-erase marker to write my website on it and it would be like a “business” <cough> card!

The idea rolled around in my mind as I listened to the speakers. I hesitated, BUT a talk regarding the 4 steps to accomplishing “virtually anything” made me realize the actual difference between “I can’t” and “I won’t”. Like Wikipedia, here was a case where I could—and more importantly should—lend financial support!

I’m very happy with the results. So thank you all!

A Modest Proposal for a Rebol Code Golf Dialect

January 8th, 2010

UPDATE: I’ve uploaded a preliminary proof-of-concept Rebmu implementation to GitHub. See http://hostilefork.com/rebmu/ for details.


StackOverflow has a tag for so-called “Code Golf”, which has the goal of attempting to perform a programming task with a program that has a minimum number of ASCII characters.

There are several loopholes:

  1. You can obviously define a language which specifically performs only the one task, and uses a single-character program to do it (e.g. if the task is to print “Hello World”, you can make a fictitious language in which the single character program h will do it)
  2. You can compress your program into a form where it is no longer the sort of thing a human can reasonably read or write (e.g. the hexadecimal representation of assembled machine code)

But a real Code Golf language needs to be Turing complete. Furthermore, I feel that you should be able to give an arbitrary challenge to a programmer they could write a working program without machine assistance. It should also be feasible to make minor adjustments to the program’s behavior without using some kind of tool. My opinion is that in this respect, Rebol has potential to be the most impressive language for Code Golf ever created.

However, Rebol has striven for a verbose English-like wording scheme. So out of the box, its ability to compete is hampered against less ideal languages that have been purposefully shortened for this purpose (like GolfScript) Yet I began to wonder if the language could be configured in a trivial way that preserved its basic character (so it still passed the language parser) but that made it more terse.

I’ve decided to call my idea “Rebmu” (REBμ) the Microsocopic Rebol Dialect for solving code golf challenges! You can find a proof-of-concept source file on GitHub which has some documentation, but this post goes into some detail as well…

http://github.com/hostilefork/Rebmu/blob/master/rebmu.r

Read the rest of this entry »


Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported