No one balance

When I was starting this blog I had to come up with a name. I considered Balanced Programming but rejected it. To me this suggested that there might be one true balanced way of programming and I just don’t think that’s right. The balance depends on the circumstances: the product, the people, the situation. Getting the right balance has to be a process in itself.

Access control syntax

I’ve talked about Bob Nystrom’s work before. He wrote the book Game Programming Patterns which was impressive. He’s also written another book Crafting Interpreters as he’s interested in language design. Recently he wrote a post about Access Control Syntax which is about how to go about adding modules to his scripting language. Specifically how to specify what’s internal and external to the modules.

Different language go about this in different ways:

  • Modifier keywords are used by Java to explicitly mark the category for individual identifiers.
  • Modifier sections are used by C++ to mark a series of identifiers as belonging to the category.
  • Naming conventions are used by Python to suggest how the identifiers should be accessed.
  • Export manifests are used by Lisp to list which identifiers should be exposed.
  • Declaration markings are used by Oberon to mark the category for individual identifiers.

He considers pros and cons for each:

  • Is the technique obvious? A keyword announcing something as public or external should be very easy for someone to work out or pick up. A special declaration symbol or a naming convention might well not be understood or even noticed.
  • What should the default be? If everything is public by default then it’s easy to integrate but potentially dangerous. If everything is private by default then coding safely is easy but using it might be harder.

I liked all this of this thinking. He’s got a specific problem and he’s trying to find the right balance amongst conflicting goals.

He considers the possibilities of modifiers:

In Rust, pub is a really nice little keyword to flip to public when the default is private, but there is no obvious converse. private would be the longest keyword in my language. pri doesn’t read like anything.

I don’t like the pub keyword. I’ve discussed my ideas about good naming conventions before. For him pri doesn’t read like anything but, for me, pub also doesn’t read like anything. For me the a good name should be a short word but no shorter than that. While I can guess what pub might mean in a new language from context it’s meaning doesn’t leap out at me. I suspect it strongly depends on what other languages you’ve used and what keywords they use. For me the limiting factor with language isn’t how quickly I can type it out. In the end there’s more reading than writing and clarity in reading is more important than speed in writing.

This isn’t his final idea and his article doesn’t conclude with a firm decision on what to go for. While I don’t like some of the options Bob is looking at that doesn’t mean he shouldn’t thinking about them and even pick them. There is no one true balance. He’s writing a hobby project and wants to make a language that encourages getting things done. He acknowledges that for a systems critical language defaulting to private is the better choice.

If I was making a language I would be tempted by a private by default and a public keyword. That’s safe, explicit and only takes 6 characters. I would wonder about marking a section as well but perhaps not like C++ as the keywords don’t seem to have proper ownership there. It would deserve proper thought.

In the end

While there might not be a single right way of doing things there are plenty of wrong ways. Stopping to think about what you’re doing and why are a good way to avoid those. While I probably won’t be jumping to use his language I’ll be interested to see any other choices he makes for it.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *