Wednesday, February 10, 2010

How I solve problems

I'm not really sure how I solve problems. What I'm betting though, is that I could improve my problem solving ability by paying attention to the process as I bumble through it. Maybe we all could. So let's define this with a touch of formalism.

Where I'm at

I have a problem to solve. I've got an existing program, and I need to make some changes to it to enhance its functionality. I must think that this is a hard problem, because I have procrastinated significantly on it, and every time I go to start it, I get a little lost.

The sense of being lost comes from a few directions.

1) There are multiple ways to solve the problem - some easier than others, but with hard to quantify costs of later complexity and code to rework.

2) The existing program is a hacked together mess.

3) I haven't really solved this problem before.

4) There are technical tools which would help with some of my possible plans for moving forward, but I am not certain that those are necessary or, more importantly, allowed.

Knowing this, I see my primary boundaries (and solutions to them) as:

1) I have a goal and a starting point, but no real hints about a transformation function to arrive there. I need to choose what path I'll walk along.

2) The existing program may be useful later, but for now, it must be disregarded. I'll see what I can salvage once I know how I want to do this. Note: this is easy, because the existing program is only a few hundred lines of C/C++ in a single file.

3) This just makes me a little less sure of myself.

4) I do not know enough about the limitations on the assignment to make good assessments for technology to use or to not use. It is unspecified in the design document which technology I cannot use. So, I'll just assume it's allowed unless we're told it's not. Within reason.

What next?

I need to choose a path, and that would be easiest to do if I just start working along a hypothetical path. I've been bogging myself down in the different possibilities at the start and not wanting to commit - well, I'll just start thinking my way through the beginning (and then the rest) in as high level a manner as I can. This is a problem well suited to a top-down design, and I know (from up above) that I don't have to keep much of my existing work.

So the next step is: draft out some plans.

Depending on the sort of work I'm doing, I like to make plans a variety of ways. I tend to work well by expressing things verbally, which means I like to talk through them. This is why I'm writing this blog post.

Next up, I want to do some more specific planning. Like code planning. But rather than pop open vim (where I'm fast when I know what I'm doing, and slow when I don't), or MSVC++ (where I'm constantly trying to think of how to do things better), I'll work on paper, with a pen. This will make diagramming (should I want to do it) faster, and help to free me from thinking about technical details for the moment. Right now I don't want technical details; I want high level organization, overall understanding, and to work through some math. Paper is the perfect technology for this.

But what I really have to do right now, is mark some students in a class I'm TAing, for the next three and a half hours. It'll be hard to work during, but hey, it's a living. :)

Monday, January 25, 2010

School's on

Entering week 3 of Semester 6, all looks well. The lineup for this semester:

CIS 4800: Graphics
CIS 4650: Compilers
CIS 3120: Digital Systems
PHIL 2100: Critical Thinking
PHIL 2370: Introduction to Metaphysics

The rundown for each of them:

Graphics

OpenGL and its associated helper libraries - pushing and popping matrices and gluing together random bits of code to make a game called Qix(beware the audio!), which is rather fun to play.

Compilers

Constructing a compiler to translate a Pascal-ish language (termed Pish) into MIPS Assembly. We're starting with DFAs and simplistic ideas of scanning, then walking forward through parsing, generating meaningful symbol tables, abstract syntax trees, intermediate code, register allocation, and machine code generation. It should be an awesome project to get through.

Digital Systems

Starting with CMOS networks of transistors to build basic gates and then gluing gates together to make a half-adder, then a simple 8 bit ALU, then a CPU with a data and control path. We'll be seeing the theoretical and practical side of digital design - touching on minimization of boolean expressions, hazard detection and reduction, designing for cost/speed/safety, and some neat things at the end about FPGAs and such.

Critical Thinking

A lot of hullabaloo about arguments. This is a course about using, identifying, and thinking about people's arguments in day to day life and an academic context. It's really the english half of symbolic logic (conversely the math half), which I took over a year ago. I'd better do pretty damn well in it.

Intro to Metaphysics

We read a bunch of old stuff and discuss it with the prof, basically. Good reading, good discussion, all about foundational and arguably (oh so arguable!) useless topics like identity, time, the structure of universe, and the nature of reality. Some smart people in there.

Also going to put my name in the hat for B. Comp Senator again, and.. yeah. Good semester, I think. (And hope.) (And a democamp this week! I will try to go!)

