Jump to content

  • Log In with Google      Sign In   
  • Create Account

Python is King


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 vtwin   Members   -  Reputation: 103

Posted 11 March 2003 - 09:41 AM

Python is King. Is that enough to start another thread?
def insert (self, key):
  if self.tree:
     self._insert (self.tree, key)
  else:
     self.tree = node(key)
 
Python is outrageously fun. Why do we need this thread? Well, all of us Lounge Python Penguins would like to discuss Python. Discussions never get enough detail in the General Programming Forum. I''d like to discuss (and debate) Python here. Everything. Not just through HTTP. Not just ActiveX. Not just through OpenGL. Not just databases. All of it. I want people who disagree with Python or despise it to participate. I want people who advocate it to participate. I want people to share Python snippets of code. I need this. I am no Python expert myself when it comes to programming in Python. But I''m not an expert with regard to much of what has been accomplished with Python, either. A good thread to raise Python awareness would be great. But not specific to any particular problem domain or contentious topic. Yes, we can encompass all of that, and go off on topics with regard to those subjects, but let''s not limit ourselves to one domain.

Sponsor:

#2 bishop_pass   Members   -  Reputation: 108

Posted 11 March 2003 - 09:44 AM

Imitation is the sincerest form of flattery. Did you know that I made the first ultimate thread as well? Now we're going to see King threads.

Anyway, a Python thread is a wonderful idea. However, regarding the royal lineage, I think it breaks down like this:

Lisp is King.
Python is Prince.

This seems clear. Lisp is the father, and Python is the son, who strives to one day fill his father's shoes. However, it isn't clear that Python is heir to the throne. Python is more like a snake in the grass.

By the way, I'm not entirely sure what a Lounge Python Penguin looks like. I might better be able to visualize a Lounge Python Snake.

Now, on to the discussion of Python, its merits, and shortcomings, and how it is striving to fill its father's shoes.

[edited by - bishop_pass on March 11, 2003 5:06:26 PM]

#3 Fruny   Moderators   -  Reputation: 1653

Posted 11 March 2003 - 10:10 AM

quote:
Original post by bishop_pass
Imitation is the sincerest form of flattery. Did you know that I made the first ultimate thread as well? Now we''re going to see King threads.


How long until the Ultimate King thread shows up ?



[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]


#4 vtwin   Members   -  Reputation: 103

Posted 11 March 2003 - 10:12 AM

quote:
Original post by bishop_pass
Imitation is the sincerest form of flattery. Did you know that I made the first ultimate thread as well? Now we''re going to see King threads.


Yes. And did you know I made the second Ultimate Thread, (in other words) the first to imitate you. You should feel very flattered!.. or something.

Anyway, personally I''d perfer Python''s syntax over Lisp''s anyday..but my knowledge of Lisp essentially ends with semantics.

#5 bishop_pass   Members   -  Reputation: 108

Posted 11 March 2003 - 10:17 AM

quote:
Original post by vtwin
Yes. And did you know I made the second Ultimate Thread, (in other words) the first to imitate you.

Actually, munkie has that dubious honor. But please, let''s not turn this thread into a meta-thread which discusses itself just like a Lisp program might be inclined to do. We should be discussing Python.
quote:
Original post by vtwin
Anyway, personally I''d perfer Python''s syntax over Lisp''s anyday..but my knowledge of Lisp essentially ends with semantics.

But does this help or hinder you? Part of the idea of Lisp is to get it to modify components of its own program at runtime, which means it needs to be able to pick it apart at runtime.

#6 SHilbert   Members   -  Reputation: 647

Posted 11 March 2003 - 10:30 AM

SHilKazHatGame uses python scripting. It''s built right into the object system. Very pretty

#7 DakeDesu   Members   -  Reputation: 100

Posted 11 March 2003 - 10:31 AM

quote:
Original post by bishop_pass
By the way, I''m not entirely sure what a Lounge Python Penguin looks like. I might better be able to visualize a Lounge Python Snake.


It is really simple.

