Defensive programming is a style of programming designed to minimize the possibility of bugs introduced by code changes or unforeseen usage of the software.

learn more… | top users | synonyms

0
votes
1answer
424 views

Should we always write Defensive null check in code? [duplicate]

Are there any scenarios where we should not write defensive checks for null? Should we write defensive code or check for NULL every time we have passed a parameter or received a value back from a ...
0
votes
0answers
46 views

Boolean condition before variable [duplicate]

I have noticed this style from time to time: if ( 0 == myVar ) Rather than: if ( myVar == 0 ) Is this just the individual programmers idiom? A defensive programming style? Does anyone know if it ...
0
votes
2answers
373 views

Defensive Programming vs. Exception Handling [duplicate]

I have a question about defense programming and handling of exceptions. Here is a pseudo-code snippet first: try { // do some core logic; } catch (BadException e) { ErrorCode ec = ...
3
votes
3answers
264 views

Is it worth to try write foolproof data structures?

The problem We need to store data in a table-like way, but we have very strict space constraints (~1Mb per table of 10k+ rows). We store data like this: ID | reviews | factor | score | interval | ...
36
votes
8answers
6k views

Defensive Programming vs Exception Handling?

I'm working through the book "Head First Python" (it's my language to learn this year) and I got to a section where they argue about two code techniques: Defensive coding vs Exception handling. Here ...
10
votes
2answers
1k views

Differences between Design by Contract and Defensive Programming

Could Designing by Contract (DbC) be a way to program defensively? Is one way of programming better in some cases than the other?
11
votes
3answers
229 views

Do I need to deal with the situation where private methods are called through reflection?

When creating a library, must I ensure that the private methods must work as expected when called not by other methods of the same class, but by another library through reflection? For example, if a ...
9
votes
4answers
645 views

How defensive should we be?

We've been running Pex over some code, and it has been showing some good things (well bad things, but showing them before it gets to production!). However, one of the nice things about Pex is that it ...
23
votes
3answers
3k views

if ('constant' == $variable) vs. if ($variable == 'constant')

Lately, I've been working a lot in PHP and specifically within the WordPress framework. I'm noticing a lot of code in the form of: if ( 1 == $options['postlink'] ) Where I would have expected to ...