Becoming a free software developer, part III: Programming for the impatient
Short URL: http://fsmsh.com/1755
- 2006-09-12
-
Write a full post in response to this!
I finally began learning python. I wrote my last program in the 80s in Apple Basic, and here I am again starting to learn a new language. I can already guess what my biggest problem will be. I am incredibly impatient. How can I learn to program when I refuse to read the documentation all the way through? Will I succeed in writing a program or am I doomed to give up? No need worrying about it. I type python on the command-line, and start.
Python is already loaded on my computer, so typing python on the command line gives me the python prompt which looks like three greater than signs in a row. I decide to follow the tutorials by typing into the program and seeing what it returns.
Python.org has got a nice list of beginning tutorials on a page called Beginner’s Guide to Python. I picked a tutorial to start with called Learning to Program.
I Breezed through the first couple of pages stopping when I found the Hello World program. You aren’t really learning to program until you do Hello World. The tutorial actually said to write print 'Hello there!', but I am a traditionalist. At the prompt I wrote print 'Hello world!' and Hello world! popped up. I was on my way!
In a previous blog, I decided to write a program called period tracker(PT) that counts how many days since a person’s last menstrual period. First, I opened a text file and started to think out what logically I had to do to make the program work.
The program requires me to subtract dates from dates. It takes more than simple math to subtract September 27 from October 12. Each month has a different number of days, and the program had to know that. Would I need to construct a table so the program knew how many days were in each month? Would I have to make a calendar counting each day from January first and converting the input dates?
But then I thought, surely someone has done this before. Python has modules that do stuff like this. I just needed to find out which modules controlled these calendar functions. I asked my local python expert (read husband) and he showed me where to find the documentation for python on my computer (mine was in a file at /usr/share/doc/python2.4/html/index.html). I tried to tell him that I had found the documentation on a website but he poo pooed me for trying to use offsite documentation.
Anyway, there were two modules that looked like they might be useful for this program. Calendar for general calendar-related functions and datetime for basic date and time types. Looking through the documentation, I saw that datetime has a class object called date that can add and subtract dates. My first goal was to figure out how to import and run a module that would subtract a date from a date and return a number.
To load a module I typed import and the module name. It explained this in the calendar documentation, but how do I use the class object date? I better go back to my tutorial and see if it has anything on modules.
I searched the table of contents and found the page on functions and modules. Having skipped a few pages I found it a bit hard to read, but “Faith favors the fearless” or “hope helps the helpless” or something like that. I’m sure that there is some aphorism for blindly going where angels fear to tread. Anyway, it says that you can use the sys module to exit from python. Cool! I had not even thought about how to leave the program yet.
I skimmed through, and not finding what I was looking for I tried typing a few commands. Just guessing really. Mostly I got back error messages.
At times like these I must pause. I realize that blindly typing things into the computer can have consequences. I realize that doing such things has caused me problems in the past such as the time I reformatted my program disk by mistake. I think that I should be a good girl and calmly read the directions. But the fact is I am not a good girl. I am a nervous, flighty, distractable, impatient woman who wanted to know how to do this yesterday and who has no patience for incompetence. I want it to work, and I want it to work now. Once I have a quick and dirty outline of a program I figure that I can sculpt it into something neater.
When I read the official documentation, I’m annoyed that there aren’t more examples. Not understanding the syntax, I type in things that sound reasonable, but are wrong. Perhaps blindly guessing may not be the best way to learn how to program. Who knew?
So I slowly go back and begin reading everything that applies to python modules from the top of the page, then in my python window I type: print dir(datetime) and it returns a valid answer this time instead of an error. ['MAXYEAR', 'MINYEAR', '__doc__', '__file__', '__name__', 'date', 'datetime', 'time', 'timedelta', 'tzinfo']These are the classes under the module datetime.
Reading the documentation page, I find that the difference between one date and another is called a timedelta. This timedelta number can show me the number of days since the last menstrual period which is the first piece of data that my program will compute. Python modules can do it. I can make this work. I step back and plan the program again.
Period tracker will have a number of functions.
- I ask for a list of dates of first day of each menstrual period.
- Then I subtract them finding the timedelta between each of them.
- Next I can average all of them and find the average length of a menstrual period.
- Then I add the timedelta to the last date shown to predict the date the next period will start. I might do this to the end of the year.
- I should also do a range and compute the percent error in the calculation.
- I should have some part of the program that looks for missed periods and either inserts a period where there should have been, or removes the data so that it doesn’t mess up the average, or flashes a pregnancy alert.
OK, Maybe I’m going a bit too far on the last one. I still need to figure out how to subtract one date from another, and how to write a program in a text file. So far I have only used the command line. But at least I have started now. When you are first learning, you should take baby steps, but sometimes it’s hard not to try to run before I can walk.
Write a full post in response to this!
Similar articles
Do you like this post?
Vote for it!
Copyright information
This entry is (C) Copyright by its author, 2004-2008. Unless a different license is specified in the entry's body, the following license applies: "Verbatim copying and distribution of this entire article is permitted in any medium without royalty provided this notice is preserved and appropriate attribution information (author, original site, original URL) is included".
Biography
Rosalyn Hunter: Rosalyn Hunter has been on the internet since before the web was created. Born into a family of instructors, she has made it her life's goal to teach others about the important things in life, such as how to type
- Rosalyn Hunter's posts
- Login or register to post comments
- 23148 reads
- Printer friendly version (unavailable!)