First image the penguin. Now give the penguin a silly walk--one not suited for it. Now, have this penguin start yelling "NI!" at people it does not like, and whistling to itself, ''Every Sperm is Sacred,'' ''I bet you they won''t play this song on the radio,'' ''Always look on the bright side of life,'' and ''the Ballad of Sir Robin the Brave.''

(I think you can now figure out what the langauge is named after)

As for Python''s advantages:
My major reason for switching from Perl, was the fact that Perl4 code is still found all over. Perl5 was released in 1996... so I guess with them working on Perl6, I do not want to attribute to Perl5 existing a good seven years of Perl6''s life.

For the most part, Python is a clean version of Perl with a decent OOP implementation (rather than Perl5''s quick hack of an OOP implemenation).

-=-
I think signatures are unprofessional.
Dude! You''re getting a signature virus!

#8 vtwin   Members   -  Reputation: 103

Posted 11 March 2003 - 10:44 AM

quote:
Original post by bishop_pass
Actually, munkie has that dubious honor.


Just to clarify..I am Munkie (well, before the account was hijacked). I''m not sure if my IP has shifted since then, but you can ask Drew or Dave for verification. Heh, whatever, anyway, back to the topic..

quote:

But does this help or hinder you? Part of the idea of Lisp is to get it to modify components of its own program at runtime, which means it needs to be able to pick it apart at runtime.


Personally I''ve never needed to employ something of that nature, so Lisp''s ability to do so has no bearing on me. Like I said, I have little experience with Lisp so my opinion is purely based on my history.

#9 blueEbola   Members   -  Reputation: 464

Posted 11 March 2003 - 11:51 AM

Programming in python is a pleasure .

It''s got beautiful syntax, nice OOP design, and you can create working code nearly as fast as you type. Not to mention that it has an excellent set of standard libraries connected to it. I''ve used it for a few months now, for small things like utilities, for fun, and for some prototyping. Here''s a little tool i made that converts a binary file into a C array:


  
import sys

# dup( count, char )
def dup(c, s):
result = ""
for i in range( c ):
result = result + s
return result

