Re: Strong typing and physical units

2020-07-28 Thread Paolo Invernizzi via Digitalmars-d-learn
On Tuesday, 28 July 2020 at 11:04:00 UTC, Cecil Ward wrote: Of course, in C I used to do something like strong typing with an opaque type achieved by using something like typedef struct _something {} * type1; and then I had to do casting to get back the real type, which was unchecked but it did

Re: Strong typing and physical units

2020-07-28 Thread Cecil Ward via Digitalmars-d-learn
I just remembered: another favourite bug of mine would be mixing up indices, using an index with the wrong array, an index to a different array entirely. they’re all just a nightmare load of meaningless ints or uints or hopefully size_t’s.

Re: Strong typing and physical units

2020-07-28 Thread Cecil Ward via Digitalmars-d-learn
Of course, in C I used to do something like strong typing with an opaque type achieved by using something like typedef struct _something {} * type1; and then I had to do casting to get back the real type, which was unchecked but it did prevent the user from mixing up the types type1 and type2 s

Re: Strong typing and physical units

2020-07-28 Thread Cecil Ward via Digitalmars-d-learn
On Tuesday, 28 July 2020 at 07:16:53 UTC, Petar Kirov [ZombineDev] wrote: On Tuesday, 28 July 2020 at 04:40:33 UTC, Cecil Ward wrote: [snip] By the way, I found 2 implementations of unit of measurement in D: https://code.dlang.org/packages/units-d https://code.dlang.org/packages/quantities

Re: Strong typing and physical units

2020-07-28 Thread Petar via Digitalmars-d-learn
On Tuesday, 28 July 2020 at 04:40:33 UTC, Cecil Ward wrote: [snip] By the way, I found 2 implementations of unit of measurement in D: https://code.dlang.org/packages/units-d https://code.dlang.org/packages/quantities

Re: Strong typing and physical units

2020-07-27 Thread WebFreak001 via Digitalmars-d-learn
On Tuesday, 28 July 2020 at 04:40:33 UTC, Cecil Ward wrote: I found an earlier post somewhere about work someone has done on physical units such as kg, volts and so forth. It would be very good to catch bugs such as volts_t v = input_current; [...] This is easily done and uses enums: (o

Strong typing and physical units

2020-07-27 Thread Cecil Ward via Digitalmars-d-learn
I found an earlier post somewhere about work someone has done on physical units such as kg, volts and so forth. It would be very good to catch bugs such as volts_t v = input_current; But that isn’t nearly enough. With strong typing where we can create arbitrary subtypes that are chosen to