question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

null should be supplied for missing values - not an empty string

See original GitHub issue

Consider:

class MyOptions
{
    public MyOptions(string foo)
    {
    }

    [Option(Required=false)]
    public string Foo {get;}
}

If I don’t specify foo on the command line, it’s going to be provided as an empty string ("") in the constructor. It really should be null instead, both logically and to differentiate against an actual empty string parameter.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
vesuviancommented, Nov 12, 2020

Google landed me here because I’m running into the same Enumerable null default problem as Adhara3.

My two cents: I think null is descriptive in saying “this option was not used” rather than “the user provided no parameters for this option”. Checking for null is totally safe, whereas checking for .Any() could show warnings about multiple enumeration.

Providing a Default parameter and then not obeying that is really unhelpful. It would be helpful if an exception was thrown for null because it at least clarifies the intended behaviour, but I’d prefer if null was handled properly and an exception only be thrown if the property type is non-nullable.

2reactions
ericnewton76commented, Dec 4, 2017

I believe the change falls in line with least surprise principal. I tried to investigate when a string.empty got substituted for null in the first place and couldnt find a logical reason why. Perhaps its related to F#?

This pull request seems fine to me. We’ll see if a rash of F# guys come beating down our doors 😄 We’ll point them in this direction and to explain how to somehow manage F# compliance with the existing CLS compliant languages

I watched a demo about domain driven design with F# and there was some (initially contrived) decently good reasons for using F# over others.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Insert empty string in Oracle [duplicate] - sql
In Oracle, an empty string is equivalent to NULL . ... Note that in SQL, NULL represents an unknown value, not an empty...
Read more >
Use empty string, null or remove empty property in API ...
I would supply null in a situation where I want to explicitly say "no, this data is not there". And omit the key...
Read more >
When storing missing data, should I store them as NULL?
It's possible to convert an empty string to a NULL value using update, PROVIDED WHEN THE TABLE WAS CREATED NOT NULL CONSTRAINT WASN'T...
Read more >
Comparing the Semantics of Null, Zero, and Empty String ...
An empty value would imply that the person does not have a cell phone, whereas a NULL would signify that he or she...
Read more >
Question - FME Community - Safe Software
I'm trying to parse a date field, but it's not parsing the Nulls/Empty/Missing entries despite being selected to.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found