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 7010707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:01:46+00:00 2026-05-27T22:01:46+00:00

I’m not really into type-safety as a concept but many consider it important for

  • 0

I’m not really into type-safety as a concept but many consider it important for well written code and think that for some of the most important factors such as for code to scale well, be reusable, be robust etc… it needs to be type safe.

Languages like C# take type-safety seriously, they are statically typed and generics in C# are considerably more typesafe than C++ templates. Even ArrayList which is considered not as typesafe as List<> being that it is a List<object> is much more typesafe than for example a List<dynamic>, which I think should be possible but is certainly obscure.

However I wonder, again using C# as an example why there is still null. I like and approve of null but it’s not in keeping with the type safety of the rest of the language.

Perhaps in some respects ‘null’ improves performance preventing everything needing to be constructed by default but it also requires extra time-consuming runtime checking for the computer to throw null exceptions and the such.

String s = null;
int n = s.Length; // error like a type error, even if technically it isn't
  • 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-27T22:01:46+00:00Added an answer on May 27, 2026 at 10:01 pm

    I’m not really into type-safety as a concept

    Maybe you should be.

    for code to scale well, be reusable, be robust etc… it needs to be type safe.

    I don’t think it needs to be type safe, though it surely does help. Lots of people write code in C++, a language which has relatively weak type safety (because pointers can be converted to and from arbitrary integers). Nevertheless, C++ is also a language which has been designed to encourage code reuse via robust code encapsulated in classes.

    Also, don’t confuse static type checking with type safety. Some would argue that dynamically-checked languages are every bit as “type safe”; they just do their type system verifications at runtime instead of compile time.

    Langueges like C# take type-safety seriously

    Indeed.

    generics in C# are considerably more typesafe than C++ templates.

    I don’t see any evidence for this assertion. Type checking on generics is different than type checking on templates, but both are type checked. The fundamental difference is that a generic assumes that any type that meets the constraints could be the type argument and therefore requires the program to pass static type checking for any possible type argument. Templates on the other hand only require the type arguments that you actually use to pass static type checking.

    Even ArrayList which is considered not as typesafe as List<T> being that it is a List<object> is much more typesafe than for example a List<dynamic>, which I think should be possible but is certainly obscure.

    Well, dynamic is an interesting case. Like I said before, dynamic basically means “move the type checking of this thing to runtime”.

    I wonder why, again using C# as an example there is still null. I can see how in some respects it is faster than ensuring everything is constructed by default but isn’t it a huge type-safety issue

    You are right to raise this concern; nulls do throw a difficult problem at the type checker. One would like a statically-typed language to be “memory safe” — to ensure that no invalid bit pattern ever makes its way into a variable annotated with a particular type. C# (outside of the unsafe subset) achieves this goal except that the all-zero null reference bit pattern is always legal in a variable annotated with a reference type, even though that bit pattern refers to no valid object.

    You can certainly come up with languages that do not have null references and are statically type checked; Haskell is a good example. Why not do the same in C#?

    Historical reasons. Null references are very useful, despite their dangers, and C# comes out of a long tradition of programming languages which allow null references.

    I personally would have preferred it if we’d baked nullability into the framework from day one, so that you could have nullable or non-nullable value types, and nullable or non-nullable reference types. Remember that the next time you design a type system from scratch.

    also requires extra time-consuming runtime checking for the computer to throw null exceptions and the such

    That’s actually not that bad. The way these things are usually implemented is the virtual memory page that contains the null pointer is marked as not readable, writable or executable. An attempt to do so then results in an exception raised by the hardware. And even in the cases where you do have to do a null check, comparing a register to zero is pretty quick.

    There are worse problems. For example, arrays aren’t “type safe” either in the sense that you can’t statically type check whether a program is guaranteed to access only valid indices of an array. The CLR does a lot of work to make sure that every array access is valid.

    Unsafe array covariance is also problematic; this is a bona-fide problem with the type system. We have to do type checks every time you write an element of a more-derived type to an array of its base type. That’s my candidate for “worst feature” of the CLR.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.