Click here to Skip to main content
15,915,324 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: What is meant by Defensive Programming? Pin
BillWoodruff3-Nov-15 5:01
professionalBillWoodruff3-Nov-15 5:01 
GeneralRe: What is meant by Defensive Programming? Pin
PIEBALDconsult3-Nov-15 12:46
mvePIEBALDconsult3-Nov-15 12:46 
GeneralRe: What is meant by Defensive Programming? Pin
zandam3-Nov-15 22:35
zandam3-Nov-15 22:35 
GeneralRe: What is meant by Defensive Programming? Pin
Mycroft Holmes3-Nov-15 13:52
professionalMycroft Holmes3-Nov-15 13:52 
GeneralRe: What is meant by Defensive Programming? Pin
R. Erasmus3-Nov-15 23:29
R. Erasmus3-Nov-15 23:29 
GeneralRe: What is meant by Defensive Programming? Pin
Kirk 103898214-Nov-15 3:05
Kirk 103898214-Nov-15 3:05 
GeneralRe: What is meant by Defensive Programming? Pin
Ferd Really4-Nov-15 4:55
Ferd Really4-Nov-15 4:55 
GeneralRe: What is meant by Defensive Programming? Pin
Kirk 103898214-Nov-15 5:05
Kirk 103898214-Nov-15 5:05 
Oh, I have done it that way in a hurry!

But what happens when len(A$) is NEAR the limit of a string length (ie has less than 32 characters left). You could actually lose the right side of the string!!!

Also, the 32 was chosen for simplicity, as was the space. I believe the actual code had a variable for the length, and another for the padding character.

But the nuances is what makes defensive programming powerful. Most people don't think in terms of limits. They EXPECT a "small" string to be passed in when they are WRITING the code, and it NEVER dawns on them how the code could be called in the future.

I know from first (and second) hand experience that defensive style programming reduces errors and the debugging efforts required. I would rather fail with ASSERT() failures than to let code execute with bad parameters and pray for good luck.

GeneralRe: What is meant by Defensive Programming? Pin
Sucramsy4-Nov-15 8:44
Sucramsy4-Nov-15 8:44 
GeneralFOSW OTD 03. November 2015 1. Hint Pin
HobbyProggy2-Nov-15 23:46
professionalHobbyProggy2-Nov-15 23:46 
GeneralRe: FOSW OTD 03. November 2015 Pin
Kornfeld Eliyahu Peter2-Nov-15 23:51
professionalKornfeld Eliyahu Peter2-Nov-15 23:51 
GeneralRe: FOSW OTD 03. November 2015 Pin
HobbyProggy2-Nov-15 23:55
professionalHobbyProggy2-Nov-15 23:55 
GeneralRe: FOSW OTD 03. November 2015 Pin
Kornfeld Eliyahu Peter3-Nov-15 0:00
professionalKornfeld Eliyahu Peter3-Nov-15 0:00 
GeneralRe: FOSW OTD 03. November 2015 Pin
HobbyProggy3-Nov-15 0:05
professionalHobbyProggy3-Nov-15 0:05 
GeneralRe: FOSW OTD 03. November 2015 Pin
Brittle16183-Nov-15 1:38
Brittle16183-Nov-15 1:38 
GeneralRe: FOSW OTD 03. November 2015 Pin
super3-Nov-15 0:35
professionalsuper3-Nov-15 0:35 
GeneralRe: FOSW OTD 03. November 2015 Pin
OriginalGriff3-Nov-15 0:45
mveOriginalGriff3-Nov-15 0:45 
GeneralRe: FOSW OTD 03. November 2015 Pin
super3-Nov-15 0:49
professionalsuper3-Nov-15 0:49 
GeneralRe: FOSW OTD 03. November 2015 Pin
HobbyProggy3-Nov-15 0:49
professionalHobbyProggy3-Nov-15 0:49 
GeneralRe: FOSW OTD 03. November 2015 Pin
Brittle16183-Nov-15 1:38
Brittle16183-Nov-15 1:38 
GeneralRe: FOSW OTD 03. November 2015 Sorry Pin
HobbyProggy3-Nov-15 0:57
professionalHobbyProggy3-Nov-15 0:57 
GeneralRe: FOSW OTD 03. November 2015 1. Hint Pin
_Maxxx_3-Nov-15 1:00
professional_Maxxx_3-Nov-15 1:00 
GeneralRe: FOSW OTD 03. November 2015 1. Hint Pin
HobbyProggy3-Nov-15 1:02
professionalHobbyProggy3-Nov-15 1:02 
GeneralRe: FOSW OTD 03. November 2015 1. Hint Pin
Nicholas Marty3-Nov-15 1:04
professionalNicholas Marty3-Nov-15 1:04 
GeneralRe: FOSW OTD 03. November 2015 1. Hint We have a Winner! Pin
HobbyProggy3-Nov-15 1:06
professionalHobbyProggy3-Nov-15 1:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.