Skip navigation

Monthly Archives: June 2013

Looks life I need a new monitor…..dammit.

What I love about the Internet is the community that happens at times.  I posted my game code up for all to see and review and I received a lot of good feedback.  One guy, Bob, event went out of his way to help me understand classes and wrote up a basic structure for my style of game.

from collections import OrderedDict # for storing menus.

# adjust for Python 2 or 3
import sys
if sys.version[0] >= ‘3’:
getUserInput = input
else:
getUserInput = raw_input

def main():
place = ‘road’ # starting place
while place:
place = places[place].enter()
if not place:
ans = getUserInput(‘enter yes if you want to play another round.’)
if ans == ‘yes’:
place = ‘road’

class Choice:
def __init__(self, prompt, next, description=None):
self.prompt = prompt
self.key = prompt.partition(‘ ‘)[0].lower() # get 1st word of prompt
self.description = description
self.next = next

class Place:
defaultChoice = Choice(”, ‘cycle’, “I don’t understand that!”)
def __init__(self, name, description):
self.name = name
self.description = description
self.choices = OrderedDict()
self.menu = ”

def addChoice(self, choice):
key = choice.key
self.choices[key] = choice
self.menu += choice.prompt + ‘\n’

def enter(self):
print(self.description)
while True:
userChoice = getUserInput(self.menu[:-1]).l

ower()
choice = self.choices.get(userChoice, self.defaultChoice)
if choice.description:
print(choice.description)
if choice.next != ‘cycle’:
return choice.next# create the kingdom
places = {}place = Place(‘road’, ‘You are standing on a road. Nearby is a small house’)
place.addChoice(Choice(‘Enter the house’, ‘house’))
place.addChoice(Choice(‘South’, ‘road2’))
places[place.name] = placeplace = Place(‘road2’, ‘You are standing on a road, surrounded by howling wolves.’)
place.addChoice(Choice(‘Run for your life’, ”, ‘outrun a wolf? ha!’))
places[place.name] = placeplace = Place(‘house’, ‘You are in a small house. There are keys here. A stairway ascends.’)
place.addChoice(Choice(‘Climb the stairs’, ”, ‘your foot breaks a weak riser and you fall to your death’))
place.addChoice(Choice(‘Exit’, ‘road’, ‘you leave the house’))
places[place.name] = place

main() # start the game

I tried running it and get an immediate error.
ImportError: cannot import name OrderedDict

Well, let me do some research into this and see if it’s just a Python version issue because in the code there is something about checking version and using different routines.

Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2

Ah ha, the Docs on OrderedDict say new for version 2.7 whereas I seem to have version 2.6.  How odd though, I thought I was running 2.7 all this time.  Off to Google to find a link/how-to on this.

I found this link, which does include an automated script to do the update for you (this one compiles from source) but experience has shown that such things never turn out exact and I really can’t be bothered to spend hours and hours trying to figure out what went wrong.

Then I found this link, which suggests using a mix of Debian versions, which I know causes bad things to happen.  Besides, Debian Wheezy is now stable and as soon as I get an external HD, I’ll be backing everything up and upgrading my OS, which includes v2.7 of Python.  So, time to wait then I can try this code out.

I will say this though.  From what I read in the above code, I’m not convinced that it will be any easier to program.  It just doesn’t look/feel intuitive enough when trying to debug an error message that might come up.  That and it seems to scream ‘complication’ when the following is to be adhered to.

      The Zen of Python

    Beautiful is better than ugly.
    Explicit is better than implicit.
    Simple is better than complex.
    Complex is better than complicated.
    Flat is better than nested.
    Sparse is better than dense.
    Readability counts.
    Special cases aren't special enough to break the rules.
    Although practicality beats purity.
    Errors should never pass silently.
    Unless explicitly silenced.
    In the face of ambiguity, refuse the temptation to guess.
    There should be one-- and preferably only one --obvious way to do it.
    Although that way may not be obvious at first unless you're Dutch.
    Now is better than never.
    Although never is often better than *right* now.
    If the implementation is hard to explain, it's a bad idea.
    If the implementation is easy to explain, it may be a good idea.
    Namespaces are one honking great idea -- let's do more of those!

Side Note: Why the hell is WordPress suggesting “Pink(singer)” for this post?!?! Also, they suggest ‘transportation’ for just about every, single post I have written for any of my blogs here after the publish phase.  What gives WordPress??  You desperate for some Transportation posts??