Saturday, December 26, 2009

So, generic programming

This is a good read.

It's an interview with Alexander Stepanov, and contains gems like:
"I find OOP technically unsound. It attempts to decompose the world in terms of interfaces that vary on a single type. To deal with the real problems you need multisorted algebras - families of interfaces that span multiple types. I find OOP philosophically unsound. It claims that everything is an object. Even if it is true it is not very interesting - saying that everything is an object is saying nothing at all. I find OOP methodologically wrong. It starts with classes. It is as if mathematicians would start with axioms. You do not start with axioms - you start with proofs. Only when you have found a bunch of related proofs, can you come up with axioms. You end with axioms. The same thing is true in programming: you have to start with interesting algorithms. Only when you understand them well, can you come up with an interface that will let them work."
and
"You can't write a generic max() in Java that takes two arguments of some type and has a return value of that same type. Inheritance and interfaces don't help. And if they cannot implement max or swap or linear search, what chances do they have to implement really complex stuff? These are my litmus tests: if a language allows me to implement max and swap and linear search generically - then it has some potential."
Good stuff; making me think.

Thursday, December 24, 2009

Customizing the blog a bit

This layout has always been rather insistent that I have a very thin middle column in which to place my posts. It's bugged me for a long time, but I decided that messing with the CSS template was outside of my competence level and just asking for trouble.

At the same time, I've always wanted to be able to place code into the blog without it looking like some awful monster crapped out unformatted text.

Well this morning I've fixed these issues.

The latter was as easy as googling "showing code in blogspot" and then following the instructions at the top link.

Essentially, you go to the Layout section of your dashboard, click "edit HTML", find a tag "]]></b:skin>", and insert some CSS in the section above it. It adds the necessary stuff to make pre and code tags to work wonderfully.

Then it recommends running code through a converter to quickly change it to escaped-text before posting it.

I feel like (and am, really) a script kiddie but hey, I've got code showing up in my blog like so:
#include<stdio.h>
#include<stdlib.h>

int main(int argc, char *argv[])
{
int a, b, c;
int *d = NULL;

a = 5;
b = 6;
c = 7;
d = malloc(sizeof(int));
d[1] = 8;

if(argc == 2)
{
printf("What a lame example!\n");
}

free(d);
return 0;
}
which is wonderful.

Then I got to thinking "Hey, I'm a cocky CSS editing fiend, why not solve the problem of the blog's lacking width?" And I looked over the code in the layout section.

I found in there (this is likely specific to this template)
#header-wrapper {
width:660px;
margin:0 auto 10px;
border:1px solid $bordercolor;
}
#main-wrapper {
width: 410px;
float: $startSide;
word-wrap: break-word; /* fix for long text breaking sidebar float in IE */
overflow: hidden; /* fix for long non-text content breaking IE sidebar float */
}
and
#footer {
width:660px;
clear:both;
margin:0 auto;
padding-top:15px;
line-height: 1.6em;
text-transform:uppercase;
letter-spacing:.1em;
text-align: center;
}
These all have 'width' attributes that look like they're big enough to be most of the screen, and they're the only similar ones in the file. 660 pixels isn't very wide - I imagine it was set at that to work on an 800x600 screen, should one need to see my page.

Well you know what? I'm officially leaving those people in the dust.

Following some common design advice of 960 pixelwidth pages (see 960.gs), I decided to directly increase 660 to 960, and 410 (correspondingly) to 710. This widened the main post section of my blog considerably, and seems to have had no negative consequences.

Hooray for a productive blogging morning.

Python Fun

Every programmer, when learning something new, hits on that devilish quandary:

"What should I program?"

And I am a man like all others, who twiddles my thumbs and wonders "ah... if only I had something to /do/ with this language, I would really start to learn it!"

Well, I've decided to just dink around uselessly and see what comes of it. Then share.

The things we'll cover:
  • Some stupid string stuff
  • some more stupid string stuff, with numbers involved
  • then some regular old math

stupid string stuff:

First I started off playing with the string and list functions, and interchanging between them. Throughout this, I might duplicate existing functionality -- if I do, comment and tell me how to do it better! I'd love to learn.

I decied that I wanted to take a string, say "Hey man, what's up?" and insert stuff between each letter. I couldn't really find a quick way to do this, but some related things popped up.
a = "Hey man, what's up?"
a.split()
will give you ['Hey', 'man', 'what\'s', 'up?'] - and that's nice, but I want things broken down to the letter. So I wrote a function breakout:
def breakout(input):
r = []
for i in input:
r.append(i)

