This tag should be used for questions where you are handling null variables or values.

learn more… | top users | synonyms

6
votes
2answers
135 views

A possibly-terrible alternative to conditionals full of null checks

I am always super annoyed when I have to write a bunch of if statements whenever I have to traverse an object graph of possibly null objects. As there is not yet a ...
3
votes
1answer
49 views

Set a font for a UITextView if the font is nil or not equal to desired font

Main question I am setting a font for a UITextView that is a subview in a custom view. I only set it if the user didn't specify the font size in the Interface Builder. I have the following working ...
0
votes
1answer
53 views

Sorting object with null values underscore sortBy

I'm sorting my object by its property ActivityOrder, which will sometimes contain null values if the user has not explicitly ...
7
votes
3answers
347 views

Comparing two objects having two nullable date fields

ExpiryDates has two properties PSL_ExpiryDate and MNL_ExpiryDate of type nullable date. I am ...
-4
votes
1answer
59 views

Determining request status

This code gets request status based on request type and some mapping info. I'm wondering if there is a way to write nice conditional expressions in if statement. Expression should test if ...
10
votes
3answers
703 views

Constructing a query string using StringBuilder

I speedily wrote a bunch of crappy checks, to check whether strings are empty, in order to build a query string. ...
-1
votes
3answers
42 views
6
votes
1answer
69 views

Detecting gyroscope data using promises

In a plugin that I am currently authoring, I am using a function to check whether the device provides gyroscopic data. Although intuitively this can be easily resolved by checking the value of ...
2
votes
1answer
49 views

Handle NullValueInNestedPathException

I am looking for a elegant solution to this. I am new to Spring framework. I have a method: ...
1
vote
2answers
1k views

Check for null/empty in dictionary

I am doing the following about 10 times with other strings, so the code is duplicated. How can I refactor this? queryWhere is a ...
5
votes
1answer
121 views

Multiple functions to establish a fallback value for a property until not null

I have a property (called "Head") that can be set externally. When "Head" is not set, it uses Unity3D's MonoBehaviour functions to try to find the best value for ...
2
votes
1answer
169 views

Maybe getting a character from a list of strings

I'm trying to transition from JavaScript to PureScript (a Haskell spinoff that transpiles to JavaScript). For starters I coded this: ...
4
votes
2answers
118 views

Verifying value before parsing

I am writing some Java code and am coming across a try/catch block in which I decided to verify the value is not null before parsing it: ...
1
vote
1answer
28 views

Argument order with default value

I have a library with two methods: one takes an object and vararg strings, the other takes a default value as well. They are currently implemented as: ...
3
votes
1answer
31 views

Return most recent non null field values for multiple unknown fields

I am attempting to create a stored procedure that looks at one table and imports changes in that table to another. This stored procedure is going to be preformed on multiple source tables and will ...
3
votes
1answer
41 views

Returning the next node

What is considered to be a good programming practice for returning value from the function? For example, if we have a function in C named ...
5
votes
2answers
1k views

C# approach to prevent null references in strings

My insight here is that it's usually not useful to distinguish between null and empty strings. Sometimes it is, but usually not. Usually I like to assign my strings ...
2
votes
0answers
43 views

Basic Binary Tree in Go

As an exercise I have written a basic binary tree implementation in Go. Tree struct: ...
8
votes
2answers
104 views

Making Multiple Copies of a Pattern

Here's a function for making multiple copies of a block of memory in another block of memory. It handles the case when the size of the target is smaller than or not a perfect multiple of the source ...
3
votes
1answer
77 views

Implementing a binary operation for the null object pattern

Today I needed to implement a class for representing rectangular regions with some binary operations such as merging or intersection. ...
4
votes
3answers
163 views

Classifying rows of data by the number of days to close

DataTable looks like below I would like to simplify this code in a better manner. ...
5
votes
2answers
153 views

Detecting change of a name or a part

We have a fair amount of code which looks like this: ...
2
votes
2answers
211 views

Gather first letter from each string in a list of strings

