3 ms·
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.
by ainar-g 9y ago
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.
- mjburgess 9y agoAt 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.
- crawshaw 9y agoOne 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 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.