News for hackers. Stuff that matters.
Re:Programming Languages as Constraints by sharpercoder on Friday June 03, 2016 @04:30PM (#11833043)
One inability I am thinking about lately is disallowing primitive types on public members. Take C#, but properties and methods would only allow returning and taking class/struct types.

This way you enforce strict use of objects, enforcing expressivity. No more `double meters` but `Meter meters`.

Re:Programming Languages as Constraints by 14113 on Friday June 03, 2016 @05:19PM (#11833352)
How you you encode "dimensionless" quantities within such a system?
Re:Programming Languages as Constraints by tomsmeding on Friday June 03, 2016 @05:20PM (#11833356)
You have stuff like Integer right? Which doesn't really bring you anything...
Re:Programming Languages as Constraints by scotty79 on Saturday June 04, 2016 @03:22AM (#11835353)
Every value has some identity in domain space. Even if it doesn't have a unit.
Re:Programming Languages as Constraints by catnaroek on Friday June 03, 2016 @10:02PM (#11834543)
A separate class for each unit of measurement isn't the right way to perform compile-time dimensional analysis. It doesn't easily support forming compound units from more basic ones.
Re:Programming Languages as Constraints by scotty79 on Saturday June 04, 2016 @03:25AM (#11835358)
I don't think this is the main point of this limitation. Main point is to prevent "primitive obsession" anti pattern.
Re:Programming Languages as Constraints by catnaroek on Saturday June 04, 2016 @02:26PM (#11837355)
What you call “obsession”, I call “preventing preventable mistakes”, and it's actually a good thing. There are perfectly viable ways to perform compile-time dimensional analysis, for example, parameterizing scalar types by the exponents of “primitive” dimensions.
Re:Programming Languages as Constraints by scotty79 on Sunday June 05, 2016 @04:02AM (#11840066)
http://c2.com/cgi/wiki?PrimitiveObsession

It's completely orthogonal to you argument.

Re:Programming Languages as Constraints by catnaroek on Sunday June 05, 2016 @05:07AM (#11840211)
That sounds even worse. Why should primitive types be treated as second-class entities that can only arise as private implementation details of a class?

In any case, my original point still stands:

(0) Dimension errors are really what one seeks to prevent by discouraging things like `double meters;`.

(1) Making a separate class for each unit of measurement doesn't compose or scale well. Dimensional analysis is a fundamentally structural business, and this really calls for compile-time arithmetic with the exponents of primitive dimensions. But, of course, if your hammer is Java-shaped...

Re:Programming Languages as Constraints by scotty79 on Sunday June 05, 2016 @06:41AM (#11840368)
> Why should primitive types be treated as second-class entities that can only arise as private implementation details of a class?

Because primitives are meaningless. String has no meaning. "Message" does. "Contact person" does and has conceptually nothing in common with a "Message". Why should they be both of type String?

The real problem with primitive obsession is that it stifles software evolution. Suddenly Message needs to keep other data or have some methods associated with it. Every place where it was used is suddenly invalid because you need to go from String to class and inheriting from primitive is just silly if at all possible.

That's what you want to prevent. It has almost nothing to do with units or dimensional analysis.

Re:Programming Languages as Constraints by catnaroek on Sunday June 05, 2016 @07:27AM (#11840447)
> Because primitives are meaningless.

That depends on your problem domain. If I'm implementing a library of data structures and algorithms (which I have to do, because most standard libraries are subpar on this front), then I definitely want to work with raw integers or sequences (but probably not strings - they should be just a special case of sequences).

> "Message" does. "Contact person" does and has conceptually nothing in common with a "Message".

No disagreement in this particular case. It's indeed best to have separate types for things on which different operations make sense. But, personally, I find it more tasteful to have little to no algorithmic logic at the level of business domain entities. Algorithms work on mathematically structured data.

Re:Programming Languages as Constraints by sharpercoder on Monday June 06, 2016 @11:17AM (#11847379)
But math is a problem domain as well. I rather have specialized types to work with there as well, for above mentioned reasons (intention, documentation).
Re:Programming Languages as Constraints by hartez on Friday June 03, 2016 @05:24PM (#11833376)
That actually sounds like a fun Roslyn analyzer project.