Skip to main content

Questions tagged [defensive-programming]

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

2 votes
1 answer
311 views

Is it possible to restructure code to avoid this copy-paste bug? [closed]

I came across quite a subtle bug the other day, where there are two sections of similar code that were supposed to use different variables, but copy-pasting had lead them to use the same variable. I'...
Joel Gibson's user avatar
-2 votes
1 answer
68 views

Automated Encryption Keys

A question that I have been wondering for quite some time now, is how do two devices send encrypted data over the internet know the encryption keys to encrypt and decrypt the data, or more importantly ...
TheAdmin's user avatar
1 vote
3 answers
343 views

Is `print statements` a defensive programming technique?

We had an exam and the question paper asked which of the following is not a defensive programming technique. I've answered it as print statement, that a print statement is not a defensive programming ...
kai's user avatar
  • 245
3 votes
4 answers
313 views

Should a transformation function take a nullable and return a nullable or should the caller handle nullability

Often I need to transform a type to another, such as a networking model to a data model, or a data model to a binary representation. Should these transformation functions take an Optional/nullable ...
Michael Ozeryansky's user avatar
1 vote
5 answers
1k views

Limits of Defensive Programming acknowledging that Exception Handling should be avoided

I've read Defensive Programming vs Exception Handling? and if/else statements or exceptions, but none contain something relevant to what I'm searching for. Taking into account that exception handling ...
Lefteris008's user avatar
2 votes
1 answer
753 views

Is using the copy constructor in an object's construction is bad? [duplicate]

I was reading this page about using the new keyword in the constructor, and I was wondering if it applies to copy constructors for collections. Suppose I have a Book class and a collection to store a ...
user avatar
0 votes
1 answer
53 views

Dealing with server errors/database data when processing client requests

Suppose my server PHP end point follows something along the lines of the following: Client sends request to server. Server updates a record Server might do some PHP processing... Server updates record ...
user avatar
3 votes
3 answers
180 views

Should I use a physical units library for modelling domain properties if I don't need to perform computations on them?

I'm working on the data model of a service describing houses and flats. This involves storing quantitative physical properties of certain features of the premises, for example: Speed of the Internet ...
H2CO3's user avatar
  • 437
1 vote
1 answer
535 views

Is a General Exception In Addition To Expected Exceptions Defensive or Unecessary?

I have read this and this and this: if my question misses the point in those answers, please point it out and we'll get this one deleted. These questions indicate that this may actually be a bad thing ...
user58446's user avatar
  • 327
2 votes
2 answers
1k views

Stack implementation by Design by Contract vs Defensive Programming

I am trying to write Stack code using the two techniques i.e Design by Contract vs Defensive Programming but I am not sure if I am doing right or not.I am not throwing any kind of exception or error ...
Grad student's user avatar
5 votes
3 answers
4k views

What is the difference between debugging and antibugging?

The terms debugging and antibugging seem to be widely used for referring to tools, measures and design patterns to get rid of bugs. After reading Peter Norvig's Paradigms of Artificial Intelligence ...
fr_andres's user avatar
  • 171
107 votes
14 answers
13k views

Does TDD make defensive programming redundant?

Today I had an interesting discussion with a colleague. I am a defensive programmer. I believe that the rule "a class must ensure that its objects have a valid state when interacted with from outside ...
user2180613's user avatar
  • 1,792
0 votes
3 answers
138 views

Defensive coding against an 'official' WSDL service specification

Earlier today I was asked to diagnose an issue in some development code. It turned out that the issue was caused by a new stub implementation returning random data which did not match the service ...
Kinexus's user avatar
  • 303
118 votes
16 answers
24k views

Should I add redundant code now just in case it may be needed in the future?

Rightly or wrongly, I'm currently of the belief that I should always try to make my code as robust as possible, even if this means adding in redundant code / checks that I know won't be of any use ...
KidCode's user avatar
  • 2,213
4 votes
1 answer
3k views

Checking for nil in Go [closed]

In Go, is it idiomatic to check for nil and return an error if a parameter is nil? Should pointer method receivers ever include nil checks? I've seen a lot of code in other languages where people ...
sqroot's user avatar
  • 49

15 30 50 per page