Questions tagged [defensive-programming]

Defensive programming is a form of defensive design intended to ensure the continuing function of a piece of software in spite of unforeseeable usage of said software. Defensive programming techniques are used especially when a piece of software could be misused mischievously or inadvertently to catastrophic effect.

148 questions
0
votes
2 answers

Working around superfirst

Here, AsciiChecker enables the matrix specification in the text form. abstract class AsciiChecker extends AlgoritmicChecker { String[] ascii; AsciiChecker(String title, final String ... ascii) { super(title, ascii[0].length(),…
Val
  • 1
  • 8
  • 40
  • 64
0
votes
3 answers

Defensive techniques for ASP.MVC for internet facing site

I am working on my first asp MVC project that will ultimately end up on a publicly accessible web server (I have worked on some internal apps in MVC). What techniques, practices should I be thinking about (specific to MVC or otherwise) to improve…
Michael Gattuso
  • 13,020
  • 2
  • 25
  • 29
0
votes
2 answers

Proper form in C++

Possible Duplicate: What is the difference between these (bCondition == NULL) and (NULL==bCondition)? From this question it says "const object on left side of comparison" is some how "better" than doing otherwise. Why is this?
Celeritas
  • 14,489
  • 36
  • 113
  • 194
0
votes
2 answers

Can I prevent a derived class from calling its own functions? (C++)

Consider the following base class, which will count how many times I call CallDerivedFunction: class B { public: B() {numCalls = 0;} void CallDerivedFunction() {numCalls++; DerivedFunction();} int GetNumCalls() {return numCalls;} …
-1
votes
3 answers

validating content of input file

I have this defensive-programming issue that I don't really know how to solve. I have this function that takes file path and size of table (rows / columns count) as arguments and I'm looking for better way of validating the input file. I assume…
Sword22
  • 266
  • 3
  • 15
-1
votes
1 answer

Is it possible to programmatically set the webpages a userscript can run on?

I'm currently developing a userscript that could be in use for a few years after I've left the company. The target audience has basic computer literacy--enough to fill out a simple configuration menu. I worry that the scripts could break because the…
-1
votes
6 answers

Is there nothing wrong with digits in identifier name?

Since in C\C++\Java - int 2a ; //invalid suffix "a" on integer constant Is there nothing wrong with digits in the rest of variant name although it's valid syntax ? Like - int num1 ; int num_1st ; int num_2nd ;
URL87
  • 10,667
  • 35
  • 107
  • 174
-2
votes
1 answer

Can [NSApplication sharedApplication] ever return nil?

In a MacOS app in Objective-C is it possible for [NSApplication sharedApplication] to return nil or is it a safe assumption that this will never return nil? The Documentation describes the behavior: Returns the application instance, creating it if…
user16217248
  • 3,119
  • 19
  • 19
  • 37
-2
votes
2 answers

Java : A method which accepts a string as a parameter, what input validation would make the method defensible?

Homework Problem:: I came across this question in a quiz of secure coding: When creating a defensible method in java that accepts a string and compares it to a predefined value, what input validation would make the method defensible? public static…
Shweta
  • 219
  • 5
  • 18
-2
votes
1 answer

Exception Class declared but not thrown

Here test is not throwing an Exception object , yet i had handled it . Since Exception is an checked exception shouldn't it throw a compiler error of unreachable code in the catch block class Ece extends Exception {} public class Excep { public…
-2
votes
3 answers

Is it possible to stop try catch from returning null

If someone calls my method, I want to defensively deal with the problem. Usually I just return null. I decided to implement a try catch but it looks like I just end up returning null anyway. Can I write my try catch in such a way that at the end of…
Mike John
  • 818
  • 4
  • 11
  • 29
-3
votes
2 answers

Why doesn't the rangeCheck method in the java.util.ArrayList class check for negative index?

/** * Checks if the given index is in range. If not, throws an appropriate * runtime exception. This method does *not* check if the index is * negative: It is always used immediately prior to an array access, * which throws an…
-3
votes
2 answers

How to restart loop if an alphabet is given as input by user in C++

I have written a code about guessing a secret number, but I have a problem when an alphabetic character is given as an input instead of an integer. It halts the program. What how can I resist this problem. srand(time(0)); int a,secret; secret=rand()…
1 2 3
9
10