Training, Open Source computer languages

PerlPHPPythonMySQLhttpd / TomcatTclRubyJavaC and C++LinuxCSS

Search our site for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
A better alternative to cutting and pasting code
If you're new to coding, you'll be so concerned to be writing code that works that you may not take a look at coding technique. Your nose will be so close to the grindstone as you work that you won't take the time to look and ask "Do I need to keep grinding anyway?"

If you find yourself writing a piece of code and thinking "surely someone has done this before", they probably have, and the code is probably available to you - either as a standard PHP function of in resource libraries such as the PEAR and PECL. ((See footnote for other languages))

If you find yourself cutting and pasting part of your code, then STOP! - you should be turning that code into a function! "But I need to change a few things in the copy" I hear you saying. Maybe you do - and you have just identified those parts of the function code that will need to be passed in to it as parameters.

I wrote the text above in relation to PHP, but the same thing applies in almost every language.

In Perl, you write your shared code in a sub, and look on the CPAN resource library.

In Python, you write your shared code using a def, and look in the cheeseshop resource library.

In Java and C++ you write a method, in C a function, and in Tcl you write a proc. As I recall, in Fortran it's a subroutine or a function, and you may also come across words like macros and procedures ...
(written 2007-04-26 18:38:23)

 
Associated topics are indexed under
Y105 - Python - Functions, Modules and Packages
H105 - PHP - Functions
T207 - Tcl/Tk - Procedures and Variable Scope
P209 - Subroutines in Perl
C204 - C and C based languages - Functions, Macros and programs in multiple files
R104 - Ruby - Control Structures
J706 - Java - Objects and Classes

Back to
Cheddleton, Staffordshire
Previous and next
or
Horse's mouth home
Forward to
Grand Central Station

Some other Articles
Leaning tower of Cheeser
Back button - ensuring order are not submitted twice (PHP)
Extended Credit request - train in June and be paid in September
Grand Central Station
A better alternative to cutting and pasting code
Cheddleton, Staffordshire
A contrast in room rates and facilities
HTML - example of a simple web page
It can take more that one plus one to get two.
Private Java Course - A customer's pictures
1638 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 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).

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