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.

Tuesday, March 10, 2009

Coding right feels good.

I have been converting my 2750 project from a hellish nightmare to dreamy pie. When I first wrote things, back in assignment one, I needed a main, and server functions. Thus, main.c and serverfuncs.c were born.

How much hard coded, non-modular spaghetti I managed to throw together is ridiculous. Over the course of the next two assignments, I expanded main.c and serverfuncs.c - never by much. It was incremental, but repeated. Over and over again I added a single function, three lines here, four there.

I ended up with a 150 line main.c with a 70 line while loop full of garbage, and a 550 line serverfuncs.c, which had keyboard io, dynamic library loading, network functions, fifo functions - shit was not so cash.

My project has been to nicify this in time to use it for the database portion of the assignment, which will be due in a day or two. I am feeling very good about it at the moment.

main.c
common.h
common.c
network.h
network.c
gui.h
gui.c
dynamics.h
dynamics.c
httparse.h
httparse.c

Are now my code files. Main is about 20 lines of intensely readable code, and everything else just works marvelously at the moment. The only errors valgrind gives are dlopen() related, and there are no leaks.

What became network.c used to be a series of functions which figured out the size of a file, read the entire thing into memory as a string, then repeatedly ran a function on the string which would find replacement tags and replace them. It then wrote the string to a temporary file, which would be read back in moments later to be sent out to the client.

The repeated function - this was the worst part. "replacements" was called on the string 'data', which could be very large. "replacements" would load up the first search string, and then perform a strstr() on "data" repeatedly looking inside it. When it found the string it wanted, it would perform a lot of loopy string manipulation and pointer arithmetic, allocate a new string of a slightly altered size from data's, copy everything over, then free data. Repeatedly until it couldn't find the search string in data any more. Repeatedly until it ran out of possible search strings.

Now, when a tag is found by yacc, it gets passed into the new "replacements", which acts very similarly, but only on a small piece of text, and in a much less complicated fashion with less string and pointer manipulation. It was nice to see entire functions bite the dust as everything became streamlined.

I still have the gui/fifos to reimplement (the code is there, just needs to be brought over), and lex/yacc to fix. Then there's the database portion of the assignment. Which is due Wednesday at midnight / Thursday at 9:00 AM. In other words, I haven't got a lot of time left.

This has been a good part of an ongoing lesson in time management. Balancing the development of this code with TAing, SOCIS, Senate, and 3 other courses (now 2) has been difficult, but not impossible.

I've gained a lot of respect for proper code as opposed to messy code - and learned that even the intent of "doing things right" is meaningless when you don't know what "right" is, or adhere to it when you find out.

Challenges ahead? I'm not certain how to actually find the dynamic bits with whitespace - unless lex and yacc return every possible tag and I check it, I have no idea how I'm going to get them to find a dynamically loaded string as part of a precompiled token/rule.

Also, there's the instability that my program had during the last assignment. I don't know what caused it - and I spent a long, long time walking through valgrind traces looking. If I can make it be more stable with a <20 line delta, that's great - but it's unlikely I can do so.

Also: letter writing went well enough. Glad to have that done. And good night.

Sunday, March 1, 2009

Calculation Complete!

On a particularly inane note, after some calculation, since the beginning of this project (16 weeks, 2 days, 10 hours, 36ish minutes ago), I have (by one naive metric) averaged a bit better than a post every two days.

60 posts (now), divided into that time, comes out at about 1.9 days / post. I'd like to get that number below 1, but I'm happy with my progress and commitment. Go team Wyatt.

My notes:

5:54 PM, November 6th, 2008
6 minutes
6:00 PM, November 6th, 2008
6 hours
12:00 AM, November 7th,
2 days
12:00 AM, November 9th, 2008
16 weeks
12:00 AM, February 28th, 2009
4 hours
4:00 AM, March 1st, 2009
30 minutes
4:30 AM, March 1st, 2009

16w2d10h36m, 59 blog posts

16 * 7 + 2 + ((10 + (36 / 60)) / 60)

