Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6327319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:15:23+00:00 2026-05-24T17:15:23+00:00

The thing that really bothers me the most about some programming languages (e.g. C#,

  • 0

The thing that really bothers me the most about some programming languages (e.g. C#, Javascript) is that trying to access a property of null causes an error or exception to occur.

For example, in the following code snippet,

foo = bar.baz;

if bar is null, C# will throw a nasty NullReferenceException and my Javascript interpreter will complain with Unable to get value of the property 'baz': object is null or undefined.

I can understand this, in theory, but in real code I often have somewhat deep objects, like

foo.bar.baz.qux

and if any among foo, bar, or baz is null, my codes are broken. 🙁 Further, if I evaluate the following expressions in a console, there seem to be inconsistent results:

true.toString() //evaluates to "true"
false.toString() //evaluates to "false"
null.toString() //should evaluate to "null", but interpreter spits in your face instead

I absolutely despise writing code to handle this problem, because it is always verbose, smelly code. The following are not contrived examples, I grabbed these from one of my projects (the first is in Javascript, the second is in C#):

if (!(solvedPuzzles && 
      solvedPuzzles[difficulty] && 
      solvedPuzzles[difficulty][index])) {
      return undefined;
   }
return solvedPuzzles[difficulty][index].star

and

if (context != null &&
   context.Request != null &&
   context.Request.Cookies != null &&
   context.Request.Cookies["SessionID"] != null) 
{
   SessionID = context.Request.Cookies["SessionID"].Value;
}
else
{
   SessionID = null;
}

Things would be so much easier if the whole expression returned null if any one of the properties was null. The above code examples could have been so much simpler:

return solvedPuzzles[difficulty][index].star;
    //Will return null if solvedPuzzles, difficulty, index, or star is null.

SessionID = context.Request.Cookies["SessionID"].Value;
    //SessionID will be null if the context, Request, Cookies, 
    //Cookies["SessionID"], or Value is null.

Is there something I’m missing? Why don’t these languages use this behavior instead? Is it hard to implement for some reason? Would it cause problems that I’m overlooking?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:15:24+00:00Added an answer on May 24, 2026 at 5:15 pm

    Would it cause problems that I’m overlooking?

    Yes – it would cause the problem where you expect there to be non-null values, but due to a bug, you’ve got a null value. In that situation you want an exception. Failing silently and keeping going with bad data is a really bad idea.

    Some languages (such as Groovy) provide a null-safe dereference operator which can help. In C# it might look something like:

    SessionID = context?.Request?.Cookies?["SessionID"]?.Value;
    

    I believe the C# team have considered this in the past and found it problematic, but that doesn’t mean they won’t revisit it in the future of course.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One thing that really bothers me about Google Code is that fact that it
One thing that really interests me that I don’t see much written about or
I used to work in JavaScript a lot and one thing that really bothered
There is one thing I really love about LXML, and that the E builder.
One thing that's really been making life difficult in getting up to speed on
I have a kind of strange thing that I really nead for my text
I'm considering dumping boost as a dependency... atm the only thing that I really
i didn't really know how to title this question, but here's a thing that
It's really simple, I just want one screen. Wow, that [shiny thing] must have
it's a really weird thing - i have a website that works perfectly in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.