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))
KISS - one action per statement please - Perl

"Nice program, Bill - but the output is a bit verbose. Can you take out some print statements". So said one of my delegates' bosses this week, late in the day just before a new application went live. Alas ... the application fell over just because the print had been removed.

In Perl - that was the language in use - you can assign variables within your print statement, and that's what had been done. So taking out the print caused it to fall over. What you can do and what you should do are two different things, and it requires a thoughtful programmer and an excellent manager to the make the best of coding, apply standards and end up with a maintainable program that fits the user's requirement well.

Sample code - what NOT to write:
foreach $value (1..5) {
  print ("... ");
  print ("Value is now ",$sum+=$value,"\n");
  }
print ("Triangle 5 is $sum\n");


Without the print it becomes:
foreach $value (1..5) {
  print ("... ");
  }
print ("Triangle 5 is $sum\n");


When those are run:
grahamellis$ perl avoidthis
... Value is now 1
... Value is now 3
... Value is now 6
... Value is now 10
... Value is now 15
Triangle 5 is 15
grahamellis$ perl liketheplague
... ... ... ... ... Triangle 5 is
grahamellis$


Does this just apply to print statements? No - anywhere you're undertaking two actions in a single statement is liable to come back an bite you late on.

Don't write $r = $p++; as it changes two variables - much clearer to write $r = $p; $p++;.

Don't use printf. PLEASE. As it both formats and prints. Use instead sprintf and then do a separate print. That way, you have the later flexibility to apply further string manipulation - for example if data originally destined for a command window is now to be output to a browser.

You should not write:
printf ("< %.2f",$maxprice);

But rather:
$poundamount = sprintf ("< %.2f",$maxprice);
print $poundamount;


Because you can enhance the latter as follows:
$poundamount = sprintf ("< %.2f",$maxprice);
$poundamount =~ s/</&lt;/g;
print $poundamount;


We (or rather "I" - I'll take the blame) made the mistake on a previous version of the Well House Consultants web site too - in HTML. The image on the left is 132 pixels wide, and I wanted an 8 pixel space to the right of it. What easier than to add the 8 white pixels to the images? So that's what I did and built up quite an image library ... to find my self well and truely in trouble when we wanted to add the ability to change background colour for users. We ended up, temporarily, with a dirty looking white band to the right of every image and it was only fixed by a rather messy procedure to - guess what - replace the single image with two functions with two images each with a single function.

Are you familiar with KISS (post title) ... if not, see next post!
(written 2006-12-05)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
P711 - An Introduction to Standards in Perl
  [242] Satisfaction of training - (2005-03-11)
  [668] Python - block insets help with documentation - (2006-04-04)
  [743] How to debug a Perl program - (2006-06-04)
  [945] Code quality counts - (2006-11-26)
  [1047] Maintainable code - some positive advice - (2007-01-21)
  [1221] Bathtubs and pecking birds - (2007-06-07)
  [1345] Perl and Shell coding standards / costs of an IT project - (2007-09-11)
  [1395] Dont just convert to Perl - re-engineer! - (2007-10-18)
  [1555] Advanced Python, Perl, PHP and Tcl training courses / classes - (2008-02-25)
  [1728] A short Perl example - (2008-07-30)
  [1853] Well structured coding in Perl - (2008-10-24)
  [1863] About dieing and exiting in Perl - (2008-11-01)
  [2375] Designing your data structures for a robust Perl application - (2009-08-25)
  [2688] Security considerations in programming - what do we teach? - (2010-03-22)
  [2875] A long day in Melksham ... - (2010-07-17)
  [3398] Perl - making best use of the flexibility, but also using good coding standards - (2011-08-19)
  [4326] Learning to program - comments, documentation and test code - (2014-11-22)


Back to
Practical polymorphism in action
Previous and next
or
Horse's mouth home
Forward to
CSL, KISS and RTFM
Some other Articles
Perl - $_ and @_
Perl - a list or a hash?
Realistic on line shoot'em up
CSL, KISS and RTFM
KISS - one action per statement please - Perl
Practical polymorphism in action
George Hotel and Well House Manor, Melksham
Breaking a loop - Ruby and other languages
Products that our customers want more of
1st, 2nd, 3rd revisited in Ruby
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/965_.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb