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

learn more… | top users | synonyms

5
votes
4answers
706 views

Generic Null/Empty check for each property of a class

I have created a method to check for null/empty values of class properties and if any null property is found I'm stopping the checking process and returning the result as true. I'm used a solution ...
5
votes
2answers
408 views

An attempt to make a linked list iterator “safe”

I was practicing my C++ routine and decided to code up this simple linked list data structure. Furthermore, I made an attempt to make the list iterator "safe" in the sense that it throws an exception ...
1
vote
4answers
149 views

Calling a function on an object if not null

Here is code for check null in object: ...
2
votes
2answers
39 views

Pythonic way to convert XML attribute to float, or else get None

My Python code is converting XML attributes in an ElementTree to appropriate values. How do I best convert a value in this dict to a ...
7
votes
4answers
807 views

Inserting a DBNull value into a database

I have code which works pretty well. I just need some of your opinions on how to write it better with fewer line of code. I want to use a ternary operator but I couldn't make it work so I did an ...
6
votes
1answer
108 views

Tomorrow: rainy with a chance of null objects

In an attempt to hide from the sun outside, I gave the community challenge "Rainfall" a try. Code here, specific questions below. ...
3
votes
2answers
63 views

C# enumerable property like .Any that accounts for nulls

Brief Description: A generic extension method that performs the same function as IEnumerable.Any(), but does not throw an error when passed a parameter with a <...
3
votes
1answer
52 views

Grabbing SQL records: Nullable bool to bool

So I have a method that does a lookup in an existing List<T>, populated elsewhere by grabbing the records from a SQL table holding configuration data for each ...
2
votes
2answers
83 views

Row-wise mean imputation in R

Someone on SO asked how to fill in the NA's with row means. His example code was: ...
1
vote
3answers
81 views

Instantiating a property when the required attributes have been set

I have a simple class which holds my product. Someone can add a serial to this product and also a purchase id. On change of the properties, I want to check whether both properties are set, and get the ...
1
vote
1answer
223 views

Validating that only certain values are unset

I am checking data output in some testing code, and only some fields can be None, but I think this can be better: ...
1
vote
1answer
122 views

Rails Grape API Endpoint optional params validation in update

I have the following rails grape api endpoint in the users resource: ...
2
votes
1answer
58 views

Avoiding “warning: Use of uninitialized value” when fetching an integer CGI parameter

I was using this code to fetch a CGI parameter: $page = int(param('page')); This sometimes results in: ...
2
votes
2answers
67 views

Custom map on `Array`

I have the following problem: Given an Array, apply a certain method x to each Array ...
2
votes
4answers
64 views

Throwing exceptions if there is not exactly one box retrieved

(Note: this is originally posted as this SO question ) I'm trying to refactor the error logging and exception throwing into a method. Original code: ...
1
vote
1answer
190 views

Merging two hashes with the mean values of each key if both hashes exist

There are two methods, hash1 and hash2, that return hashes or nil. The hashes have the same ...
4
votes
3answers
192 views

Sort array of hashes with nil values last

I wrote a method which sorts an array of hashes by given hash keys. The method should put nil values at the end. ...
3
votes
1answer
152 views

Getting JSON data from an HTTP response using conditional binding

I am new to Swift and I am trying to use the optional binding feature in as efficient way as possible but I am a bit confused on how to use it (if I can) in this scenario: ...
0
votes
0answers
47 views

LINQ SQL query to display the status of tracked computers

This is my existing LINQ SQL. At the moment it works, however the using the coalescing operator for null results on the "let" clauses make me feel like I'm violating some sort of unwritten rule. Is ...
0
votes
4answers
66 views

iOS SDK object to represent a place

I am building an iOS SDK to be consumed by apps. I am building an object that represents a physical place. The interface looks like so: ...
3
votes
3answers
117 views

Add the first non-null item from one list to another list

Given these two methods, is it defensible that one is better than the other? In what terms? Performance? Elegance? Readability? ...
1
vote
1answer
72 views

