On Wednesday 10 January 2007 21:56, David Anderson wrote:
> Hi,
>
> So, now that the code is reindented, here is the first documentation patch.
>
> On a side-note, I have a couple of questions regarding the code of the
> AIC driver.
>
> The mode passed to aic_set_vector is defined as an U32, with possible
> values #define'd. Is there a reason the API does not use an enum (and
> then cast it to U32 when setting the register, obviously) ? 

This is somewhat of a taste issue.

I don't like the use of enums for values with a physical meaning that needs 
translation from enum space into physical space because this is wasteful and 
confusing and error prone. I think enums are great for abstract values with 
no physical meaning eg. state machine states etc.

My absolute pet hate usage of enum that I have seen is 

enum{
baud_300,
baud_600,
baud_9600,
...
}

In the called function this then needed some code like

  switch(baud_enum_passed_in){
  case baud_300:
     br = 300;
    break;
   case baud_600:
   .....
}

Unfortunately one of the cases got duplicated (a missing break caused a fall 
through) but in all that repeated code it was relatively difficult to spot

Just using 9600 or whatever as a straight value would have been a lot easier!


> Same 
> question for the isr parameter: any reason to make the caller cast the
> value, rather than accept a void(*)(void) and cast it to U32 in the
> function?

I have a very good reason for doing this....

I am sometimes a lazy slob!

This code has been stolen from something I wrote in a hurry a few years ago. 
It was late at night and my brain was fried and I could remember U32 far 
easier than that whole void(*)(void) thing....

Every now and then I see the warning fly past as I compile and I think hey I 
should fix that, then that lazy slob that lives inside my body takes over 
again!

-- Charles


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Lejos-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lejos-discussion

Reply via email to