Re: Anyway of knowing whether a integer is odd or even
| From: | J Smith | Date: | Wed, 10 Oct 2001 15:27:00 +0000 |
| Subject: | Re: Anyway of knowing whether a integer is odd or even | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-70680@lists.php.net to get a copy of this message | ||
David Otton wrote:
>
> This is subjective of course, but... yes. "(x%2)" is the most common
> way to derive odd and even numbers. Manuals and tutorials use it,
> prime-sieves use it. Bit-masks aren't in common use outside systems
> programming.
>
> The programmer that has to follow you 6 months down the line doesn't
> care that you shaved a few clock cycles off by being clever... he does
> care that you left him clean, easily readable code.
Being clever by using a relatively common technique... Nefarious!
>
> MOD is also the more general solution - how would you change the code
> to colour every nth line red?
Change all of one line? It's not like we're re-writting 1000 lines of code
here.
>
> (BTW, a quick test show that 1 billion (i&1) in a loop execute in 9
> seconds, while (i%2) execute in 12 seconds. C (not PHP), MSVC++6,
> PIII800. Which means I gain 3 billionths of a second on each test if I
> use the bitwise operator.)
Okay, this is certainly more true now, with faster processors, more RAM,
etc. But years ago, there was a difference.
>
>>And why wouldn't you want to get the most performance out of your code,
>>regardless of the language, scripting or otherwise? Especially when it's a
>>one or two character switch that makes the difference?
>
> Because programmer time is /vastly/ more valuable than machine time.
> Do you remove comments from your scripts because parsing /* */ //
> symbols soaks up CPU time?
In PHP this might matter a bit (unless you use the Zend Encoder or Cache or
something), but I'm traditionally a C and C++ guy, and after compilation
comments don't mean much.
>
>>I doubt that PHP should be classified as a scripting language any more
>>than Perl is. Scripting languages are usually used to glue different
>>applications together, like a shell script that uses awk and sed or
>>whatever. PHP can be used to build applications, so it's more than a
>>scripting language. Interpreted language is more like it.
>
> "Scripting language" is a common-usage synonym for "interpreted
> language", and has been for several years. ("Your search for scripting
> language found 387 results on www.perl.com.")
>
> http://www.tuxedo.org/~esr/jargon/html/entry/Python.html
>
> Not that I don't agree with you...
>
> djo
I've never liked that scripting term either. It makes it sound like bash or
a DOS batch script or something. It's so misleading. Perl used to fit the
moniker a bit more, before it got all big and started weighing in at 900
pounds.
J