Hacker News new | ask | show | jobs
by gorgoiler 30 days ago
It’s nice they tried with a more fleshed out exemplar. Polymorphism (“generics”) and interfaces (“OOP”) would have been even better to see, especially across any kind of visibility boundary enforced by the language (packages, and the like.)

Programming to an abstract interface — and in large codebases, enforced visibility controls — represent the middle ground everyone wants, in my experience, between “OOP” and “sir, this is C”.

4 comments

Subtyping and generics raise the question of whether containers are covariant or contravariant.
Why would that be true?
Yes,

The example definitely shines. Doing something barely non-trivial is great since it gives a feeling for the language. I wish other language introduction pages would take note.

I really like this language introduction.

It does feel like you need some shared understanding with the author about what the interesting parts of a programming language are and what can be left implicit.

Perhaps the author and I have similar intuitions? I guess I also like that isn't pure LLM output style. It was refreshing to see some human work.

> Polymorphism (“generics”) and interfaces (“OOP”) would have been even better to see

Yep. Interface-based (true) delegation between objects would be my go-to if it existed.

a more fleshed out exemplar

What's the difference between an exemplar and an example?

between “OOP” and “sir, this is C”.

That's more templates, ownership and operator overloading.

Polymorphism is not a modern way to program because it introduces dependencies and enormous speed hits from pointer chasing, both of which are corrosive to a good program.

An example is any random instance of something that illustrates a concept. You can load up a document with examples to demonstrate a range of possibilities. An exemplar is the chosen best way to model and explain a concept.

So in a programming text for a new language, one would use examples of things that are strings, or examples of structures one might declare. You might even see examples of multiple ways to solve a problem in code. An exemplar though shows the one best - or at least most recommended - way to do something in the language.

An exemplar is the chosen best way to model and explain a concept.

Why would you use a worse example and how do you know the example you are looking at is the best?

You'd choose something that's less than ideal if you're including multiple examples, because it's unlikely every example is the best one. You might give an example labelled specifically as a bad example. The word exemplar might be more familiar to many English speakers as the form "exemplary".

It can be difficult to know if your example is the exemplar. It can be reasonably assumed that if the creator of the language provides only one example, it at least should be the best one. It is at least the best one in the docs if it's the only one.

They said a 'more fleshed out exemplar' which means that the current exemplar must not be an exemplar.
I suppose that depends on whether by "best example" one means "the best example presented", "the best example extant", or "the best example possible".