Re: [PHP] Re: Conditional compilation

2008-08-20 Thread Micah Gersten
You can always call a function with a DEBUG flag and execute certain
parts if it's set or not.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Robert Cummings wrote:
> On Fri, 2008-08-15 at 18:34 -0500, Shawn McKenzie wrote:
>   
>> Herman Gomez wrote:
>> 
>>> Hi,
>>>
>>> Here is something I used to do in C/C++ to include/exclude automaticaly 
>>> all debugging code at compiling time:
>>>
>>> #define debug TRUE
>>> #ifdef(debug)
>>> //debugging code
>>> #endif
>>>
>>> That way I can include/exclude easily all debugging code in the final 
>>> compiled code. In PHP I have not been able to find anything like that.
>>> The only solution I've found is having this kind of code in every debug 
>>> code block:
>>>
>>> if ($debug) {
>>> //debugging code
>>> }
>>>
>>> But this means that the debugging code is in the final compiled 
>>> (interpreted) code, wasting cpu cycles even if there won't be any 
>>> debugging in production.
>>>
>>> Does somebody know if there is something like conditional compilation in 
>>> PHP that I can use?
>>>
>>> Regards,
>>> Herman Gomez
>>> Madrid, Spain.
>>>   
>> Well PHP isn't compiled it's interpreted.  Still I don't see much diff 
>> and no overhead between the following:
>>
>> #ifdef(debug)
>>  //debugging code
>> #endif
>>
>> ---and---
>>
>> if (defined('DEBUG')) {
>>  //debugging code
>> }
>>
>> I don't think checking a define is cpu intensive or even measurable. 
>> You could "assume" that it's defined as true or false and:
>>
>> if (DEBUG === true)) {
>>  //debugging code
>> }
>>
>> Still, I don't think that even checking $debug is measurable.
>> 
>
> That depends on where the conditional exists. In C you can place it
> anywhere, including wihtin a tight loop. In PHP you end up having to
> either take an overhead penalty or duplicate code to force the
> conditional outside of a tight loop.
>
> Contrast the following:
>
> 
> if( DEBUG === true )
> {
> for( $i = 0; $i < 100; $i++ )
> {
> // Do something common between DEBUG and !DEBUG modes.
> // Do something dependent on debug mode.
> }
> }
> else
> {
> for( $i = 0; $i < 100; $i++ )
> {
> // Do something common between DEBUG and !DEBUG modes.
> }
> }
>
> ?>
>
> Versus:
>
> 
> for( $i = 0; $i < 100; $i++ )
> {
> // Do something common between DEBUG and !DEBUG modes.
>
> if( DEBUG === true )
> {
> // Do something dependent on debug mode.
> }
> }
>
> ?>
>
> Now depending on what "Do something common between DEBUG and !DEBUG
> modes" does, it can be a real PITA to do code duplication to optimize
> debug mode handling, but on the other hand, you really don't want to
> check if DEBUG is enabled 1 million times.
>
> If I recall though... a few years ago the answer to this question was
> that there's no reason why you can't use the C pre-processor to
> accomplish the same thing with PHP. The down side though is that then
> you lose debugging information such as the real line number on which an
> error occurs.
>
> Cheers,
> Rob.
>   

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Conditional compilation

