Acknowledged
CIQQA-3223

API doc: ChannelAssignment.initialize code example incorrectly features direct call to GenericChannel.initialize()

using Toybox.Ant;

var channelType = Ant.CHANNEL_TYPE_RX_NOT_TX  // Bidirectional Receive (Slave)
var network = Ant.NETWORK_PUBLIC;             // Ant public network
// Get the channel
channelAssign = new Ant.ChannelAssignment(channelType, network);

// Initialize the channel - assumes message callback method
GenericChannel.initialize(method(:onMessage), channelAssign);

Clearly Generic.Channel.initialize() can't be called directly; this should be replaced with a call to new GenericChannel.

https://developer.garmin.com/connect-iq/api-docs/Toybox/Ant/ChannelAssignment.html

  • Yes, totally agree with everything written here. If I wouldn't be able to figure out this if I haven't find a working example on github.

  • On a side note, I think it's too bad that Monkey C uses the same syntax for calling static methods on a class and for calling an instance method on the parent class, and the only difference is context.

    Same the fact that "as" is used for both type binding/annotations and type casst.

  • Also, I realize that the example is probably meant to represent the initialize function of a class that is derived from GenericChannel, in which case the example would make sense.

    Again, this would not at all be clear unless you *already knew that*, which kind of defeats the purpose of the example.

    (This isn't the first time that we've seen this pattern in a CIQ API Doc example, where it apparently shows a code fragment from the initialize function of a class derived from some standard CIQ class like View, except that the example does not make this clear at all.)

    In other words, the example makes sense when rewritten as this:

    I doubt many CIQ noobs would make that leap tho.

  • As a side note, none of these code examples make sense, because they all seemingly have code in the global scope which should properly be in a non-global scope (in a function).

    If you paste this example into an empty .mc file, it simply won't compile.

    Yes, experienced devs will "know what you mean", but neophytes won't.