Best voted contents
-
Special 301: FOSS users. Now we're all Communists and Criminals
Gary Richmond, 2010-03-05 -
Microsoft's Internet Driving Licence: stupid, unworkable and unenforceable
Gary Richmond, 2010-03-10 -
The Bizarre Cathedral - 69
Ryan Cartwright, 2010-03-12 -
Making a videoloop with Kino and Audacity
Terry Hancock, 2010-02-18
Buzz authors
Free Software news
- RT @ohnewein R&D in #SouthTyrol http://tinyurl.com/yz9hak8 Where others come for vacation ;-) #freesoftware #rand #android #augmentedreality
- AdvanceTo: #Softwaretool #USAcentric #Management #MyReaction #TammyFennel #Bestpractices #Freesoftware #Twitter http://tinyurl.com/o23vxr
- fanalytics: #Socialmedia #Darkside #Socialmedia #Socialinformationprocessing #Marketing #Twitter #Freesoftware http://tinyurl.com/qf79zc
- When are YOU get your copy of this AWSOME FREEsoftware? Check it out at http://bit.ly/5NJCME
- ah, nem contei, aqui é tudo linux, show de bola #freesoftware
Similar entries
Other sites
- The Top 10 Everything (Dave). The good, the bad and the ugly.
- Free Software news (Dave & Bridget). All about free software -- free as in freedom!
- Book Reviews: Illiterarty (Bridget). Book reviews, blogs, and short stories.
Hot topics - last 60 days
-
Linux performance: is Linux becoming just too slow and bloated?
Mitch Meyran, 2010-01-26 -
Web code is already open - why not make it free as well
Ryan Cartwright, 2010-01-20 -
Save "Sita Sings the Blues" from the Flash format: can you convert FLA?
Terry Hancock, 2010-01-29 -
Question Copyright's "Minute Memes" challenge copyright rhetoric
Terry Hancock, 2010-01-15 -
Special 301: FOSS users. Now we're all Communists and Criminals
Gary Richmond, 2010-03-05
Hot topics - last 21 days
Odiogo
Free Software Magazine uses Apollo, project management and CRM for its everyday activities!

