Click here to Skip to main content
15,915,160 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
Munchies_Matt3-Nov-15 2:39
Munchies_Matt3-Nov-15 2:39 
GeneralRe: What is meant by Defensive Programming? Pin
Eytukan3-Nov-15 3:24
Eytukan3-Nov-15 3:24 
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 
I always thought about programming differently after I accidentally coded a few infinite loops that crashed because of lack of stack space, or what not...

Later, it was described as defensive programming.

My favorite example, is one I blew up. Given a string, pad it to the left until it is 32 characters in length.
A$ = " " + A$ until len(A$) = 32

Which, of course, if you are given a string that is already too long, this will crash.
So, quickly I learned

While len(A$) < 32 do A$ = " " + A$

Always look for the comparison that avoids doing work under the most conditions. Here, there are a LOT of times you know to stop. The = was limited to exactly one condition.

That one lesson, I have used over the years, and I refactor code that is logically correct when changed to be like this. The reduction of errors/issues is amazing. (truth is, I hate debugging, and prefer to desk check my code. I grew up with OVERNIGHT compilers, so syntax errors cost you a day. In fact, all errors cost you a day)

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 
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 

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.