Re: Programming style: using Classes or inline



* muppet <scott asofyet org> [2006-03-17 15:50]:
I think a "require" of a file that does not define a package may
behave similarly to what C does.

Sort of. `require`ing a file multiple times wonât load it
multiple times. In Perl, you get that using `do $filename`,
which equates to `eval slurp($filename)` (except that thereâs no
builtin `slurp`).

But even that is not the same. An `#include` in C is a purely
textual inclusion, so it does not have any semantics at the
language level. It does not affect scopes, f.ex. Of course, this
is a truism, because `#include` is handled by the preprocessor
long before the compiler even sees the source, so the compiler
actually has no idea what macros or includes where there before.

In Perl, there is no such thing as âdoes not affect scope,â
unless maybe your main program consists of an elaborate version
of

    eval slurp( $file1 ) . slurp( $file2 ) . slurp( $file3 );

which gets you back to the C-ish purely textual processing.

But the Perl way, of course, is much better; and not because Perl
does it that way. Itâs the way every language designed with
modularity in mind works. C never was. (Not that Iâm dissing C,
mind. C is extremely good at what C is good at.) Not that you
have much choice where Perl is concerned, because Perl is
extremely hard to parse and makes it even harder to safely paste
together pieces of source code programmatically; this makes
preprocessing (eg. source filters) highly buggy and dangerous.

[NB.: this is only half directed at you-as-in-muppet, of course;
half of it is more for the benefit of anyone who does not already
know all this.]

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]