Thread: Re: language war

Re: language war

From
"Jay O'Connor"
Date:
 >I have yet to find a language that is as extensible, powerful, and easily
 >modular as PHP.  My favorite feature is the fact that I can include
 >arbitrary files, using a line of code:
 >include "$next_file.php";
 >Then whichever file shares the name (minus the .php extension) with the
 >$next_file variable will be included.  This enables me to write
engines that
 >allow for event-driven programming in stateless web environments.  I have
 >not been able to find an elegent solution to this problem either in
Perl or
 >PHP.

I'm assuming you meant "either in Perl or Python" since you describe PHP
solution

Dynamically importing modules based on variables like you show above is
certainly possible in Python.   I did for a text parsing that imported a
different parser based on a command line switch from the user.  If you
want details, I can send them, but the gist is that what you are asking
for is possible in Python

Other than that, see my latest post on comp.object for details of
redefining Python classes on the fly for extensibility.




Re: language war

From
"Jay O'Connor"
Date:
 >>My favorite feature is the fact that I can include
 > >arbitrary files, using a line of code:
 > >include "$next_file.php";

 >Dynamically importing modules based on variables like you show above is
 >certainly possible in Python.

Here's an elaborate example:  I have two modules (A.py and B.py) that
both define the function test().  My main driver prompts the user for
input and based on the input will import the module and call test() in
the imported module, which will print either "module A" or "module B"
depending on what was imported, or an error message if the input didn't
matcha  module.  This illustrates a complete example, but you can
simplify it really to "mymodule = __import__ (next_file)" where
next_file is a variable name

====================
--A.py
def test ():
        print "module A"


--B.py
def test ():
        print "module B"
--dynamicimport.py
print "Test Dynamic Import"

request = raw_input ("enter 'a' or 'b'")
modName = request.upper()
mod = None

try:
    mod = __import__(modName)
except:
    print "unable to import %s" % modName

if mod:
    mod.test()
else:
    print "Sorry, no appropriate module"
====================


Re: language war

From
"Marc A. Leith"
Date:
Enough already!

I don't believe that the PostgreSQL General list is an appropriate place to
debate 'my favorite language is better than your favorite language'.

I've programmed in many different languages (FORTRAN, ALGOL, PL/1, Pascal, C,
many variations of BASIC, Lisp, APL, SNOBOL, COBOL, Modula2, C++, VB, PHP, Java
to name a few), each for a different reason, but each valid at the time, for
the problem at hand. Often, I could chose which I wanted from a selection - I
picked the one that I believed could solve my problem the best.

I've learned in 25 years of coding - there is NO RIGHT ANSWER, NO ONE LANGUAGE
for all uses. (See PL/1 aka PL/C above - Programming Language Complete).

My point is simple - languages come & go. Debate your RELIGIOUS views elsewhere.

Marc A. Leith
redboxdata inc.

E-mail:mleith@redboxdata.com

Quoting Jay O'Connor <joconnor@cybermesa.com>:

>  >>My favorite feature is the fact that I can include
>  > >arbitrary files, using a line of code:
>  > >include "$next_file.php";
>
>  >Dynamically importing modules based on variables like you show above is
>  >certainly possible in Python.
>
> Here's an elaborate example:  I have two modules (A.py and B.py) that
> both define the function test().  My main driver prompts the user for
> input and based on the input will import the module and call test() in
> the imported module, which will print either "module A" or "module B"
> depending on what was imported, or an error message if the input didn't
> matcha  module.  This illustrates a complete example, but you can
> simplify it really to "mymodule = __import__ (next_file)" where
> next_file is a variable name
>
> ====================
> --A.py
> def test ():
>         print "module A"
>
>
> --B.py
> def test ():
>         print "module B"
> --dynamicimport.py
> print "Test Dynamic Import"
>
> request = raw_input ("enter 'a' or 'b'")
> modName = request.upper()
> mod = None
>
> try:
>     mod = __import__(modName)
> except:
>     print "unable to import %s" % modName
>
> if mod:
>     mod.test()
> else:
>     print "Sorry, no appropriate module"
> ====================
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
>       subscribe-nomail command to majordomo@postgresql.org so that your
>       message can get through to the mailing list cleanly
>