[PD-dev] Refactoring Pure Data (2 of 2)

Mathieu Bouchard matju at artengine.ca
Tue Sep 12 23:49:32 CEST 2006


On Tue, 12 Sep 2006, Vincent Lordier wrote:

> Let me take a quick example to illustrate my point :
> (from s_inter.c, removed #ifdefs for this example)
>
> void sys_set_priority(int higher)
> {
>   struct sched_param par;
>   int p1 ,p2, p3;
>   p1 = sched_get_priority_min(SCHED_FIFO);
>   p2 = sched_get_priority_max(SCHED_FIFO);

What's wrong in your example is that you rename p2 to something else, 
instead of removing it. p2 is not used in your example. However, when I 
look at the source, I see that it's because of the #ifdefs that you 
remove.

Even considering the actual implementation instead of the simplified 
example, I wouldn't consider that renaming p1 to priority_min is 
really helping anyone, because they already know p1 is the minimum 
priority by looking two lines above. All uses of p1 lie within 5 lines of 
code, so using a longer name doesn't do much more than making the name 
longer to read. In some extreme situations (not this function) this can 
make the code harder to read, as the longer names clutter the function.

>      fprintf(stderr, "priority %d scheduling enabled.\n", priority);
>       fprintf(stderr, "couldn't change process priority to %d.\n",
> priority);
>       fprintf(stderr, "%s (%d)", strerror(error_desc), error_desc);

You didn't replace the fprintfs by posts. It should be posts because then 
it can be routed through the GUI.

> - Localization can be done here,

No, localization should be done in the GUI. What should be done 
server-side, is to make error messages easier to process by the GUI.

> - Safe fprintf can be used to avoid overflow.

Which overflow?

> An explicit name saves the dev brain power at coding time ;)

I assert that often it doesn't. A name shouldn't be more explicit than it 
needs to be, and it's certainly possible for names to be too explicit, and 
i don't mean the "parental advisory" sys_defaultfontshit, I mean saying 
things that are too obvious because they're already in your face 15 times 
in the same page and cause the code to go on for longer than you should 
have to read.

  _ _ __ ___ _____ ________ _____________ _____________________ ...
| Mathieu Bouchard - tél:+1.514.383.3801 - http://artengine.ca/matju
| Freelance Digital Arts Engineer, Montréal QC Canada


More information about the Pd-dev mailing list