Tagged Questions

The tag has no wiki summary.

learn more… | top users | synonyms

7
votes
1answer
141 views

Null Object Pattern and Input validation - copy real implementation or silently accept everything?

I have a WifiComponent in my Camera in my client application. It's responsible for handling the Wifi-related functionality of the Camera. The Camera represents a real world camera. This WifiComponent ...
0
votes
1answer
83 views

Inheritance is a null property in the parent a bad practice?

I am not a very experienced programmer. So I ask. The field in question is the "Amount" field. I store an amount only in a couple levels of the derived class. The code is a slice of the POCO ...
2
votes
3answers
178 views

How to use Option Type Pattern in a language that doesn't support generics?

I've been interested to start using the Null Object / Option Type approach for replacing my old habits of null-checking multiple parts of my code. But, from the many examples I saw out there, it seems ...
4
votes
6answers
828 views

Is it bad practice to resolve null arguments to default static variables?

First, let me show you an example (written in ActionScript 3.0): class GameObject { public static function MakeFromName( pName:String, pAtlas:TextureAtlas ...
1
vote
4answers
235 views

How to ideally calculate profit margin with zero sales

How do you handle the following scenario without null? You have this problem (In Java): BigDecimal sales = ...; BigDecimal cost = ...; BigDecimal profit = sales.subtract(cost); // Profit Margin = ...
48
votes
5answers
4k views

How do languages with Maybe types instead of nulls handle edge conditions?

Eric Lippert made a very interesting point in his discussion of why C# uses a null rather than a Maybe<T> type: Consistency of the type system is important; can we always know that a ...
31
votes
10answers
7k views

If null is bad, why do modern languages implement it? [closed]

I'm sure designers of languages like Java or C# knew issues related to existence of null references (see Are null references really a bad thing?). Also implementing an option type isn't really much ...
1
vote
4answers
289 views

Alternatives to null values and option-like types

Related to this question i want to know if there is a concise way to eleminate null values out of code in general or if there is not. E.g. imagine a class that represents a user with birthday as ...
0
votes
1answer
63 views

What is the appropriate Data URI to use for 0-byte content?

I have a method that generates a data URI from a byte array. In the event the input byte array is empty, what is the appropriate thing for the method to do? Here are the options I see: return data:, ...
4
votes
4answers
2k views

Returning null or a empty value/throw exception? [duplicate]

Various programming books suggest that methods should not return null values (Clean Code for example). Instead of returning null default values (0 or empty string or empty object) should be returned ...
2
votes
2answers
134 views

Handling “unspecified” values in software

So I'm working on a software product where we have a number of fields that the customer can leave blank, some of which are numeric. To persist these in the database we use nullable columns. Easy ...
3
votes
4answers
792 views

Use null object as argument to method

Consider the following piece of code class Foo { public: //... bool valueFirstGet(int& value) const { if(this==nullptr) {return 0;} ...
25
votes
9answers
1k 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 ...
15
votes
4answers
2k 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
757 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
727 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
308 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
168 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
127 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
145 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
2answers
784 views

Does 'consider returning Null Object' apply to a DAO read method?

I was looking for an answer to the question of what a DAO should return when a search ends up to be for an entity that does not exist. There are some generic previous questions related to returning ...
5
votes
2answers
455 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 ...
8
votes
7answers
4k 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
364 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
573 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
977 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 ...
9
votes
2answers
4k 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 ...
13
votes
5answers
4k 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 ...
6
votes
6answers
10k 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. ...
27
votes
4answers
3k 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 ...
61
votes
14answers
9k 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 ...
54
votes
24answers
16k 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 ...
12
votes
3answers
3k 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 ...
17
votes
6answers
37k 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
2answers
306 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
3k 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
811 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 ...
11
votes
7answers
5k 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
3k 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
122 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
9k 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 ...
7
votes
10answers
2k 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
2k 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 ...
42
votes
11answers
41k views

SQL: empty string vs NULL value

I know this subject is a bit controversial and there are a lot of various articles/opinions floating around the internet. Unfortunatelly, most of them assume the person doesn't know what the ...