Click here to Skip to main content
15,922,696 members
Home / Discussions / C#
   

C#

 
AnswerRe: related to crystal report Pin
karthiknss29-Oct-09 22:42
karthiknss29-Oct-09 22:42 
GeneralRe: related to crystal report Pin
NarendraSinghJTV1-Nov-09 23:06
NarendraSinghJTV1-Nov-09 23:06 
QuestionNULLABLE type Pin
RINSON VARGHESE28-Oct-09 2:48
RINSON VARGHESE28-Oct-09 2:48 
AnswerRe: NULLABLE type Pin
Keith Barrow28-Oct-09 2:55
professionalKeith Barrow28-Oct-09 2:55 
AnswerRe: NULLABLE type Pin
Abhishek Sur28-Oct-09 3:31
professionalAbhishek Sur28-Oct-09 3:31 
AnswerRe: NULLABLE type Pin
Keith Barrow28-Oct-09 4:17
professionalKeith Barrow28-Oct-09 4:17 
GeneralRe: NULLABLE type Pin
Abhishek Sur28-Oct-09 5:13
professionalAbhishek Sur28-Oct-09 5:13 
GeneralRe: NULLABLE type Pin
vtchris-peterson28-Oct-09 5:34
vtchris-peterson28-Oct-09 5:34 
GeneralRe: NULLABLE type Pin
Keith Barrow28-Oct-09 5:56
professionalKeith Barrow28-Oct-09 5:56 
GeneralRe: NULLABLE type Pin
Rick Shaub28-Oct-09 8:11
Rick Shaub28-Oct-09 8:11 
GeneralRe: NULLABLE type Pin
Keith Barrow28-Oct-09 14:38
professionalKeith Barrow28-Oct-09 14:38 
GeneralRe: NULLABLE type Pin
vtchris-peterson28-Oct-09 10:02
vtchris-peterson28-Oct-09 10:02 
GeneralRe: NULLABLE type Pin
Keith Barrow28-Oct-09 14:25
professionalKeith Barrow28-Oct-09 14:25 
vtpdawg wrote:
I don't see how if (val == -1) is much different than if (val == null)


Of course, if you take this as an example there is little difference. Consider the example of the number indicating a "status" of some kind to display on the UI. One implementation (albeit artificial and not necessarily the best) would be to reference with number with a dictionary:

Dictionary <int,string> lookup;

public void SetupLookup()
{
  lookup = new Dictionary <int,string>();
  lookup.Add(-1, "Unkown");
  lookup.Add(0,"Naughty");
  lookup.Add(1, "Nice");
}

//This is the "clean" non-nullable example 
public void string Lookup(int foo)
{
  return lookup[foo];
}

//This is less clean nullable example, for this example the -1 key in the dictionary is not needed.... 
public void string Lookup2(int& foo)
{
  if(foo.HasValue)
    return lookup[foo];
  return "Unknown";
}


This example isn't perfect, but serves to illustrate the point. Now, we need to handle the null properly in the nullable type case . Once you decide to put the nullable type in, this sort of checking necessarily propagates throughout the code if the code is written to be robust. Additionally, there are fewer problems binding non-nullable types as you can (as in the above example) resolve -1 to something directly.


vtpdawg wrote:
You mention "rogue nulls hanging around" like they're some loitering punks harassing passerbys


In a database context, this is exactly what they are like. Smile | :)


vtpdawg wrote:

null is not something to be feared, the prudent developer should just be in the practice of always considering null when dereferencing objects.


Agreed, but it is surely better to factor these out by design? One of the things I don't like about c# is the fact that objects are nullable by default (unlike c++) because we have to write a boilerplate code to allow for this.

The point I was trying to get across was just that nulls are best avoided and rarely needed, not that nulls should never be used. There are good counter arguments to everything I have said here, many of which I have sympathy with, it's opinion that the arguments in favour of avoiding nulls outweigh these (Others of course disagree!).

CCC solved so far: 2 (including a Hard One!)

GeneralRe: NULLABLE type Pin
vtchris-peterson28-Oct-09 14:53
vtchris-peterson28-Oct-09 14:53 
GeneralRe: NULLABLE type Pin
Keith Barrow29-Oct-09 0:17
professionalKeith Barrow29-Oct-09 0:17 
GeneralRe: NULLABLE type Pin
vtchris-peterson29-Oct-09 4:10
vtchris-peterson29-Oct-09 4:10 
GeneralRe: NULLABLE type Pin
Keith Barrow29-Oct-09 5:14
professionalKeith Barrow29-Oct-09 5:14 
GeneralRe: NULLABLE type Pin
Mycroft Holmes28-Oct-09 14:53
professionalMycroft Holmes28-Oct-09 14:53 
GeneralRe: NULLABLE type Pin
Keith Barrow29-Oct-09 0:20
professionalKeith Barrow29-Oct-09 0:20 
QuestionOutlining option is not coming on right clicking in text Pin
abcurl28-Oct-09 2:19
abcurl28-Oct-09 2:19 
AnswerRe: Outlining option is not coming on right clicking in text Pin
Abhishek Sur28-Oct-09 3:31
professionalAbhishek Sur28-Oct-09 3:31 
AnswerRe: Outlining option is not coming on right clicking in text Pin
Richard MacCutchan28-Oct-09 4:02
mveRichard MacCutchan28-Oct-09 4:02 
QuestionRe: Outlining option is not coming on right clicking in text Pin
abcurl28-Oct-09 4:19
abcurl28-Oct-09 4:19 
GeneralRe: Outlining option is not coming on right clicking in text Pin
Richard MacCutchan28-Oct-09 4:52
mveRichard MacCutchan28-Oct-09 4:52 
QuestionRegular Expression Find And Replace ? Pin
Jacobb Michael28-Oct-09 2:10
Jacobb Michael28-Oct-09 2:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.