Skip to main content

Questions tagged [null]

Null is the absence of a value. Null is typically used to indicate that a reference or pointer variable points to no object in memory.

Filter by
Sorted by
Tagged with
8 votes
7 answers
5k views

We have entities with numeric properties, they are of boxed types (e.g. Integer). Typically, each of those properties has a pair of getters: getInt(), which returns zero on null values, and ...
Sergey Zolotarev's user avatar
3 votes
5 answers
1k views

I work with a lot of Groovy code. One feature of the language is the "safe navigation operator" (?), which I think of as an inline null check. There are many things about Groovy that I like, ...
Gus Murphy's user avatar
2 votes
1 answer
246 views

With the introduction of JEP 358 in Java 14, which provides more informative NullPointerException (NPE) messages, is it advisable to remove existing explicit null checks in cases where the null-check ...
ftb457932's user avatar
3 votes
4 answers
4k views

Some fields may be optional. That is, a value doesn't have to be ever assigned to it. Luckily, Java has a special null-safer type for optional values — Optional However, if I try to make a field of ...
Sergey Zolotarev's user avatar
0 votes
2 answers
128 views

I am practicing tactical DDD and having trouble as exemplified below. Fundamentally, whether some fields of the value object should be nullable depends on another field of the same value object. ...
STHA's user avatar
  • 71
-7 votes
1 answer
159 views

Since we all know that few couple days ago there was a global outage (BSOD) because of the CrowdStrike updated which caused that global outage and the reason behind that was just an ...
procrastinator1771's user avatar
5 votes
5 answers
1k views