Constructing query conditions from answers that may be null

I was thinking about this after recently reading about the new Null Conditional Operators in C# 6.0. So here is my code that I am currently working on... ...
-1
votes
3answers
228 views

Nullable boolean value with property

Our Sonar code analysis server tells me Boolean literals should not be redundant. Redundant Boolean literals should be removed from expressions to improve readability. Tag: Clumsy and ...
2
votes
0answers
60 views

Extracting data for a tag cloud using Lazy.js

I've just started using Lazy.js, which is my first exposure to a "functional style" javascript library. I'm still utterly lost as to which of the hundred different functional javascript libraries to ...
4
votes
2answers
70 views

Conditional logic to determine if popup menu should be visible

I have this small piece of code written in a class. I am looking for a nicer way to write this, preferably avoiding nested if statements like what I currently have: ...
2
votes
0answers
93 views

Improved NullGuard v4 that supports property chains, methods and ignores value types

While working on my simple NullGuard recently I quickly came to the conclusion that this is not enough so I build a more advanced null checking. Once again I ...
6
votes
1answer
114 views

NullGuard for throwing more informative exceptions

This small utility class is my solution for a more convenient way for checking against null. I also wanted to have more informative NullReferenceExceptions but I ...
2
votes
1answer
111 views

Ignore nil values and unwrap optionals returning the value as the wrapped type

My primary concern is that this has been written as a global function. I think it would be better if this was a function of the SignalProducer class but I am not ...
10
votes
3answers
1k views

“Suspicious comparison of integer references” while checking for a monotonically increasing sequence

I have the following code which iterates on an Integer[] and makes sure that the the values in the array are in ascending order and that there are no neighbouring ...
0
votes
3answers
66 views

Validation null values (preconditions)

I would like to know an alternative, more elegant way to write the following methods. I am especially not enthusiastic of the nested if statement or ...
1
vote
2answers
92 views

Reducing code complexity for UsergridClient constructor

I'm initializing a class in JavaScript with a bunch of complex property checks. Codacy is showing that this is bad design and recommends reducing cyclomatic complexity. I'm at a loss for how to ...
5
votes
1answer
354 views

Two overloaded methods to move an e-mail message to another mailbox folder

I have an API for managing an email mailbox. There is a class called Message, and it has two Move overloads: ...
2
votes
1answer
76 views

Check if objects have coordinates

Here's a function: ...
5
votes
3answers
252 views

Avoid printing attributes of the nil object in Rails

Currently, when I'm wanting to print a value for my class I do the following... <%= @person.team.name if @person.team.present? %> This seems really ...
0
votes
0answers
44 views

Extracting path of first parameter, if it exists

I have the following code: ...
5
votes
1answer
510 views

Filtering out empty Optionals

I want to convert my list of optional strings to a list of strings by getting rid of the empty Optionals Is there a shorter version for achieving this than the following code (except statically ...
1
vote
1answer
51 views

Null check when enabling Up navigation in Android

This upvoted SO answer and this upvoted SO answer both check for null in a similar way: they call a function in the if or assert ...
4
votes
2answers
163 views

Treat undef in Perl's <=> operator as +inf instead of 0

I have to sort some numbers with Perl. But some of the numbers are undefined. Perl's compare operator <=> treats undef as -...
5
votes
3answers
295 views

Checking for an undefined nested variable in a JS object

Is there a better or shorthand way to perform a check on whether or not a variable within (possibly several levels of) an object is null or undefined? What I would currently do to check is: ...
6
votes
2answers
157 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
591 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 ...
1
vote
2answers
1k 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
815 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
71 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 ...
12
votes
3answers
6k 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
75 views

Return array or null result for application of a command to a list

I have such method: ...
6
votes
1answer
270 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
92 views

Handle NullValueInNestedPathException

I am looking for a elegant solution to this. I am new to Spring framework. I have a method: ...
2
votes
2answers
12k 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
169 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 "...