defensive-programming Questions

2

Solved

Zoran Horvat proposed the usage of the Either type to avoid null checks and to not forget to handle problems during the execution of an operation. Either is common in functional programming. To ill...
Through asked 3/8, 2020 at 14:35

3

What is the best way to get meaningful file access error messages, in a portable way from std::fstreams ? The primitiveness of badbits and failbits is getting to be bit annoying. I have written my ...
Pizza asked 14/4, 2010 at 16:52

24

Solved

I'm reading some lecture notes of my C++ lecturer and he wrote the following: Use Indentation // OK Never rely on operator precedence - Always use parentheses // OK Always use a { } block ...
Godforsaken asked 30/8, 2012 at 8:50

1

Solved

This example is being discussed as likely "gotcha" when using pattern matching: NOT_FOUND = 400 retcode = 200 match retcode: case NOT_FOUND: print('not found') print(f'Current value ...

14

Solved

I need to store sensitive information (a symmetric encryption key that I want to keep private) in my C++ application. The simple approach is to do this: std::string myKey = "mysupersupersecret...
Easternmost asked 30/10, 2009 at 8:31

7

Solved

Erlang's (or Joe Armstrong's?) advice NOT to use defensive programming and to let processes crash (rather than pollute your code with needless guards trying to keep track of the wreckage) makes so ...
Strychnic asked 8/12, 2010 at 22:57

12

Solved

For C++ development for 32-bit systems (be it Linux, Mac OS or Windows, PowerPC or x86) I have initialised pointers that would otherwise be undefined (e.g. they can not immediately get a proper ...
Mature asked 11/8, 2009 at 1:24

9

Solved

I discovered that it is possible to extract the hard-coded strings from a binary. For example the properties view of Process Explorer displays all the string with more than 3 characters. Here is t...

3

Solved

I am new to Vala programming and have experiences with Java and .NET yet I haven't been able to find anything useful on how to log with Vala. Is there any useful logging facility like log4j or log4...
Scuppernong asked 1/5, 2012 at 16:28

3

Solved

Uncle Bob says: "Defensive programming, in non-public APIs, is a smell, and a symptom, of teams that don't do TDD." I am wondering how TDD can avoid an (internal) function to be used in an uninte...
Mcelroy asked 21/8, 2017 at 13:3

5

Solved

I have this debate with my colleague about this piece of code: var y = null; if (x.parent != null) y = x.parent.somefield; My point of view is that in the place where the code is, x.pare...
Preferential asked 7/3, 2014 at 0:46

20

Solved

I've been a professional software engineer for about a year now, having graduated with a CS degree. I've known about assertions for a while in C++ and C, but had no idea they existed in C# and .NET...

2

Solved

The documentation on QObject::moveToThread() for Qt5.3 explains that the moveToThread() method can fail if the object has a parent. How would I detect this failure in my code? I realize that simpl...

2

Solved

These days I am reading the second edition of Effective Java by Joshua Bloch. In the item 39 he mentions that it is a good idea to make defensive copies of mutable objects passed as arguments, say ...
Methyl asked 20/2, 2014 at 3:41

5

In my most C++ project I heavily used ASSERTION statement as following: int doWonderfulThings(const int* fantasticData) { ASSERT(fantasticData); if(!fantasticData) return -1; // ,,, return WO...
Balls asked 19/8, 2008 at 23:19

9

Solved

Is it silly of me to leave unreachable break statements in a case that just throws an Exception anyway? The defensive part of me wants to leave it there in the event that the logic changes. Another...

5

What is a copy constructor? Can someone share a small example that can be helpful to understand along with defensive copying principle?
Worsted asked 22/2, 2013 at 9:31

1

Solved

After reading the following blog : http://xania.org/200711/ambiguous-overloading I started asking myself "should I not always explicit define my constructors?" So I started reading more th...

7

I have two different kinds of strings I'm passing around and using in my code, and the two are closely related, but should not be confused for one another. I thought I could help myself avoid error...
Importune asked 21/6, 2012 at 14:46

5

I have an object that is not safe for multithreaded applications (in several ways), and I want to provide an internal check to make sure that critical methods are not accessed concurrently. Questi...
Ecuador asked 15/5, 2012 at 19:46

2

A couple days ago, I have following theoretical questions on the exam: (a) Explain what is meant by defensive programming when dealing with exceptional circumstances that may occur during the exec...
Desolate asked 22/9, 2011 at 17:58

2

Solved

The question I want to ask you is quite wide but in the same time it's very concrete. First, I have to say, that I mostly interested in answers which are applicable in the .net environment. Well, ...

5

I want to make a private member variable that is private even to the class that owns it, and can ONLY be accessed by its getters and setters. I know you can do this with auto-properties like priva...
Faruq asked 5/8, 2011 at 3:56

4

Solved

Is it possible for split to return a null String[]? I am curious as I want to try to be as defensive as possible in my code without having unnecessary checks. The code is as follows: String[] par...
Shortcircuit asked 1/8, 2011 at 17:26

2

Solved

So far I had little concern about overall security considerations, because I have been developing only promotional and uncritical iPhone apps. Currently, however, I'm working on a Mac application ...
Calumet asked 23/5, 2011 at 15:38

© 2022 - 2024 — McMap. All rights reserved.