General Comments and Observations

On this page I describe my approach to programming, some of the logic of the ar package, and some general observations and insights about my Python experiences that I am hopeful will assist the reader bypass some of the issues I initially found confusing.

For me, programming is easy, writing correct mathematical algorithms is difficult, and infrastructure is hard. Whatever your disposition, don't let struggling with the harder stuff make you believe you are failing at the easier stuff.

The AR package:

For those who are curious about the naming convention, the name for the top-level package, ar, is an acronym derived from my gaming pseudonym, Arcane Rhino. The original package name was my initials, "js", but this was confusing to some who thought it was a repository for javascript.

GUI:

I chose Tcl/Tk for my GUI uses because it ships with Python and is cross platform. One serious drawback, however, is it relies on the local implementation of Tcl (Tool Command Language) and the Tk graphical toolkit, which often doesn't play very nice with OS X.

Naming Conventions in the AR Package:

In an effort to maintain readable code, I try to follow the PEP 8, Style Guide for Python Code, as closely as possible. That said, for assignments that exist for the duration of only a few lines of code or are otherwise exceptionally local in scope, I do utilize the hated lowerThenTitleCase nomenclature. I actually dislike the look but code readability trumps aesthetics in this case.

Insights for Newbies:

Class Considerations:

Generally, either a class or a function could be written to accomplished any particular task. The big question is which is the correct object (most pythonic) for the task at hand. While the answer to this question is sometimes more art than science, as a general guideline, if you wish to maintain some state or objects across tasks, or instantiate multiple instances of an object, a class is more appropriate. If you are needing to perform a single task, usually on passed variables, a function is more appropriate.

Nomenclature

An assignment is the syntax of assigning a value to a variable (e.g. x = 1). The terms assignment and variable are often used interchangeably, however, so don't let it throw you when they are.

A class method is a function that exists within the scope of a class.

A class attribute can be either a class method or a class assignment. (e.g. For the examples self.variable and self.method, both variable and method are attributes of self, which is the standardized "self" name of an instantiated class: See below.)

Why use self.assignment rather than ClassName.assignment

In brief: If a hypothetical class named ClassName has an attribute named example_assignment, changes made to ClassName.example_assignment will change ClassName.example_assignment and all instances of example_assignment. Changes made to self.example_assignment, however, will only change that instance of self.example_assignment.

See the following link at stackoverflow.com for a simple demonstration: python-why-use-self-in-a-class

While statements:

It is important to note that evaluation of the while condition occurs at the end of each full loop. This is true even if the condition to exit the while statement occurs prior to the last line. See while_statement_examples for a couple of demonstrative examples.

Multiple assignments on a single line:

When reasonable, I prefer stylistically to have multiple assignments on a single line. Care must be take when doing so, however, because unlike some other languages, a,b = [],[] will have a very different result than a = b = [].
See multiple_assignments_single_line_example for a demonstration.