
On a "Learning to Program in xxxx" day, we start off from basics and develop (first) a very simple input - calculate - output program then (second) we extend it to include conditional code and repeated code.
During the course of the day, delegates will ask "what about xxxx" and "could it do yyyy", and the example's expanded to show that. It's also expanded to illustrate the background behind the language and how certain things work.
The final result is a fabulously useful example for delegates ... and something that looks a bit past its prime for the outside reader - rather like a straggly dead flower. However, there is still some benefit in such an example, especially for pulling back during future courses for me to highlight one feature or another - so
[here] from yesterday is such an example in C.
So what would I do if I was to 'refactor' this program?
• I would move to one statement per line (take out the illustration of how statements can be split between lines and put several per line
• I would move away from so many compile time constants and make values that would probably vary in the future into variables (a config file, perhaps)
• I would change the messages into something more prosaic and less fun
• I would turn the capacity into an integer variable
• I would turn
type into a string
• I would remove the "program completed" message which is printed in the middle of the program (it now shows how conditional code ends with everything coming back together.
• I would add some sort of counter on my final loop to see how many times I had been round it - the user is probably going to want to know how many trains he needs to take his soccer crowd without counting output lines
•
and I would certainly improve commenting!
All of our public programming courses start with an optional "learning to program in xxx" day, for delegates new to programming, or who are rusty, or who feel that formal teaching will help them. Delegates who have strong prior programming expereince in anothe language can join us instead from the second morning onwards, when we do a fast start / revision to bring the whole class together. Not only does that get the experienced newcomers running quickly without the need to sit though a slower day, but it also ensures that newcomers get a repeated thorough introduction to the vital fundamentals, and in two slighly different ways to help enforce that most critical element of the language - the basics!
Upcoming public courses -
[here]. If you have a group looking to learn to program in C, C++, Java, Lua, PHP, Ruby, Perl, Python or Tcl, please ask about private courses too. Writing in early December - I'm running a public course this week, and then I have 2 weeks of private courses in the run up to Christmas. But we're open for 2015 bookings and they'll be honoured at 2014 prices if you book by 31st December.
(written 2014-12-02)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
C202 - C and C based languages - A first practical program [888] Turning C from source to a running program - (2006-10-06)
[2580] C course inspires new teaching examples - (2010-01-16)
[3121] New year, new C Course - (2011-01-05)
[3236] C - a first program that does something useful for you - (2011-04-09)
[3590] Defining, declaring and initialising variables in C - (2012-01-24)
[4632] Remember to ask the question before you listen for the answer - (2016-01-26)
Q100 - Object Orientation and General technical topics - Learning to Progam [116] The next generation of programmer - (2004-11-13)
[1605] Learning and understanding scripting programming techniques - (2008-04-08)
[1963] Best source to learn Java (or Perl or PHP or Python) - (2008-12-28)
[1985] Learning to program as a part of your job - (2009-01-10)
[2001] I have not programmed before, and need to learn - (2009-01-19)
[2048] Learning to program in PHP, Python, Java or Lua ... - (2009-02-19)
[2092] Tracking difficult bugs, the programmer / customer relationship - (2009-03-20)
[2286] New to programming? It is natural (but needless) for you to be nervous - (2009-07-14)
[2294] Can you learn to program in 4 days? - (2009-07-16)
[2326] Learn a new programming language this summer. - (2009-08-06)
[2504] Learning to program in ... - (2009-11-15)
[2505] I almost put the bins out this morning - (2009-11-16)
[2898] Programming Standards from the start! - (2010-08-02)
[2973] Learning to program - where to start if you have never programmed before - (2010-09-28)
[3120] Learning to write good programs in C and C++ - separating out repeated code - (2011-01-04)
[3551] Some terms used in programming (Biased towards Python) - (2011-12-12)
[3895] Flowchart to program - learning to program with Well House - (2012-10-14)
[4008] Reading and checking user inputs - first lessons - Ruby - (2013-02-17)
[4318] Learning to Program - how we start to teach you at Well House Consultants - (2014-11-16)
[4322] Learning to Program - the conditional statement (if) - (2014-11-21)
[4323] Learning to program - Loop statements such as while - (2014-11-22)
[4324] Learning to program - variables and constants - (2014-11-22)
[4325] Learning to program - what are algorithms and design patterns? - (2014-11-22)
[4326] Learning to program - comments, documentation and test code - (2014-11-22)
[4575] Learning not just what a program does, but how to design it in the first place. - (2015-11-06)
C203 - C and C based languages - Conditionals and Loops [353] Wimbledon Neck - (2005-06-20)
[962] Breaking a loop - Ruby and other languages - (2006-12-03)
[1191] Smart English Output - via PHP and Perl ? : operator - (2007-05-18)
[1220] for loop - how it works (Perl, PHP, Java, C, etc) - (2007-06-06)
[1582] Ruby, C, Java and more - getting out of loops - (2008-03-19)
[1696] Saying NOT in Perl, PHP, Python, Lua ... - (2008-07-04)
[2002] New C Examples - pointers, realloc, structs and more - (2009-01-20)
[2570] Function Prototypes in C - (2010-01-11)
[3004] Increment operators for counting - Perl, PHP, C and others - (2010-10-18)
[3200] How a for loop works Java, Perl and other languages - (2011-03-12)
[3243] Breaking the running sequence - an introduction to conditional statements and loops - (2011-04-11)
[3384] Loops - a comparison of goto, while and for - (2011-08-10)
[3397] Does a for loop evaluate its end condition once, or on every iteration? - (2011-08-18)
Some other Articles
Segmentation Fault, Segmentation Violation, Bus Error, Stack Smashing Command line and file handling in CSimple C structs - building up to full, dynamic examplePassing arrays into functions in CLearning to program sample program - past its prime, but still usefulTest Driven Development - a first example of principle in CFlexible public courses - residential or commuting, programming newcomer or experienced, C or C++Splitting out code into name blocks for clarity and reusabilityMisty Melksham MorningFirst Java Application - calculating the weight of a tablecloth