| |||||||||||
| |||||||||||
printf - a flawed but useful function
Many languages have printf statements ... and yet from a computer scientist's viewpoint, printf is a flawed function. In order for code to be clean and re-usable, functions should be designed to perform a single task. Alas, printf performs two tasks - it both formats the information that's entered in to it AND it then sends that information to an output stream.
What's the better alternative? Where you have printf, you probably have sprintf as well and that's a much better function - it just returns you the formatted string. So I'm advocating that, in Perl for example, you should write: $tstring = sprintf("%02d:%02d",$hour,$min); print ("Ths time of this record was $tstring\n"); (written 2006-02-22 06:34:48) Associated topics are indexed under P207 - Perl - File HandlingH109 - PHP - Input / Output
Some other Articles
Familiar names, close to homeIf its Sunday, it must be the Norland Perl - its up to YOU to check your file opened Easy, Free, Reliable internet access printf - a flawed but useful function Looking for leading not bleeding edge News in Ireland Greetings from Dublin Coming or going? Look out for the motor cyclist 1636 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 pageThis 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). |
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||