Wednesday, September 30, 2009

Assignment Progress and Bloody Braces

Well, I've finally started seriously working on Assignment 1 for OOP344, and I have noticed a few things about myself. First off, I am a much sloppier coder when I am working with someone else's code, I go through and figure out what the code does, then I proceed to roughly patch each individual problem piece by piece, and I find that by the time I have completely fixed the problem, it looks ridiculous, for example, by the time I was done fixing one of the parts in Assignment 1, I realized I had three consecutive if statements that could have easily been packed into one. There are often other redundancies as well, but since I am satisfied that it finally works, I just write a comment in caps the clean up the code, which I hopefully won't miss when I finally submit it.
Which brings me to my next problem... Braces, more accurately, brace styles. The standard, or at least what I often see from other programmers looks like this:

Function(arg, arg){
code;
if(arg){
code;
code;
}
code;
}


I HATE this style, it makes it so damn easy to misplace a brace, put the a line of code in the wrong block, and in general is a pain in the ass to read. I much prefer this method:

Function(arg, arg)
{
code;
if(arg)
{
code;
code;
}
code;
}

This looks so much better, easier to read, if you misplace a brace, it will glare out at you, you can easily see what code belongs to what function or what code belongs to what conditional or loop statement. I realize it takes up an extra line every time, but I'd easily be willing to pay that for code that isn't so infuriating to look at.

Friday, September 25, 2009

Challenge II

Here is my result for challenge 2, she works but she is ugly.

void io_display(const char *str, int row, int col, int len){
io_move(row, col);
len <=0?io_putstr(str);:{int i=0; while(len--) io_putch(str[i]?str[i++]:' ');}
return;}

In fact, I'll do one worse.

void io_display(const char *str, int row, int col, int len){
io_move(row, col);
len <=0?io_putstr(str);:{int i=0; while(len--) io_putch(str[i]?str[i++]:' ');}}

Since most compilers don't need the return to be specified. I'm not sure how she works in terms of efficiency, but this is a small piece of code IMO, and a great way to get your co-workers to hate you.

Thursday, September 17, 2009

OOP344 GetInt Challenge

Well, here she is, written from scratch and shiny as a penny, and no I don't know what I mean by that. I tried to eliminate any limitations or inefficiencies as I could, I don't think its perfect, but I tested it and it seems to run beautifully. I managed to accomplish this on my bus ride home from york to Hamilton, and subsequently haven't had anyone look it over yet, but I don't think I made any "no-no's" as Fardad calls it.

*EDIT* I noticed some mistakes in the code, I used C++ comments in C, for whatever reason I used val -= val * 2 instead of val = -val.

-------------------------------------------------------------------------------------------------


/*This GetInt fuction was written by JP Hughes (CloudScorpion)*/
/*This function first checks to see if val is negative, inserting a - in the first slot of the
strint array if it is. The function then proceeds to find the remainder of a divition of the
int val by 10, storing the value in the next slot in the array. Once complete, the function checks
if there is a - in the fist slot, if so if increases count to account for the difference, then
proceeds to reverse the values in the array so they do not appear backwards, then corrects the
count to its original value. Finally the function caps the array with a NULL byte at the end
of the string. */
void GetInt(char *strint, int val)
{
int count=0, c2 = 0; /*two counters required to keep track of the placement in for statements*/
char tmp; /*A char to hold a temporary value during the reversing process*/

if(val < 0) /*checks if the val is negative*/
{
strint[0] = '-'; /*if so, it inserts the - in the array*/
val = -val; /*inverts the value of val so it is positive*/
count ++;
c2++; /*counters are ajusted for later use*/
}
if(val > 0) /*This is used to ensure the value is not 0*/
{
for(; val > 0; count++)
{
strint[count] = val % 10 + 48; /*systematically inserts the numbers in reverse order*/
val /= 10; /* using ascii numbers, then removes the number from val*/
}
if(strint[0]=='-') count++; /*checks if the number is negative and adjusts the counter*/
for(; c2 < count/2 ; c2++)
{
tmp = strint[c2]; /*reverses the order of the numbers in the array by swapping the*/
strint[c2] = strint[count - c2 - 1]; /*numbers with the number on the other side of*/
strint[count -c2 - 1] = tmp; /* the array*/
}
if(strint[0]=='-') count--; /*corrects the counter if it was adjusted*/
}
else
{
strint[0] = '0'; /*if the value is 0, it is simply put in the first slot of the array*/
count++;
}
strint[count] = 0; /*finishes off the string with a NULL byte*/
return;
}

Tuesday, September 15, 2009

OOP344 prelim progress

All the early stuff is almost done on my end, and I got myself a group so I'm feeling pretty good, though I accidentally missed half a class and insanely missed my first quiz, but that is just my luck.

I realize we will be covering the primary platforms (VCC, Linux, ect) but I am also wondering if we might be covering some more abstract platforms such as gaming platforms or compilers for small devices like smart phones or PDAs, even briefly. This is likely more complicated that I know of and from what little I understand about this topic we would likely need some form of SDK to be able to build programs for such devices or whatnot. Eh, I'm really just thinking out loud, but more info on this would be awesome.

Tuesday, September 8, 2009

OOP344 Blog

Well, here it is, my new blog, though I hate the word blog and I don't know why blogs didn't get called something more reasonable and logical but w/e. I've always avoided blogs because I consider the act of frequent blogging to be nearly as vile as participating in social networking sites, which is, as far as I am concerned, the cancer of the internet that usually accomplishes next to nothing and is infested with juveniles frantically trying to relate to others and gather as many "friends" as possible so they can convince themselves that they aren't the awkward social outcast that they truly fear they are.

But enough of my miserable ranting, as ranting on a blog about the uselessness of social networking sites and blogs is in itself borderline hypocritical. For once owning a blog makes sense in the context of the OOP344 course, as it may actually aid in programming and communication with my classmates. The idea of open source programming is interesting, though I do not honestly think the ideal of open source programming will be overly applicable to the field I plan on entering, video game programming, as that industry has a fairly secretive and closed source environment. None the less, I am sure I will find this course absolutely brilliant and essential to becoming a more efficient and skilled programmer.

As I final note, from now on I'll keep my posts to minimal length as I can't imagine what I am writing to exquisitely interesting. I will likely not refer to this as a blog for much longer and instead call it a journal, because as far as I am concerned a blog is a sea creature from metroid, shown in the picture I have posted. (Well its a blogg but w/e)