2008-08-15 Thread Robert Cummings
On Fri, 2008-08-15 at 22:56 -0500, Shawn McKenzie wrote:
> Robert Cummings wrote:
> > On Fri, 2008-08-15 at 18:34 -0500, Shawn McKenzie wrote:
> >> Herman Gomez wrote:
> >>> Hi,
> >>>
> >>> Here is something I used to do in C/C++ to include/exclude automaticaly 
> >>> all debugging code at compiling time:
> >>>
> >>> #define debug TRUE
> >>> #ifdef(debug)
> >>> //debugging code
> >>> #endif
> >>>
> >>> That way I can include/exclude easily all debugging code in the final 
> >>> compiled code. In PHP I have not been able to find anything like that.
> >>> The only solution I've found is having this kind of code in every debug 
> >>> code block:
> >>>
> >>> if ($debug) {
> >>> //debugging code
> >>> }
> >>>
> >>> But this means that the debugging code is in the final compiled 
> >>> (interpreted) code, wasting cpu cycles even if there won't be any 
> >>> debugging in production.
> >>>
> >>> Does somebody know if there is something like conditional compilation in 
> >>> PHP that I can use?
> >>>
> >>> Regards,
> >>> Herman Gomez
> >>> Madrid, Spain.
> >> Well PHP isn't compiled it's interpreted.  Still I don't see much diff 
> >> and no overhead between the following:
> >>
> >> #ifdef(debug)
> >>//debugging code
> >> #endif
> >>
> >> ---and---
> >>
> >> if (defined('DEBUG')) {
> >>//debugging code
> >> }
> >>
> >> I don't think checking a define is cpu intensive or even measurable. 
> >> You could "assume" that it's defined as true or false and:
> >>
> >> if (DEBUG === true)) {
> >>//debugging code
> >> }
> >>
> >> Still, I don't think that even checking $debug is measurable.
> > 
> > That depends on where the conditional exists. In C you can place it
> > anywhere, including wihtin a tight loop. In PHP you end up having to
> > either take an overhead penalty or duplicate code to force the
> > conditional outside of a tight loop.
> > 
> > Contrast the following:
> > 
> >  > 
> > if( DEBUG === true )
> > {
> > for( $i = 0; $i < 100; $i++ )
> > {
> > // Do something common between DEBUG and !DEBUG modes.
> > // Do something dependent on debug mode.
> > }
> > }
> > else
> > {
> > for( $i = 0; $i < 100; $i++ )
> > {
> > // Do something common between DEBUG and !DEBUG modes.
> > }
> > }
> > 
> > ?>
> > 
> > Versus:
> > 
> >  > 
> > for( $i = 0; $i < 100; $i++ )
> > {
> > // Do something common between DEBUG and !DEBUG modes.
> > 
> > if( DEBUG === true )
> > {
> > // Do something dependent on debug mode.
> > }
> > }
> > 
> > ?>
> > 
> > Now depending on what "Do something common between DEBUG and !DEBUG
> > modes" does, it can be a real PITA to do code duplication to optimize
> > debug mode handling, but on the other hand, you really don't want to
> > check if DEBUG is enabled 1 million times.
> > 
> > If I recall though... a few years ago the answer to this question was
> > that there's no reason why you can't use the C pre-processor to
> > accomplish the same thing with PHP. The down side though is that then
> > you lose debugging information such as the real line number on which an
> > error occurs.
> > 
> > Cheers,
> > Rob.
> 
> Great!  Then the answer is:   wait,   wait,
> 
> write it in C!

Well PHP does have a great extension system so you can plug in your own
C code ;)

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Conditional compilation

2008-08-15 Thread Shawn McKenzie

Robert Cummings wrote:

On Fri, 2008-08-15 at 18:34 -0500, Shawn McKenzie wrote:

Herman Gomez wrote:

Hi,

Here is something I used to do in C/C++ to include/exclude automaticaly 
all debugging code at compiling time:


#define debug TRUE
#ifdef(debug)
//debugging code
#endif

That way I can include/exclude easily all debugging code in the final 
compiled code. In PHP I have not been able to find anything like that.
The only solution I've found is having this kind of code in every debug 
code block:


if ($debug) {
//debugging code
}

But this means that the debugging code is in the final compiled 
(interpreted) code, wasting cpu cycles even if there won't be any 
debugging in production.


Does somebody know if there is something like conditional compilation in 
PHP that I can use?


Regards,
Herman Gomez
Madrid, Spain.
Well PHP isn't compiled it's interpreted.  Still I don't see much diff 
and no overhead between the following:


#ifdef(debug)
//debugging code
#endif

---and---

if (defined('DEBUG')) {
//debugging code
}

I don't think checking a define is cpu intensive or even measurable. 
You could "assume" that it's defined as true or false and:


if (DEBUG === true)) {
//debugging code
}

Still, I don't think that even checking $debug is measurable.


