Daeer-Projects / Converter.Temperature

The temperature convertions methods created as extension methods.
MIT License
3 stars 0 forks source link

README

Converter.Temperature This project was created to extract out the main conversion code from the Temperature Converter applications in the other repositories. I am using this as a way to show how my development skills have changed over the years, as I get to be a better developer.

Contributors Forks Stargazers Issues MIT License

Build Status

Table of Contents
  1. Introduction
  2. How to use the library
  3. Credits
  4. License
  5. Contributing
  6. Contact
  7. Testing

Introduction

These extension methods will convert different types of temperatures to other types.

Temperature types

Data types

Built With

This library is built using the following tech stacks.

How to get setup

The project is a Visual Studio solution (.sln).

  1. Fork, clone or download the repo.
  2. Open the solution in your favourite IDE (VS, Rider, VSCode, etc).
  3. Build the solution.
  4. Run the unit tests.

How to use the library

There are more details on the project wiki.

The details contained on the wiki are more comprehensive. This document is to show you how I decided the library should be consumed.

Ideas

To start with, I had a few ideas on how to do the extension methods but decided on using a fluent style. This is a common style used in development. I also think it looks nicer.

Originally, the extensions looked like this:

    var tempToConvert = 34; // an int.
    var convertedTemp = tempToConvert.CelsiusToFahrenheit();

Then I thought that this looked a bit naf so, I went with setting up the from first, then the to. This follows the fluent pattern.

Now it is used like this:

    var tempToConvert = 34; // an int.
    var convertedTemp = tempToConvert.FromCelsius().ToFahrenheit();

For version 2 I added an additional usage like this:

    var tempToConvert = 34; // an int.
    var convertedTemp = tempToConvert.From<Celsius>().To<Fahrenheit>();

Before you decide which one is best for you, don't forget to check the benchmark results here.

What to do for edge cases

I'm working on what I want the library to do when an exception could be thrown. This is when we have the edge cases of values that are too small or too large for the type being converted to.

E.g.:

From a float type with a value close to the max value of a float, converted from Celsius to Fahrenheit. Because a Fahrenheit value is greater than the celsius value, then we can't convert correctly.

Should this throw an exception or just return the original value?

Well, returning the same value would seem like all is well, even though the converted value is wrong. Thinking about this means that for me, it should throw an exception for the calling application to handle.

If anyone has any better ideas, then I would be willing to change this behaviour.

More Information

For more information on the project and where it is heading, see the wiki.

Credits

I am the sole creator of this library/project. However, I should credit "Google" and "Wikipedia" for helping with the conversion calculations.

Acknowledgements

License

This repo and library are using the MIT license.

Contributing

See the included Contributing File for more information.

Contact

David Clark - @CoderDaeer

Daeer-Projects - Daeer Projects

Testing

The project does have a unit test project that covers as much as possible of the code base.

There is also a benchmark project that shows how the conversions perform.

This will show more usages and examples of how to consume the library.