![]() |
|
#1
|
||||
|
||||
C Coding StyleI am in the process of upgrading my linux kernel and I came upon this file that I found extremely interesting.
This (attached file) is the linux kernel maintaners view of the proper syntax for C. I found this very enlightening and thought it may be a good source for others as well. This matches my coding style. Not only that, but the items where I vary, I actually feel that this is a better style approach than mine. It is interesting that they mention Kernighan and Ritchie, as this was the authors of the first book that I learned C from and as mentioned in the file, the prophets of the C language. I think that they would faint if they saw some of the modern C/C++ code being written. To clarify, C++ is not C. C++ is an OO language first and foremost. Therefore much of the coding style around C++ is created from its OO relatives and not from the original C. I am not bashing C++, quite the opposite, I absolutely love some of the features of C++. But I am questioning the deviation from C syntax highlighting. One more thing. If you are being taught C++ or C, the syntax style that your professor prefers is the correct one at that time. You can set your own style as you work on your own projects. I would love to hear differing opinions on this. I am not posting this to say this is the way everyone should code, but rather to open a dialogue about different coding styles. |
||||
|
#2
|
||||
|
||||
|
That is one MESSY text file. Could you please attach one that is more organized and easy to read?
|
|
#3
|
||||
|
||||
|
Quote:
Actually, no, I can't. It is not mine and I don't particularly want to rewrite it. Remember, it is a "text" file, not an RTF or a formatted file. And quite frankly for a text file, I find it extremely readable. My suspicion is that you are using Windows text editor with no word wrap. My suggestion is to use wordpad with word wrap (which I believe is a default) as it recognizes both the *nix way for a newline as well as the windows way for a newline. |
|
#4
|
||||
|
||||
|
Well you're right in one aspect. I am using notepad to view it. I only use my Fedora installation to mess around and learn various things. I'll be using it more once I start unix programming, though.
edit: opened in it wordpad. MUCH better. thanks for the tip |
|
#5
|
||||
|
||||
|
I do have a gripe with the info in the coding style text file. And that is it's blind acceptance as in:
Quote:
And I completely disagree with the statement about readability. I find the following much easier to read: CPP / C++ / C Code:
My bottom line is decide for yourself what is correct for your style. Try my way, try K&R's way, make up your own way. Then decide what makes sense to you -- keeping in mind other people may have to read you code too. So use some common sense. |
|
#6
|
||||
|
||||
|
I TOTALLY agree with you WaltP
PHP Code:
I never figured out why people generally preferred it the other way... __________________
J de Silva Learning Journal | GIDForums™ | GIDNetwork™ | GIDWebhosts™ | GIDSearch™ |
|
#7
|
||||
|
||||
|
Quote:
On this we agree 100%. The main thing is to think about style and readability and then come up with a style that suits you. While the placement of my brackets and if/else statements is exactly like that discussed in the file (and in my opinion, it is the more readable way ), I disagree with their use of 8 spaces for a tab. I agree with the rational (shorter, less complicated functions) but not the practice.Probably, the biggest reason that I posted it was its discussion of mixed case variables and function names. This is a personal pet peeve of mine and I thought I may be the only one in the *modern* programming world that cringes everytime I see a mixed case variable. Once again, this is my opinion and not something I am preaching. Walt, one thing to keep in mind when reading this file, is that it is presented somewhat tounge in cheek. There is no need to take this file offensively or even follow its suggestions. (unless you are going to be contributing to the linux kernel sometime soon. ) |
|
#8
|
||||
|
||||
|
Yeah, I agree with Walt about the braces. The file did have some good advice, but I was really astonished at how the file tried to forcefully tell its readers that there was only one right way to do braces :-P
|
|
#9
|
||||
|
||||
|
Quote:
By the way, speaking of smileys, what significance are and ? Are they just for fun or do they have a deeper meaning? I kinda like the hairy one. Looks like me in the morning... |
|
#10
|
||||
|
||||
|
That banana was my AIM buddy icon for quite awhile.
|
Recent GIDBlog
Review: Gel laptop cooling pad by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| coding a word with a givin factor | funnyf | C++ Forum | 2 | 13-Jan-2004 09:32 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The