Constraint Type

See Instead: PredicateTypes, rather than the rant below.

But that page talks about instances, properties, objects.. and I want little to do with that. AntiCreation.

I'd rather call it "validation", not "types". But, that may then trigger another HolyWar about the definition of "types" if we try to get into the meat of the difference.

Validation is a process; types are, trivially, not processes, and therefore anyone who would rather call types 'validation' is someone who would rather be wrong than accept trivial truth.

Consider that this isn't necessarily a page about computer theory and academia.. but rather.. think about real life. Why type of car do you have? One that has a 5 speed gearbox limit? Does it only reach 200mph? Is it the one that is red? A type is just a label for "some kind of thing". I consider a type anything that can be described differently than something else.. and the dictionary agrees. All the TypeTheory talk seems like a bunch of over analyzed lightbulbs to me. What type of light bulb is that? 100 watt or 200 watt? 60 watt? Let's not overanalyze the hell out of types. Keep it simple.

{You're keeping it "simple" by dismissing the complexity implied by "described differently". The multitude of ways to describe "differently" -- and to gain power and expressivity in such descriptions without losing validity and/or acceptable performance in implementations -- is the basis of TypeTheory. Don't make the mistake of regarding TypeTheory as mere academic navel-gazing because the domains with which you're familiar do not appear to demand sophisticated type systems.} I'll add: only the naive believe they can 'keep' something simple before doing enough analysis and exploration to 'get' it there in the first place.


It would also be nice to constrain types to miles and celsius rather than say integer or byte. This can partly be done or emulated using objects or records or structs.. but we want to brainstorm ideas on this page on how to make constrained types more useful.

Databases usually do not let one define many types, they just give you some fixed ones. This is partly for practical reasons, as we can't extend everything to the perfect ways we want. It is possible databases (and/or languages) just need to give us at least a few more fixed options that are missing right now.. and we might do okay with that. And/or an extension system with our without it.. might be useful (but then premature optimization fans will see a problem here).


If we just keep everything as a string and validate it with a regex (or better, a plugin parser function)... this is a constraint, and is related. so I will not argue that validation is something completely different than a type. Of course types go through validation. The page title was just thought up and was not meant to aruge whether a type contains some sort of validation or not. Types that are strong at compile or run time are of course validated and validation is related to typing. Type systems can save the programmer from reinventing checks in his algorithms each time. Hopefully with a type system this leads to less software bugs and even more focus on unit tests that don't try to reinvent the type system by unit tests.


A problem with programmers and our current type system is that we are stuck in this mode of thinking that binary is GoodEnough and that everything is a 1, 0, 8, 256, 32, 1024, etc.

Let's abstract away from that or wishfully hope for a decimal based CPU. BinarySucks?. TwoFingeredComputer.

Or there is the boolean and null issue. True and False are a nice constraint.. but null? Is null a constraint? Or is that just stupidity?

We need constraint oriented types... such as ranges, limits, restrictions.

Maybe there are types.. but they need to be constrained in manners different than our current (brain damaged) type system.

Programmers should not be thinking in 256, 8, 16, or 32 necessarily. Nor should we just be using booleans and nulls.

Rather

  this column can accept values from 10 to 30

this field can accept only numbers that are positive and not A to Z characters

this item can only accept strings with A to Z

this cell can only accept decimal values with 2 trailing positions

this column can accept true or false (sometimes YES or NO)

this column can accept "not applicable", "not entered yet", or "string"

this cell can accept "not entered yet", or numbers from 1 to 100

Simply these are "kinds of constraints" or "types of constraints".


A simple validation constraint plugin idea for a database:

  function pluginConstraint(const s: string): boolean
  begin
    result:= false;
    // check if string contains numbers, characters, whatever
    if validate(s) then result:= true;
  end;

begin setupConstraint(@pluginConstraint, toSomeDatabase) end;


Why nulls do not help us constrain our data:


See also: ThereAreNoTypes, TwoFingeredComputer, ConstraintModels, TypeTheory, SpecializationByConstraint, WeakTypesLie


MarchZeroEight

CategoryTypingDebate


EditText of this page (last edited May 23, 2008) or FindPage with title or text search