Click here to Skip to main content
15,906,567 members
Home / Discussions / C#
   

C#

 
GeneralRe: Named Pipe reading very slowly Pin
akhanal28-Oct-09 11:21
akhanal28-Oct-09 11:21 
GeneralRe: Named Pipe reading very slowly Pin
Paulo Zemek29-Oct-09 1:11
Paulo Zemek29-Oct-09 1:11 
Question"View Only" mode for WebBrowser class? Pin
Matthew Klein28-Oct-09 6:03
Matthew Klein28-Oct-09 6:03 
AnswerRe: "View Only" mode for WebBrowser class? Pin
EliottA28-Oct-09 6:45
EliottA28-Oct-09 6:45 
GeneralRe: "View Only" mode for WebBrowser class? Pin
Matthew Klein28-Oct-09 7:50
Matthew Klein28-Oct-09 7:50 
GeneralRe: "View Only" mode for WebBrowser class? Pin
EliottA28-Oct-09 8:43
EliottA28-Oct-09 8:43 
QuestionDeveloping LogonUI With C# ? Pin
Sehlor28-Oct-09 4:27
Sehlor28-Oct-09 4:27 
AnswerRe: Developing LogonUI With C# ? Pin
Abhishek Sur28-Oct-09 5:19
professionalAbhishek Sur28-Oct-09 5:19 
Questionrelated to crystal report Pin
NarendraSinghJTV28-Oct-09 3:31
NarendraSinghJTV28-Oct-09 3:31 
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 

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.