114.44166666666666 / 60 = 1.9073611111111111, ~1.9

I'd like to thank python for being my desktop calculator.

Saturday, February 28, 2009

New Things

I just finally replaced those awful speakers I've been dealing with for the past few years. There was an issue with the power connection on them, and my jerry-rigged solution finally gave out. I had the power cord pegged underneath my computer monitor, and a deck of magic cards holding pressure on the speaker. It was awful. Anyway, these are nothing crazy - just a $40 2.0 system that doesn't sound awful. Insignias from Future Shop.

I also bought headphones - after so foolishly leaving my other pair in a classroom, I decided I would shell out for another pair and just take much better care of them. Sennheiser PMX-60's. I like them so far, and bought the replacement warranty, so I can be abusive to them like I'd like to be. .. I also just checked them out online and found I've overpaid by about $20. Presently deciding if it's worth the hassle of returning them and waiting for shipping.

Going to work on 2750 tonight, and probably watch some Scrubs. I've got big ideas for how to reorganize that code - and I'm excited to get in there and do this right. Also bought a sweater that I swear Sheldon could wear.

A sentence I'm happy with: "Sometimes you make me feel... Like I am Worf and we are on the Starship Enterprise."

Sunday, February 22, 2009

The coding (working) groove

As a personal note:

I love working. I love coding, reading, playing music, doing math questions - counting these here as types of work - they are always intensely fun. I just also love doing nothing. If one were to count it as a type of work for the sake of argument, then you could say I get stuck in the groove of doing nothing.

This is just one more brick in the wall that reads: Whatever you have to do, you have less time to do it than you believe. Whoever you love knows it less than you think they do, and whatever you apply yourself to, you can enjoy.

I guess it's a bit of a steal from "A journey of a thousand miles starts with a single step."

-also, Microsoft Interview time is scheduled. I'll be writing about this more soon.

Saturday, February 14, 2009

Mission: Success

Slightly less time spent running about than I planned on, but I covered good ground. My trip went as follows...

Part I

Ran around the college bend,
Trotted up to the Hanlon,
Slinked onto Centennial's grounds,
Maneuvered to the top of the sled hill,
Waited.
Rollicked down the slope,
Frollicked across the field,
Sauntered onto the hidden path,
Emerged onto Edinburgh.

Part II

Trekked toward downtown,
Rocked into the great river,
Walked across Wellington,
Strolled up to Waterloo.
Music'd.
Stole past the Montessori School,
Followed under the train tracks,
Visited God in his house,
Caught a falling star.

Part III

Ate the rice of the double sun,
Stood in the royal bank with everyone,
Jogged across the square,
Wandered down baker to the bridge.
Moonrose.
Revisited old haunts,
Returned home nostalgic,
Fled long held memories,
Worshipped long known prophecies.

Part IV

Heard the oncoming future,
Zipped along the tunnel,
Descended the hilltop stairs,
Bounded onto the hundred,
Train'ed.
Found my way to Elizabeth,
Hopped a bus back downtown,
Purhased a Large Quebec (and got my own fork),
Stalked beneath the tracks.

Part V

Ate past the silent fast food stores,
Texted on the bridge,
Explored through the park,
Deposited my garbage.
Laughed.
Sang my song to a different tune,
Bolted up the hill,
Greeted an unforeseen friend,
Wound up back home.


Ah, what a way to express an adventure. I had fun. Especially the falling star, and the simultaneous train viewing. That was a good touch. We are now on the flipside: you have been caught.

Friday, February 13, 2009

Enjoy this while I can.

My feet work. I am not ill. For the first time in a half decade I simply feel good.


I am going on an adventure. New music: check. Ambitious plans: check.

Catch you on the flipside.

Tuesday, February 10, 2009

Another quick bit here-

I need to sleep better, clean more, organize more, and think less.

... That is all? I wouldn't say work more or harder, but work smarter for sure. Like that screensaver from mom's 486 back in 1992. "Don't work harder, work smarter! Do it!"

Yeah. Too late at night. Goodnight, moon.