That depends on where the conditional exists. In C you can place it
anywhere, including wihtin a tight loop. In PHP you end up having to
either take an overhead penalty or duplicate code to force the
conditional outside of a tight loop.

Contrast the following:



Versus:



Now depending on what "Do something common between DEBUG and !DEBUG
modes" does, it can be a real PITA to do code duplication to optimize
debug mode handling, but on the other hand, you really don't want to
check if DEBUG is enabled 1 million times.

If I recall though... a few years ago the answer to this question was
that there's no reason why you can't use the C pre-processor to
accomplish the same thing with PHP. The down side though is that then
you lose debugging information such as the real line number on which an
error occurs.

Cheers,
Rob.


Great!  Then the answer is:   wait,   wait,

write it in C!

-Shawn

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Conditional compilation

2008-08-15 Thread Robert Cummings
On Fri, 2008-08-15 at 18:34 -0500, Shawn McKenzie wrote:
> Herman Gomez wrote:
> > Hi,
> > 
> > Here is something I used to do in C/C++ to include/exclude automaticaly 
> > all debugging code at compiling time:
> > 
> > #define debug TRUE
> > #ifdef(debug)
> > //debugging code
> > #endif
> > 
> > That way I can include/exclude easily all debugging code in the final 
> > compiled code. In PHP I have not been able to find anything like that.
> > The only solution I've found is having this kind of code in every debug 
> > code block:
> > 
> > if ($debug) {
> > //debugging code
> > }
> > 
> > But this means that the debugging code is in the final compiled 
> > (interpreted) code, wasting cpu cycles even if there won't be any 
> > debugging in production.
> > 
> > Does somebody know if there is something like conditional compilation in 
> > PHP that I can use?
> > 
> > Regards,
> > Herman Gomez
> > Madrid, Spain.
> 
> Well PHP isn't compiled it's interpreted.  Still I don't see much diff 
> and no overhead between the following:
> 
> #ifdef(debug)
>   //debugging code
> #endif
> 
> ---and---
> 
> if (defined('DEBUG')) {
>   //debugging code
> }
> 
> I don't think checking a define is cpu intensive or even measurable. 
> You could "assume" that it's defined as true or false and:
> 
> if (DEBUG === true)) {
>   //debugging code
> }
> 
> Still, I don't think that even checking $debug is measurable.

That depends on where the conditional exists. In C you can place it
anywhere, including wihtin a tight loop. In PHP you end up having to
either take an overhead penalty or duplicate code to force the
conditional outside of a tight loop.

Contrast the following:



Versus:



Now depending on what "Do something common between DEBUG and !DEBUG
modes" does, it can be a real PITA to do code duplication to optimize
debug mode handling, but on the other hand, you really don't want to
check if DEBUG is enabled 1 million times.

If I recall though... a few years ago the answer to this question was
that there's no reason why you can't use the C pre-processor to
accomplish the same thing with PHP. The down side though is that then
you lose debugging information such as the real line number on which an
error occurs.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: Conditional compilation

2008-08-15 Thread Shawn McKenzie

Herman Gomez wrote:

Hi,

Here is something I used to do in C/C++ to include/exclude automaticaly 
all debugging code at compiling time:


#define debug TRUE
#ifdef(debug)
//debugging code
#endif

That way I can include/exclude easily all debugging code in the final 
compiled code. In PHP I have not been able to find anything like that.
The only solution I've found is having this kind of code in every debug 
code block:


if ($debug) {
//debugging code
}

But this means that the debugging code is in the final compiled 
(interpreted) code, wasting cpu cycles even if there won't be any 
debugging in production.


Does somebody know if there is something like conditional compilation in 
PHP that I can use?


Regards,
Herman Gomez
Madrid, Spain.


Well PHP isn't compiled it's interpreted.  Still I don't see much diff 
and no overhead between the following:


#ifdef(debug)
//debugging code
#endif

---and---

if (defined('DEBUG')) {
//debugging code
}

I don't think checking a define is cpu intensive or even measurable. 
You could "assume" that it's defined as true or false and:


if (DEBUG === true)) {
//debugging code
}

Still, I don't think that even checking $debug is measurable.

-Shawn

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php