What is a property?

5 days ago (alperenkeles.com)

Maybe I have a bit of a brain problem, but for me, 90% of the effort that goes into learning anything in tech is spent on identifying which nouns are Nouns, and which are just nouns, and the (often mushy) semantics of how people use those nouns in varying contexts and sub-contexts. I understand the reasons for this complexity - domain-specific terminology is valuable and forms naturally from pre-existing words. It's just that, in tech, everything is abstract, and everything consists of multiple contexts spread across multiple dimensions (vertically, in abstraction layers; horizontally, in use cases), so the domain-specific terminology explodes like an exponential web. Sometimes I'm talking to somebody and they are using some word, and it takes me days to even realize that they are using it in a much more specific context than I assumed. It's a little hellish.

  • "Property" here comes from mathematics (and I guess similar definition to science). What are the properties of this function? E.g. x * y has the property that x * y = y * x.

    So we do import stuff from Mathematics alot.

    I think we need better tutorials. It is a hard problem. How to teach something, who is your audience. For an AI tutorial, do I need to explain what inference is? Maybe. If I don't and they don't know it is another weird word.

    In terms of brain problem - I have the same thing. It is worse inside the corporate barrier as there is no internet documentation on what the terms mean. I think all we can do is slow down and write cheat sheets until we remember.

  • Since we are talking about Haskell, its type system can be explored to answer the question of what is considered a Property by the quickcheck library.

    The Property type is a datatype for which the definition is private. So we look at functions that creates Property objects. We find

        class Testable prop where
          property :: prop -> Property
    

    This means anything of the class Testable can be turned into a Property. So let's look at what are the instances of this class. We immediately find

        instance Testable Bool
    

    This means any boolean can be turned into a Property. But more interestingly we find

        instance (Arbitrary a, Show a, Testable prop) => Testable (a -> prop) 
    

    This means any function where the argument has a generator and the result can be turned into a Property can itself be turned into a Property. This implies that for example a function of `Int -> Bool` can be turned into a property. And due to currying, `Int -> Int -> Bool` can also be turned into a property.

    This basically covers the first half of the article.

    We continue to find other functions that returns Property objects. We find

        forAll :: (Show a, Testable prop) => Gen a -> (a -> prop) -> Property
    

    This states that if we have a function where we explicitly provide a generator and it returns anything that can be turned into a Property, it can also be turned into a Property. This is different from the instance above only by providing an explicit generator.

    We also find the implication operator:

        (==>) :: Testable prop => Bool -> prop -> Property 
    

    This states that if we have a Bool, and anything that can be turned into a property, we also have a property.

    You see, the beauty of Haskell and similar languages is that you don't need to first gain an intuitive understanding of those vocabularies of a library. The library designer has built up an abstraction of those vocabularies and Nouns and the compiler is tasked to enforce it. You can get things wrong, and the compiler just yells at you. Or you can just mechanically find things to fill in the blanks ("hole-driven development") without understanding the vocabularies. It's your choice.

  • I agree. It’s especially weird moving across related domains because suddenly something you think you know has changed meaning. For instance eBPF is “verified”, but the verification is almost completely unrelated from the usual connotations.

  • It doesn't help that many texts approach this as a very pseudo-mathematics abstract. It's not a function, it's an implication. It's there are satisfactions of preconditions, there's a thousand different things.

    Unfortunately, very few texts and tutorials on property-based testing actually tell you how to see what properties are. I have it on paper somewhere in some workshop materials. But online I think this is one of the very few that describe what they are: https://fsharpforfunandprofit.com/posts/property-based-testi...

    • Good link. I think that explanation works because it's somewhat closer to providing concrete examples of the kinds of tests you can write.

  • The worst thing is being corrected about minutiae. It's not a "property" it's an attribute/field/member/key/column/variable/getter/function/procedure. Deep down it's all variables. Even the constants are variables from the viewpoint of the CPU that has to load it in its registers.

    Sometimes I see people saying "in LANG, obj.foo is just 'syntax sugar' for foo(obj)" and I think that technically it has always been "syntax sugar" and there have always been ways to call any "method" with any "object" of any "type."

    Sometime along the way we decided that "syntax sugar" means "it means the same thing as" but except for (<cast OtherType>obj).foo(), which means that the semantics of "syntax sugar" don't mean it's simpler than the phrase it was supposed to replace.

    • > It's not a "property" it's an attribute/field/member/key/column/variable/getter/function/procedure.

      For what it's worth, to a researcher in the field of programming languages (like the author of the post), these all have distinct unambiguous meanings. At least as far as PL goes, almost every term has a well-defined meaning, but as those terms were adopted into less-than-academic contexts, the meanings have diluted.

      "Property" is such a term in the context of programming languages research, and, in particular, it is a very specifically defined term in the realm of property-based testing (no surprise).

      > Even the constants are variables from the viewpoint of the CPU that has to load it in its registers.

      No; this is not what "variable" means. Registers are properties of the processor, i.e., they are implementation details; variables are an abstract concept from the domain of the formal language specification.

      > Sometime along the way we decided that "syntax sugar" means "it means the same thing as" but except for (<cast OtherType>obj).foo(), which means that the semantics of "syntax sugar" don't mean it's simpler than the phrase it was supposed to replace.

      No; this is not what "syntax sugar" means. If a language defines some syntax f and it "expands to" some other syntax g, then f is syntax sugar for g. This is well defined in Felleisen's "On the Expressive Power of Programming Languages" [0]. For example, Python's addition operator `+` is implemented in terms of a method `__add__`; therefore, `a + b` is syntax sugar for `a.__add__(b)`, because the former syntax is built on top of the latter.

      Notably, syntax sugar has nothing to do with casts; casts are semantic, not syntactic. There are also no promises about whether syntax sugar makes something "easier"; it's simply the ability to syntactically express something in multiple ways.

      [0] direct PDF: https://www2.ccs.neu.edu/racket/pubs/scp91-felleisen.pdf

  • "which nouns are Nouns, and which are just nouns"

    English (int al) distinguishes "proper" nouns as a subset of nouns. A proper noun is a name and is capitalized. Hence you might write: King Charles is a king. Now, you also capitalize the first word of a sentence but here King is not the first word of a sentence - King Charles is a name. If you make a small change (indefinite to definite article), you get: King Charles is the King. The second king becomes a moniker and no longer just a description.

    English also tends to get capitalization-loopy as soon as religion rocks up (any religion).

    You can obviously ignore all that bollocks and write whatever you like, mostly without blushing!

    Some other related languages eg German, capitalize all nouns.

    • Maybe this is a joke about the dangers of being abstract going over my head, but I don’t think they literally meant they don’t understand capitalization rules :)

    • I was being humorous/pithy. I meant e.g. the difference between "property" (the dictionary word) and "property" (the programming word, which is a domain-specific usage of the dictionary word) and "property" (as in Property-Based Testing, an even more domain-specific usage). It's analogous to the concept of regular nouns vs proper nouns, but not the same (which is why I didn't use the term "proper noun").

The property being tested in this example is “after inserting a row into a database table, the same row can be read back again.”

The insert statement isn’t independent of the database because the table needs to exist and its schema has to allow the inserted values. If the database is generated randomly, you need access to it to generate an insert statement that will work.

This is straightforward to do if the library is designed for it. Using my own TypeScript library [1]:

const insertCaseArb: Arbitrary<InsertCase> = arb.from((pick) => {

  const db = pick(dbArb);
  const table = pick(arb.of(...db.tables));
  const values = pick(rowArbForTable(table));

  return {
    db,
    tableName: table.name,
    insert: {
      kind: "insert",
      table: table.name,
      values,
    },
  };
 });

Why might that be difficult? Some property testing libraries don’t let you call a pick function directly.

[1] https://jsr.io/@skybrian/repeat-test