Reply to Re: Macros in php

Your name:

Reply:


Posted by Tim Martin on 11/18/66 11:45

Jerry Stuckle wrote:
> Tim Martin wrote:
>> 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.

For example, Sutter / Alexandrescu, "C++ Coding standards". They dismiss
macros in no uncertain terms. You could argue about quite how widely
accepted this viewpoint is (not that I have any interest in such an
argument).

I deliberately phrased it like that to avoid giving the impression that
I endorse this consensus myself. Personally, I think there are plenty of
valid uses for macros in C (provided they are used with care). Whether
the benefits outweigh the costs in PHP (or indeed C++) is much less obvious.

> 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.

That wouldn't be a valid argument, but that wasn't the extent of my
argument. You have to weigh up the potential benefits against costs. The
fact that inexperienced programmers might end up using them to create
unmaintainable code is a very definite cost. So far I haven't seen any
real benefits.

Out of interest, do you think that register_globals should be enabled by
default, since it causes no problems for people who write correct code?

>> 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.

The question is whether the same thing can be achieved by judicious use
of existing constructs, without having to introduce macros into the
language. So far, I haven't seen any proof otherwise.

Tim

[Back to original 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

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