Type Tag Discussion

A discussion moved from WhyNumberingShouldStartAtOne:


So-called "dynamic" languages are frequently rife with abominations. Few popular languages are as muddled as PhpLanguage.

Agreed. I consider flag-free to be a LiberatingConstraint to simplify dynamic typing model. I'll live with the few drawbacks.

What's a "flag-free"?

Sorry, I meant "tag-free". I used to use "flag", but others here preferred "tag" and I concurred. Related: DefinitionOfTypeTag, ColdFusionLanguageTypeSystem.

The only "tag-free" popular languages are assembly language and ForthLanguage. The majority of languages associate a type with every value, even if that type (in some languages) is usually "character string".

That is true, but that doesn't necessarily means it's "good". Perl and ColdFusion are also languages that use tag-free typing. A compromise may be to include tags as an option, but create built-in and library operations that don't rely on the tag. In other words, have the tag there if a given developer wants to use it, but don't otherwise encourage it in the "base" language. One-based indexing is one way to help. -t

I used to rant against excess OOP usage/hype, and now I rant against excess tag usage/hype. Dynamic languages have grown too "tag heavy". (By the way, we should probably move this discussion to some other topic or section.) -t

How do you measure "tag heavy"? How do you distinguish it from "tag light"? By the way, Perl internally represents numbers (for example) in three different formats. Perl's numeric operators typically work on only one of the three formats, but which of the three depends on the operator. So, when a numeric operator is invoked, Perl may have to reformat a number so it's appropriate to the given operator. Is that still a "tag-free" language? If it is, how does the language know which representation is currently used for any given number, in order to (possibly) reformat it for a given operator?

There are some operations/tricks that simply can't be done without a tag. DefinitionOfTypeTag has some examples. Reformatting a number doesn't require a "tag". What you describe appears to be parsing and/or validation.

Neither. Perl simply associates a type with every value, and uses that type to determine whether or not a reformat is needed.

