> this sounded like fun, so I wrote a simple "comment remover" for PHP
> source code. Tested it on some 50,000 lines of our PHP code and it
> didn't break anything ...
Wow that was quick!!
> It is written in PHP because I don't like Perl :) The code is
> intentionally not optimized for efficiency, but for comprehensibility.
> What do you think about it?
I've just run it and it does indeed not break anything :o) It totally
doesn't need to be optimized, so I quite agree with your choice of
readability. (I agree too. Perl is a bit wierd...)
> I have attached the code to this mail - I hope attachments are OK on
> this list.
Yip, provided they are less than 100KB
> Test it like this:
>
> php -q commentremover.php yourfile.php > yourfile_nocomments.php
>
> Please note that this currently removes ALL comments. Special handling
> for the copyright + version comments is not implemented yet.
We'd need to add this, but that's the hardest bit done. It might be nice to
remove the empty lines where the comments came from too?
> I hope this seems useful to you.
Yeah I just did some testing to find out how much difference it made. Size
wize, pretty stunning. We went from 199KB to 99KB. Performance wise I
barely noticed a difference though. Hmmm. Perhaps it's dependant on
platform and hardware?
Running the getLastChild DOM tests takes 90ms with the normal class, and
92ms with the stripped down class :o/
Running the appendChild tests takes 325ms with the normal class and about
327ms with the stripped down class.
I'm Win 2000 Prof, SP2, Athlon XP 1.4GHZ, Php 4.1.1
Does anyone else have any stats they could share?? Does it really make a
difference?
We might ship a commentless version anyway, cos halfing the size of the file
is bound to do something good...
Opinions?
Nigel
|