Hacker News new | ask | show | jobs
by redgrange 1256 days ago
I see so many uses of the term ADT that I can't really give anyone a confident definition
2 comments

Using ADT to mean “abstract data type” does not mean anything more than what most people mean when they say “type”. Outside of distinguishing from other meanings of the word “type” there is no practical reason to ever say it. It doesn’t sound fancy, it just sounds like getting high on your own supply of acronyms. It is not an important term to learn as a beginner in the first chapters of a programming book. We should stop using it in resources like this.

Otherwise, ADT can also refer to “algebraic data type” which means the ability to compose types together thereby adding or multiplying the different values the resulting type can take. Product types (aka structs) multiply over their fields; two int fields when taken together can take on (# different values of int) * (# different values of int) different values. Sum types add over their variants: a Rust enum “enum OptionalInt { Some(i32), Maybe(i32), None }” can take (# different values of i32) + (# different values of i32) + 1 different values.

Most languages have structs and that’s the “product type” sorted, so ADT generally refers to a language having tagged enums. C doesn’t have that but you can emulate it (quite badly) with unions and enums. Good examples of languages with ADTs are OCaml, Haskell, Rust.

> Using ADT to mean “abstract data type” does not mean anything more than what most people mean when they say “type”.

Abstract data type is a type where you don't get direct access to the information contained in it. The encapsulation is what makes it "abstract".

We should call it an opaque data type then.
That thing was named much before the other ADT became popular. The name is spread over a lot of past texts, and not in wide use anymore.

There's no point in changing anything.

Is a Java ArrayList considered an ADT like stack, queue, set, etc?
In the context of C programming, ADT usually means an opaque struct with some related functions.
An abstract data type (ADT) is a structured type for which a client cannot access the data components for variables of this type. The client understands the type in terms of its operations, provided by a set of functions which operates on variables of this type. The set of functions is called the interface of the ADT. Note that this definition requires information hiding but not inheritance or polymorphism.
How would you distinguish that definition from one for "type"?
> How would you distinguish that definition from one for "type"?

The crucial difference between an abstract data type and a concrete data type is that the content is hidden in the former case.