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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:01:26+00:00 2026-05-15T13:01:26+00:00

I envisage the ability to write fluent code that adds meaning to numbers within

  • 0

I envisage the ability to write fluent code that adds meaning to numbers within codebases. Say you wanted a number to represent a distance in miles. You’d have something like:

Usage:

var result = myMethod(100.Miles());

I think this would be much more readable than simply passing in the int, plus you could presumably apply bounds checking to the Miles type.

Extension method and struct implementation:

static class IntExtensions
{
  public static Miles(this int i) { get { return new Miles { Count = i }; } }
}

public struct Miles
{ 
  public int Count { get; private set; } //optionally perform bounds checking
} 

Would such an idea be useful, or is it too late on a hot Friday?

Edit: Yes, doesn’t look quite so neat without extension properties… Apologies for the rushed invalid code. It was just an idea.

  • 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-15T13:01:27+00:00Added an answer on May 15, 2026 at 1:01 pm

    It’s an interesting idea, but I would ask for a really strong use case before doing something like this. For one thing, once a number is cast as a “mile”, you can no longer treat it as an int. You either have to implement the whole gamut of operators, or cast the miles back to integers before performing arithmetic on them. It’s a lot of extra work if there’s no good reason to do it.

    There are some cases where this would be a good strategy, though. I think I remember hearing about a multi-million-dollar rocket or something that failed NASA once lost a $125 million space ship because programmers were passing the wrong units of measure into a function. This would help you to avoid that problem.

    On a related note, you might be interested in F#, which has built-in support for units of measure.

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

Sidebar

Related Questions

Scenario I have a line of code whereby I pass a good number of
Evening all :) I'm looking to create a Java web application. I envisage that
I am working on some code that impliments various features such as a PID
I have a number of classes that are decorated with DebuggerDisplayAttribute. I want to
I have a Python module that I would like to upload to PyPI. So
We have a dynamic languaging system that doesn't use conventional resource files; fetching resources
I've been thinking about creating a Java framework that would allow programmers to specify
Good morning, I have found that many of my customers have MS Access already
I have a list of classes, but different children have different properties that need
We have a very large GWT project that results in a monolithic app about

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.