News for hackers. Stuff that matters.
Re:Rust solves the problem of incomplete Kernel Linux API docs by GolDDranks on Saturday August 31, 2024 @12:44PM (#41410050)
It's not _just_ memory safety. In my experience, Rust is also liberating in the sense of mutation safety. With memory safe languages such as Java or Python or JavaScript, I must paranoidly clone stuff when passing stuff to various functions whose behaviour I don't intimately know of, and that is a source of constant stress for me.
Re:Rust solves the problem of incomplete Kernel Linux API docs by miki123211 on Saturday August 31, 2024 @01:05PM (#41410213)
Also newtype wrappers.

If you have code that deals e.g. with pounds and kilograms, Dollars and Euros, screen coordinates and window coordinates, plain text and HTML and so on, those values are usually encapsulated in safe wrapper structs instead of being passed as raw ints or floats.

This prevents you from accidentally passing the wrong kind of value into a function, and potentially blowing up your $125 million spacecraft[1].

I also find that such wrappers also make the code far more readable, as there's no confusion exactly what kind of value is expected.

[1] https://www.simscale.com/blog/nasa-mars-climate-orbiter-metr...

Re:Rust solves the problem of incomplete Kernel Linux API docs by db48x on Saturday August 31, 2024 @01:18PM (#41410301)
As much as I like Rust, I don’t think that it would have solved the Mars Climate Orbiter problem. That was caused by one party writing numbers out into a CSV file in one unit, and a different party reading the CSV file but assuming that the numbers were in a different unit. Both parties could have been using Rust, and using types to encode physical units, and the problem could still have happened.
Re:Rust solves the problem of incomplete Kernel Linux API docs by tialaramex on Saturday August 31, 2024 @02:07PM (#41410626)
Yeah, even an extremely powerful units type system like C++ mp-units doesn't fix "I assumed this number was feet and you assumed it was millimetres".

But both the mp-units and this lighter weight Rust approach would at least make you write that down in the software. There's some chance the mistake is realised, whereas when it's just an organisational assumption that just doesn't happen.

Re:Rust solves the problem of incomplete Kernel Linux API docs by westurner on Saturday August 31, 2024 @03:32PM (#41411280)
W3C CSVW supports per-column schema.

Serialize a dict containing a value with uncertainties and/or Pint (or astropy.units) and complex values to JSON, then read it from JSON back to the same types. Handle datetimes, complex values, and categoricals

"CSVW: CSV on the Web" https://github.com/jazzband/tablib/issues/305

7 Columnar metadata header rows for a CSV: column label, property URI, datatype, quantity/unit, accuracy, precision, significant figures https://wrdrd.github.io/docs/consulting/linkedreproducibilit...

CSV on the Web: A Primer > 6. Advanced Use > 6.1 How do you support units of measure? https://www.w3.org/TR/tabular-data-primer/#units-of-measure

You can specify units in a CSVW file with QUDT, an RDFS schema and vocabulary for Quantities, Units, Dimensions, and Types

Schema.org has StructuredValue and rdfs:subPropertyOf like QuantitativeValue and QuantitativeValueDistribution: https://schema.org/StructuredValue

There are linked data schema for units, and there are various in-code in-RAM typed primitive and compound type serialization libraries for various programming languages; but they're not integrated, so we're unable to share data with units between apps and fall back to CSVW.

There are zero-copy solutions for sharing variables between cells of e.g. a polyglot notebook with input cells written in more than one programing language without reshaping or serializing.

Re:Rust solves the problem of incomplete Kernel Linux API docs by pessimizer on Saturday August 31, 2024 @02:05PM (#41410614)
Unless the unit was part of the type, and why wouldn't it be? A unit error is a type error. You don't have to say that something is 5 long, you can say that it's 5 inches long. And the function can be made only to accept a length in inches, and you can implement :Into<Inches> on your length type for an automagic conversion.
Re:Rust solves the problem of incomplete Kernel Linux API docs by nurettin on Saturday August 31, 2024 @03:30PM (#41411270)
That wouldn't be enough unless the csv somehow kept serialized column type in the header and the deserializer knew how to interpret it.
Re:Rust solves the problem of incomplete Kernel Linux API docs by db48x on Saturday August 31, 2024 @04:22PM (#41411676)
Of course, but that doesn’t solve the problem. The problem here is that two separate organizations with completely different software were communicating via CSV file. There was a contractual obligation between them that required them to use specific units, but no technical collaboration. The problem was not in their software, but in the management and engineering discipline of the two groups.
Re:Rust solves the problem of incomplete Kernel Linux API docs by kwhitefoot on Saturday August 31, 2024 @01:43PM (#41410456)
> prevents you from accidentally passing the wrong kind of value into a function,

You can do this in other languages such as Pascal with subtypes and something functionally equivalent in C# and other object oriented languages.

Re:Rust solves the problem of incomplete Kernel Linux API docs by 0cf8612b2e1e on Saturday August 31, 2024 @01:48PM (#41410492)
I do not think the claim was that this is a unique construct to Rust.
Re:Rust solves the problem of incomplete Kernel Linux API docs by the__alchemist on Saturday August 31, 2024 @01:26PM (#41410343)
IMO, this is one of the most underrated advantages of Rust over most (all I've used) alternatives. Mutation is explicit/principle-of-least-surprise.