How do the MediaWiki pros keep their PHP pretty? Do they use http://en.wikipedia.org/wiki/Prettyprint#Code_Beautifiers ?
On Tue, Apr 15, 2008 at 12:22 PM, jidanni@jidanni.org wrote:
How do the MediaWiki pros keep their PHP pretty? Do they use http://en.wikipedia.org/wiki/Prettyprint#Code_Beautifiers ?
No, we write the code in the correct style in the first place.
I think it's partly because everyone who writes patches respects the chosen formatting standard used throughout Mediawiki. I know that when I write code to submit, I make sure to format it properly and adjust any existing formatting as needed to keep indentions and the like properly spaced.
That, I don't think Brion lets bad code go live :-P
-Chad
On Mon, Apr 14, 2008 at 10:54 PM, Andrew Garrett andrew@epstone.net wrote:
On Tue, Apr 15, 2008 at 12:22 PM, jidanni@jidanni.org wrote:
How do the MediaWiki pros keep their PHP pretty? Do they use http://en.wikipedia.org/wiki/Prettyprint#Code_Beautifiers ?
No, we write the code in the correct style in the first place.
-- Andrew Garrett
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
Chad schreef:
That, I don't think Brion lets bad code go live :-P
That's actually true: Brion usually reads through every commit he pushes live, so he'll catch (and fix) blatantly ugly code. It should be noted that brace and parenthesis styles are somewhat mixed in the MW code (especially in the API), but those are minor differences such as not putting an extra space after a ( or putting a { on a separate line.
Roan Kattouw (Catrope)
On Tue, Apr 15, 2008 at 9:51 AM, Roan Kattouw roan.kattouw@home.nl wrote:
It should be noted that brace and parenthesis styles are somewhat mixed in the MW code (especially in the API), but those are minor differences such as not putting an extra space after a ( or putting a { on a separate line.
The "official" brace style, as stated in docs/design.txt, in K&R: opening braces go on the same line. This is followed pretty carefully throughout the entire core code base:
aryeh@aryeh-desktop:/var/www/trunk/phase3$ find -iregex '^.*.(php|inc)$' -exec grep '^\s*{' {} + | grep -v languages/messages | wc -l 510 aryeh@aryeh-desktop:/var/www/trunk/phase3$ find -iregex '^.*.(php|inc)$' -exec grep '^.*[^\s].*{' {} + | grep -v languages/messages | wc -l 22440
(Some spot-checking makes it seem like those hits are all legit -- with a few weird outliers like "blah {$varname}".) Parenthesis spacing is more spotty:
aryeh@aryeh-desktop:/var/www/trunk/phase3$ find -iregex '^.*.(php|inc)$' -exec grep '(if|while|for|foreach) ( ' {} + | wc -l 5861 aryeh@aryeh-desktop:/var/www/trunk/phase3$ find -iregex '^.*.(php|inc)$' -exec grep '(if|while|for|foreach)([^ ]' {} + | wc -l 858 aryeh@aryeh-desktop:/var/www/trunk/phase3$ find -iregex '^.*.(php|inc)$' -exec grep '(if|while|for|foreach) ([^ ]' {} + | wc -l 2024 aryeh@aryeh-desktop:/var/www/trunk/phase3$ find -iregex '^.*.(php|inc)$' -exec grep '(if|while|for|foreach)( ' {} + | wc -l 4198
Personally I like the last of those, like if( condition ) {. But the first, like if ( condition ), seems to be about as common. Maybe we should adopt a convention. :)
Simetrical schreef:
On Tue, Apr 15, 2008 at 9:51 AM, Roan Kattouw roan.kattouw@home.nl wrote:
It should be noted that brace and parenthesis styles are somewhat mixed in the MW code (especially in the API), but those are minor differences such as not putting an extra space after a ( or putting a { on a separate line.
The "official" brace style, as stated in docs/design.txt, in K&R: opening braces go on the same line. This is followed pretty carefully throughout the entire core code base:
aryeh@aryeh-desktop:/var/www/trunk/phase3$ find -iregex '^.*.(php|inc)$' -exec grep '^\s*{' {} + | grep -v languages/messages | wc -l 510 aryeh@aryeh-desktop:/var/www/trunk/phase3$ find -iregex '^.*.(php|inc)$' -exec grep '^.*[^\s].*{' {} + | grep -v languages/messages | wc -l 22440
Hmm, it appears brace style is (inadvertently) very well-observed in the API, even though I generally put the opening brace on a separate line: $ grep '^\s*{' *.php | wc -l 1 $ grep '^.*[^\s].*{' *.php | wc -l 1549
Parenthesis style is significantly different, though (the second is my preferred style, the third was Yuri's) $ grep '(if|while|for|foreach) ( ' *.php | wc -l 17 $ grep '(if|while|for|foreach)([^ ]' *.php | wc -l 397 $ grep '(if|while|for|foreach) ([^ ]' *.php | wc -l 635 $ grep '(if|while|for|foreach)( ' *.php | wc -l 43
Roan Kattouw (Catrope)
On Tue, Apr 15, 2008 at 11:16 AM, Roan Kattouw roan.kattouw@home.nl wrote:
Hmm, it appears brace style is (inadvertently) very well-observed in the API, even though I generally put the opening brace on a separate line: $ grep '^\s*{' *.php | wc -l 1 $ grep '^.*[^\s].*{' *.php | wc -l 1549
You're missing subdirectories.
$ find includes/api -iregex '^.*.(php|inc)$' -exec grep '^\s*{' {} + | wc -l 111 $ find includes/api -iregex '^.*.(php|inc)$' -exec grep '^.*[^\s].*{' {} + | wc -l 1549
Do you really feel it's necessary to use a different brace style than all of core code? The API is a part of the core software here. Not to mention variable naming conventions, etc., etc. Not that it really matters, but . . .
Simetrical schreef:
On Tue, Apr 15, 2008 at 11:16 AM, Roan Kattouw roan.kattouw@home.nl wrote:
Hmm, it appears brace style is (inadvertently) very well-observed in the API, even though I generally put the opening brace on a separate line: $ grep '^\s*{' *.php | wc -l 1 $ grep '^.*[^\s].*{' *.php | wc -l 1549
You're missing subdirectories.
$ find includes/api -iregex '^.*.(php|inc)$' -exec grep '^\s*{' {} + | wc -l 111 $ find includes/api -iregex '^.*.(php|inc)$' -exec grep '^.*[^\s].*{' {} + | wc -l 1549
There aren't any in includes/api, except .svn, which shouldn't be counted.
Do you really feel it's necessary to use a different brace style than all of core code? The API is a part of the core software here. Not to mention variable naming conventions, etc., etc. Not that it really matters, but . . .
I don't. It's just that there are multiple acceptable variations on the general coding style (I believe the CODING-STYLE file explicitly says that it's OK to use a slightly deviating style, as long as you don't do very weird things) which are used in the core as well as in the API; it's just that the distribution of these styles in the API is very different from the distribution in the rest of the core.
Basically, this is about small differences like if (foo) vs. if(foo) vs. if( foo ) vs. if ( foo ), function foo()\n{ vs. function foo () {, and (something we didn't run regexes on) func('foo','bar') vs. func( 'foo', 'bar' ).
Roan Kattouw (Catrope)
On Tue, Apr 15, 2008 at 11:46 AM, Roan Kattouw roan.kattouw@home.nl wrote:
There aren't any in includes/api, except .svn, which shouldn't be counted.
Well, my count seems to be more correct than yours *somehow*:
$ find includes/api -iregex '^.*.(php|inc)$' -exec grep '^\s*{' {} + | head includes/api/ApiQueryUserContributions.php: { includes/api/ApiQueryUserContributions.php: { includes/api/ApiQueryAllimages.php: { includes/api/ApiPageSet.php: { includes/api/ApiPageSet.php: { includes/api/ApiPageSet.php: { includes/api/ApiPageSet.php: { includes/api/ApiPageSet.php: { includes/api/ApiQueryBlocks.php: { includes/api/ApiQueryBlocks.php: {
There's not just one, in other words. grepping includes/api/*.php gets me the same count, 111.
I don't. It's just that there are multiple acceptable variations on the general coding style (I believe the CODING-STYLE file explicitly says that it's OK to use a slightly deviating style, as long as you don't do very weird things) which are used in the core as well as in the API; it's just that the distribution of these styles in the API is very different from the distribution in the rest of the core.
Well, yes. But de facto, we've adopted the K&R brace style overwhelmingly. I certainly change any deviations if I see them. It looks ugly to have different styles used throughout the code, whether or not there's any document that declares one style or another as preferable.
jidanni@jidanni.org a écrit :
How do the MediaWiki pros keep their PHP pretty? Do they use http://en.wikipedia.org/wiki/Prettyprint#Code_Beautifiers ?
I do it while coding. vim let me know when I am not respecting the conventions :
http://www.mediawiki.org/wiki/Manual:Coding_conventions
wikitech-l@lists.wikimedia.org