I've set up a ternary operator in place of a pile of if-else's, the final expression being nullptr in order to finish the loop, like so: int menuSelect; std::string operation=""; (...
Hench's user avatar
  • 61
0 votes
3 answers
200 views

Semantically, C++ std::optional, Rust Option<T>, and other optional/nullable types represent a value that can be present or absent: you have to handle both cases, or you can opt-in to crash. Is ...
JJW's user avatar
  • 9
1 vote
4 answers
3k views

When retreiving data with an api and saving it in a DTO, some values are nullable: null on initial class initialization but VS also warns you for this. For example, an employee: public class ...
Jannick Breunis's user avatar
16 votes
10 answers
5k views

I was looking at an SQL query recently and found what I think is likely a bug. It was related to case statements on inequalities. I was trying to replace it with a min/max type alternate and when ...
JimmyJames's user avatar
  • 31.1k
4 votes
3 answers
1k views

I was reading the excellent book by Axel Raushmayer, Tackling TypeScript. In this section of Chapter 7, the author makes the interesting claim In many programming languages, null is part of all ...
Ray Toal's user avatar
  • 1,335
20 votes
8 answers
9k views

Let's consider the following test. [Fact] public void MyTest() { // Arrange Code var sut = new SystemWeTest(); // Act Code var response = sut.Request(); // Assert ...
BAmadeusJ's user avatar
  • 326
2 votes
4 answers
742 views

I am working on implementing some stock order types for a financial technology application. There are six different types of stock orders - market, limit, stop_loss, stop_loss_limit, trailing_stop, ...
Treker's user avatar
  • 197
2 votes
3 answers
234 views

Suppose that we have a SQL relational database for, let's say, asset management system. It uses a table of assets (1 row per one real-world object). There can be various metadata etc. To allow the ...
jiwopene's user avatar
  • 191
47 votes
8 answers
30k views

I've recenlty been greeted by CS8603 - Possible null reference return, which indicates that my code could possibly return null. It's a simple function that looks up an entity in a database by id - if ...
MechMK1's user avatar
  • 669
-1 votes
1 answer
101 views

Backstory: I have subclasses that are supposed to override and define various functions, but not neccessarily all of them. They can't remain purely virtual though for obvious reasons, and so I am ...
Anon's user avatar
  • 3,649
-1 votes
2 answers
5k views

Frequently in applications we encounter situations that could throw a NullReferenceException; for example, assuming the following method's argument is a user defined reference type, accessing the ...
Taco's user avatar
  • 1,175
-2 votes
3 answers
502 views

Considering example below, one observe that for reference type argument is successfully understood as nullable parameter. For value type conversion to T?/Nullable<T> fails. T Method<T> ( T?...
Yarl's user avatar
  • 298
0 votes
2 answers
766 views

Suppose I am buying coffee. There are several types of coffee (A1, A2, A3), but sometimes I want to make a reference to all types of coffee (like if I had a coffee "grouped"). Considering ...
André Luís Oliveira's user avatar
4 votes
1 answer
6k views

Our project changed the object existence checks from foo == null or foo != null to Objects.isNull(foo) or Objects.nonNull(foo). I never got an explanation why that should be better, that's why I ask. ...
Matthias Ronge's user avatar
0 votes
1 answer
178 views

This come with a debate with my colleague that I'm using nullable object type. type Value = Node | null const [v0, setV0] = React.useState<Value>(null) const [v1, setV1] = React.useState&...
Mengo's user avatar
  • 669
69 votes
11 answers
19k views

This comes with a debate with my colleague that I'm using null as an object initial state. type Value = Node | null const [value, setValue] = React.useState<Value>(null) function test(v: Value) ...
Mengo's user avatar
  • 669
2 votes
1 answer
322 views

Considering Kotlin Java Interop: Null Safety and Platform Types Why is code like this legal in Kotlin? fun envString(key: EnvVars): String { return System.getenv(key.toString()) } getenv() can ...
F.P's user avatar
  • 609
1 vote
5 answers
2k views

Instead of checking the null and throwing exception each time we call findByOrderNumber method, I came up with this pattern by taking advantage of a default method, are there any patterns misused here ...
user3595026's user avatar
94 votes
11 answers
21k views

AFAIK, Option type will have runtime overhead, while nullable types won't, because Option time is an enum (consuming memory). Why not just mark optional references as optional, then the compiler can ...
Chayim Friedman's user avatar
0 votes
3 answers
3k views

Probably the answer is you can't. However, I would like to have a work-around to solve my problem. Objective I am trying to create a program in which I try to avoid nulls as much as possible. ...
Ricardo Duran's user avatar
3 votes
5 answers
12k views

I wanted to follow up on this previous question I asked related to @Laive comment, but I couldn't think of an excellent way to do so without asking another question, so here we go. With the previous ...
Ertai87's user avatar
  • 187
3 votes
4 answers
338 views

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
1 answer
179 views

Let's say I have an which is loosely can be represented as: public class AnObject{ public AnObject(String name, String value, UUID id) { this.name = Objects.requireNonNull(...
Denis's user avatar
  • 113
1 vote
1 answer
1k views

Assuming we have following message that will be used to update data and it just got updated to version 2. message HelloRequest { string name = 1; // version 1 bool is_valid = 2; // version 2 } ...
Jan Paolo Go's user avatar
0 votes
0 answers
199 views

I'm new to software engineering and right now I'm focused on learning the best practices to consistently write robust code. Recently I've been maintaining an application built by other people and/or ...
StackLloyd's user avatar
-1 votes
3 answers
459 views

I have a case where I have a dictionary object and a value with no key. The object can have the system values and then a user value. I have to store that value. I could use a reserved word or I ...
1.21 gigawatts's user avatar
40 votes
8 answers
11k views

For example, suppose I have a class, Member, which has a lastChangePasswordTime: class Member{ . . . constructor(){ this.lastChangePasswordTime=null, } } whose lastChangePasswordTime ...
ocomfd's user avatar
  • 5,760
29 votes
3 answers
7k views

There is a pattern in C# classes exemplified by Dictionary.TryGetValue and int.TryParse: a method that returns a boolean indicating success of an operation and an out parameter containing the actual ...
Sebastian Redl's user avatar
-2 votes
1 answer
939 views

Is it a good practice to use the static member methods to check if an object of a class is NULL or not. The object would be sent through the parameters offcourse. Something like, #include <...
Haris's user avatar
  • 105
11 votes
1 answer
7k views

Let's take the classical example of a function that may return a number or not. In typescript this can be represented like this: function f(): number | undefined {} A more elaborate way would be to ...
heapOverflow's user avatar
-1 votes
2 answers
207 views

Using a website with Javascript as example. Let's say I have script A which only performs a specific function on page Foo. For example something like sorting elements in a list. Script A is only ...
kalenpw's user avatar
  • 109
-2 votes
2 answers
636 views

I want a class A, and I want the relation that A can have zero or one X. So I wrote this class: public class A { private X x = null; public A() {} public A(X x) { this.x = x; } ...
klutt's user avatar
  • 1,448
1 vote
2 answers
2k views

Not using UncheckedIOException, NullPointerException possible public void callerMethod() { Object result = ioMethod(); // call instance method of result } public Object ioMethod() { ...
Mario Ishac's user avatar
1 vote
1 answer
392 views

We are building API which mainly passes database objects back and forth between user and database, so the main flow of information is quite basic: Table (view) <-- ORM --> C#/Java/etc. Objects &...
Tuomas Kujala's user avatar
3 votes
1 answer
342 views

I do not understand how you think about it:https://wiki.php.net/rfc/nullable_types when It is widely confirmed, that using nulls is bad practice Where am I wrong? thanks. I'm not criticizing !. I ...
BruceStackOverFlow's user avatar
1 vote
3 answers
4k views

Which solution is most logical? The value can be null, but when not null it must be a string. This (First): function setValue(string $value = null); To me this is bad; since we can now call the ...
Stefan's user avatar
  • 87
38 votes
15 answers
11k views

This is one of the rules that are being repeated over and over and that perplex me. Nulls are evil and should be avoided whenever possible. But, but - from my naivety, let me scream - sometimes a ...
gaazkam's user avatar
  • 4,529
2 votes
3 answers
16k views

I use code object != null to avoid NullPointerException. Is there a good alternative to solve this as follow ? if (someobject != null) { someobject.doCalc(); } This will not work for ...
Chaminda Bandara's user avatar
3 votes
3 answers
4k views

I have a RESTFUL api, one of the endpoints is receiving search criteria which contains property for "Title". Should I allow consumers to send either null (or eliminate the property) or Empty string in ...
Dabbas's user avatar
  • 260
1 vote
2 answers
2k views

Let's take an example of class with 3 dependencies and one method. class Example { private readonly IDependency1 _d1; private readonly IDependency2 _d2; private readonly IDependency3 _d3;...
Patrik Bak's user avatar
-1 votes
1 answer
351 views

Do Special Case or Null Object design patterns still provide value when application behavior, not just object behavior has to change? I was tasked with revisiting an old application and refactoring ...
PieMaker's user avatar
8 votes
8 answers
3k views

As a CS student, I've learned a decent number of programming languages over the years, most of which have had some concept of a "nullable" or "optional" type. Note that I'm not talking about null ...
ApproachingDarknessFish's user avatar
2 votes
3 answers
265 views

When I program in Java, I make all nullability explicit; that is, an instance of Foo is assumed to be non-null, and if I want it to be null, I use a @Nullable annotation (or better, Optional<Foo>...
Nick Tobey's user avatar
5 votes
4 answers
1k views

This question is a clearer version of a question I posted on SO. I have a C++ Planner object with a method that computes a Route from a start point to a destination point. Planner is the owner of the ...
Greg82's user avatar
  • 159