Re: [edk2] Coding Standard query

Subject: Re: [edk2] Coding Standard query

From: Andrew Fish <afish@apple.com>

To: Ifan Llwyd <ifan.llwyd@yahoo.co.uk>, edk2-devel@lists.sourceforge.net

Date: 2012-05-10 17:40:57

Ifan,

I wrote the grandfather/grandmother of this document a long time ago....

The academic data shows the most important part of the coding standard is consistency (uniformity). There is alway an argument to made that XYZ is an example of why a rule should be one way or another. There is always a tradeoff, and in general we strive for simplicity in the rules. 

Andrew Fish

Uniformity is the key theme of these rules. Although you may disagree with many of the decisions made here, please try to swallow your indignation and conform to these standards. In addition, some of the style suggestions will also help you avoid pitfalls inherent in the C language. The goal of this document is making you, and those who follow you, more productive.
Some of the strict rules for protocol and driver construction may seem overly onerous. Dont panicthere is a method to our madnesswe intend to construct wizards to aid in the construction of protocol include files and device driver templates. The consistency will prevent name collision and require much less rote memory (or code surfing) to remember the names of protocol declarations or GUID definitions.
In conclusion, its uniformity, uniformity, uniformity. With that said, this document is not intended to be dogma. If there are valid reasons to violate a rule, it is okay, as long as the senior developers on the project all agree its okay.
A good software engineer will think about maintaining a consistent and uniform coding style. Having a set of rules to follow allows you to spend more time solving real problems and less time thinking about style. If you are a more junior software engineer, and you dont think about what it will take to maintain your code, you may not see the benefitbut now is a good time to start, so you can be a good software engineer. Junior software engineers will also benefit by being able to understand other peoples code much easier because the code will be written in a consistent manner. Consistency and uniformity enable productivity.



On May 10, 2012, at 4:26 AM, Ifan Llwyd wrote:

I've just been checking my code against the coding standard (EDKII C Coding Standards Specification Revision 0.53), and found a problem.
In section 6.8 "C Function Layout" is the statement "Initializing a variable as part of its declaration is illegal."
Is it really intended that const pointers (e.g.) are not allowed?
This seems hard to justify, especially given the advantages of const for code readability.
Is there any good case for this?
 
I think there is a clear case for something like:
...
FunctionName (
  UINT8 * Buffer,
  UINTN Length
  )
{
UINT8 * const Final = &Buffer[Length / sizeof(*Buffer)] ;
...
}
 
Of course, that can be done without the const and split into 2 lines, but it loses clarity and is less safe.
 
 
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel