Q: Where do I start when writing a program?
A: Start off by thinking about what you want to achieve, and what inputs you have available to you. In other words, look at what the customer provided and what the customer wants to get (yes, you may be your own customer!). If it's too much to think through in one step, split it into a series of stories, and write each stage in turn, frequently refactoring as you go.
As well as the inputs and outputs, think about the major structures you'll use internally within your program - your collection variables (arrays, lists, hashes, dictionaries, tuples ... whatever is available in the language of your choice), and think what is likely to be common code which will allow you to (re)use you own code later, or to call in someone else's stuff from day 1.
When you've given this some thought and you're moving to a coding stage,
write your comments first - they will in essence form a textual flowchart, help you identify pitfalls early, and avoid you coding up too many blind alleys.
On today's
Perl Course, I went through these principles, in order to start answering the question "what operating system(s) do people who use my website run?" .... you can see my initial (all comments!) design
here. I then went on to add some code - a first test or - 'spike' solution - see
here. The results of running that program on a recent log file from our own site:
Dorothy-2:perl grahamellis$ perl whatos
There are 80520 good records and 34 mucked up ones
unknown ... 49716
Googlebot ... 9574
Windows NT 5\.1 ... 21230
Dorothy-2:perl grahamellis$
which is very short .. but an excellent demonstration of principle.
Although I am talking about Perl in this note, you'll find that what I've suggested is equally suitable for use in Python, PHP, Ruby, Lua ... indeed, in all the other languages we teach. If what I've written is of interest to you, have a look at our "learning to program in ...." courses, where an extra day on the front of the main course helps newcomers to programming. But if it's stuff you're happy with, start on our ".... programming" courses which assume prior knowledge of things like this
(written 2009-06-11, updated 2009-06-12)
Associated topics are indexed under
G999 - Well House Consultants - Keynote [3164] Brown - or Mrs Sally Brown, accountant from Whitstable? - (2011-02-10)
[2537] Faster network, but not faster browsing until ... - (2009-12-14)
[2483] Clustering on Tomcat - (2009-10-30)
[2384] Looking ahead to the Autumn season of training and accommodation - (2009-08-28)
[2326] Learn a new programming language this summer. - (2009-08-06)
[2216] Past Delegate Offer - Summer Holiday / Weekend Break - (2009-06-03)
[2144] Looking for a career change - Physician to Web Site Designer - (2009-04-28)
[1975] Well House Manor Hotel - on plan for 2009 business guests - (2009-01-03)
[1955] How to avoid duplicating web page maintainance - (2008-12-20)
[1929] 2009 - Hotel, Meeting, Training Course prices - (2008-12-07)
[1859] Wiltshire at dawn - the tourist trail - (2008-10-29)
[1857] November and December Public Course Schedule - (2008-10-27)
[1773] The Longest Possible Day - (2008-08-26)
[1748] Hotel room prices - Melksham, Wiltshire - (2008-08-11)
[1676] A warm welcome for visitors from the USA - (2008-06-14)
[1615] PHP training courses every month - (2008-04-18)
[1555] Advanced Python, Perl, PHP and Tcl training courses / classes - (2008-02-25)
[1492] Well House Consultants Training and Hotel - 2008 news - (2008-01-01)
[1481] The Christmas Letter - (2007-12-22)
[1414] What we teach - expained for the non-technical - (2007-10-28)
[1319] Customer feedback - lifeblood of a business - (2007-08-25)
[1317] 2008 course schedule - Perl, Python, PHP, Linux, Java Deployment, Ruby and more - (2007-08-23)
[1245] Ensuring that our tutor answers YOUR questions - (2007-06-25)
[1161] A contrast in room rates and facilities - (2007-04-25)
[1079] Wilts and Berks - two conference / training rooms in Melksham - (2007-02-14)
[929] Presenting Melksham - for a weekend away in Wiltshire - (2006-11-17)
[898] Courses at Well House Manor - (2006-10-19)
[890] Open - (2006-10-09)
[845] Course scheduling and Geekmas - are they traditions yet? - (2006-08-26)
[774] Bed and Breakfast, or Hotel? - (2006-06-22)
[695] In the hospitality business - (2006-04-23)
[626] Not just a pretty face to answer the phone. - (2006-02-26)
[549] 2005 - Come as a student, leave as a friend - (2005-12-31)
[464] Technical Loneliness - (2005-10-14)
[452] Is enough enough? - (2005-09-27)
[428] Swindon - Chippenham - Melksham - Trowbridge - Westbury train service - (2005-08-29)
[419] Most popular courses - (2005-08-19)
[360] Spring turns to Summer - (2005-06-26)
[295] Pricing strategy - simple and fair - (2005-04-29)
[225] 10 years and counting - (2005-02-23)
[164] Well House Consultants - review of 2004 - (2004-12-31)
P050 - Perl - General [3407] Perl - a quick reminder and revision. Test yourself! - (2011-08-26)
[3332] DNA to Amino Acid - a sample Perl script - (2011-06-24)
[3322] How much has Perl (and other languages) changed? - (2011-06-10)
[3093] How many toilet rolls - hotel inventory and useage - (2010-12-18)
[2971] Should the public sector compete with businesses? and other deep questions - (2010-09-26)
[2825] Perl course - is it tailored to Linux, or Microsoft Windows? - (2010-06-25)
[2783] The Perl Survey - (2010-05-27)
[2736] Perl Course FAQ - (2010-04-23)
[2504] Learning to program in ... - (2009-11-15)
[2374] Lead characters on Perl variable names - (2009-08-24)
[2242] So what is this thing called Perl that I keep harping on about? - (2009-06-15)
[1897] Keeping on an even keel - (2008-11-21)
[1750] Glorious (?) 12th August - what a Pe(a)rl! - (2008-08-12)
[743] How to debug a Perl program - (2006-06-04)
[400] New in the shops - (2005-08-01)
[116] The next generation of programmer - (2004-11-13)
Q101 - Object Orientation and General technical topics - Programming Principles [3551] Some terms used in programming (Biased towards Python) - (2011-12-12)
[3548] Dark mornings, dog update, and Python and Lua courses before Christmas - (2011-12-10)
[3542] What order are operations performed in, in a Perl expression? - (2011-12-07)
[3456] Stepping stones - early coding, and writing re-usable code quickly - (2011-09-24)
[3026] Coding efficiency - do not repeat yourself! - (2010-11-02)
[2964] An introduction to file handling in programs - buffering, standard in and out, and file handles - (2010-09-21)
[2915] Looking up a value by key - associative arrays / Hashes / Dictionaries - (2010-08-11)
[2878] Program for reliability and efficiency - do not duplicate, but rather share and re-use - (2010-07-19)
[2769] Easy - but for whom? - (2010-05-18)
[2737] Improving your function calls (APIs) - General and PHP - (2010-04-24)
[2586] And and Or illustrated by locks - (2010-01-17)
[2550] Do not copy and paste code - there are much better ways - (2009-12-26)
[2510] The music of the stock market - (2009-11-22)
[2415] Variable names like i and j - why? - (2009-09-22)
[2327] Planning! - (2009-08-08)
[2310] Learning to write high quality code in Lua - (2009-07-30)
[2022] Pre and post increment - the ++ operator - (2009-02-03)
[2001] I have not programmed before, and need to learn - (2009-01-19)
Some other Articles
Why sendmail one way, and pop3 the other?What is CGI.pm / A dozen new examplesRunning a piece of code is like drinking a pint of beerDo not re-invent the wheel - use a Perl moduleWhere do I start when writing a program?Learning PHP, Ruby, Lua and Python - upcoming coursesRevision / Summary of lists - PerlHow important is a front page ranking on a search engine?Trowbridge - a missed opportunity? Melksham - into the breach?CSS Style Diagrams - working out where attributes come from