On Tuesday 07 April 2015 11:24:05 Kesavan, Vijay S wrote:
> There are sample applications to showcase the usage of the C-SDK at
> resource/csdk/stack/samples

Ah, I see. There's a reason I didn't find them: they're written in C++. I was 
looking for C sources...

Anyway, I had the qualification of "good" examples. I don't consider this a 
good example:

static std::string putPayload = "{\"state\":\"on\",\"power\":5}";

The payload is hardcoded! An example application should be teaching how to do 
things right...

This sample application is also designed to be a testcase, as seen by a 
variable (!) called TEST_CASE. That has implications on what the application 
does and doesn't do, since it's not designed to be a teaching tool.

Another part I feel quite strongly about is this:

    while (!gQuitFlag) {

        if (OCProcess() != OC_STACK_OK) {
            OC_LOG(ERROR, TAG, "OCStack process error");
            return 0;
        }

        sleep(2);
    }

No example, under any circumstances, should EVER use the "sleep" function. 
There are very few valid uses for the sleep/msleep/usleep/nanosleep/etc family 
of functions and most novice developers will not know them[*]. We need to 
write our examples in the way that real applications should be using the stack 
and clearly this isn't it.

[*] given that this is in our code, it's clear also that many advanced 
developers don't know either.
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

Reply via email to