Hobby Programming

Posted on February 17, 2007
Filed Under Programming, Saturday Satire |

As some readers may know, I have taken up Python programming as a hobby. I was once a world champion underwater Logo programmer, but I thought it would be nice to move on to a slightly more modern language. Before I go on, I should mention that I was once heralded as the Muten-Roshi of Logo programming due to my incredible skill with "turtle graphics" (a very useful skill).

If you have followed along so far and have no questions, please skip the rest of my post and visit this site.

For the rest of us, here is the class I just invented in my pre-entry level attempt at Python:

class Ship(object):
    'contains the attributes of the player or npc ship'
    def _init_(self, captain, hullLife, crewNumber, crewEquipment, crewArmor, crewMoral, hullType, shield, weapon, core, lifeSupport, gravity, navigation, drive, boost, inertia, reverseThrust, stability):
        self.captain = captain         # ship and captain
        self.hullLife = hullLife
        self.crewNumber = crewNumber   # crew data
        self.crewEquipment = crewEquipment
        self.crewArmor = crewArmor
        self.crewMoral = crewMoral
        self.hullType = hullType       #defesive/offensive systems
        self.shield = shield
        self.weapon = weapon
        self.core = core               # support systems
        self.lifeSupport = lifeSupport
        self.gravity = gravity
        self.navigation = navigation
        self.drive = drive             # inertia systems
        self.inertia = inertia
        self.reverseThrust = reverseThrust
        self.stability = stability
    def captainUpdate(self, newCaptain):
        self.captain = newCaptain
    def hullLifeUpdate(self, newHullLife):
        self.hullLife = newhullLife
    def crewNumberUpdate(self, newCrewNumber):
        self.crewNumber = newCrewNumber
    def crewStatUpdate(self, newCrewEquipment, newCrewArmor, newCrewMoral):
        self.crewEquipment = newCrewEquipment
        self.crewArmor = newCrewArmor
        self.crewMoral = newCrewMoral
    def attackDefenseUpdate(self, newHullType, newShield, newWeapon):
        self.hullType = newHullType
        self.shield = newShield
        self.weapon = newWeapon
    def supportUpdate(self, newCore, newLifeSupport, newGravity, newNavigation):
        self.core = newCore
        self.lifeSuport = newLifeSupport
        self.gravity = newGravity
        self.navigation = newNavigation
    def inertiaUpdate(self, newDrive, newInertia, newReverseThrust, newStability):
        self.drive = newDrive
        self.inertia = newInertia
        self.ReverseThrust = newReverseThrust
        self.stability = newStability

As you can see, the intent is to build a basic object for a space game. This particular space game may have typographical errors and misconceptions at this point, and was inspired by spaghetti and cheese (this is what happens when there is not enough ravioli in the house), but these are not the most relevant issues.

Since I mentioned Logo programming, which is actually (apparently) useful as a tool for constructivist learning, I thought I would expose my own (mis)conceptions to the world and hope that the experience of other programmers might accelerate my construction of Python "knowledge."

My own first issue with this class is that there are too many values being passed into the constructor at instantiation. At least I think so. Is this normal, or should I be organizing my classes differently? Second, I defaulted to breaking my methods into chunks. I have no idea, yet, how well this will work when I start calling these methods. For example, if the crew's equipment and armor are upgraded, but the crew moral is unchanged, I will still have to "update" all three because of the way I structured my class, will I not? Early in the program, this would not be much of an issue, but later is seems like it could make a difference. If I decided to rewrite after defining a kabillion classes and a quasitrillion functions, I think I would have issues.

It would be interesting to see what Gregory thinks about this. Not everyone knows this, but Gregory is one of the better Python programmers in existence. I know this because I am a career idea map and have worked with him professionally. If you want to see real programming, work with Gregory and be amazed; or, if that is not an option, I recommend reading his weblog.

Comments

4 Responses to “Hobby Programming”

  1. Janissary on February 17th, 2007 2:48 am

    WHAT IS PYTHON?

    -JAN

  2. Rab on February 17th, 2007 2:55 am

    see http://www.python.org
    They can explain it better than I can.

  3. Greg on February 17th, 2007 9:27 am

    Wow, that *is* quite a constructor.

    You don’t really need to allow all your class’s fields to be populated via the constructor. All of those fields/properties/whatever they are called are public as python doesn’t really have a concept of private variables.

    You can precede methods and fields with underscores to “hide” them, and it is a good practice to do so when you intend them to be hidden for encapsulation reasons. However if you haven’t, then you can access them via the dot operator from your class instance.

    It may be ideal for a game to just allow for that. Later on, you can wrap them in properties as you find things you need to do when they are set. If you name the property the same as the field and just rename the field, that will keep your class’s interface intact and limit the amount of code you need to change.

  4. Greg’s Adventures - On programming for fun. on February 17th, 2007 9:49 am

    [...] am I bringing this up? One reason is due to watching my friend Rab having fun with Python. He’s having fun. He’s doing it for fun, and thus he’s having fun. Doesn’t [...]

Leave a Reply

You must be logged in to post a comment.

  • starting your head on fire

    Delivers oxygen to your brain faster than all other methods! Proven in double blind placebo controlled studies.

  • Places to Go

  • Blogroll

    • Cato @ Liberty - Cato is a libertarian research foundation. If you wish to stay informed on public policy, you can not ignore the Cato blog. Pay them a visit.
    • Greg Lincoln
    • InQuest Journal - Blog and podcast of Nancy Beverly and Jade Macalla. All things unexplained and inexplicable will be addressed here.
    • Modo Vernant Omnia - Tampa local with many topics of interest to my readers. As you might imagine, I could not resist blogrolling a site that has tags as diverse as: economy (with views similar), spinning (as in wool), ancient Greek stuff, and occult.
    • Nassim Nicholas Taleb - Fooled by Randomness - The Economist turned me on to Mr. Taleb, a trader turned philoisopher (as described by Forbes). His writing and his thinking are quite interesting, and certainly more worthwhile than anything you will find here.
    • Ouralexander.org - Site discussing informed consent in pediatric medicine, by a family that experienced the worst possible tragedy.
    • RiskProf - An Insurance Blog - A truly marvelous blog. I know risk & insurance are less interesting to most of you than organizing your sock drawer, but this is excellent writing. Besides, if you understand insurance you have the right to complain about it.
    • Schneier on Security - This will be your favorite security blog. Bruce Schneier exposes “security theatre” and proposes realistic problems and solutions. Stay up to date on security policy and IT risk management with CRYPTOGRAM, his email newsletter.
    • The Goodly Mr. Plotkin - My excellent friend Richard Plotkin. Read his musings and insights, or wander through the social network of MySpace users. Several of his blog-friends are people I went to school or knew other ways… I wonder if they will Google me and say ‘hi.’
    • Worlds Healthiest Foods - I love this website. It is all about the nutritional value of foods that are considered ‘healthy,’ with tons of sources cited.