Tuesday, August 25, 2009

I'm just gonna leave this here

theme="Whatever magic does not already exist in nature, we have the power and perhaps, the duty, to create."


for later, when I need it

Saturday, August 8, 2009

Typing can be enjoyable for the sake of it

Every once in a while, when you get into a certain state of mind, you can easily think of what you want your hands to say and just let them fly acrsoss the keyboard for an extended period of time, as I"m doing now. It's cathartic, really, kind of a close bond between you and the machine. You just think, type, and try to take the buffer out between. Don't even look at it - at the keys, at the sctreen, just close your eyes and let the text spread out beneath you like a warm safe cloud.

I find I run upon that certain style of thought very early in the morning, when I still exist in a day the rest of the world has moved successfully on from. Living in the past, you might say, puts me into a place where my disjoint mind can do naught but want to spout out a never ending stream of ASCII love.

There are those who would take the humorous phrase, "diarrhea of the mouth", and appropriate it for the keyboard: "diarrhea of the hands" or "fingers", which manages to at once make the whole thing less and more disgusting. I am not one of those - but I am aware of them.

I saw 500 Days of Summer last night, and Terminator: Salvation (on to very different factors of form) and enjoyed them both (Terminator less). Perhaps the Esquire Article is onto something with a supposition that Sam Worthington is a very great actor (he fared well in McG's slaughterhouse, as did Anton Yelchin. But Yelchin always fares well.), and I was positively enthralled by the work of Marc Webb, Zooey Deschanel, and Joseph Gordon-Levitt. Funny and watchable, well composed and endearing. I've also finally called Joseph Gordon-Levitt by his actual name, instead of (I confess!), "that kid from 3rd rock" or "angels in the outfield". I'll strive to keep it up.

So I'm done now, my hands are no longer playing that mad piano game with my mind and are starting to make typos at merely par. Good morning to you, good night to me, and let's all have a chat sometime later this weekend yes?

Indeed.

gosh italics are fun

Thursday, August 6, 2009

Whose laughing now, Twitter?

Looks like I found an alternate means of getting my stupid messages out to the world just in time, before the great Twitter Outage of ot-nine.

Working hard, will write some fiction tonight. Summer party tomorrow, went to a tech talk earlier about Testing. Got a rad book, "How We Test Software At Microsoft". The book was written by the three guys who did the presentation, Alan Page, Ken Johnston, and Bj Rollison, who all do neat Test related stuff here at Microsoft. They're pretty cool guys, and illuminated the topic magnificently.

For those who don't know, Microsoft splits production up into "feature crews" which have a Developer (Software Development Engineer), a Tester (Software Development Engineer in Test), and a Spec-Writer / Designer (Program Manager), who all work together to create a feature. This sounds like perhaps a trivial detail from the outside, but it is a vital piece of our culture. Think about how important testing software is, and how undervalued it tends to be. Now think about your perception of "oh god microsoft makes bad products lawl". Now think about the fact that they employ about 11,000 SDEs (devs) in total, and about 9,000 SDETs (tests) - there is nearly a tester for every dev in the company. Testing is taken very seriously here, and regardless of any person's opinions on Microsoft or its products, this is a powerful defense against bugs and defects. Complex software will have issues - and our testers (in conjunction with devs, and pms) do a damn fine job of sorting those out and producing high quality software.

Anyway, that's enough of my hivemindspeak for now. Tried ModPlug recently; where has it been all my life?!

Tuesday, August 4, 2009

That Ambiguous Comma Operator

The ternary 'conditional operator' can be tricky sometimes. If you've ever looked at The 12 Bugs of Christmas and been frightened off by them, congratulations on your humanity.

After seeing a particularly confusing piece of code today, of the form:

func(a, b ? c : d, e);

I began to ponder whether func takes 2 parameters or 3, and what the heck I should assume is going on here. It also (for the first time) made the question of "does d,e evaluate to d, or to e" relevant to me. So I wrote a test program!

First, let's see what happens when we use commas in the ternary operator during assignment:

num = v0 ? v1 : v2, v3; /* each of these is a variable vn where n is the value */

This evaluates to 2. Simple enough-- let's move on.

What happens within 'func(0 ? 1 : 2, 3);'?

This case ends up being straight forward. The comma is taken as part of the parameter list and not as part of the conditional operator, regardless of the prototype of the function. I'd started out thinking that whatever works might be done (if func took 2 ints, this would treat the comma as a parameter separator, and if func took 1 int, it would be a comma operator inside the condition) - but it does not. The comma is strictly for parameters in this case. Neat - but I'm still curious what would happen to it used as a comma operator here. Should be the same as before, right? Let's force it to be used in the conditional and find out.

func((0 ? 1 : 2, 3), -1);

This is the function I tested. The second parameter (-1) isn't necessary for anything other than illustration, and so that I didn't have to rewrite the function. 'func' Now becomes meaningful to specify: it takes two ints and prints them out in the left-right order in which they were received. This is the output:

one, two: 3, -1

Wait a minute. This time, the comma operator's right hand value was treated as the expression's value! That's not the same as before! What the heck? Let's check the spec*:

3.3.17 Comma operator

Syntax

expression:
assignment-expression
expression , assignment-expression

Semantics

The left operand of a comma operator is evaluated as a void
expression; there is a sequence point after its evaluation. Then the
right operand is evaluated; the result has its type and value./43/

Example

As indicated by the syntax, in contexts where a comma is a
punctuator (in lists of arguments to functions and lists of
initializers) the comma operator as described in this section cannot
appear. On the other hand, it can be used within a parenthesized
expression or within the second expression of a conditional operator
in such contexts. In the function call

f(a, (t=3, t+2), c)

the function has three arguments, the second of which has the value 5.

Forward references: initialization ($3.5.7).
My own emphasis is added in the 'Semantics' paragraph. Clearly the right-hand operand is the one which should normally provide the value. What happened in the assignment then, which caused this to be reversed?

To the best of my knowledge, the answer is actually inside of the 'Example' paragraph. I quote,
in contexts where a comma is a
punctuator (in lists of arguments to functions and lists of
initializers) the comma operator as described in this section cannot
appear.
So the issue is that this comma is (again) not treated as part of the ternary conditional operator, but treated as an illegal comma operator floating around on the far right of an initialization. My guess is that this
If a ``shall'' or ``shall not'' requirement that appears outside of
a constraint is violated, the behavior is undefined.

(from the definition of 'undefined behaviour')
is what is allowing the situation to occur. A comma can not be placed within an initialization list and be treated as a comma operator. So if you force that to happen... whatever the heck the comma and the people who wrote the compiler have agreed on could occur.

In this particular case, it looks like what they've done (this is in gcc) is just ignore the comma and everything after it until the semicolon. Thus in the line

num = v0 ? v1 : v2, v3;

num evaluates to 2, and the ", v3" just doesn't enter the picture. Giving us our unexpected result.

Crazy cool.



* You may have noticed that this is not coming from an official ANSI or ISO standards site, and if you're particularly astute, you may have also noticed that this is merely a draft of the C90 spec. That's because I found it first and feel like C90 is good enough. But I checked the C99 spec as well (again just a draft), and the only modification is an explicit statement that a comma operator does not yield an lvalue. I only looked at drafts because ISO and ANSI are mean and don't like people to see specifications without paying money. I'm cheap, so our learning is lessened. :P

** What? a double star? That's right folks, you get a bonus note! During the writing of this post, I realized that my test program was being rather silly. I made several variables 'v0', 'v1', etc to hold simple int values. It was only while writing that I recognized I could have simply used '0', '1', etc, and that this would be less confusing to read about. I originally wrote

num = 0 ? 1 : 2, 3;

As the first expression, which now uses the variables. I didn't think this could possibly cause any difference - and was wrong! When writing a second program later to do some different tests, I used my newfound sensibility and bypassed the creation of variables. I was given the following unfriendly error code:

newterntest.c:5: error: syntax error before numeric constant

It took just a moment to recognize that this was because of the comma! The comma is (as we've discussed) unexpected and not allowed here, but it looks like this case is obviously wrong enough to the compiler writers that they generate a syntax error before the integer '3'. So whileThis on its own isn't too crazy - the crazy part is that

num = v0 ? v1 : v2, v3;

doesn't even throw a warning under -Wall -pedantic (with or without -ansi as well), while the literal integer actually causes a syntax error. Every other parenthesized use of comma operators in this situation gives at least a "warning: left-hand operand of comma expression has no effect", but our code draws a blank!

General weirdness.

edit: removed the pre/pre tags from the blockquotes. They were there by default, made the quoted text appear in a plaintext-ish font and I felt they added to the post. But in the published version, they rendered underneath the righthand column. So they're gone.

Sunday, August 2, 2009

I'm back.

I didn't forget about this (these) blog(s). I didn't stop posting for a lack of things to post. I didn't lose motivation or stop for any of the reasons I have before. This time I had something else to do that was more important - and I wasn't going to let myself spend time here when I knew I should be there. I procrastinated on it for a long time regardless, and I've finally moved past.

So let's get these cogs a cranking.

In the time I've been gone, I've flown on my first airplane, stayed in a hotel alone for the first time, climbed my first mountain, played my first game of whirlyball, had a highway cleared so my friends and I could ride along it, bought a second laptop, started an internship at Microsoft, and spent my first whole month (well, more than) in a different country. It's been quite a journey - and it's not nearly over yet.

I can't wait to be back in Canada, but I've got the rest of my work left to do, my first time skydiving to have, PAX to attend, and who knows what else? I miss my friends and family, but I'm having a good time here and I've made some new connections too. I can't say much about my work other than that I'm working on Office, and I'm coding a small feature that'll be present in a few of the major apps in Office 2010.

I've been learning lisp, listening to a lot of music, learning some foundational graphic design, and working a bit on Awesome. I'll update again soon; I have things I can show - pictures and personal work and such.

Catch you on the flipside.