# the main function
def main(i, o):
opened_file = file(i, "
rb")
output_file = file(o, "
w")
binfile = opened_file.read()
opened_file.close()
output_file.write("
/* file generated by : \n") # a little message =)
output_file.write(" bin2c © blueEbola 2002. */ \n\n")
output_file.write("unsigned int size = %d;\n" % (len(binfile)))
output_file.write("unsigned char data[] = { ")
k = 0
print "Converting... "

for k in range( len(binfile) - 1 ):
if k % 12:
output_file.write(`ord(binfile[k])` + ", ")
else:
output_file.write("\n" + dup(25, '' ''))
output_file.write(`ord(binfile[k])` + ", ")

print " done!"
output_file.write(`ord(binfile[k+1])` + " ")
output_file.write("};\n\n")
output_file.write("/* end of file: %s */
\n\n" % (o,)) # output some info
output_file.close()

# argument check
if len( sys.argv ) > 2:
main(sys.argv[1], sys.argv[2])
else:
print "
\nusage: " + sys.argv[0] + " <binary file> <output>"


#10 Starboy   Members   -  Reputation: 319

Posted 11 March 2003 - 11:51 AM

Damn, for a moment I thought this was going to be a *Monty* Python thread. Curse you!

NI!

#11 Dauntless   Members   -  Reputation: 314

Posted 11 March 2003 - 04:49 PM

I know zippo about Lisp, and some VERY rudimentary facets of Python, but I did check out this site comparing Python vs Lisp

What surprised me was how slow Python was...I mean...it's..slower.....than............java(sorry ). Conversely, I was surprised at how fast Lisp was. Also, it mentions that basically Python is a dialect of Lisp with one crucial feature missing....macros.

Since I don't know Lisp, and therefore don't know what macros are, I'm not exactly sure how good/bad this is. From looking at the chart comparing the syntax...Lisp syntax does seem a bit odd, but at least it seems very consistent. Since basically both Lisp and Python are brand new to me, Python seems a little more intuitive to me...but I think I could pick up Lisp pretty easily from looking at it.

I'm thinking of tackling Python next because I hear it's good as a scripting language for game usage. Python supposedly has good hooks into C++, and it's also very extensible through its modules. Does Lisp offer the same features?



[edited by - dauntless on March 12, 2003 7:59:44 AM]

#12 Alpha_ProgDes   Crossbones+   -  Reputation: 4692

Posted 11 March 2003 - 04:52 PM

ur link is messed up.
need to fix it.

also some C/C++ vs. Python code would be nice.
i like a good comparison.

honestly i could care less about speed and crap. i''m more
interested in good coding style and structure.

#13 Mithrandir   Members   -  Reputation: 607

Posted 11 March 2003 - 06:04 PM

quote:
Original post by bishop_pass
Imitation is the sincerest form of flattery. Did you know that I made the first ultimate thread as well? Now we''re going to see King threads.



Sorry, you lose! Please play again, though.

The first ultimate thread:
The Ultimate Game Survey, started by Raz.



#14 bishop_pass   Members   -  Reputation: 108

Posted 11 March 2003 - 08:10 PM

quote:
Original post by Mithrandir
Sorry, you lose! Please play again, though.

Oh well.


#15 SabreMan   Members   -  Reputation: 504

Posted 11 March 2003 - 10:53 PM

quote:
Original post by bishop_pass
But does this help or hinder you? Part of the idea of Lisp is to get it to modify components of its own program at runtime, which means it needs to be able to pick it apart at runtime.

quote:
Original post by vtwin
Personally I''ve never needed to employ something of that nature, so Lisp''s ability to do so has no bearing on me. Like I said, I have little experience with Lisp so my opinion is purely based on my history.

What''s being talked about is introspection , which Python can do aswell. Only, it''s a lot more difficult with Python since, like all Algol-derivatives, it has a two-level syntax (or three-level, but we''re not interested in the bytecode representation). Once you have an environment which puts a layer of arbitrary syntax between you and the abstract representation of your program, anything that you want to do to manipulate the abstract representation immediately becomes an order of magnitude harder.

For example, imagine you wanted to create a class on-the-fly. In Python, internal representation of objects consists of trees built with recursive dictionaries, which is exactly synonymous with Lisp cons cell structures (a cons cell is a two-item pair, and so is a dictionary entry). So to create a class, you would have to construct the class dictionary, and instantiate the class from some metaclass. To illustrate:

  
def standard_initialiser(inst, x):
inst.x = x

def foo(inst):
print inst.x

def make_class(name, methods=[]):
classdict = {}
# add methods
for method in methods:
classdict[method.func_name] = method
# add constructor
classdict[''__init__''] = standard_initialiser

# "type" is the metaclass...
return type.__new__(type, name, (), classdict)

C = make_class(''C'', [foo])
c = C(10)
c.foo() # prints ''10''

So, it is easy to see that the Python syntax is far removed from the internal syntax of recursive dictionaries. In Lisp, you could achieve the same thing by building an s-expression and submitting it to DEFCLASS, where the s-expression *is* the abstract representation. i.e. you build the class the same whether you do it at runtime or compile-time.

It is easy to say that the ability to do such things has no bearing on you when your language makes it hard for you to think about them. I doubt that these abilities aren''t useful to you, just that the syntactic barriers in Python makes it harder to conceptualise how they might be useful.
quote:
Original post by Dauntless
What surprised me was how slow Python was...I mean...it''s..slower.....than............java(sorry ). Conversely, I was surprised at how fast Lisp was. Also, it mentions that basically Python is a dialect of Lisp with one crucial feature missing....macros.

There''s more features missing, but whether they are crucial depends on your point of view. For example, program compilation is not a standard feature of Python. Neither are declarations, which are useful for providing information to the compiler for optimisations. There''s also something extra that Python has which takes something away, and this is the extra layer of syntax I described above. Lisp''s syntax looks "funny" for a reason. To seamlessly add macros into Python, it would have to adopt a Lisp-style syntax, otherwise there would always be a syntactic barrier to building recursive dictionary structures. Since macros are about manipulating code as if it were data, you need the same representation for code and data.
quote:

I''m thinking of tackling Python next because I hear it''s good as a scripting language for game usage. Python supposedly has good hooks into C++, and it''s also very extensible through its modules. Does Lisp offer the same features?

Yes.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS