Saturday, 24 January 2015

Code Note

-D24, M01, Y15-
Hello and welcome back to another exciting edition of this blog. This time around, I shall be stepping away from mathematical expressions and reasoning to focus upon programming itself. Over the past week or so, I have read a number of articles and blogs concerning the necessity of having such a blog.

From my perspective, a blog--as in, an internet-based journal of sorts--is not necessary; rather, a way of keeping track of one's programming endeavors is. Last year, when I first began to program seriously, I kept track of my problems via 'ye olde and relyable' pencil and paper. It would consist of written out code, which I would implement in a programming environment (known as Wing), in addition to crossed out lines of code, comments scrawled around it and within it, and various diagrams and sketches depicting both what I desired the code to do and my varying reactions as the code itself failed and/or succeeded.
Especially important was writing down exactly what caused the error(s)--less important were the excess words I employed to berate myself in the cases where I had merely misspelt code or forgotten some key characteristic of, say, a dictionary.
In doing this last semester, I assured that I would not make the same mistakes again, either from memory, or by simply referencing my previous writings.

In sum, documentation is key to effective coding. Now, it is important to note, as Mr. Mark Dalrymple did, that, when coding for clients, a computer scientist should transfer such documentation to a secure file of some sort in the event that the terms and conditions of the job require it to be sent to the client.

Until then, I shall document the bulk of my bugs and solutions on paper...and post the most notable of them on this blog. Last week, I came across a notable bug that angered me quite a bit, so here it is:
--------------------------------------------------------------------------------------------------------------------------
Problem: when initiating a class with only one argument (self) along with an instance variable creating a dictionary, Python declared that said instance variable did not exist. An AttributeError.

Solving-Process:
After indignantly shaking my head at the object's failure, I call it a few more times to be certain. Indeed, something is wrong. Try adding the instance variable as an argument? Of course that works, but not the way the object ought to. I need the object to initiate it's own empty dictionary, empty list, etc., without an additional argument!
ARGH.
All my notes say I am right. What is this?
Finally decide to speak to a fellow computer science student also taking this course, I shall call him T. T's code worked correctly and after a single comparison, I was certain that my code was structured in a nearly identical way. There are only so many ways to write an __init__ method for an object at this point in time. I shall call my code one more time.
FIX: I forgot the ending parentheses for the object consistently until this point.
This is beyond embarrassing. Never again. At least it is solved.
--------------------------------------------------------------------------------------------------------------------------
Thanks for reading, I hope I elicited a chuckle of some sort at my own expense.

No comments:

Post a Comment