|
Posted by Jerry Stuckle on 10/11/40 11:44
Tim Martin wrote:
> 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++?
>
>
>> 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;
>> }
>
>
> The difference is that macros are applied as text substitution before
> parsing is carried out. This means that macros can carry out
> substitutions on the code that would not in itself be a valid language
> construct.
>
> The classic example of misuse of this sort of technique in C is
>
> #define BEGIN {
> #define END }
>
> then you can do silly things like:
>
> for (i = 0; i < 10; i++)
> BEGIN
> printf("%d\n", i);
> END
>
> Used judiciously these sorts of techniques can open up all sorts of
> possibilities (I've seen generic type containers implemented in pure C
> using macros), but the general consensus is that the potential for
> misuse is far too great and modern language constructs have obviated all
> the genuine needs for such techniques.
>
What "General consensus"? I haven't heard that.
In fact, quite the opposite. I've heard more people wish there were C/C++ type
macros in other languages.
And just because someone might misuse them means no one can have them? People
might misuse functions - get rid of them. Someone might misuse relational
databases - get rid of them.
It's not a valid argument.
> To the OP: What are you trying to achieve with macros? With a
> combination of pass-by-reference, soft references and eval() you can
> achieve many of the things that C macros are able to achieve, with
> better syntax and less potential for misuse.
>
Make code clearer, more concise and more maintainable. All of which can be
increased by the judicious use of macros.
> Tim
> *** Free account sponsored by SecureIX.com ***
> *** Encrypt your Internet usage with a free VPN account from
> http://www.SecureIX.com ***
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|