News for hackers. Stuff that matters.
Re:Atlas, a hopefully better engineering IDE by burke on Monday May 10, 2021 @11:25PM (#27113893)
Tracking units is a thing that I rarely have a use for (as a non-engineer), but when I do, I’m totally mystified by how bad almost every language is at it. F# is the only actual programming language I found that even tries. It does a pretty decent job, but even it has some disappointing holes (e.g. not being able to understand g and kg as scaled versions of the same dimension).

I guess the overlap between physicists/engineers and type system/PLT people isn’t large enough.

Re:Atlas, a hopefully better engineering IDE by captainmuon on Tuesday May 11, 2021 @03:02AM (#27115061)
When I was a physics student, I would have loved a spreadsheet that tracks units, and automatically does conversions as needed. There is another huge thing that this enables: Tracking uncertainties. It would be awesome if you could not just write "10", but "10 cm ± 1 cm". Then the spreadsheet could do error propagation! Even the simplest case of non-correlated errors would be useful. Also you could have functions like "weighted mean" that take the errors into account. We used to do these calculations manually with extra columns and a few macros, but it was always error prone.

Also, why is there no CAD program that allows me to enter errors? When I try to model real objects, say a room, the lengths never add up 100% and I always have gaps once I'm around the room. It would be great to say all these measurements are ± 1 cm, this one is ± 5 cm, and these angles are 90° ± 1°. And then it would do least-squares, and give me a really accurate model, or tell me where I have to measure again.

Re:Atlas, a hopefully better engineering IDE by arethuza on Tuesday May 11, 2021 @05:34AM (#27116026)
For a while I toyed with writing an extensible spreadsheet engine/app that would allow extensions to do that kind of thing - maybe I should dust that idea off again! ;-)
Re:Atlas, a hopefully better engineering IDE by captainmuon on Tuesday May 11, 2021 @12:28PM (#27120118)
Seems like many people started on this but never finished it, me too. I got carried away trying to speed up my custom grid control, and borked it up when I tried to use threads :-P.
Re:Atlas, a hopefully better engineering IDE by arethuza on Wednesday May 12, 2021 @04:34AM (#27128083)
I wanted to write something that would be "spreadsheet" like that would work as a normal desktop app, as a component in a server application and on the command line as well.

Combine that with all of the other grandiose plans (writing extension in WASM) then it's no wonder that I wasn't making too much progress... interesting though!

Re:Atlas, a hopefully better engineering IDE by PascLeRasc on Tuesday May 11, 2021 @05:07PM (#27123532)
Fusion 360 has tolerance parameters, that should work for you: https://knowledge.autodesk.com/support/fusion-360/learn-expl...
Re:Atlas, a hopefully better engineering IDE by Crazor on Saturday May 15, 2021 @12:25PM (#27166578)
Well, that‘s only for drawings and not for modelling. Also it‘s manual/cosmetic.
Re:Atlas, a hopefully better engineering IDE by agumonkey on Wednesday May 12, 2021 @12:53PM (#27132439)
For the sake of humour, isn't it a chapter in OnLisp ?
Re:Atlas, a hopefully better engineering IDE by AYBABTME on Tuesday May 11, 2021 @07:50AM (#27116920)
I built a Go library that would track units + errors when I was doing my undergrad... but never published it anywhere and lost the files, sadly. Anyways, I agree this would be neat.
Re:Atlas, a hopefully better engineering IDE by sidpatil on Monday May 10, 2021 @11:52PM (#27114046)
Julia has the Unitful package [1], which does a decent job. It's quite ergonomic, and Julia's design helps with making existing code/libraries play nicely with Unitful-encoded units/values.

[1] https://github.com/PainterQubits/Unitful.jl

Re:Atlas, a hopefully better engineering IDE by papaf on Tuesday May 11, 2021 @01:58AM (#27114706)
I guess the overlap between physicists/engineers and type system/PLT people isn’t large enough.

C++ has supported units, as a library, since the early 90s. The Barton Nackman book had the initial implementation [1] and it was picked up years later by Scott Meyers [2].

[1] https://www.thriftbooks.com/w/scientific-and-engineering-c-a...

[2] https://stackoverflow.com/questions/28698558/c-dimensional-a...

Re:Atlas, a hopefully better engineering IDE by papaf on Tuesday May 11, 2021 @02:10AM (#27114767)
Although it just uses scaling, Forth also has a nice solution to unit conversion:

https://www.forth.com/starting-forth/12-forth-code-example/

Re:Atlas, a hopefully better engineering IDE by gpderetta on Tuesday May 11, 2021 @06:27AM (#27116342)
Yes, and boost.units, and to a limited extent, std::chrono.
Re:Atlas, a hopefully better engineering IDE by heisenzombie on Monday May 10, 2021 @11:45PM (#27113996)
I regularly use "pint" for Python:

https://pint.readthedocs.io/en/stable/

I'm sure it's not as good as a true type system could be, but it works pretty transparently due to Python's duck typing.

Re:Atlas, a hopefully better engineering IDE by techdragon on Tuesday May 11, 2021 @12:25AM (#27114206)
I’ll second the utility of “pint” for anything unit or quantity related in Python.

I’m literally in the middle of writing a rate limited continuously run service wrapper around some existing one shot task code and while I initially thought about just parsing the rate definition out myself because it’s pretty simple to just split on “/“ or “per”, but after thinking through the usage scenarios I just ended up using pint to convert anything it can understand as a frequency.

So anything of the form x / time unit or x per time unit, and converting it to the appropriate scale for use by the rest of my code. A whole bunch of string matching code replaced by a one line (two if I count the defensive unit type check to prevent false positive parsing problems) that looks as simple as this…

  default_sleep_interval = (1/ureg(default_rate)).to(“seconds”).magnitude
Re:Atlas, a hopefully better engineering IDE by V1ndaar on Tuesday May 11, 2021 @04:51AM (#27115791)
I've recently written a units library for Nim [0]. It's still WIP, but it's already proven extremely useful for me as a physicist.

Thanks to Nim's strong type system and metaprogramming features, it allows for a fully compile time design, without any runtime overhead (in form of special unit objects or such things; everything is a `distinct float`).

In addition Nim's unicode support, the code even looks nice!

A more complex use case (I can link more if desired): [1]

[0]: https://github.com/SciNim/Unchained/

[1]: https://github.com/SciNim/Unchained/tree/master/examples

Re:Atlas, a hopefully better engineering IDE by jimmyhmiller on Monday May 10, 2021 @11:39PM (#27113972)
Frink[0] is a language specifically designed for dealing with this kind of stuff. It has tons of units and conversions.

[0] - https://frinklang.org/#HowFrinkIsDifferent

Re:Atlas, a hopefully better engineering IDE by jcelerier on Tuesday May 11, 2021 @04:40AM (#27115718)
I have yet to see unit handling be a problem in C++, making typesafe units is a basic exercise to give to students.

Here is a good in-depth comparison of the existing libraries:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p193...

Re:Atlas, a hopefully better engineering IDE by jamil7 on Tuesday May 11, 2021 @01:38AM (#27114583)
Swift has a pretty nice measurements package built in https://developer.apple.com/documentation/foundation/measure...
Re:Atlas, a hopefully better engineering IDE by klemola on Tuesday May 11, 2021 @01:40AM (#27114590)
The Elm programming language ecosystem has the great "elm-units" library, which prevents one from mixing illogical units, and it produces logical unit combinations:

https://package.elm-lang.org/packages/ianmackenzie/elm-units...

...which is used in other packages where unit type safety is important, such as elm-geometry:

https://package.elm-lang.org/packages/ianmackenzie/elm-geome...

Re:Atlas, a hopefully better engineering IDE by rurban on Tuesday May 11, 2021 @01:14AM (#27114457)
When I implemented unit support into my engine I used the units cmdline tool. Was by far the best and easiest to use. https://www.gnu.org/software/units/manual/html_node/Command-...
Re:Atlas, a hopefully better engineering IDE by fsloth on Tuesday May 11, 2021 @01:45AM (#27114624)
Unit conversion is not the issue. It's strong typing the values themselves so that you don't actually plug in a value in feet that was thought to be in meters. This means each numeric value must have it's own type (or equivalent strong compiler or runtime backed constraints).

So instead of float, we have (eg) float_meters, float_feet and so on.

Re:Atlas, a hopefully better engineering IDE by halfdan on Tuesday May 11, 2021 @04:35AM (#27115680)
Julia has beautiful support for adding units to your programs. The nice thing about it is that you can plug unitful numbers into any other package and do math on them.

http://painterqubits.github.io/Unitful.jl/stable/

Re:Atlas, a hopefully better engineering IDE by discordance on Tuesday May 11, 2021 @04:46AM (#27115757)
Mathematica (and I guess Alpha now) has always had good support for units and dimensional analysis:

https://reference.wolfram.com/language/guide/Units.html

Re:Atlas, a hopefully better engineering IDE by PascLeRasc on Monday May 10, 2021 @11:53PM (#27114054)
This is something that Matlab really shines at with symbolic computation. Is there really not a numpy/scipy equivalent?
Re:Atlas, a hopefully better engineering IDE by techdragon on Tuesday May 11, 2021 @12:29AM (#27114221)
Sympy[0] is the major Python package I go to for symbolic calculation, it’s been more than enough for what I’ve needed (except for a few shortcomings I found in higher dimensional symbolic geometry, but I’m not going to fault them for not having my own weird esoteric use cases covered)

0 - https://www.sympy.org/en/index.html

Re:Atlas, a hopefully better engineering IDE by patal on Tuesday May 11, 2021 @05:09PM (#27123566)
How so? Every MATLAB code base I've seen rolls their own unit computation. The symbolic toolbox costs money and I've seen it on university installations only. The unitConvert command is rather new. Neither mechanisms are native to MATLAB and have awkward call patterns.
Re:Atlas, a hopefully better engineering IDE by dagw on Tuesday May 11, 2021 @02:57AM (#27115024)
Sage/Sympy is the the python library for symbolic computation
Re:Atlas, a hopefully better engineering IDE by BalinKing on Tuesday May 11, 2021 @12:30AM (#27114231)
Mathematica as well.
Re:Atlas, a hopefully better engineering IDE by publicola1990 on Tuesday May 11, 2021 @12:37AM (#27114260)
Matlab I thought use Maple for symbolic functionality, is that not the case?
Re:Atlas, a hopefully better engineering IDE by sveme on Tuesday May 11, 2021 @02:03AM (#27114729)
No, they moved to their own symbolic computation engine years ago.
Re:Atlas, a hopefully better engineering IDE by auxym on Tuesday May 11, 2021 @07:06AM (#27116571)
They bought mupad and integrated it if I remember correctly.
Re:Atlas, a hopefully better engineering IDE by neilv on Tuesday May 11, 2021 @01:59AM (#27114711)
The Curl programming language for Web applications had units for purposes like its GUI objects, circa 2000.

https://en.wikipedia.org/wiki/Curl_(programming_language)

Re:Atlas, a hopefully better engineering IDE by sk5t on Tuesday May 11, 2021 @08:12AM (#27117123)
You might find the Squants library for Scala interesting; it even seems like an apt usage of some oft-questioned language features.

https://github.com/typelevel/squants

Re:Atlas, a hopefully better engineering IDE by benhurmarcel on Tuesday May 11, 2021 @03:37AM (#27115320)
Blockpad ( https://blockpad.net/ ) and Mathematica do it.
Re:Atlas, a hopefully better engineering IDE by g_delgado14 on Monday May 10, 2021 @11:29PM (#27113920)
Isn't the "newtype" pattern something that addresses this issue elegantly?

Is there something that I'm missing here?

Re:Atlas, a hopefully better engineering IDE by heisenzombie on Monday May 10, 2021 @11:41PM (#27113975)
Not really, a units systems needs to be able to combine units in a useful way, like if I typed this:

  radius = 15 [mm]
  area = pi*radius^3
  force = 100 [N]

  def will_i_blow_up(pressure [Pa]):
    if(pressure > 1 [Gpa]):
      return "Oh no it blew up"

  will_i_blow_up( force/area )
should raise an error like "UnitsException, [N/mm^3] is not compatible with [Pa]". I could then look over my code and realize I should have written:

    area = pi*radius^2
Re:Atlas, a hopefully better engineering IDE by yladiz on Tuesday May 11, 2021 @03:02PM (#27122087)
If you have a language that supports tagged types and can overload operators, you can basically get there. I think a language like Idris and Julia (with the right packages) should be able to support this.
Re:Atlas, a hopefully better engineering IDE by cwhy on Monday May 10, 2021 @11:50PM (#27114029)
This is rather a math-specific operation (type conversion on math operators), not the scope of general purpose language. A lot of dependent typed language can achieve this naturally and most languages with ADT can simulate this.
Re:Atlas, a hopefully better engineering IDE by dragonwriter on Tuesday May 11, 2021 @01:16AM (#27114469)
> This is rather a math-specific operation

Math is a kind of a core use case for, really, almost any programming language, and is central to much of what computers are used for (as is hinted at in their name.)

Though dealing with this aspect of units is less “math-specific” than central to the relation between math and real-world meaning, which is arguably even more important than abstract math in computing applications.

Re:Atlas, a hopefully better engineering IDE by burke on Monday May 10, 2021 @11:32PM (#27113934)
Yep, it allows you to tag something a metres per second, but it doesn’t automatically make multiplying it by a duration yield a distance without writing any custom code. F# can do that, and it’s rather cool. There are dimensional analysis libraries for other languages, but none that I’m aware of baked in.
Re:Atlas, a hopefully better engineering IDE by the-dude on Tuesday May 11, 2021 @06:43AM (#27116433)
I never had one, but didn't some of the later HP calculators do this? ( the 48? )