return r
breakout("hello") returns ['h','e','l','l','o']

then you can do a str.join() - let's wrap it into a function!
def splitByChar(instring, splitchar):
return splitchar.join(breakout(instring)
you can, through this, call splitByChar("hello", '.') and receive 'h.e.l.l.o'

ah, stupid pointless string stuff.

more stupid string stuff, with some math

Next up, I decided to play with phone numbers. I decided to break them up into their constituent digits and add them. This was (as many things in python are), an easy task.
def summit(input):
sum = 0
for i in input:
if i.isdigit():
sum += int(i)

return sum
This function runs quickly through the string and adds to the sum for every integer found.

I put in my phone number, print(summit("519-703-3336")), and received 42. Exciting!

Then I got to wondering.... I wonder how many phone numbers out there sum to 42? I wonder what the distribution is like across the rang of sums from 0 to 90? Let's write some code to find out:
def smattering(input):
arr = []
for i in range(0,9*input):
arr.append(0)

temp = []
for i in range(0,input):
temp.append('9')

upper = int(''.join(temp))
upperStr = str(upper)
for i in range(0, upper):
arr[summit(str(i))] += 1
if i % 1000000 == 0:
print(str(i) + ", " + str(upper - i) + ", " + str(i/upper))

return arr
This code makes a 90-element list, then brute-force walks from 0 to 9,999,999,999 and calculates every single sum, stopping every million steps to print out how far we are in, how far we have left, and a percentage through the path we've walked. I did some simple calculations, every printout occurs about 9 seconds apart, and 9,999 of them are required to take the calculation to completion.

This translates to about 24.9 hours. That's a pretty long calculation -- and it's kind of required; summing each of 10 digits for each of 10 billion numbers is 100 billion operations no matter what way you cut it. I've left the calculation running in a terminal (two, actually - one which will conclude and print the values to the screen and to a text file, and another in an interactive terminal in case I come up with fun things I want to do to the list off the bat) - but I'm beginning to think

some regular old math

is in order to find out the answer to this question a bit faster. The clock is ticking, and I have a day to find out. I'll update once I've thought about it a bit.

Wednesday, December 23, 2009

Hard to settle

So far I've played with Python, learned some piano, written a program to help me learn large-number multiplication, played hours of Ogre Battle 64, and watched the first season and a half of Weeds. Also seen friends, walked many kilometers, and slept gratuitously.

I think a haircut is in order. Maybe not today, maybe the 27th or so. Also, laundry.

I'm going to move forward with watching the SICL videos, and then dive into the Graphics/Language stuff. Math can happen in my spare time, as can piano. I've also got a phone-interview for an internship today. I'm not certain quite what to expect - algorithms and code-related questions, a history of myself, or just good discussion. I hope it goes well.

It's been wonderful to have time not committed - when I decide I want to do something, I can generally just go do it. I've learned a lot and I feel much happier than I have in weeks.

I also fixed up my home-server's webpage, have read a bunch of my various books (Contact, The God Particle, the latest Wheel of Time book), listened to a TON of the music I've accrued over the past semester, and played with some VMs. Installing Slackware is an interesting experience to say the least.

I'll post back in a few days (likely just post-christmas) about my progress on SICL, Python, Graphics, and my C-spitting-extensions to C.

Wednesday, December 16, 2009

A flurry of activity

Well, that's another semester past.

I have from right now until January 10th to myself, effectively. It's time to decide how to use it.

So from what I can tell, my options are:

Graphics
Languages
Base Skills
Something Complex

Graphics would be making computers do graphical things for me and also making graphics myself. Playing with Blender, with the GIMP or Photoshop, with Paint and maybe Flash, reading about colour-theory and how to paint a perdy picture. I'd also be drawing a lot, and reading about basic art stuff. And of course, playing with C/OpenGL to make the computer do cool things, and learning related math (Matrix Algebra, anyone?)

Languages would be reading about and learning Lisp and Python through the development of simple (and slightly more complicated) projects with them. I would watch the SICL videos from MIT's Open Courseware, generally get a better feel for Lisp, and I'd just do stuff with Python. I would like to implement my scope/stack/reference/object stuff for C.

Basic Skills would be math and physics and chemistry and maybe biology, just learning voraciously over the break -- very largely just improving my mathematical skill and comfort level. I would also be spending a lot of time working on music and some basic technology things, like awk/sed and being a better vimmer, using the full extent of regexp's and scripting.

Something Complex would be choosing a project - I'd spend a few days choosing, then go through a design phase and build myself something good. Something that I could sell, or at least use in my day to day life. Maybe this could include working on an Open Source project, or attacking Sam Altman's company Loopt, which just does not seem to be doing a good job with my idea.

Anyway, one of those four things. I'll have to ask myself "Where do I want to be on January 10th", and my answer could be "I want to walk up to a Piano and lay down the driving rhythm line from 'Don't Stop Me Now'.", or "I want to be able to take 4 files of similar data in disparate formats and spit them sorted into a single new file, every 10 seconds or when the file exceeds 100 lines, and I want to be able to write the thing to do it in about two minutes.", or maybe "I want to be able to spend a weekend and make a simple game, with my own pixel graphics, my own physics, my own everything, and run it on Linux or Windows.", or maybe "I want to be able to do what I want to be able to do. In Lisp. (really poor recursion joke)". Ooh, or, "I want to be able to read a Wikipedia article on a mathematical topic and not have it go over my head before I'm halfway down the page."

So, which of those sounds best? Or at least, sounds like the one I'd like first? I'm going to spend an hour or two thinking about it.

Monday, November 9, 2009

The next few weeks, schoolwise

Networking,
Modelling,
3750,
and a tiny bit of databases

Networking I've got a good mental start on. I'm agreeing so far with Martin on using a linked list - I considered just making a big buffer and filling it in using some neat math, but that...

that sounds complicated. Easy to write out, hard to set up. I'd much rather save each datagram into a list and then sort the list, and iterate through it to write it out/test whether or not stuff was received. So I'm going to set up my listeners, send out the request, read everything in, sort and check my data (likelier I'll sort as I read), rerequest what I haven't got, repeat until I've got everything, then write the data out. Cool.

Haven't looked at modelling or databases yet. Will do so soon.

Have a meeting for 3750 tomorrow, we'll have discussion and such, and get back on track.

Alright, school is looking manageable. Modelling and Networking are both due circa Nov 26th, DB will be sooner, and 3750 is ongoing and constant. This iteration (final) is due next Thursday.

Then Finals!

Tuesday, November 3, 2009

TA ta ta

Just dropping a note whilst TAing:

registered for my courses for next semester: phil: critical thinking and phil: intro to metaphysics, also cis: digital systems, cis: computer graphics, and cis: compilers -- compilers isn't actually signed up yet, I have to get waived in like everyone else.

finally got "The Great Hunt", book 2 of the Wheel of Time back. I'd left it on the plane on the return-trip from Tucson. Also bought "The Light Fantastic", because I freaking love discworld.

Started reading manga. Got through a volume of Legend of the Strongest Man: Kurosawa last night, and I've started on Trigun. Downloaded Gambling Emperor Zero v1 and 2 as well. I'm gonna check what sort of things I find at the end of the internet for marvel comics now. I knew I liked this format - just never got into it.

It's a time of great opportunity: Networking and Modelling aren't due until late November, and there's no more midterms. I have only to push forward on 3750 and get a decent (>75%) mark, same with databases, and I can safely devote some time to side projects. I'm looking at you, Awesome.

Which reminds me: What the hell, blogroll? I've posted since "Still Working". I posted last night. I posted a week or two ago. Yet you insist on showing that I haven't worked on my project in 3 months. I've remade the blogroll, deleted caches, tried alternate URLs, it always pulls up some ancient thing out of the XML. confusion++;

I'll try to figure that out

Monday, November 2, 2009

Breaking the rules

It's 2:03, and I promised myself about a week (maybe a bit more?) ago that I would absolutely fundamentally definitely start going to bed by 1 as a soft deadline, with 2 as an absolute final hard deadline. By 2 AM, I would be lying down in my bed, trying to sleep.

Well, here we are. 2:04.

I'll be done this in a few minutes, it's okay. I feel like this quarter hour of blogging is more important to me in the long run than this quarter hour of sleep. I'd rather look back and remember this, than vaguely remember a dream I may have had at some point in the future. So let's move on! (this was the title's namesake by the way, I broke my new rule. This isn't the first, the last, or even a notable time I've done so). So let's move on to a few random tidbits worth mentioning.

Justice is awesome. I've known this for a while (I started listening in earnest back in the summer), but some things, like their unreleased fabriclive mix, are just staggeringly good.

I became vegetarian after being vegan. My original reasoning for switching to being vegan was that we have no right to hold any dominion over any creature, aside from the thought of "might is right", which isn't at all universalisable, or even really that reasonable at all. A friend of mine (Andrew Stoneburgh) suggested the argument that we are actually being farmed right now. What if we're in the matrix, and being farmed, would I be cool with that or freak out about it? And after some deep consideration, I'm really okay with it. I am fine with that thought. Continuing that, if I'm okay with being farmed without my consent, it is unreasonable for me to have a problem with farming animals. I do still have problems with the way they are treated, absolutely. I just don't feel like the very notion of farming is evil or wrong, which brings use of animal products back into reasonability. Still not okay with killing them for their meat though.

Well, that's about it for now. I'm hoping that November will be a good, productive month. I don't have too much to think about scheduling wise, just TAing and assignments at the end, and 3750. Signing up for courses as soon as possible, and OSAP for next semester. Hoping to take Compilers with McCaughan, Graphics with Calvert, and some other stuff or something.

Okay, it's 2:33. Half an hour is enough. Goodnight, world.

Thursday, October 8, 2009

Robyn can't figure out the difference between dependency and composition

That's what you get for a title when I'm writing a brief post at 4:00 AM. You get a snippet of something a confused housemate says regarding UML diagrams.

-- A breakthrough! He has realized that what he is observing is aggregation. Now he has expressed a desire to know what aggregation really means. I can dig it.

I am prepared to believe that there is more good music than I can hear out there, and it's a fascinating thought. Every stone turned brings about a revelation of a musician who leaps not off the page, but out of the speakers? That was a good try at being clever, I guess.

The past week has been pretty full!

I travelled to Arizona on Tuesday, September 29th, to attend the Grace Hopper Celebration of Women in Computing, with my friends Melanie Veltman and Ali Tremblay. Ali and I flew out through Toronto and Dallas Fort Worth to Tucson, where the amazing weather embraced us (so warm! at night even!) and the intriguing desert flora crowded in to be awesome and bizarre. 20 foot cacti and strange green trees, spiny little bushes, and prickly fuzzy bulbus things were scattered about!

That was just the environment. The conference itself took place at a right-fancy hotel nestled between some tall (cactus covered!) hills on the outskirts of Tucson. Google, Microsoft, the NSA, Facebook, IBM, Intel, Amazon, Intuit, Sun, many more businesses, many universities, and thousands of attendees from all over the world at various levels of academia and industry attended the conference, to celebrate the role of women in the field of computing.

I had the educational and intriguing experience of witnessing an inverted female:male gender computer science ratio while in attendance. I was not on the receiving end of hostility or under attack, but it was at times lonely, isolating, or embarrassing. Being the only male in a room while a gender issue is discussed is bizarre - you can feel all eyes glancing at you. I may have abstractly understood what it is like to be a woman in a male dominated field before, and while I cannot claim to have a full understanding of the experience now, I am definitely more learned.

Please don't misconstrue this as me saying I in any way had a bad time! Everyone I met was intriguing and friendly. I made some new friends and we explored the conference and some of the foothill paths around the hotel. The Grace Hopper Conference is an unbelievably friendly and supportive place - everyone seemed interested to learn about one another. I feel lucky to have attended and to have met some of the most interesting people in the world - I'll definitely try to attend again.

And oh, the weather! This reminds me though, I have to post photos I took.

The time since our return has been one of the least sensible in terms of sleep schedules that I've ever held during regular class time. I have not fallen asleep before 7AM on any of Saturday (after flying in), Sunday, Monday, or Tuesday night. It's Wednesday and here I am, 5:08 AM, wrapping up my evening. I'm preparing for a whopper of a sleep at a projected 4 hours. There's quizzes tomorrow, assignments and deliverables due, friends to visit, movies to see, then friday. Which is TAing, more assignments, and then probably heading to London for Thanksgiving. Which means I won't be around home for a weekend until the 17th. I can't wait to see my family!

Final notes: I'm trying to be vegan. Have been for a week or two, it's going okay. Causes a lot of moral self-reflection. I still think meat and animal products are delicious and I wish I could eat them, but I must not due to the moral imperative.

Hopefully I start a new trend of regular blogging.