Code Monkey home page Code Monkey logo

Comments (4)

triplepoint avatar triplepoint commented on August 15, 2024

I'm not sure what you mean, what change to the constructor signature are you proposing? The interface for instantiating the object in your example seems the same as the current constructor; am I missing something?

Regardless, as far as the proposed change to allow for multiple conversions at once, I disagree that there's a need for it. How is it any better than:

$area = new Area(1000200.000304, 'm^2');
$actual = array();
foreach (array('km^2', 'm^2', 'cm^2', 'mm^2') as $to_unit ) {
    $actual[$to_unit] = $area->toUnit($to_unit);
}

Moving this sort of behavior into a library doesn't really gain any additional utility, and it adds costs in terms of library complexity and obscure interfaces.

I'd rather keep this library as straightforward as possible, unless there's a compelling need to add additional behavior. Does that make sense?

from php-units-of-measure.

scalopus avatar scalopus commented on August 15, 2024

Hi, it doesn't work like that because we don't have function to get modulation yet.

In my case 1.5 km should return as 1km + 500m (something like these) or 1.1 ft may return in 1 ft + 1/12 inches. or Time 86700 secs may return as 1 day + 5 minutes or 5100mg may return as 5g + 100 mg.

For my real usage (sorry, for example about Thai area unit), we use Rai (equals to 400 sq.m.) Ngan (equals to 100 sq.m.) and Sq.Wa (4 sq.m).

We don't say 401 sq.m. , we don't say 100.25 Sq. Wa. but we say 1 Rai + 0.25 Sq. Wa.

something like that.

I'm missing one part, in previously, I have put the fraction part as here
https://github.com/scalopus/php-units-of-measure/blob/master/source/PhpUnitsOfMeasure/UnitOfMeasure.php#L53

but your repository just merged #9 in the master here.
https://github.com/triplepoint/php-units-of-measure/blob/master/source/PhpUnitsOfMeasure/UnitOfMeasure.php#L53

so, I just think that it would be too long and complicate to method to add some more option to the constructor.

What I proposed is that may use something like

new UnitOfMeasure(array(
'from_native_unit ' => .....,
'to_native_unit' => ......,
'alias' => ......,
'fraction' => ......,
'translator' => .....,
etc...
));

because the multiple unit may not have to implement in all UnitOfMeasure (Like Temperature), so, I think that to make it as above, it will be like optional.

let me know if this kind of feature should be in this library.

from php-units-of-measure.

mauris avatar mauris commented on August 15, 2024

Actually I'm proposing more than this.

We can actually put all these into a definitions file and a loader will load the configuration. (maybe we can use packfire/config)

The units are not defined in the code, but in the definitions file.

from php-units-of-measure.

triplepoint avatar triplepoint commented on August 15, 2024

Ah, I'm sorry Scalopus, I misunderstood your first example. I see now what you're getting at.

It's a neat idea, but I think it's beyond the complexity limit that I'm willing to entertain for this project. I'd encourage you to explore this idea in a separate library, maybe using this one internally to do some of the conversions?

from php-units-of-measure.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.