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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:43:40+00:00 2026-06-06T19:43:40+00:00

Let’s say I have double length that can be either a real length or

  • 0

Let’s say I have double length that can be either a real length or not ready yet since we got no length yet in the server and there is nothing to send to the client. We need to pass this length from the server to the client as part of a fixed data protocol. The client currently uses the length only once, but might use it more than that in the future.

  1. Pass double length and bool isLengthValid, and in every place you use length, check if isLengthValid
    -Clean design without mixing data types but user have to remember to check

  2. Pass double? length, and in every place you use length, check if length==null
    -Design is clear (since it’s a nullable) but if you look and the type. Also – there will be an exception if someone uses without checking (good and bad, depends how you look at it)

  3. Make a class Length instead of double. The class will have a clear interface of GetLengthIfYouCheckedIt or something.
    Very readable and hard to make mistakes but design is a little over done.

What is your solution?

  • 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-06-06T19:43:42+00:00Added an answer on June 6, 2026 at 7:43 pm

    I say option2:

    • What you want is precisely why nullables were introduced.
    • Instead of adding a method to check wether it’s a valid number or not, you’d use the built-in Nullable<double>.HasValue, just as it was meant for it.
    • Making a class for Length makes it doubly closed: it’s only for LENGTH and it holds a Double. Think of how many of such classes you’ll have to make and maintain for TIME/DateTime, MONEY/Decimal etc. It will never end.
    • The option 1 is just your own rolled Nullable<T> rewrapped with another name.

    In other words, enforce the DRY principle, and use Nullable<T> 😉

    HTH,

    Bab.

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

Sidebar

Related Questions

Let's say I have a Car class in a game that can be played
Let's say I have two maps: typedef int Id; std::map<Id, std::string> idToStringMap; std::map<Id, double>
Let say i have some words AB, AAB, AA. AB is not a prefix
Let's say we have this kind of loop (pseudocode) double d = 0.0 for
Let's say I have a number (e.g. double) and transform it using some format
Let's say I have some code that does some floating point arithmetic and stores
Let's say I have a class Point : class Point { public double? x,
Let's say I have the following code: protected void ReservationForm() { double x =
Let say we have two arrays: DateTime[] wDates = new DateTime[20000]; double[] wValues =
let's say I have a class that does some calculations. This set of calculations

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.