I'm learning Haskell on my own, and I'm wondering if this is idiomatic Haskell. In particular: is it a common pattern to "wrap" the result in a list in order to make a function total? (that's what I ...
6
votes
2answers
7k views

Check if any of class properties is not null/empty/was assigned

I have a class that I use to display on a web page fieldset. However, all of the properties of this class are optionally filled in by the user, which means all of them could be null/default. In this ...
12
votes
8answers
2k views

IsNullOrWhiteSpace check for Java

I am needing to write my own IsNullOrWhiteSpace check for Java but am wondering if this is the best method to do so ...
1
vote
4answers
60 views

Defaulting parameters to false

In my rails controllers, I am consistently using this logic: ...
3
votes
1answer
60 views

MySQL case statement with two tables

How can I improve the following working SQL statement for better performance and consistency? ...
0
votes
3answers
3k views

Cast an object to Decimal? or Int? etc but leave it as null if it is null

In a case like this: object A1 = null; Decimal? B = Convert.ToDecimal(A1); object A2 = null; int? C = Convert.ToInt32(A2); Note that in case where ...
7
votes
2answers
201 views

Use different contructors of disposable class

I have a very simple helper class to validate credentials. Sometimes the domain has a value, sometimes not. Depending on this, a different constructor for ...
2
votes
2answers
69 views

Assign Specific Value If BitField Is True

My colleague created this SQL to handle certain user selections which are based on an on/off bit flag. The goal is to identify those individual bit flags with a specific integer which will be used in ...
11
votes
4answers
1k views

Writing null-safe code to set form values

I will ask my question using the following example: HTML ...
3
votes
1answer
68 views

Correct practice for Python properties that depend on other attributes

When a property is essentially a boolean value for whether or not an attribute exists or is set a certain way, is it more appropriate to create an object that does not list the option attribute in its ...
5
votes
4answers
396 views

NULL-eating / elimination version of fgets() in C

I've come up with the following routine to read data from a file stream, but I don't want any NULLs in the stream to terminate the string early. This function will ...
0
votes
1answer
89 views

Checking a value before assigning it to variable

Throughout my code, I find myself testing if the output of a function is undefined or blank before i use the output. In this case, getQuery checks if the property of an object is either blank or if ...
7
votes
3answers
195 views

Creating check parameter class instead of repetitive null checks

What I'm trying to accomplish is to have a error checking class mostly to check if parameters that are pass null but also data structures within class are not null. So my thought is a clean static ...
7
votes
3answers
188 views

Too many null checks in an XML-to-XML transformation

I'm writing a conversion mechanism in C#. I deserialize a big XML document of one type and return a big XML document of another type (via serialization of another object). While I'm doing the ...
1
vote
1answer
945 views

Null checking in nested getter calls [closed]

I have the following piece of code and I would like to see what different approaches would be to solve that in a more elegant way. The thing is that I don't know whether is better to have the null ...
6
votes
2answers
1k views

Writing a generic performance efficient isEmpty method which can check for null or emptiness

I am writing a utility method which can check for empty and null string, or collection or an object or any general types - ...
2
votes
2answers
166 views

Using Common Table Expression and Outer queries

In following query I'm use both Common Table Expression and Outer queries. Apparently both looks same to me. If I summarize my requirement, I have employees in ...
7
votes
1answer
888 views

Getting matching items in lists based on nullable properties

I'm iterating through two lists to find matching objects. The objects have two string properties, Id1 and Id2 below. If ...
10
votes
1answer
205 views

Organization data class

I believe I have made the following data class quite decently, and I'd like a thorough review on it. The code is built on Java 8 and uses the Builder and Serialization Proxy pattern, it is used to ...
4
votes
1answer
170 views

Is checking for null redundant while using Contract Annotator from JetBrains?

I'm curious whether checking for null is redundant in this concrete example. ...
7
votes
2answers
236 views

PHP isset over use? Good or bad?

First, I'm in no way an experienced PHP coder. This is my 5th time working with PHP, so if you see anything that can bee improve, please point them out for me. I have the code checking for the ...
3
votes
2answers
228 views

Duplication with nested null checks

How can I improve this code with nested null check statements? ...
6
votes
2answers
152 views

Inventory check with too many else-ifs

I am using if else statements: ...
1
vote
1answer
156 views

Alternative to null check after DOM traversal?

I have this code working, but I'm not sure if it's the best way to write it. I was watching a JS talk on Maintainable JavaScript, and saw that I probably shouldn't be comparing my element to null, ...
14
votes
2answers
1k views

Using finally with return statement or not

I was wondering if it is the proper way to always put the return statement of a function with a try-catch clause in the finally ...
1
vote
2answers
45 views

Domain object toString null check

Following advice to "Make good use of toString() for all Domain classes", I made what I thought was the most useful toString ...
6
votes
2answers
310 views

How do I better structure Java code to avoid dereferencing null? [closed]

I have the situation where as long as the user gives valid input, the StringBuilder object will not be null. ...
5
votes
2answers
3k views

Extension method to return a default value for any null value

I'm creating an extension method that can be used on any type. The idea is that if this method is called, it checks if value is null. If null, it needs to return a default instance of the specified ...