CVS: main/libmpcodecs pullup.c,1.20,1.21
CVS change done by Alex Beregszaszi Update of /cvsroot/mplayer/main/libmpcodecs In directory mail:/var2/tmp/cvs-serv15342 Modified Files: pullup.c Log Message: adding proper parenthesing Index: pullup.c =================================================================== RCS file: /cvsroot/mplayer/main/libmpcodecs/pullup.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- pullup.c 21 Oct 2004 11:55:19 -0000 1.20 +++ pullup.c 31 Jan 2005 11:21:31 -0000 1.21 @@ -218,16 +218,16 @@ struct pullup_buffer *pullup_lock_buffer(struct pullup_buffer *b, int parity) { if (!b) return 0; - if (parity+1 & 1) b->lock[0]++; - if (parity+1 & 2) b->lock[1]++; + if ((parity+1) & 1) b->lock[0]++; + if ((parity+1) & 2) b->lock[1]++; return b; } void pullup_release_buffer(struct pullup_buffer *b, int parity) { if (!b) return; - if (parity+1 & 1) b->lock[0]--; - if (parity+1 & 2) b->lock[1]--; + if ((parity+1) & 1) b->lock[0]--; + if ((parity+1) & 2) b->lock[1]--; } struct pullup_buffer *pullup_get_buffer(struct pullup_context *c, int parity) @@ -253,8 +253,8 @@ /* Search for any half-free buffer */ for (i = 0; i < c->nbuffers; i++) { - if (parity+1 & 1 && c->buffers[i].lock[0]) continue; - if (parity+1 & 2 && c->buffers[i].lock[1]) continue; + if (((parity+1) & 1) && c->buffers[i].lock[0]) continue; + if (((parity+1) & 2) && c->buffers[i].lock[1]) continue; alloc_buffer(c, &c->buffers[i]); return pullup_lock_buffer(&c->buffers[i], parity); }
On Monday, 31 January 2005 at 12:21, Alex Beregszaszi wrote:
CVS change done by Alex Beregszaszi
Update of /cvsroot/mplayer/main/libmpcodecs In directory mail:/var2/tmp/cvs-serv15342
Modified Files: pullup.c Log Message: adding proper parenthesing
Oh, good. I've been keeping exactly the same patch in my tree for months, but I've never had the time to post it with proper explanation why it is needed. Thanks. -- MPlayer RPMs maintainer: http://rpm.greysector.net/mplayer/ "I am Grey. I stand between the candle and the star. We are Grey. We stand between the darkness ... and the light." -- Delenn in Grey Council in Babylon 5:"Babylon Squared"
Hi,
Modified Files: pullup.c Log Message: adding proper parenthesing
Oh, good. I've been keeping exactly the same patch in my tree for months, but I've never had the time to post it with proper explanation why it is needed. Thanks.
I had this since months there aswell :) -- Alex Beregszaszi e-mail: alex@fsn.hu Free Software Network cell: +36 70 3144424
On Tue, Feb 01, 2005 at 05:10:19PM +0100, Dominik 'Rathann' Mierzejewski wrote:
On Monday, 31 January 2005 at 12:21, Alex Beregszaszi wrote:
CVS change done by Alex Beregszaszi
Update of /cvsroot/mplayer/main/libmpcodecs In directory mail:/var2/tmp/cvs-serv15342
Modified Files: pullup.c Log Message: adding proper parenthesing
Oh, good. I've been keeping exactly the same patch in my tree for months, but I've never had the time to post it with proper explanation why it is needed. Thanks.
it's not needed and i was going to flame alex for not knowing c order of operations and cluttering the code (which is considered external imported code, not mplayer-native code) for cosmetics. but it's not worth arguing over... rich
Hi,
Update of /cvsroot/mplayer/main/libmpcodecs In directory mail:/var2/tmp/cvs-serv15342
Modified Files: pullup.c Log Message: adding proper parenthesing
Oh, good. I've been keeping exactly the same patch in my tree for months, but I've never had the time to post it with proper explanation why it is needed. Thanks.
it's not needed and i was going to flame alex for not knowing c order of operations and cluttering the code (which is considered external imported code, not mplayer-native code) for cosmetics. but it's not worth arguing over...
It's not about my knowledge but about bad compilers... -- Alex Beregszaszi e-mail: alex@fsn.hu Free Software Network cell: +36 70 3144424
On Tue, Feb 01, 2005 at 08:53:14PM +0100, Alex Beregszaszi wrote:
Hi,
Update of /cvsroot/mplayer/main/libmpcodecs In directory mail:/var2/tmp/cvs-serv15342
Modified Files: pullup.c Log Message: adding proper parenthesing
Oh, good. I've been keeping exactly the same patch in my tree for months, but I've never had the time to post it with proper explanation why it is needed. Thanks.
it's not needed and i was going to flame alex for not knowing c order of operations and cluttering the code (which is considered external imported code, not mplayer-native code) for cosmetics. but it's not worth arguing over...
It's not about my knowledge but about bad compilers...
rotfl, is there a compiler that compiles this wrong?? maybe gcc3? :)))) rich
On Friday 04 February 2005 17:37, D Richard Felker III wrote:
On Tue, Feb 01, 2005 at 08:53:14PM +0100, Alex Beregszaszi wrote:
Hi,
Update of /cvsroot/mplayer/main/libmpcodecs In directory mail:/var2/tmp/cvs-serv15342
Modified Files: pullup.c Log Message: adding proper parenthesing
Oh, good. I've been keeping exactly the same patch in my tree for months, but I've never had the time to post it with proper explanation why it is needed. Thanks.
it's not needed and i was going to flame alex for not knowing c order of operations and cluttering the code (which is considered external imported code, not mplayer-native code) for cosmetics. but it's not worth arguing over...
It's not about my knowledge but about bad compilers...
rotfl, is there a compiler that compiles this wrong?? maybe gcc3?
:))))
It's also about clarity, a few parentheses too much never hurt readability of code or mathematial formulas aswell. If in doubt, use em :-) It's a bit like: if(x) for(;x<y;x++) if(x%2) do_some_thing(x); versus: if(x) { for(;x < y; x++) { if(x%2) { do_some_thing(x); } } } Both are syntactically correct, but the first version is surely more error-prone when changing code and less readable. And if you're to lazy for wrtiting parentheses, simply get a good editor like vim, that does the job for you.
rich
-- Best Regards, Atmos ____________________________________________ - MPlayer Developer - http://mplayerhq.hu/ - ____________________________________________
On Sat, Feb 05, 2005 at 01:01:56AM +0100, Felix Buenemann wrote:
On Friday 04 February 2005 17:37, D Richard Felker III wrote:
On Tue, Feb 01, 2005 at 08:53:14PM +0100, Alex Beregszaszi wrote:
Hi,
Update of /cvsroot/mplayer/main/libmpcodecs In directory mail:/var2/tmp/cvs-serv15342
Modified Files: pullup.c Log Message: adding proper parenthesing
Oh, good. I've been keeping exactly the same patch in my tree for months, but I've never had the time to post it with proper explanation why it is needed. Thanks.
it's not needed and i was going to flame alex for not knowing c order of operations and cluttering the code (which is considered external imported code, not mplayer-native code) for cosmetics. but it's not worth arguing over...
It's not about my knowledge but about bad compilers...
rotfl, is there a compiler that compiles this wrong?? maybe gcc3?
:))))
It's also about clarity, a few parentheses too much never hurt readability of code or mathematial formulas aswell. If in doubt, use em :-)
It's a bit like:
if(x) for(;x<y;x++) if(x%2) do_some_thing(x);
versus:
if(x) { for(;x < y; x++) { if(x%2) { do_some_thing(x); } } }
Both are syntactically correct, but the first version is surely more error-prone when changing code and less readable.
I disagree STRONGLY! The first version is much more readable to me, for two reasons: 1. it doesn't clutter the surrounding code with lots of useless lines and needlessly separate what comes before and after by lots of distance. 2. it's a lot more internally readable. I would be VERY pissed to find code like the second example you wrote above. Unneeded braces are one of my biggest pet peeves in C coding style.
And if you're to lazy for wrtiting parentheses, simply get a good editor like vim, that does the job for you.
It has nothing to do with laziness, it's a matter of readability. Rich
D Richard Felker III wrote:
On Sat, Feb 05, 2005 at 01:01:56AM +0100, Felix Buenemann wrote:
a few parentheses too much never hurt readability of code or mathematial formulas aswell. If in doubt, use em :-)
It's a bit like:
if(x) for(;x<y;x++) if(x%2) do_some_thing(x);
versus:
if(x) { for(;x < y; x++) { if(x%2) { do_some_thing(x); } } }
Both are syntactically correct, but the first version is surely more error-prone when changing code and less readable.
I disagree STRONGLY! The first version is much more readable to me, for two reasons:
1. it doesn't clutter the surrounding code with lots of useless lines and needlessly separate what comes before and after by lots of distance. 2. it's a lot more internally readable.
Well, FWIW, I find the second option to be - while, yes, more cluttered in some sense - also more readable; it's simply that when everything is all on one line as it is in the first example, it's noticeably harder (i.e. requires more concentration) to tell where statements begin and end, and in the case of nested parentheses to tell which close matches with which open. Breaking it off into multiple lines allows the statements to be separated out visually, which makes it considerably easier to tell at a glance what is part of something else and what is separate. It does, as I said, mean more clutter in one sense, but it's less dense and contains more 'signposts' (an obscure reference if ever I've made one), so I think it comes out at worst equal in the end.
I would be VERY pissed to find code like the second example you wrote above. Unneeded braces are one of my biggest pet peeves in C coding style.
I don't know if I'd say "pissed", but I'd very likely be less happy to find code written in the style of the first example than the second; at the very least, I'd be less likely to think it worth the effort to try to read it and figure out what it does, because it *does* take me more effort. -- The Wanderer Warning: Simply because I argue an issue does not mean I agree with any side of it. A government exists to serve its citizens, not to control them.
Hi, On Sun, Feb 06, 2005 at 12:49:35PM -0500, The Wanderer wrote:
D Richard Felker III wrote:
On Sat, Feb 05, 2005 at 01:01:56AM +0100, Felix Buenemann wrote:
a few parentheses too much never hurt readability of code or mathematial formulas aswell. If in doubt, use em :-)
It's a bit like:
if(x) for(;x<y;x++) if(x%2) do_some_thing(x);
versus:
if(x) { for(;x < y; x++) { if(x%2) { do_some_thing(x); } } }
Both are syntactically correct, but the first version is surely more error-prone when changing code and less readable.
I disagree STRONGLY! The first version is much more readable to me, for two reasons:
1. it doesn't clutter the surrounding code with lots of useless lines and needlessly separate what comes before and after by lots of distance. 2. it's a lot more internally readable.
Well, FWIW, I find the second option to be - while, yes, more cluttered in some sense - also more readable; it's simply that when everything is all on one line as it is in the first example, it's noticeably harder (i.e. requires more concentration) to tell where statements begin and end, and in the case of nested parentheses to tell which close matches with which open. Breaking it off into multiple lines allows the statements to be separated out visually, which makes it considerably easier to tell at a glance what is part of something else and what is separate. It does, as I said, mean more clutter in one sense, but it's less dense and contains more 'signposts' (an obscure reference if ever I've made one), so I think it comes out at worst equal in the end.
I think you are mixing two things here: putting all in one line, which IMHO is bad because especially after a few changes it will make the line longer that 80 characters and also because it makes cvs diff much more difficult to understand. But adding unneeded braces is not any better, it takes up much too much spaces - given the fact that I usually can only see 25 to 50 lines of code at once I find it _very_ annonying when more than 10 consist only of braces. Also, if you have so many nesting levels it's really hard to see which closing brace belongs to which opening one. That's almost like making a sub-function consisting of only 2 lines - there are case where this is a good idea, but they are _very_ rare. Greetings, Reimar Döffinger
Reimar Döffinger wrote:
Hi, On Sun, Feb 06, 2005 at 12:49:35PM -0500, The Wanderer wrote:
D Richard Felker III wrote:
On Sat, Feb 05, 2005 at 01:01:56AM +0100, Felix Buenemann wrote:
a few parentheses too much never hurt readability of code or mathematial formulas aswell. If in doubt, use em :-)
It's a bit like:
if(x) for(;x<y;x++) if(x%2) do_some_thing(x);
versus:
if(x) { for(;x < y; x++) { if(x%2) { do_some_thing(x); } } }
Both are syntactically correct, but the first version is surely more error-prone when changing code and less readable.
I disagree STRONGLY! The first version is much more readable to me, for two reasons:
1. it doesn't clutter the surrounding code with lots of useless lines and needlessly separate what comes before and after by lots of distance.
(Condensing my apparent argument here: I don't necessarily agree with either "useless" or "needless".)
2. it's a lot more internally readable.
(I disagree; I think that, at best, it's equally readable.)
Well, FWIW, I find the second option to be - while, yes, more cluttered in some sense - also more readable; it's simply that when everything is all on one line as it is in the first example, it's noticeably harder (i.e. requires more concentration) to tell where statements begin and end, and in the case of nested parentheses to tell which close matches with which open. Breaking it off into multiple lines allows the statements to be separated out visually, which makes it considerably easier to tell at a glance what is part of something else and what is separate. It does, as I said, mean more clutter in one sense, but it's less dense and contains more 'signposts' (an obscure reference if ever I've made one), so I think it comes out at worst equal in the end.
I think you are mixing two things here: putting all in one line, which IMHO is bad because especially after a few changes it will make the line longer that 80 characters and also because it makes cvs diff much more difficult to understand.
Agreed.
But adding unneeded braces is not any better, it takes up much too much spaces - given the fact that I usually can only see 25 to 50 lines of code at once
This could be a considerable part of our difference; I habitually work in a window large enough to display closer to 80 lines at a time.
I find it _very_ annonying when more than 10 consist only of braces. Also, if you have so many nesting levels it's really hard to see which closing brace belongs to which opening one.
The latter point can be handled by making sure that each closing brace is aligned (indented) to match its opening statement and/or opening brace - which I thought was standard practice anyway; I make it a habit to always set a sub-block off with braces, even in the case where the block is only one line long (as in the do_some_thing(x) function call above). It helps me to tell that the single line is a separate block, and where that block begins and ends; it may be a little redundant with the indentation, but I find that indentation alone is not always enough to make the result readily parseable. I could be persuaded to agree that the practice of putting the open braces on separate lines is a bad one; I don't do that myself. I do, however, think that it is/can be worthwhile to put the closing brace on a separate line, although that may vary as a function of available screen space. ...it's just occurred to me that this kind of discussion probably doesn't belong on the CVS-log list, and quite possibly not on the MPlayer lists at all...
That's almost like making a sub-function consisting of only 2 lines - there are case where this is a good idea, but they are _very_ rare.
<shrug> Apparently I disagree. I'll admit that it's not often that I've found occasion to use a function of two lines or fewer (not counting simple callbacks), but the situation is not quite the same, and I find the additional degree of demarcation provided by enclosing all code blocks in braces to be worthwhile. -- The Wanderer Warning: Simply because I argue an issue does not mean I agree with any side of it. A government exists to serve its citizens, not to control them.
Well my overall point is, one sure is able to obfuscate code to the highest extend by using all sorts of simplifications allowed by the language used, but this will - as also with real spoken languages - make it harder to understand for people not so fluent in the language. So in a colaborative project one should agree to use more redable syntax vs. more compact one. In single person project I leave the decision to every one's own liking. For example I'm quite a perl wiz and like to make use of it's shortcuts when I code for myself. But in a group project this will lead to many people being unable to understand what the heck my code does. This might be different extremes, but I hope you get the point. -- So let's close this discussion. -- -- Best Regards, Atmos ____________________________________________ - MPlayer Developer - http://mplayerhq.hu/ - ____________________________________________
participants (7)
-
Alex Beregszaszi -
D Richard Felker III -
Dominik 'Rathann' Mierzejewski -
Felix Buenemann -
Reimar Döffinger -
syncmail@mplayerhq.hu -
The Wanderer