105 different version too!

The BASICS’ Page

As I’ve been on this quest to understand the Class function in Python, which is a form of Object Orientated Programming, I am slowly finding some resistance to the ‘must use OOP!  All the time!” type of mentality.  So, being the type willing to consider many ideas before making up my own mind, I’ll be reading more on this stuff.  For now, here is some food for thought.  My quick cursory of the article seems to mean OOP is just another tool that may or may not be the best for a given coding scenario.

By , 20 Apr 2013

Introduction

The last decade has seen object oriented programming (OOP) dominate the programming world. While there is no doubt that there are benefits of OOP, some programmers question whether OOP has been overrated and ponder whether alternate styles of coding are worth pursuing. To even suggest that OOP has in some way failed to produce the quality software we all desire could in some instances cost a programmer his job, so why even ask the question?

This is getting ridiculous.  How can you even complete a course when the course gives you the equivalent of ‘bad filename or input’.  It’s an error that tells you nothing.  They need to seriously review their process for automatic code checking when you submit your code for system review.

I finally realized today that I _can_ just continue with the exercises by merely selecting the next one from the drop-down choice and not just be stuck waiting to find out why my code is supposedly ‘wrong’.  I also found out that there is a bug in that particular exercise.  Two days and suddenly realizing that my code is just fine.  Talk about screwing up new people to learning code.

So, taking this new-found knowledge with me as I go, I find this little gem of a bug.

 

So yup, moving right along.

If you are new to learning programming, you need to understand that you will be using someone else’s programming to learn programming, and it is rarely perfect.  Document the error and move on.

Seems I made a rather dumb mistake and uploaded a version of the core code that was a partial conversion for the next update, and thus failed miserably when you ran it.  I am mobile but did a quick edit and updated the link with something that at least works and doesn’t throw errors immediately.

Thanks for your patience and efforts!

 

Something that is ultimately frustrating to new learners is that when you are taking a course and you run into a problem, and the solution isn’t findable, you are stonewalled till someone replies on the forum to your post.

This is mainly a big issues when you have a course with an ‘artificial environment’, such as Code Academy and Coursera course that I have tried so far.  So this means you need be taking multiple courses just to keep learning.  No one like to say “well, worked 20mins on this today, can’t do any more so guess I’ll watch YouTube videos till someone replies.”

I bet some of you are probably thinking “Just search for the answer!” That is a perfectly normal thing to say and one that I have never failed to do.  Right now the problem is that I have a perfectly valid code that works just fine on my own system yet the CodeAcademy program keeps asking if I’m using an if/else statement in my program when clearly I am doing so as evidenced by the perfectly working response when I run the same code in my terminal.

Good think we am far from lacking resources and things to do online with such learning 🙂

 

I put the code availability on a mailing list and some suggested I use github or the like.  I had heard of it before and my basic idea of what it is, is that it’s a place where you put your software and you can update it while the updates are being tracked and you develop it.  You can also share the code with other people, who can help or maybe even take it in a different direction.  This is all I knew from what I have heard/read about.  So I decide to check it out.  I setup an account, and then I decide to read about how to use this and what it really is.

1.3 Getting Started – Git Basics

Git Basics

So, what is Git in a nutshell? This is an important section to absorb, because if you understand what Git is and the fundamentals of how it works, then using Git effectively will probably be much easier for you. As you learn Git, try to clear your mind of the things you may know about other VCSs, such as Subversion and Perforce; doing so will help you avoid subtle confusion when using the tool. Git stores and thinks about information much differently than these other systems, even though the user interface is fairly similar; understanding those differences will help prevent you from becoming confused while using it.

I want you to read that again.  Was the question answered?  Not in the least!  Hell, they went right off the damn track in the second sentence that didn’t even come CLOSE to start to answer the question.  The page does go on for another 4.5 screens (that’s with a 23″ monitor at 1680*1050).  I don’t know about you but when someone says ‘in a nutshell’ that usually means the idea is described in a sentence or two.  Not 4 1/2 pages!

There is a rampant problem out there.  It’s a self-recursive issue.  You don’t know how to do something because you don’t know how to do it.  If you know how to do it, then you know how to do it.  So, never used Git before(or anything else like it) then don’t start there, they don’t really explain things easily.

Yeah…I’m ranting.  Most  The vast majority of software documentation sucks because it is written by the people who use it and they always, and I mean always, skip over the obvious steps needed for people who have never used their product before.