Coder Social home page Coder Social logo

No readability-improving typealiases? about ampere HOT 3 CLOSED

ole avatar ole commented on July 24, 2024
No readability-improving typealiases?

from ampere.

Comments (3)

Jeehut avatar Jeehut commented on July 24, 2024

By the way, here's the content of my HandyMeasurements.swift file:

import Foundation

typealias Acceleration = Measurement<UnitAcceleration>
typealias Angle = Measurement<UnitAngle>
typealias Area = Measurement<UnitArea>
typealias ConcentrationMass = Measurement<UnitConcentrationMass>
typealias Dispersion = Measurement<UnitDispersion>
typealias Duration = Measurement<UnitDuration>
typealias ElectricCharge = Measurement<UnitElectricCharge>
typealias ElectricCurrent = Measurement<UnitElectricCurrent>
typealias ElectricPotentialDifference = Measurement<UnitElectricPotentialDifference>
typealias ElectricResistance = Measurement<UnitElectricResistance>
typealias Energy = Measurement<UnitEnergy>
typealias Frequency = Measurement<UnitFrequency>
typealias FuelEfficiency = Measurement<UnitFuelEfficiency>
typealias Length = Measurement<UnitLength>
typealias Illuminance = Measurement<UnitIlluminance>
typealias Mass = Measurement<UnitMass>
typealias Power = Measurement<UnitPower>
typealias Pressure = Measurement<UnitPressure>
typealias Speed = Measurement<UnitSpeed>
typealias Temperature = Measurement<UnitTemperature>
typealias Volume = Measurement<UnitVolume>

from ampere.

ole avatar ole commented on July 24, 2024

Thanks for the suggestion. There was no deep rationale behind not including them at the time. But now that you made me think about it, I don't think it's the right thing to do. A library should be as familiar as possible to users; if it needlessly used a different terminology than the official APIs (or other libraries), I don't think that would be in the interest of most users.

If app developers define their own typealiases in code that nobody outside their team interacts with, that's much less problematic, of course.

I'm closing this, but feel free to comment if you'd like to discuss this further.

from ampere.

Jeehut avatar Jeehut commented on July 24, 2024

I agree for the most part. But at the same time I don't think it would hurt much as the names are chosen exactly like the Unit suffixes. Also if people see multiplication and division between different measurement types, they'll need to look up the Ampere documentation anyways. If your argument is "people will immediately understand that length/duration=speed" then the same argument is true for recognizing the types, also. On top of that the alt-clicking on the type they'll immediately see that it's a type alias for Measurement, if they are curious (that's what I do, if I don't know a type yet).

But having all that said, I'm absolutely okay with your decision, I don't think it'll make a huge difference. In any case my code above can be copied over into projects if people are interested in the typealiases anyway. Thanks for getting back to this and keep on writing those useful posts! 👍

from ampere.

Related Issues (15)

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.