Journal Articles
Browse in : |
All
> Journals
> CVu
> 174
(12)
All > Journal Columns > LettersEditor (132) Any of these categories - All of these categories |
Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xt and user-summary-[publicationtype].xt. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-) Please place your own templates in themes/yourtheme/modules/articles . The templates will get the extension .xt there.
Title: Comments
Author: Administrator
Date: 08 August 2005 05:00:00 +01:00 or Mon, 08 August 2005 05:00:00 +01:00
Summary:
Body:
Not that huge a postbag this edition, but something in Pete Goodliffe's Professionalism article #32 did catch the eye of Chris Smith.
I have just read your article 'Professionalism in Programming #32' (C Vu, June 2005). You invited us to voice our disagreements, so here it is: I disagree. :-)
My (single) complaint is with your improved version of the 'greatest_common_divisor function. To quote your article: Try feeding it a negative argument. This is a more robust (and more efficient) version written in C++:
int greatest_common_divisor(int a, int b) { a = std::abs(a); b = std::abs(b); ...
My complaint is that you are enforcing restrictions on the input which are not visible to the 'clients' of your function - you are effectively saying "my function can't handle negative numbers, so I will silently convert them to positive numbers". (Granted, you could detail this restriction in comment, but that's not the point.)
I would have preferred the following:
unsigned int greatest_common_divisor( unsigned int a, unsigned int b)
That clearly states that you should not call this function with negative values. (And, if you do the compiler will warn you.)
Now I invite you to disagree with me. :-)
Chris Smith
Firstly, thanks so much for taking the initiative (and the time) to reply to the challenge I laid down in this article. Any writer really appreciates feedback! For years I've been trying to provoke some kind of response in my articles (either in letter form, or on accu-general) so it's great that #32 has provoked people to think and reply.
Also, well done for using your brain and disagreeing with what I wrote. Too many people fall into the "mindlessness trap" when reading books, magazines, even stuff online. You must always filter what you read through your own knowledge and understanding, and only accept what's definitely useful. Just because something is in print, that doesn't mean it's gospel (I know that some of the stuff I've written over the years has been drivel, and no one's challenged me about it!).
So, to your specific point: I understand what you're getting at, but (within my granted freedom to do so) I disagree with you! At no point did I state that a negative argument is invalid input. Indeed, it is most definitely a valid form of input. However, negative input would have caused an infinite loop in the original (typographically challenged) version of the GCD function.
The corrected version accounts for this by converting all input values to positive integers before working on them. The side effect of this is to only ever return positive GCD values but, more often than not, that is what's required anyway.
Of course, if negative values were invalid input then it's preferable to make this explicit in the code by careful choice of data type.Thanks again for your response. I hope my future columns elicit the same level of response!
Pete Goodliffe Do you have any points you wish to be raised about anything to do with C Vu? If so, please just drop me a line - <cvu@accu.org>.
Notes:
More fields may be available via dynamicdata ..