Monday, July 12, 2021

Avoiding Tour De Force Sample Code

Sample code is a wonderful way to teach and learn coding.  The problem with a lot of sample code is that it is just too complicated and to fancy. I call it tour de force code because it seems like the authors are trying to show off how awesome their coding skills are. That’s probably a bit harsh but I feel like using 1,000 lines of code to show off every single feature of a concept/API/Class or what ever is overwhelming. It is the sort of thing that sends beginners a message that things are over their head.

I’ve always tried to avoid over complicated examples that I write for students. Far too many of the samples one finds from major vendors are either too complicated or leave out important information that beginners are not likely to have. Of course most samples on the internet are written for professional developers so that’s understandable. Beginners (students) requirements are far different from those of professional developers.

It doesn’t have to be that way though. The Phidgets website (see my post on Phun with Phidgets for context) has a sample code generator that I really like. (https://www.phidgets.com/?view=code_samples ) There are a number of options depending on how much a developer wants to do themselves and how much they want generated. Any way you do it there will be lots to do to make your final program. The samples are very basic but they do let one test a device and see some of its features. I wish more companies did things like this.

Over the years I have written some code generators myself. In fact, one of my masters degree projects was a simple “compiler” that generated code in multiple languages to work with a user interface library.  It generated very basic code that handled the most repetitious and tedious parts of the code so that a developer could focus on the interesting parts of code. It had the advantage that it used as input the markup language for the documentation system. It’s a shame that commercial systems like that don’t exist today.

I’m starting to think that writing code generators might be an interesting project. Something like a user interface that asks for variable names and things like loop parameters and generates code snippets. Some provisional IDEs, Visual Studio for example. provide help with generated snippets but I think that coding a generator might help students understand the code they use better. It’s just an idea at this point but I want to think more about it.

No comments: