Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Does anyone know the term for this? I had "Type Driven Development" in my head, but I don't know if that's a broadly used term for this.

It's a step past normal "strong typing", but I've loved this concept for a while and I'd love to have a name to refer to it by so I can help refer others to it.



I've seen it being referred to as "New Type Pattern" or "New Type Idiom" in quite some places. For example in the rust-by-example book [1].

[1] https://doc.rust-lang.org/rust-by-example/generics/new_types...


Using basic types for domain concepts is called 'primitive obsession'. It's been considered code smell for at least 25 years. So this would be... not being primitive obsessed. It isn't anything driven development.

Different people draw the line in different places for this. I've never tried writing code that takes every domain concept, no matter how small, and made a type out of it. It's always been on my bucket list though to see how it works out. I just never had the time or in-the-moment inclination to go that far.


I think often times it's enough to have enums for known ints, for example and have some parameter checking for ranges when known.

Some languages like C++ made a contracts concept where you could make these checks more formal.

As some people indicated the auto casting in many languages could make the implementation of these primitive based types complicated and fragile and provide more nuisance than it provides value.


Yep! I recently started playing with Ada and they make tightly specifying your types based upon primitives pretty easy. You also have some control over auto conversion based upon the specifics of how you declare them.


The overall idea of using your type system to enforce invariants is called typeful programming [1]. The first few sentences of that paper are:

"There exists an identifiable programming style based on the widespread use of type information handled through mechanical typechecking techniques. This typeful programming style is in a sense independent of the language it is embedded in; it adapts equally well to functional, imperative, object-oriented, and algebraic programming, and it is not incompatible with relational and concurrent programming."

[1] Luca Cardelli, Typeful Programming, 1991. http://www.lucacardelli.name/Papers/TypefulProg.pdf

[2] https://news.ycombinator.com/item?id=18872535


Strongly Typed Identifier

https://en.wikipedia.org/wiki/Strongly_typed_identifier

> The strongly typed identifier commonly wraps the data type used as the primary key in the database, such as a string, an integer or universally unique identifier (UUID).


It's taking the original idea behind Hungarian notation (now called "Apps Hungarian notation" to distinguish from "Systems Hungarian notation" which uses datatype) and moving it into the type system.

To keep building on history, I'd suggest Hungarian types.


They were already called "painted types" by same the inventor of Hungarian notation. Simonyi used this term in his PhD thesis, Meta-programming, in 1976! (Published 1977).

Meta-programming also introduced a notation which was the precursor to Hungarian Notation (page 44,45), so painted types technically pre-date Hungarian Notation.

https://web.archive.org/web/20170313211616/http://www.parc.c...

Relevant quote:

> These examples show that the idea of types is independent of how the objects belonging to the type are represented. All scalar quantities appearing above - column numbers, indices and so forth, could be represented as integers, yet the set of operations defined for them, and therefore their types, are different. We shall denote the assignment of objects to types, independent of their representations, by the term painting. When an object is painted, it acquires a distinguishing mark (or color) without changing its underlying representation. A painted type is a class of values from an underlying type, collectively painted a unique color. Operations on the underlying type are available for use on painted types as the operations are actually performed on the underlying representation; however, some operations may not make sense within the semantics of the painted type or may not be needed. The purpose of painting a type is to symbolize the association of the values belonging to the type with a certain set of operations and the abstract objects represented by them.


"Type driven development" is usually meant to say you will specify your system behavior in the types. Often by writing the types first and having the actual program determined by them. Some times so completely determined that you can use some software (not an LLM) to write it. (The name is a joke about the other TDD.)


You're correct that this is far from a new idea.

Relevant terms are "Value object" (1) and avoiding "Primitive obsession" where everything is "stringly typed".

Strongly typed ids should be Value Objects, but not all value objects are ids. e.g. I might have a value object that represents an x-y co-ordinate, as I would expect an object with value (2,3) to be equal to a different object with the same value.

1) https://martinfowler.com/bliki/ValueObject.html

https://en.wikipedia.org/wiki/Value_object


The method in the article is very close to the idea of a "branded type". Though maybe there's a distinction someone can point out to me.


"newtype", or kind of (but not exactly) the opposite of "Primitive Obsession"




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: