xsl-list
[Top] [All Lists]

Re: typescript [was: Re: [xsl] How to write (existential) predicates with maps/Why is there no effective boolean value for a map?]

2019-02-13 09:12:26
On Wed, Feb 13, 2019 at 3:08 AM Liam R. E. Quin liam(_at_)fromoldbooks(_dot_)org
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
.....

Typescript uses structural typing, not named typing.

Actually this statement is not entirely correct -- a Typescript
programmer can use both. To achieve strict typing, which people like
me would prefer, just change:

   class Student { ...}

to

  class Student implements Person { ...}

I believe that offering differing typing choices (starting from no
typing at all -- all Javascript code is valid in Typescript as
Typescript is a superset of Javascript) is an intentionally-designed
flexibility in the language. Of course, many developers such as myself
would use just strict typing style, so that when the transpiler
reports typing errors one will correct them even before compile-time.

Cheers,
Dimitre


On Wed, Feb 13, 2019 at 3:08 AM Liam R. E. Quin liam(_at_)fromoldbooks(_dot_)org
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

On Wed, 2019-02-13 at 08:46 +0000, Mukul Gandhi 
gandhi(_dot_)mukul(_at_)gmail(_dot_)com
wrote:
Sorry, if this is off topic.
It is. I have changed the subject line, but it is also getting off the
mailing list’s topic. I’ll answer because we can compare typescript's
interface-based type system to that of XSLT (briefly).

I've been reading about Typescript, during this thread. On the link,
https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html
following sample program appears,
[garbled gibberish here]

Ungarbling, i get,
class Student {
    fullName: string;
    constructor(public firstName: string, public middleInitial: string, 
public lastName: string) {
        this.fullName = firstName + " " + middleInitial + " " + lastName;
    }
}

interface Person {
    firstName: string;
    lastName: string;
}

function greeter(person : Person) {
    return "Hello, " + person.firstName + " " + person.lastName;
}

let user = new Student("Jane", "M.", "User");

document.body.innerHTML = greeter(user);

So you are asking, does a Student object confom to the Person
interface?  That is, does the object have the required public fields.
We can see by inspection that it does.

I'm not been convinced, how above typescript program can be correct.
A
Student object is being created (with the let statement), and it is
passed
to the greeter function. The greeter function is defined to accept
Person
(interface). In the above program, there is no syntactic link between
Student and Person (class Student is not written implementing the
interface
Person, and the structures of class Student and interface Person are
different

Correct. However, the Student object has the same structure as a Person
object. Typescript uses structural typing, not named typing. This is
sometimes called duck typing, after a Monty Python sketch (if she
weighs the same as a duck she must be a witch).

Early XQuery drafts used structural typing, i think because (some of)
the developers perhaps didn’t have good understanding of XST and DTDs
tand the fact that name-based typing, with its explicit syntactic
links, was an essential part of XML.

Why is this? Because the point of XML is not trusting data at system
boundaries. That is a large part of why we have DTDs and XSD. Duck
typing says, if you say it’s a metric velocity and it has a number, i
believe you. Named typing says, a metricVelocityType and an
imperialVelocityType value are not compatible without conversion.

We ended up with named typing in XSLT, XPath and XQuery, thankfully.
Its less convenient for some things, but a better cultural fit, and
more suited to the sort of tasks we might attempt.

Liam


--
Liam Quin, https://www.delightfulcomputing.com/
Available for XML/Document/Information Architecture/XSLT/
XSL/XQuery/Web/Text Processing/A11Y training, work & consulting.
Web slave for vintage clipart http://www.fromoldbooks.org/

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>