You are here: Re: Macros in php « PHP Programming Language « IT news, forums, messages
Re: Macros in php

Posted by Jerry Stuckle on 12/20/97 11:44

Kimmo Laine wrote:
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
> news:GLKdnZ0WTq631qvZnZ2dneKdnZydnZ2d@comcast.com...
>
>>Kimmo Laine wrote:
>>
>>>"Emil" <emjot_wytnij_to_@podczta.onet.pl> wrote in message
>>>news:e15ag1$3ee$1@news.onet.pl...
>>>
>>>
>>>>Is there any hope that new versions of PHP
>>>>will support macros similar to C or C++?
>>>>I've searched manual and didn't find anything
>>>>except define directive, but it can be used
>>>>to define constant values only.
>>>>Of course it is not THAT neccessary functionality,
>>>>but it could be very useful.
>>>>
>>>
>>>
>>>
>>>What's the actual difference between a function and a macro? How would
>>>use of macros differ from functions?
>>>
>>>Let's pretend there is a way of defining a macro in php...
>>>define ("MAX($a,$b)", "(($a<$b)?$b:$a)");
>>>
>>>vs.
>>>
>>>function max( $a, $b ) {
>>> return $a < $b ? $b : $a;
>>>}
>>>
>>>And use them like this:
>>>MAX($a,$b); // This is macro, so much easier!
>>>max($a,$b); // This is plain old dull function! Bah, no no, not like
>>>this...
>>>
>>>I mean.... WTF?
>>>
>>
>>Macros are more efficient.
>>
>>Personally, one construct I use heavily and would like to replace with a
>>macro:
>>
>> $var = isset($_POST['postvar']) ? $_POST['postvar'] . 'default value';
>>
>>I use something similar for a get/post, session and cookie values. It
>>would be very nice to have a macro.
>
>
>
> And tell mme again why you couldn't write a function instead of a macro to
> do that?
>
> Just so we all remember what we're talking about here... In C a macro is a
> syntax replacement that the precompiler uses to both optimize the code
> (avoid the unnecessary function jump for a short task) and make it easy to
> write for the coder. The complier simply translates a pseudo code (the
> macro) to actual code when the code is compiled to executable. Since PHP is
> not precompiled, I don't see how this could be of any use. The php source
> code should be precompiled in order to get the replaced... Macros just don't
> have a purpouse in run-time compiled language like they do in precompiled
> languages.
>

I know exactly what a macro is in C - I've been programming C for over 20 years.

And yes, the can still be more efficient in PHP. Remember - each page is NOT
reparsed every time it is requested. PHP can also cache pages, then pull the
code right from the cache.

So yes, they can be more efficient.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация