Dave's Notebook

Writing Practice by David Rickmann.

Command Interface: Modularisation.

The original plan for my boat interface project was that I would build a console in the wheelhouse After I built the wheelhouse… with touchscreens integrated into it. Each touchscreen would have an LCARS panel loaded, but would work independently. Any data they needed (or generated) would be fetched from a central server (or sent back) as needed. Each display could be set to any panel as needed, but would have it’s own primary function. So, a few panels to, by default, control environmental functions, panels to show maps or navigation stuff, but reconfigurable.

With this in mind it makes sense to try and modularise the code I’m putting together down to panel level. The entire UI and Server functions should be, as much as possible, their own thing.

This is where shiny modules come in. Modules are a pair of UI and Server functions that live in their own file and can be run (and tested) entirely separately from the rest of the application.

Modules create a namespace, and that’s where their functions live. This makes sure that you can create an element in a module (let’s say a button in module “weatherpanel”) and call it “button1” and also a have a “button1” in the main body of your code and the two won’t get confused. button1 and weatherpanel::button1 are two different things.

Modules can also be reused. Arguably reusable code is the main reason for modules, but currently I’m only building whole panels out of modules. I will probably end up with some smaller modules as I proceed. . When you call a module you need to tell it what it’s name is.

weatherpanel("wp1")

This creates a weatherpanel called “wp1”. The name is quite important because you also need to tell your programme where the UI for it is. That looks like this:

weatherpanelUI("wp1")

We could, if we wanted, have a different weather panel and call it “wp2”. The two panels would exist completely seperate from each other. They wouldn’t have any idea that the other existed. This is a bit pointless in the case of a module like weatherpanel, but for some other panels may be very useful.

All in all. Modules are good. They help us turn quite complicated applications into smaller ones. I spent much of today turning everything I’d so far done into modules.