Linked Questions

4439 votes
73 answers
1.5m views

I use x != null to avoid NullPointerException. Is there an alternative? if (x != null) { // ... }
273 votes
20 answers
84k views

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 at ...
Nicholas Mancuso's user avatar
134 votes
14 answers
28k views

When programming by contract a function or method first checks whether its preconditions are fulfilled, before starting to work on its responsibilities, right? The two most prominent ways to do these ...
andreas buykx's user avatar
39 votes
6 answers
32k views

I've seen this question but have a few more questions about the usage of the assert keyword. I was debating with a few other coders about using assert. For this use case, there was a method that can ...
Big_Bad_E's user avatar
  • 817
20 votes
11 answers
5k views

I used to work for a company where some of the lead architect/developers had mandated on various projects that assertions were not to be used, and they would routinely be removed from code and ...
Jesse Pepper's user avatar
  • 3,263
20 votes
9 answers
15k views

I'm working on a library that generates reports of devices. The generate_report (const std::string& no) member function can fail due to various reasons: invalid report no. invalid state (the ...
user avatar
20 votes
6 answers
10k views

Is there any library that aids in implementing the design by contract principle in a C++ application? In particular, I'm looking for a library that facilities the usage of the principle, something ...
yesraaj's user avatar
  • 48.3k
8 votes
8 answers
13k views

Assertion is used to check whether a condition is met(precondition, postcondition, invariants) and help programmers find holes during debugging phase. For example, void f(int *p) { assert(p); p-&...
Eric Z's user avatar
  • 14.7k
2 votes
8 answers
4k views

When designing a class, should logic to maintain valid state be incorporated in the class or outside of it ? That is, should properties throw exceptions on invalid states (i.e. value out of range, ...
Scott Davies's user avatar
  • 1,379
14 votes
3 answers
8k views

A methodological question: I'm implementing an API interface to some services, using node.js, mongodb and express.js. On many (almost all) sites I see code like this: method(function(err, data) { ...
MarcoS's user avatar
  • 17.8k
9 votes
1 answer
10k views

At work, I ran upon this method and it troubled me. The fact that the name of the method, the documentation and the implementation don't really fit each other aside (and the pass true to make the ...
Shirraz's user avatar
  • 302
6 votes
3 answers
7k views

Since Matlab is interpreted, typically spend a lot of time at the beginning of the function enforcing the function signature. For example if nargin ~= 2; error('must provide two input args a and b');...
brown.2179's user avatar
  • 1,900
-3 votes
1 answer
9k views

I have read through fluentassertions.com and still confused as to what happens if a var is null or not null. so for instance if you have object someitem = null; then have someitem.Should()....
scripter78's user avatar
  • 1,177
2 votes
4 answers
919 views

is it bad practice to use asserts within methods? e.g. def add(x, y): assert isinstance(x, int) and isinstance(y, int) return x + y Any ideas?
RadiantHex's user avatar
  • 25.7k
-3 votes
2 answers
374 views

I have a programme that adds new positions to structure list. Structure definition is: struct data { char name[50]; char surname[50]; float income; float taxed_income; char ...
user3426015's user avatar