null should be supplied for missing values - not an empty string
See original GitHub issueConsider:
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:
- Created 6 years ago
- Reactions:1
- Comments:14 (9 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.