coding style question
I've noticed that in 2.6 many of the constructs like:
typedef struct foo { blah }
have been changed to
struct foo { blah }
what was the reasoning for this?
Thanks
Jay
Signature · 4 lines
* Jay Denebeim Moderator rec.arts.sf.tv.babylon5.moderated * * newsgroup submission address: [email protected] * * moderator contact address: [email protected] * * personal contact address: [email protected] *
Quoted 9 lines · Jay Denebeim
I've noticed that in 2.6 many of the constructs like:
typedef struct foo { blah }
have been changed to
struct foo { blah }
what was the reasoning for this?
We hate typedefs.
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon the nation that is attacked, and every man will be glad of those conscience-soothing falsities, and will diligently study them, and refuse to examine any refutations of them; and thus he will by and by convince himself that the war is just, and will thank God for the better sleep he enjoys after this process of grotesque self-deception." -- Mark Twain
Quoted 1 line · Matthew Wilcox
On Wed, Feb 25, 2004 at 06:16:48PM +0000, Jay Denebeim wrote:
(I mentioned typedefs being removed)
Quoted 3 lines
Quoted 1 line
what was the reasoning for this?
We hate typedefs.
Well, that's certainly convincing. Funny that, I don't recall hating typedefs, in fact I distinctly recall liking them and being happy when they were added to Lattice's Amiga compiler back in the stone age. Is there some particular reason 'we' hate them?
Jay
Signature · 4 lines
* Jay Denebeim Moderator rec.arts.sf.tv.babylon5.moderated * * newsgroup submission address: [email protected] * * moderator contact address: [email protected] * * personal contact address: [email protected] *
On Wed, 25 Feb 2004 11:40:27 -0700 (MST) Jay Denebeim wrote:
| On Wed, 25 Feb 2004, Matthew Wilcox wrote: | | > On Wed, Feb 25, 2004 at 06:16:48PM +0000, Jay Denebeim wrote: | (I mentioned typedefs being removed) | > > what was the reasoning for this? | > | > We hate typedefs. | | Well, that's certainly convincing. Funny that, I don't recall hating | typedefs, in fact I distinctly recall liking them and being happy when | they were added to Lattice's Amiga compiler back in the stone age. Is | there some particular reason 'we' hate them?
For anything other than very basic types, they hide/obfuscate data structures. If it's a struct, we had rather see a struct used there.
--
~Randy
In article <[email protected]>,
Quoted 2 lines · Randy.Dunlap
For anything other than very basic types, they hide/obfuscate data structures. If it's a struct, we had rather see a struct used there.
Okay, that's more or less what I figured it was, thanks. Personally I never found that it did that for me, the 'struct' always seemed redundant. That's just my opinion though, and I can certainly understand others.
Thanks for the answer.
Jay
Signature · 4 lines
* Jay Denebeim Moderator rec.arts.sf.tv.babylon5.moderated * * newsgroup submission address: [email protected] * * moderator contact address: [email protected] * * personal contact address: [email protected] *
Quoted 3 lines
Personally I
never found that it did that for me, the 'struct' always seemed redundant.
I don't find it redundant at all -- it tells me the type is a structure as opposed to a scalar or pointer. Realistically, no one studies the declarations of types before reading the code that uses them. When I see a variable foo, it helps me a lot to guess what the variable is if I know it is a structure.
For that reason, the usual anti-typedef rule is just "we hate typedefs for structs," since the only difference between "struct foo" and "foo_t" is that one uses slightly fewer characters and obscures the fact that it is a structure. On the other hand, the difference between "int" and "pid_t" is much greater. The name "pid_t" carries a lot of information in it that "int" does not.
Quoted 4 lines · Jay Denebeim
Quoted 1 line · Matthew Wilcox
On Wed, Feb 25, 2004 at 06:16:48PM +0000, Jay Denebeim wrote:
(I mentioned typedefs being removed)
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
what was the reasoning for this?
We hate typedefs.
Well, that's certainly convincing. Funny that, I don't recall hating typedefs, in fact I distinctly recall liking them and being happy when they were added to Lattice's Amiga compiler back in the stone age. Is there some particular reason 'we' hate them?
Hi here's part of Greg's presentation from some time back:
http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/mgp00024.html
Really you want the next slide off the above ;-)
-- Patrick Mansfield
On Wed, 25 Feb 2004, Patrick Mansfield outgrape:
Quoted 14 lines · Jay Denebeim
Quoted 12 lines · Matthew Wilcox
Quoted 2 lines · Jay Denebeim
(I mentioned typedefs being removed)
Quoted 3 lines
Quoted 1 line
what was the reasoning for this?
We hate typedefs.
Well, that's certainly convincing. Funny that, I don't recall hating typedefs, in fact I distinctly recall liking them and being happy when they were added to Lattice's Amiga compiler back in the stone age. Is there some particular reason 'we' hate them?
Quoted 6 lines
Hi here's part of Greg's presentation from some time back:
http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/mgp00024.html
Really you want the next slide off the above ;-)
"... and we hates hobbitses."
Sorry, just couldn't resist, but that voice popped into my head.
Signature · 5 lines
Clay Haapala ([email protected]) Cisco Systems SRBU +1 763-398-1056 6450 Wedgwood Rd, Suite 130 Maple Grove MN 55311 PGP: C89240AD "You thought there wouldn't be a nuclear war? There have been *seventeen* of them!" -- from "Millenium", by John Varley
Two reasons I can think of off the top of my head:
* POSIX prefers "struct foo" as opposed to "foo" or "foo_t"
* typedefs obscure the fact that a data structure is in fact a structure, and not a native machine type. Typically typedefs are best used for discrete elements those contents are either opaque or a single value.
Jeff