Where is this "associating" happening? How can one test for its existence? (Let's assume we are testing the language behavior, not opening up the hood and studying a particular implementation. Ideally a language is defined by its behavior (I/O), not by a given compiler/interpreter implementation.)

Unless you're "opening up the hood and studying a particular implementation", why should it matter where the associating is happening? All that matters is that it does happen. It's what the language does: it uses a value's type to determine whether the value needs to be cast or not.

It matters because we (developers) mostly define and judge languages by their behavior, not by their implementation. Implementations should be swappable in theory anyhow. You seem to be using an interpretation of what the interpreter is doing. In the "tag" model, the variable has (at least) two parts: the value and the type tag. In a non-tag language, it has no (detectable) tag. An operation may do validation and/or parsing to process an operation, but it does not need a tag associated with the variable itself to do such. -t

Some argue that the "tag" is also an implementation detail, but really it's a model. Being a model, it may or may not reflect actual implementation. One may call a model a virtual implementation. And, models and implementations are perhaps interchangeable concepts, but that's another philosophical cave to explore another time. -t

From the above, your model appears to boil down to this: "A variable may (or may not) have a type." Some languages associate types with variables -- and constrain the variable's values to that type -- but some don't and allow assignment of values of any type. I'm not sure value (pun intended) is added by bringing tags into it, and it alludes to certain implementation mechanisms whether you intend it or not.

The "tag" means that there is something "separate" from value portion of a variable (or variable-like object). To me it's a pretty strait-forward concept, but hard to rigorously define in English. DefinitionOfTypeTag gives experiments that may tease out whether there is something extra besides just the value. It's not (just) an implementation mechanism because it affects externally-observable behavior.

Generally most language have operations to extract the value, and extract or examine the type (type-name or testing). If it's possible for the second to vary while the first stays the same, that strongly suggests that "type" is or can be independent of "value". Languages that don't have type tags will usually parse the value to determine or approve a "type". -t

I still don't see how this adds anything to the simple and intuitive notion that some languages associate a type with a variable, and others do not. The difficulties you claim exist appear to be entirely in your own mind. The vast majority of my students certainly don't have any problem with it, and the few who do are inevitably having such conceptual difficulties with programming in general that I don't see how tags would help. At best, invoking "type tags" would add complexity to something that, for them, is already way too complex.

Perhaps they are not ready for such models or discussion yet. When programmers start out, they often use a lot of trial and error to figure out such things. But after a while one starts wanting consistent mental models to be able to predict the behavior of languages without having to use trial and error or wait until gotcha's happen. Your students maybe haven't reached that stage yet. That's fine, but that doesn't mean the issues go away, only that they are swamped by others at the time.

If that's the case, then I'm not clear where you intend your "tag model" to be of value. If it's not intended for beginners, then who should use it? More advanced programmers easily appreciate the behaviour of various type systems without the artifice of tags. A mental model consisting of, for example, "every variable has a type, and values assigned to it must be of matching type" is trivially understood even by novice programmers.

And they are "not in my mind", I gave explicit examples. It can be shown that PHP differs from ColdFusion in externally observable behavior, for example. Thus, you are wrong on that one. I started using the tag model when trying to "explain" to myself why different dynamic languages handle "types" differently. A pattern emerged: tag languages and non-tag languages. And the non-tag languages were easier to handle, which got me wondering why people want to keep the miserable tag model.

Obviously, there are differences in TypeSystem behaviour and they are easily illustrated. Your apparent belief that people (in general, presumably) have difficulty understanding these, or that "type tags" help people understand them, is what appears to be in your own mind and your mind alone.

See above. Illustrate away. I gave code and tag examples, your turn...

Huh? I'm referring to your illustrations. They are easily created. What is in your own mind is the belief that "type tags" help people understand trivial notions like "a value is of a given type" or "a variable is of a given type, and can only be assigned values that match the type" because they find these difficult to grasp. They don't, except when they're already irredeemably lost. In that case, "type tags" don't help, because nothing will.

If you can make a visual or notational representation of them and write down steps a hypothetical interpreter goes through to evaluate expressions, it can give students or newbies a concrete sense of what is happening. It's a "machine" they can see and x-ray and follow the steps of with their own eyes in a step-by-step "mechanical" way.

You're describing implementation of languages, not their conceptual basis.

It can answer questions such as "why does appending a "+0" at the end of a JavaScript expression force "ambiguous" expressions to be "numbers"? And what is meant by "ambiguous"? One can give examples and compare them to non-ambiguous variable examples. What does the {v,t} of an ambiguous variable look like compared to the {v,t} of a non-ambiguous variable? It can also explain why some static languages are static: you can't change a variable's tag during runtime. -t

How does that any better than, "you can't change a variable's type during runtime"?

Because "seeing" it happen step-by-step, and compared to the alternatives (such as flex t's), often makes it clearer in the student's mind. Statements of rules like you give sometimes don't sink in because one cannot see it "in action" and in contrast to other statements (or representatives there of). That's why math theorems are often given with a set of problems to work out where students apply them, and are often required to show the steps. One "executes" the rules with samples to make them more concrete. If it's a common teaching technique for math, why is it (allegedly) not useful for code processing understanding? Are they that different, or are math teachers "doing it wrong"?

There is absolutely nothing wrong with working out problems, seeing processes happen step-by-step, and examining the internal workings of systems to understand them better. I encourage all of these things. Unfortunately, your model is none of these. Mainly, it's incomplete (it's {v, t}, essentially), but when you appear to add to it, or attempt to explain it, we get unrecognisable phrases like "flex t's" or "if two or more variables are being operated on and are mixed types, does the "t" override syntactical context and which "t" gets priority as far as alternative interpretations". I have no idea what those mean. For a model that's supposed to add clarity, it sure seems obscure.

You underestimate the ability of neophyte programmers to understand trivial concepts. Perhaps you're projecting your unusual difficulties with abstraction onto programmers in general?

I'm going based on my experience with other programmers. If your experience with such differs, so be it. I can't download your life experience, and vice verse. My statement above about "instinctive pattern recognition" is an accurate statement based on my actual experience with other coders, and I swear to God, Buddha, and all the Indian gods that it is true to the best of knowledge. And yes, I do have difficulty with your view of "abstraction". Thank God/Buddha/etc. I didn't get you as my instructor. Further, different students learn different ways. Some are verbal, some are visual, some like symbols, some like words, etc. The more angles you present the same info from, the more likely something is to "click" with a given student.


Example scenarios to explore:


TagFreeTypingRoadMap


OctoberTwelve


EditText of this page (last edited October 16, 2012) or FindPage with title or text search