Keep it up Ros, you may finish in time for your menopause...
Submitted by Anonymous visitor on Thu, 2006-09-14 06:46.
Vote!Sorry, my non-PC side got the better of me there.
I'm totally confident you can achieve all the steps you listed for your program. As long as you break everything down to simple steps (and it looks like that's what you're doing) you can't go wrong.
Sometimes it can help to do a little mini project like a proof of concept or something on the side, so jou don't get bogged down too much. I know it helps me when working on long projects. Nothing motivates like success.
Dennis
you'll get through
Submitted by Anonymous visitor on Fri, 2006-09-15 08:08.
Vote!that was something! I would have to wish you luck. I know that you will get to succeed on this. Just be patient enough and you will perfect everything .
http://www.ayboston.com
You will learn more than you think
Submitted by Anonymous visitor on Fri, 2006-09-15 13:26.
Vote!Setting yourself challenges is a great way to approach life in general. You will be amazed at what you can achieve. When you try to learn a computer language you will also learn a lot of other things. For one thing, you will gain a deeper understanding of how your computer works. It will also help you to think problems through in a logical manner.
I didn't know how to do this either, so you inspired me to experiment. Here is my result.
import datetime
k = datetime.date(2000, 3, 17)
l = datetime.date(2002, 7, 4)
print l - k
Now, how about a program that calculates how many shopping days until Christmas? Happy programming!
subracting dates
Submitted by Anonymous visitor on Fri, 2006-09-15 15:11.
Vote!You might wish to look into converting to/from Julian date. Julian date is a day numbering (starts at noon officially, because it was invented by an astronomer :), so that you don't have to worry about month boundaries...just subtract.
COMMENTS WIPED DUE TO BUG
Submitted by admin on Sat, 2006-09-16 07:31.
Vote!Unfortunately, about 13 comments on this blog entry were lost due to a bug in Drupal. The bug is currently being investigated.
If you commented on this post yesterday and cannot see your comment now, please accept out apologies and post your comment again.
Apologies also to Rosalyn.
Thanks
- FSM Staff
Kindred spirit
Submitted by Anonymous visitor on Sun, 2006-09-17 05:49.
Vote!I've never met a female programmer. I feel I'm in it alone. I'm not patient at all and hate to read documentation. So I can completely relate. I want to learn it all....Perl/CGI, PHP, C++, .Net (Lord knows why...I just know I need to keep up with everything and not just stick with unix based languages). I've gotten side tracked due to work but I'm in the position now that I may have a lot of free time on my hands during part of the week. I have a few complicated projects lined up. Nothing that I need to rush on....just projects that I want to see if I can code. Trying to decide on the best language.....thinking of perl.
Good luck with this.
Tonya
Documentation is vital
Submitted by Anonymous visitor on Tue, 2006-09-19 04:50.
Vote!I don't understand this "hate to read documentation" mentality. Documentation is vital, if only because there's no way you can hold in your head all the information you need.
For instance, while doing any Python programming, I have two pages permanently open in Firefox: the Python Library Reference and the Language Reference. From here I can hop immediately to a relevant page that explains further some point about some code I'm working on.
If you're not doing this, then chances are you're not using the language to its full effect. This can manifest itself in code written in a long-winded, roundabout fashion, that could be rephrased much more concisely. In Python, at least, the concise version is often easier to understand and easier to maintain, as well.
Lawrence D'Oliveiro
Gotta be kidding apout perl
Submitted by Anonymous visitor on Sun, 2006-09-17 21:14.
Vote!> Trying to decide on the best language.....thinking of perl.
If there was the slightest hint that you were joking I'd let that go, but as you seem to be serious about it... FOR THE LOVE OF GOD DON'T DO IT! Perl is a horrible hack that happens to work mostly ok for one-liners or throwaway little scripts, but will suck your brain and make you regret the moment you decided to write your first over-hundred-lines program. You know, programs are read far more often than written and perl has been fairly described as "write-only" language. Trust me on this, you don't want to decipher a non-trivial 3-months-old perl script, even if you wrote it (let alone someone else).
Same holds at a lesser degree with PHP since it's more or less a dumbed-down version of perl aimed at web "programming". It's the easiest to learn compared to the alternatives if you want to hack a few dynamic pages here and there but as a language is inherently flawed, ignoring all modern language design principles and leaving with you a mess of program logic entangled with presentation (html).
If you're looking for a language that keeps a healthy balance between elegance and practicality, learn Python and/or Ruby. Both languages are fairly high level and have more commonalities than differences; most people's preference to one or the other usually comes down to personal taste. Ruby seems to be somewhat more orthogonal and elegant, Python is currently faster and has much larger standard and 3rd party libraries (though the gap may shrink in the coming years after the hype around Ruby on Rails). My personal preference is python (love the clean syntax and the included batteries) but I'd certainly consider Ruby as a reasonable alternative should I decide to leave python behind sometime in the future.
Hope this helps,
George
Comments my comments?
Submitted by Rosalyn Hunter on Mon, 2006-09-18 01:15.
Vote!Is it possible that only posts by annonymous cowards are being allowed here? I watched my husband type in a comment that never appeared. Let's get that Drupal bug fixed!!
-Rosalyn
Test comment
Submitted by Tony Mobily on Mon, 2006-09-18 12:48.
Vote!Hello,
This is a test comment, to see if it appears and if it's owned my Merc!
Probably lost due to the bug
Submitted by Dave Guard on Mon, 2006-09-18 13:25.
Vote!Hi Rosalyn,
Your husband's comment was probably one of those lost when the bug did its work. Not very many people bother logging in to comment. It seems even people who have registered can't be bothered logging in before commenting even though they can win the book competition if they do. Still I'd rather anonymous comments than none at all.
I hope this improves in the coming months.
Bye
Was held for moderation
Submitted by Terry Hancock on Mon, 2006-09-18 18:26.
Vote!My post was 'held for moderation'. I'm guessing it's because it contained a lot of links (it was a list of links to Python resources).
Matter of statistics
Submitted by Anonymous visitor on Mon, 2006-09-18 02:09.
Vote!Not only do you have to calculate the average interval, but you should also calculate the standard deviation as well. This is because biology does not run on clockwork (who am I to tell you this? you know it already), so there will be some drift, and your predictions will get less and less accurate further out.
It would also help if, instead of calculating the average from all your records right back to whenever, that you only kept a "running average", going back say, a year or two at most. That way your calculation will adapt better to drift, and your prediction for a particular date in the future will become more accurate as it gets closer.
Lawrence D'Oliveiro
Python Tutorial Videos (ShowMeDo)
Submitted by Anonymous visitor on Mon, 2006-09-18 13:28.
Vote!Hi there. Over at ShowMeDo.com we have a growing set of (free) educational videos, mostly for programming (34 for Python right now with more to come). You might like Jerol's introduction to Python objects, and our IDE sets may give you a few pointers towards new development environments. My founding partner Kyran has a set on GUI programming with wxPython which might help if want to add a user-interface?
We're moving towards larger, more useful tutorial sets. John Montgomery has a set on writing Java applets, it'll be a 10-part set when finished (but using Java, so not so useful to you) - but a great example of where we're heading. We are always looking for feedback on how we could improve, if you have thoughts?
Ian Ozsvald (ian@showmedo.com - one of the founders of ShowMeDo.com)
Don't bite more than you can chew
Submitted by Seun on Mon, 2006-09-18 23:28.
Vote!Thats how it works. Just keep learning, don't bite more than you can chew or you'll want to quit. Don't hop to another language just yet, continue with python, when its time to learn something new you'll know.
To complete your current project successfully I suggest you play around with modules you intend to use in your program so you'll understand exactly how to implement them in your program.
Just be steady in your learning and you're there.
.s.I..s.ra....el
Some useful python links
Submitted by Terry Hancock on Tue, 2006-09-19 19:34.
Vote!Okay, I'm going to try posting this again:
You complain about a lack of examples in the Python documentation, and you are not the first to notice this. There are, however, a number of third party sites that attempt to fill this void. Two of the best:
Useless Python
A collection of python snippets that demonstrate various tricks and usages. As the name implies, this is not production code, just fun demos.
ActiveState Developer Network
Active State maintains a python distribution, and a website with lots of programmer distributions (I think they work with other languages too, based on the site). Anyway, there are a lot of nice "cookbook" examples on this site.
And here's yet another python tutorial, you may like:
Python as a First Programming Language for Everyone
Happy hacking!
Good luck! When you do
Submitted by jonnyb13 on Wed, 2006-11-15 06:12.
Vote!Good luck! When you do perfect this, be sure to get a load of questions from me. I am a beginner and have very little knowledge about this. When I do learn enough, I'll be looking towards you for help! Where can I learn more about htis python?