Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Showing what programming errors look like - web site pitfall

One of the elememts of a programming training course is showing people what happens when something goes wrong. We all make "silly" coding mistakes from time to time, and these often result in a syntax error when we compile (C, C++, Java), start to run (Perl, PHP, Python, Ruby, Lua) or reach the statement with the error (Tcl). Such errors are "hard" in that the code fails, very obviously, to execute and we can't proceed with testing. But sometimes our silly coding mistakes result in source code that's syntactically correct, but does the wrong thing when run. Sometimes that's dramatically wrong - at other times, it's subtle. And showing newcomers to a programming language (perhaps newcomers to programming) the more commonly nade mistakes of this sort, how they manifest themselves, and how to be sure that you spot them all as soon as possible and certainly before you release code to users is an important element of what we do.

So - our training notes have a few examples in them which intentionally show the errors, and their effect. They're followed by an explanation of the problem, and a corrective action.

All source code examples from our notes are available on this web site; we offer a listing my module [here] and a global index [here] to help past delegates, and others find them. And every single example carries the explanatory text:

This is a sample program, class demonstration or answer from a training course. It's main purpose is to provide an after-course service to customers who have attended our public private or on site courses, but the examples are made generally available under conditions described below.

Past attendees on our training courses are welcome to use individual examples in the course of their programming, but must check the examples they use to ensure that they are suitable for their job. Remember that some of our examples show you how not to do things - check in your notes. Well House Consultants take no responsibility for the suitability of these example programs to customer's needs.


Frustratingly, that message doesn't always get read - the examples may be seen out of context. From an email last night:

  you have ($age = 21) which is an assignment statement, and as such always evaluates to true
  it should be ($age == 21) or even ($age eq "21")
  It might also be nice to add 21 to your test set so that people see that the elsif works as opposed to two different tests over 21


And those words mirror fairly well what the notes for the old "Introduction to Progamming in Perl" course used to say ...

If you use a single = sign, you're asking for the expression on the right to be evaluated and saved into the variable named on the left, and then the resultant value to be tested to see if it's true or not. That's very rarely what you mean in an if statement, and never what you mean if you're assigning a constant values. You should probably have write a double equals == which compares the numeric value of the expressions to the left and right of the == comparison and gives a true result if they're the same, and a fales result if they differ. There are other types of comparison available too, which we'll look at later ...


Our courses will ALWAYS show you what can go wrong with code - it's a necessary element of testing to make sure that delegates who leave us are ALWAYS aware of the risk of program bugs, of how they manifest themselves, of what causes them, and how to fix them, and I can't think of any better way to illustrate the point than by a demonstration of code which contains actual errors, and running it to show error messages and / or incorrect output. And we're committed to making our code available post-course to all delegates. Which leaves me with a bit of a problem - examples read out of context, and flagged as wrong and indeed very silly to have included on the web site of a company that knows what it's doing!.

I've revisited the example that shows the error, changed the title to indicate that it shows the wrong way to do it, and added extra comments in the code to that effect as well. I've done that reluctantly, as the source code example is no longer what's shown in the books, but if 1 person reported the page as having a mistake, 10 others will probably have thought so and not bothered to report it, and the view of us they've formed will have done us no good. Let's hope that people actually read the extra stuff I've added!

See for yourself ... the updated example is [here], and there's also a corrected example [here].

The suggestion of adding an extra data test case - 21 - is an excellent one, and I've done that. Thanks to my correspondent Adam for the suggestion (and indeed for his email which triggered the extra text within my example to help explain what it shows rather more thoroughly!)




P.S. - Some similar examples

Here's another example in the same course module that may also look wrong out of context. We're demonstrating the protection of \ and $ characters within double quoted strings in Perl ... there's a better (corrected?) example [here].

The VAT rate has changed from 17.5 to 15 to 17.5 to 20% ... and there are examples in past notes showing each of these rates. We have NOT gone back to exit the web site, so you'll see examples such as [here] and [here] using an old rate. For a live application, you should isolate changeable values such as the VAT rate into a configuration file, but to do so in an early course example would obfurscate the code for the newcomer ...



(written 2013-03-06)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
P204 - Perl - Conditionals and Loops
  [353] Wimbledon Neck - (2005-06-20)
  [930] -> , >= and => in Perl - (2006-11-18)
  [1191] Smart English Output - via PHP and Perl ? : operator - (2007-05-18)
  [1468] Lexical v Arithemetic testing, Bash and Perl - (2007-12-11)
  [1477] Decisions - small ones, or big ones? - (2007-12-18)
  [1607] Learning to program in Perl - (2008-04-11)
  [1696] Saying NOT in Perl, PHP, Python, Lua ... - (2008-07-04)
  [1727] Equality and looks like tests - Perl - (2008-07-29)
  [2351] Ternary operators alternatives - Perl and Lua lazy operators - (2009-08-12)
  [2550] Do not copy and paste code - there are much better ways - (2009-12-26)
  [2711] For loop - checked once, or evety time? Ruby v Perl comparison and contrast - (2010-04-07)
  [2832] Are you learning Perl? Some more examples for you! - (2010-06-27)
  [3004] Increment operators for counting - Perl, PHP, C and others - (2010-10-18)
  [3397] Does a for loop evaluate its end condition once, or on every iteration? - (2011-08-18)
  [3895] Flowchart to program - learning to program with Well House - (2012-10-14)
  [4322] Learning to Program - the conditional statement (if) - (2014-11-21)
  [4323] Learning to program - Loop statements such as while - (2014-11-22)

G504 - Well House Consultants - Writing Notes
  [4] Seeing the wood for the trees. - (2004-08-06)
  [7] Writing on a Sunday - (2004-08-08)
  [9] Study room - the Oxford train - (2004-08-10)
  [394] A year on - should we offer certified PHP courses - (2005-07-28)
  [398] Training course material - why we write our own - (2005-07-30)
  [407] Theft of training material - (2005-08-09)
  [797] Writing up new C / C++ notes. - (2006-07-09)
  [979] Empty seats, Nodding Donkeys and buses - (2006-12-11)
  [982] Notes from the white board - (2006-12-14)
  [1950] Copyright of Training Notes and Web Site - (2008-12-18)
  [2010] How long should a training module be? - (2009-01-27)
  [2192] Copy writing - allowing for the cut - (2009-05-21)
  [2414] Hello World - a good traditional start to a Java course - (2009-09-22)
  [2481] Sample code with errors in it on our web site - (2009-10-29)
  [2812] What is Perl? - (2010-06-15)
  [2828] Sharing our programs - easy. Sharing our data - harder. - (2010-06-26)
  [3152] Jargon busting - (2011-01-30)
  [4009] Clear, concise examples - Ruby classes and objects. - (2013-02-17)


Back to
What is on OUR pond?
Previous and next
or
Horse's mouth home
Forward to
Easier public transport from Melksham to Bristol Airport
Some other Articles
Special characters in HTML
The VERY basics of a web page ... and web site
Official Star ratings for hotels - still worth having?
Easier public transport from Melksham to Bristol Airport
Showing what programming errors look like - web site pitfall
What is on OUR pond?
Exception, Lambda, Generator, Slice, Dict - examples in one Python program
Really Simple Class and Inheritance example in Python
Collections in Python - list tuple dict and string.
The coffee of the Stars comes to Melksham
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4031_Sho ... tfall.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb