Re:Neugram – Scripting in Go
by ainar-g on Saturday November 04, 2017 @03:22AM
(#15624130)
Can you elaborate on what syntactic conveniences are difficult to implement and why? Language design is on of my hobbies, so I really would like to know that.
[ Parent
| on HN ]
One good example is untyped constants. They form a large extension to the type system only present at compile time. It is a good example because there is an excellent blog post describing them in detail: https://blog.golang.org/constants
In particular note the difference between
const hello = "Hello, 世界"
and const typedHello string = "Hello, 世界"
one of these can be assigned to named string types, the other cannot.As a user of Go I find untyped constants to be extremely useful. They almost always do what I want without surprise. Implementing them however, is not trivial.
A tricker example is embedding. It adds a lot of complexity to the type system. As a user, it can be a bit surprising, but I admit it is very useful.
At a guess, I would describe it as a trade off between syntax and semantics.
Languages that have simpler syntax tend to have far more complex semantics (to infer what's missing, etc.).
Eg. python's semantics is horribly complex: "hello".upper() is something like str.__dict__['upper']("hello")) -- which is all run-time. Whereas say a C++ version amounts to quite a simple run-time function call on some bytes.