Subj : Re: Newb question on style and choices To : borland.public.cpp.borlandcpp From : Neil Duffee Date : Wed Jan 14 2004 03:06 pm Base8 wrote: > [snip] feedback on style and the choices [snip] Sure it was months ago but... Ed's information is bang on, as usual, and I only have 2 nit-picking items to add. > char *Password::RACFPassword() // password concatenator for RACF > [snip] > strcat(Newp,"/") ; // append a virgule to end > [snip] > strcat(Newp,"/") ; // append a virgule to end > [snip] perhaps the comments just haven't kept up with the requirements or code but you seem to be appending slashes in lieu of the 'virgule's (comma) mentioned. My guess is the comment is incorrect. [stolen from Ed's excellent sample] --------------- int Password::Validate(char *pass) // validator { if(strlen(pass) >= 5 && strlen(pass) <= 8 ) // check for correct length { if( isalpha(pass[0] )) // check if first char is alpha { return 0 ; } // return zero if passed else { return -1 ; } // return -1 if failed } } --------------- [/stolen from Ed's excellent sample] From personal style, I've always found it more readable, when doing validation routines, to code the failures first and separately. Thus I use: --------------- int Password::Validate(char *pass) // validator { if(strlen(pass) < 5 ) // is it long enough? return -1; // no. if(strlen(pass) > 8 ) // is it short enough? return -1; // no. if( isalpha(pass[0] )) // is first char is alpha? return -1; // no. // we made it here - things must be good return 0 ; } --------------- Now, this is a simplistic approach and can fail when the conditions become too inter-dependant however it will allow you to weed out the basic stuff quickly and then you work on the tricky clauses. It also allows for ease of case additions or deletions, test case generation, and you can even do some rudimentary optimization by placing the 'most likely' errors first. (fewer tests ie. isalpha([0]) occurring less often than length errors) ----------> signature = 5 lines follows <-------------- Neil Duffee, Joe Systems Guy, U d'Ottawa, Ottawa, Ont, Canada telephone:1 613 562 5800 x4585 fax:1 613 562 5161 mailto:NDuffee at uottawa.ca http://aix1.uottawa.ca/~nduffee "How *do* you plan for something like that?" Guardian Bob, Reboot "For every action, there is an equal and opposite criticism." .