Hacker News new | ask | show | jobs
by mikewarot 2 days ago
I like the idea of attaching units to a number, so that if A is 9 volts, B is 3 amps, then A*B yields 27 watts. I saw a demo years ago where it was done in C++ using type checking to make the units consistent.

There's a feature from Metamine which would be amazing to add to Pascal... the "magic equals" in which the left value of such an assignment would update any time the argument on the right changed. Adding imperative programming would be an amazing addition.

As for Lazarus/Free Pascal, the documentation is a key weakness. It merely lists the parameters and routines associated with a thing, but doesn't explain their purpose, nor give examples. This is a huge departure from the Excellent manual that came with Turbo Pascal back in the 1980s/90s.

3 comments

If you like that idea, you'd love Oxygene! It's part of the type system.

As far as docs go, would you like to critique ours? https://elements.docs.remobjects.com/Oxygene/Types/Units/ Both I and the person who wrote those docs care about human-written, informative documentation.

Holy cow... that is fscking amazing! I'm sorry, but I was distracted by the amazing power of that type mechanism. I can't imagine what kind of very cleaver, or better yet, very elegant mechanism is underlying that type system.

As for the Documentation itself.... you've all done an amazing job.... just browsing through https://elements.docs.remobjects.com/Concepts/Nullability/ it dawned on me that the same documentation represents the concept across multiple programming languages in a very clear and easy way.

I was trying to figure out what happens when a null gets encountered at run time, and couldn't find it in the documentation.... then it dawned on me that the whole point of this might be to prevent that from even happening, ever.... is that right?

You've definitely Nerd Sniped me with Oxygene. 8)

---

Ok, now back to the original objection I had to the Lazarus/Free Pascal documentation.... unfortunately it's present in Oxygene as well. Take a look at the ButtonClick() methon on the page for TButton, https://elements.docs.remobjects.com/API/DelphiRTL/Classes/T...

The parameter aEvent: is listed, but there's no telling what it actually means or does, or how to use it. I know that if I used this daily it would likely be sufficient, but for me coming fresh into it, it's a brick wall. I just want to put a button on the screen.

Maybe it's just me? but this is the type of thing that seems everyone counts as sufficient. I get that there are an insane amount of parameters and fields to document, but there must be at least a hint of how to use things, and what exactly they mean.

Another example would the the "TabStop" property in TCheckBox, there's no telling what that actually does. I have a guess, but there's no description of what it does, how to use it, etc.

----

PS: One minor note (very minor) is this typo in the text on the Units page you referenced:

  The relationships work both ways, i.e. Speed multiplied by a Time wdl ahain yield a Distance.
PPS: I'm sorry if I'm too demanding, but I was trying to be specific about things, to give you details.
Not demanding at all. This is fantastic. I will pass it on to the person who wrote the docs, I think he'll be really happy with your feedback. "fscking amazing" is a real compliment.

And yes, that doc is lacking... That library is actually deprecated, which may be why. These days we support the Delphi object model / ABI, so we can link directly to Delphi packages the same way we speak the Obj-C or other ABIs. So that library is not necessary. Perhaps we should remove the doc altogether.

Edit: and to answer your question, if something is nullable, it can be null validly and so you could deref and get an AV, but you can also use the colon : operator for safe access, or `coalesce`.

https://elements.docs.remobjects.com/Oxygene/Expressions/Mem...

https://elements.docs.remobjects.com/API/SystemFunctions/Coa...

If it's `not nullable` it cannot be null, ever, enforced as part of the type system.

> "fscking amazing" is a real compliment.

love it, yeah.

typo: fixed. Also, point taken about the sometimes empty API docs. We gotta see what we can do there to improve this.
Absolutely! This is something quite a few languages have already embraced, either built into the language or through libraries. It's a really useful feature, and it would be cool to see it become more common.
>I like the idea of attaching units to a number, so that if A is 9 volts, B is 3 amps, then A*B yields 27 watts.

I asked an LLM:

>do fsharp and ada also have the units of measure feature.

it said:

Yes—both F# and Ada support units of measure, though in different ways. F# has first-class, built-in language support for units of measure, whereas Ada does not mandate a single built-in units system in the core ISO standard, but GNAT provides compile-time dimension checking via aspects, and third-party Ada libraries implement it as well. F# (Built-in Language Feature) F# treats units of measure as a first-class feature of its static type system: Compile-time safety, zero runtime cost: Units are checked at compile time and erased in compiled .NET code, so there is no runtime overhead (and no unit metadata carried around at runtime). Algebraic unit inference: You define base units with [<Measure>] (such as type V or type A, or use SI units from FSharp.Data.UnitSystems.SI) and combine them with multiplication, division, and powers. Multiplying volts (float<V>) by amps (float<A>) automatically yields float<V A> (or a derived unit like W if defined). Type inference: Functions working over units can often infer generic measure parameters (like float<'u>) automatically without heavy boilerplate. Ada (Compiler Aspects & Libraries) The core Ada language standard does not define a single universal units-of-measure syntax, so approaches vary depending on your compiler and libraries: GNAT Dimension_System and Dimension aspects: GNAT (starting from Ada 2012 extensions) supports compile-time dimensional analysis using the Dimension_System and Dimension aspects (including System.Dim.Mks). Like F#, checks happen at compile time with no runtime overhead, though it is a GNAT extension rather than portable across every Ada compiler. Ada libraries: Developers also use dedicated libraries—such as Dmitry Kazakov's Units of measurement for Ada or SI unit packages—which handle physical dimensions, conversions, and even shifted units like Celsius or Fahrenheit (some doing checks at runtime or via type/record representations.