The null tag has no wiki summary.
15
votes
6answers
644 views
Why most “well-known” imperative/OO languages allow unchecked access to types that can represent a 'nothing' value?
I have been reading about the (un)convenience of having null instead of (for example) Maybe. After reading this article, I am convinced that it would be much better to use Maybe (or something ...
13
votes
4answers
977 views
Why doesn't Java String have static string manipulation methods?
Why didn't Java designers create static versions of string manipulation methods in the java.lang.String class? The following methods are what I refer to, but the question can be extended to other ...
0
votes
1answer
199 views
Should we always write Defensive null check in code? [duplicate]
Are there any scenarios where we should not write defensive checks for null?
Should we write defensive code or check for NULL every time we have passed a parameter or received a value back from a ...
3
votes
1answer
361 views
What are the disadvantages of self-encapsulation?
Background
Tony Hoare's billion dollar mistake was the invention of null. Subsequently, a lot of code has become riddled with null pointer exceptions (segfaults) when software developers try to use ...
7
votes
5answers
260 views
In retrospect, has it been a good idea to use three-valued logic for SQL NULL comparisons?
In SQL, NULL means "unknown value". Thus, every comparison with NULL yields NULL (unknown) rather than TRUE or FALSE.
From a conceptional point of view, this three-valued logic makes sense. From a ...
2
votes
3answers
162 views
Is it good practice to not filter values according to nullability?
Sometimes when I create an API that should enable getting a single value or all values I use the following pattern (passing NULL to the API, means get all rows):
@Usernames - comma separeted list of ...
2
votes
3answers
114 views
Avoiding null in a controller
I'm trying to work through how to write this code.
def get(params):
""" Fetch a user's details, or 404 """
user = User.fetch_by_id(params['id'])
if not user:
abort(404)
# ...
2
votes
1answer
110 views
design strategy pattern with null checking
When the context class can accept a null strategy, is there another way to do it without check if its null?
Is this considered a good strategy design implementation?
class MainApp{
static void ...
2
votes
4answers
325 views
Does 'consider returning Null Object' apply to a DAO read method?
I was looking for an answer to the question of what the dao should return when a search end up to be for a nn entity that does not exist.
There are some generic previous questions related to ...
5
votes
2answers
236 views
Requiring Explicit Null Reference Handling
One of the problems I have with null references is that they may not be exceptional. In my current position, there are few requirements and you are lucky if conventions are followed. This means being ...
7
votes
7answers
2k views
When should pointers be checked for NULL in C?
Summary:
Should a function in C always check to make sure it is not dereferencing a NULL pointer? If not when is it appropriate to skip these checks?
Details:
I've been reading some books about ...
3
votes
2answers
292 views
Purpose of Base Address?
What's the purpose of a base address in an executable?
For example, in Microsoft Visual C++'s linker, you can set a base address, or use the default of 0x1000000. But with virtual memory, why would a ...
3
votes
2answers
297 views
null values vs “empty” singleton for optional fields
First of all I'm developing a parser for an XML-based format for 3D graphics called XGL.
But this question can be applied to any situation when you have fields in your class that are optional i.e. the ...
7
votes
8answers
722 views
AND is better or using Internal “IF”
In a situation like this:"
if ((metadata != null) && (metadata.TypeEnum != VariantInfoMetadata.CellTypeEnum.Status))
do you recommend to keep the code as it is above? Or is it better to ...
7
votes
2answers
1k views
Check parameters annotated with @Nonnull for null?
We've begun using FindBugs and annotating our parameters with @Nonnull appropriately, and it works great to point out bugs early in the cycle. So far we have continued checking these arguments for ...
0
votes
1answer
773 views
How to check for null in most sql's - “column is null” or “column = null” [closed]
I'm not sure of the right syntax to use.
Is it
select * from tlb
where flag is NULL
or
select * from tlb
where flag = NULL
Is the answer the same for oracle, sqlserver and Postgres?
11
votes
4answers
3k views
null pointers vs. Null Object Pattern
Attribution: This grew out of a related P.SE question
My background is in C / C++, but I have worked a fair amount in Java and am currently coding C#. Because of my C background, checking passed and ...
3
votes
6answers
4k views
What does it mean to do a “null check” in C or C++?
I have been learning C++ and I am having a hard time understanding null. In particular, the tutorials I have read mention doing a "null check", but I am not sure what that means or why it's necessary.
...
26
votes
4answers
2k views
Where are null values stored, or are they stored at all?
I want to learn about null values or null references.
For example I have a class called Apple and I created an instance of it.
Apple myApple = new Apple("yummy"); // The data is stored in memory
...
53
votes
13answers
6k views
Should one check for null if he does not expect null?
Last week, we had a heated argument about handling nulls in our application's service layer. The question is in the .NET context, but it will be the same in Java and many other technologies.
The ...
20
votes
10answers
1k views
Are nullable types preferable to magic numbers?
I have been having a little bit of a debate with a coworker lately. We are specifically using C#, but this could apply to any language with nullable types. Say for example you have a value that ...
53
votes
24answers
9k views
How can I explain the difference between NULL and zero?
Working on a problem that uses the percent change formula:
percent change = 100 * [(new value - old value) / old value]
How would I explain the difference if new value or old value = NULL, rather ...
9
votes
3answers
1k views
Should I store False as Null in a boolean database field?
Let's say you have an application that has a boolean field in its User table called Inactive.
Is there anything inherently wrong with just storing false as null? If so can you please explain what the ...
15
votes
6answers
28k views
Why doesn't “object reference not set to an instance of an object” tell us which object?
We're launching a system, and we sometimes get the famous exception NullReferenceException with the message Object reference not set to an instance of an object.
However, in a method where we have ...
4
votes
1answer
206 views
Nulls in every type and checked exceptions in Java?
I know that null being added to every type in Java is a source of much frustration regarding the language's type system. At the same time I generally hear complaining about checked exceptions - that ...
5
votes
4answers
2k views
What is the difference between a pointer pointing to 0x0 location and a pointer set to NULL?
Is a pointer pointing to 0x0000 the same as a pointer set to NULL? If NULL value is defined in the C language, then what location does it physically translate to? Is it the same as 0x0000. Where can I ...
8
votes
9answers
750 views
Should security restrictions cause a service to return null or throw an exception?
I'm in a bit of a disagreement with a more experienced developer on this issue, and wondering what others think about it; our environment is Java, EJB 3, services, etc.
The code I wrote calls a ...
9
votes
7answers
3k views
How does throwing an ArgumentNullException help?
Let's say I have a method:
public void DoSomething(ISomeInterface someObject)
{
if(someObject == null) throw new ArgumentNullException("someObject");
someObject.DoThisOrThat();
}
I've been ...
19
votes
13answers
2k views
Why are null references shunned while throwing exceptions is considered okay?
I don't quite understand the consistent bashing of null references by some programming language folks. What's so bad about them? If I request read access to a file that doesn't exist then I'm ...
3
votes
2answers
115 views
Best Way to Express Meta-Info on Missing Data?
I work in healthcare IT, reviewing data management processes of various observational studies. One problem I have repeatedly faced is the poorly encoded data, especially when some values are missing.
...
7
votes
9answers
6k views
Best way to handle nulls in Java?
I have some code that is failing because of NullPointerException. A method is being called on the object where the object does not exist.
However, this led me to think about the best way to fix ...
5
votes
10answers
1k views
Property-coalescing operator for C#
The null-coalescing operator in c# allows you to shorten the code
if (_mywidget == null)
return new Widget();
else
return _mywidget;
Down to:
return _mywidget ?? new Widget();
I ...
4
votes
8answers
1k views
How will you handle NULL values in your application?
At what level do you prefer to handle Null values in your application?
My personal preference at the moment is the DB. When I build a view, I ensure that I return a value in place of a NULL value. So ...