Skip to main content
-3 votes
2 answers
86 views

I'm writing tests with Hypothesis to test functions with restricted range. Consider the following toy example: import math from hypothesis import assume, example, given def inc(value: float) -> ...
Carl Patenaude Poulin's user avatar
0 votes
3 answers
1k views

I am trying to create a calculator and use defensive programming to avoid unexpected events and user inputs. I included a try/except block for user input & for zero division. When I input the ...
Youzohka's user avatar
1 vote
1 answer
106 views

I am writing code to learn defensive error handling in javascript. The program calculates distance, time or speed depending on the user's choice. This bit works fine. I then tried to add a try catch ...
Vermillion Orange's user avatar
1 vote
2 answers
876 views

How to loop through a directory in Python and open wave files that are good whilst ignoring bad (corrupted) ones? I want to open various wave files from a directory. However, some of these files may ...
Boris Reif's user avatar
-2 votes
1 answer
732 views

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: ...
CPlus's user avatar
  • 5,110
2 votes
2 answers
326 views

I am fairly new to Django, and I got some feedback for my project (recipe app) that I am currently working on from my mentor about defensive programming. I have created a delete "function" ...
Erik Andersson's user avatar
-3 votes
2 answers
1k views

/** * 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 ...
Poison's user avatar
  • 409
5 votes
0 answers
880 views

Recently we started to use C# nullable reference types in our projects. Of course in our project, we use nuget libraries that don't support nullable reference types. What is the best practice of using ...
Astemir Almov's user avatar
2 votes
1 answer
117 views

Since Firestore is a NoSQL database and has no strict type rules and defined document structures, I think about handling corrupt data in my Flutter app. In case you wonder why I want to request ...
Vega180's user avatar
  • 906
0 votes
0 answers
57 views

I have some code like so: export async function handleRefresh() { if (!existsSync('postr.toml')) fail('not a postr directory'); const posts = expandGlob('posts/*'); for await (const post ...
Siddharth Shyniben's user avatar
11 votes
1 answer
562 views

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'...
Raymond Hettinger's user avatar
0 votes
1 answer
269 views

I would like to create a matrix MxN. This matrix gets the inputs from the user. I would like to use defensive programming such that the elements of the matrix have not the digit 2. For example the ...
kcantor's user avatar
  • 25
0 votes
1 answer
210 views

Computer Systems: a Programmer's Perspective says: 1 /* Illustration of code vulnerability similar to that found in 2 * Sun’s XDR library. 3 */ 4 void* copy_elements(void *ele_src[], int ele_cnt, ...
Tim's user avatar
  • 101k
0 votes
2 answers
871 views

I was writing some tests for some legacy code that validates a user's date of birth. I encounter the following method in the class. My doubt is that whether the if statement in the try block is ...
LycheeSojuYYDS's user avatar
14 votes
2 answers
23k views

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 ...
SuperJMN's user avatar
  • 14.1k

15 30 50 per page
1
2 3 4 5
10