Author Topic: HUD/Python discussion  (Read 17454 times)

0 Members and 1 Guest are viewing this topic.

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Quote
Originally posted by aldo_14
Although if the compiler detects it, why can it not auto-correct it?  Or is the nesting solely controlled by ws?


Judging from WMC's post it appears so.

Code: [Select]

if userlist:
for i in userlist:
#Add any reclaimers we missed
if isReclaimerName(i.nick) and not isReclaimer(i.nick):
xchat.command("whois %s" % i.nick)
if xchat.nickcmp(i.nick, name)==0:
return True
else:
dMsg("Unable to load userlist")
return False


The else is associated with the first if. Without the whitespace however it would be associated with the last one. Given that something like that compiler autocorrection would bugger up your code completely. There's no way for the compiler to know which of the 3 if statements the else belongs to once the whitespace is gone.

And for those who didn't get my point about cutting and pasting look what happens when I cut and paste the above code

if userlist:
      for i in userlist:
         #Add any reclaimers we missed
         if isReclaimerName(i.nick) and not isReclaimer(i.nick):
            xchat.command("whois %s" % i.nick)
         if xchat.nickcmp(i.nick, name)==0:
            return True
   else:
      dMsg("Unable to load userlist")
   return False

:eek:
« Last Edit: October 18, 2005, 12:47:33 pm by 340 »
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 
As I said, adding brackets to Python would be a matter of 8 or 9 lines of code in PHP, meaning about 50 do to it very reliably in C.
just another newbie without any modding, FREDding or real programming experience

you haven't learned masochism until you've tried to read a Microsoft help file.  -- Goober5000
I've got 2 drug-addict syblings and one alcoholic whore. And I'm a ****ing sociopath --an0n
You cannot defeat Windows through strength alone. Only patience, a lot of good luck, and a sledgehammer will do the job. --StratComm

  

Offline aldo_14

  • Gunnery Control
  • 213
Quote
Originally posted by karajorma


Judging from WMC's post it appears so.

Code: [Select]

if userlist:
for i in userlist:
#Add any reclaimers we missed
if isReclaimerName(i.nick) and not isReclaimer(i.nick):
xchat.command("whois %s" % i.nick)
if xchat.nickcmp(i.nick, name)==0:
return True
else:
dMsg("Unable to load userlist")
return False


The else is associated with the first if. Without the whitespace however it would be associated with the last one. Given something like that compiler autocorrection would bugger up your code completely. There's no way for the compiler to know which of the 3 if statements the else belongs to once the whitespace is gone.
[/B]


Sweet jeebus, that's just daft.

 Fair enough, I use a similar tabulation for Java, but at least I can change that for readability without buggering up the whole thing six ways from sunrise.

Please tell me the likes of
Code: [Select]

     if hoojiflip
                do1
                do2
                looknobracketingtoendthisandseparate

isn't legal?  Ugh.

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
The separate thing would be figgered as part of the loop b/c it's the same tab spacing out.

So, what language would everyone like to try out? 'Lua' and 'Ruby' seem like reasonable suggestions, tho I haven't looked at the API for them. Be nice to get a consensus on this.

Requirements are basically that it must support objects, member functions, and evaluate single-line expressions to a value. Oh and it must be possible to embed it in an app (ie fs2_open).
« Last Edit: October 18, 2005, 01:11:53 pm by 374 »
-C

 

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
Quote
Originally posted by WMCoolmon
Oh and it must be possible to embed it in an app (ie fs2_open).

And fully cross-platform.  Meaning: Win32, Win64, Linux/x86, Linux/x86_64, Linux/PPC, OS X/PPC (G4), OS X/PPC (G5), at the minimum.

 

Offline aldo_14

  • Gunnery Control
  • 213
Quote
Originally posted by WMCoolmon
The separate thing would be figgered as part of the loop b/c it's the same tab spacing out.


That's what I mean; ugh.  What horrible ambiguity.

Quote
Originally posted by WMCoolmon
So, what language would everyone like to try out? 'Lua' and 'Ruby' seem like reasonable suggestions, tho I haven't looked at the API for them. Be nice to get a consensus on this.

Requirements are basically that it must support objects, member functions, and evaluate single-line expressions to a value. Oh and it must be possible to embed it in an app (ie fs2_open).


I've heard good things about Lua, but I'll be damned if I can remember where or why I was looking it up.  I think maybe for some horrible distributed network testing or something.

 

Offline mikhael

  • Back to skool
  • 211
  • Fnord!
    • http://www.google.com/search?q=404error.com
There is no ambiguity. If its indented consistently with the other lines in the block, its part of the block. Its fully, completely, utterly consistent.

For sanity, never use tabs for spacing, ever. Use Spaces. Never use anything but spaces, no matter what programming language you use. Different editors expand tabs differently. Just don't do it. Its damned bad practice.

All that said, stay with Python. If the only complaint is syntactically signifigant whitespace, I dare say we have a winner. Most languages people can come up with a hell of a lot more important (and valid) things to complain about.
[I am not really here. This post is entirely a figment of your imagination.]

 

Offline aldo_14

  • Gunnery Control
  • 213
Quote
Originally posted by mikhael
There is no ambiguity. If its indented consistently with the other lines in the block, its part of the block. Its fully, completely, utterly consistent.
.


Unless you make a mistake in the tabbing.

 

Offline mikhael

  • Back to skool
  • 211
  • Fnord!
    • http://www.google.com/search?q=404error.com
Its rather obvious when you make a mistake in the tabbing, actually.

So obvious that even a non-programmer like me can see the mistake and fix it. Shocking.
[I am not really here. This post is entirely a figment of your imagination.]

 

Offline CaptJosh

  • 210
Different editors? Examples please? And please don't point out vi and emacs. I am so damn tired of that debate. They both suck. Give me mcedit any day. :D  *ducks and covers, in preparation for the approaching napalm deluge from lovers of vi and emacs alike*
CaptJosh

There are only 10 kinds of people in the world;
those who understand binary and those who don't.

 

Offline mikhael

  • Back to skool
  • 211
  • Fnord!
    • http://www.google.com/search?q=404error.com
My editor expands tabs to 4 spaces. Some editors expand it to 8. Or 5. In many editors, this is configurable on a per user basis. I like 4, but you might like 3.

Worse, some editors save tabs back as spaces, and some don't.

And yes, this is a case of vi versus emacs versus pico versus joe versus evil versus vile versus Kedit vs Gedit vs Notepad vs Context vs PFE vs... whatever.
[I am not really here. This post is entirely a figment of your imagination.]

 

Offline mikhael

  • Back to skool
  • 211
  • Fnord!
    • http://www.google.com/search?q=404error.com
And for those of you *****ing about Python not having nice clean brackets or whatever:
Quote
Python Block Delimited Notation Parsing Explained

Subject: Addition explanation of indentation for the tutorial
From: Michael McLay <@nist.gov>
Date: Mon, 9 Mar 1998 16:42:19 -0500
Message-Id: <[email protected]>
To: [email protected]

Fredrik Lundh writes:
 >
 > In fact, Python already supports block delimiters:
 >
 >     if foo: #{
 >         foo1();
 >         foo2();
 >         foo3();
 >     #}
 >
 > Inspired by Larry Wall, Guido also made sure that the ending delimiter
 > could be written in various other ways, such as #end if.  Anything to
 > empower the newbies, you know.  But real Python programmers tend
 > to omit both semicolons and curly braces, of course.

This undocumented feature of the language should be explained in the
official distribution of documentation!!  How about adding the
following as an Appendix of the Python Tutorial.  Also add a footnote
the explanation of indentation at the end of Chapter 3.

         Appendix XXX

   Python Block Delimited Notation Parsing Explained

Python incorporates a sophisticated parser and advanced notation for
recognizing block delimiters from almost any computer language.  The
foreign language notations of C, Ada Pascal, TCL, and Perl will work
in most situations.  The Python parser only requires two minor
modifications to the block notation rules of the foreign language's
grammar rules in order to be Python compliant.

The first change is the addition of a rule which states that
indentation of code is not simply a stylistic suggestion like it is in
other languages.  It is mandatory in Python.  The use of indentation
is considered good coding practice in all these languages and Python
takes this a step further by making it required by the language
grammar.  In Python the meaning of a code block which is not properly
indent is not defined.  Experienced Python programmers find this rule
to be very helpful in making everyone's code more readable.  An added
benefit is that language sensitive editors, such as Xemacs, can assist
in writing code since they are able to automate the indentation of
code blocks.

The second change to to the grammar rules of foreign languages is that
all symbols used to indicate the beginning or end of a block must be
prefixed with the '#' character.  If you are a former Pascal or Ada
programmer this will change your usual notation to:

   if x: #BEGIN
      x = x + 1
   #END

If you are more familiar with C and C++ then you will be comfortable
with either:

   if x: #{
      x = x + 1
   #}

or:

   if x:
      x = x + 1

or even:

   if x: x = x + 1

C programmers will be happy to hear that the Python parser will do the
right thing even if curly braces are not included when two trailing
statements are present:

   if x:
      x = x + 1
      y = 3 + x

This last feature will fix a common source of bugs in C, C++, and Java
programs.  

Python's parser is also sophisticated enough to recognize mixed
notations, and it will even catch missing beginning or end delimiters
and correct the program for the user.  This allows the following to be
recognized as legal Python:

   if x: #BEGIN
      x = x + 1
   #}

or even:

   if x: #{
      x = x + 1

Now as you can see from this series of examples, Python has advanced
the state of the art of parser technology and code recognition
capabilities well beyond that of the legacy languages.  It has done
this in a manner which carefully balances good coding style with the
need for older programmers to feel comfortable with look of the
language syntax.  
[I am not really here. This post is entirely a figment of your imagination.]

 

Offline aldo_14

  • Gunnery Control
  • 213
Quote
Originally posted by mikhael
Its rather obvious when you make a mistake in the tabbing, actually.

So obvious that even a non-programmer like me can see the mistake and fix it. Shocking.


I don't think so.  Not with non-trivial cases or pasted code.  Especially not if you use an auto-tabbing IDE.  If you have, say, several nested ifs, I think it'd be very annoying to read.

And...it's just nasty to me.  Too inexplicit.  Like, um, non-bracketed arithmetic is with >1 operators.  That's not a criticism on the level of 'dump it, agh agh agh!', though.  I just find it very odd.

(Are there really no brackets atall?)

NB: I believe tabs are stored as single characters in ASCII and (I believe) Unicode.  So editors could change representation based on user preferences.  Apparently some substitute spaces, although AFAIK I've never used one with that.

 

Offline mikhael

  • Back to skool
  • 211
  • Fnord!
    • http://www.google.com/search?q=404error.com
Its really something you get used too, and quickly, Aldo. I'm an idiot and I managed to figure it out, after all.
[I am not really here. This post is entirely a figment of your imagination.]

 

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
python seems to be withing my ability to grasp. so im for it.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Kazan

  • PCS2 Wizard
  • 212
  • Soul lives in the Mountains
    • http://alliance.sourceforge.net
extending the sexpression system would be less code, less memory overhead, faster execution, etc
PCS2 2.0.3 | POF CS2 wiki page | Important PCS2 Threads | PCS2 Mantis

"The Mountains are calling, and I must go" - John Muir

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Quote
Originally posted by mikhael
And for those of you *****ing about Python not having nice clean brackets or whatever:
[snip]
That does nothing to resolve the whitespace issue and in fact makes it worse by sticking a band-aid on it.  Suppose a C programmer is using #{ and #} and encounters an indentation problem.  He's going to debug his code based on the braces, not the indentations.  The result will be even more frustration.

This is not a matter of making people more comfortable with the code.  This is a fundamental design flaw of the language itself.

 

Offline Kamikaze

  • A Complacent Wind
  • 29
    • http://www.nodewar.com
Quote
Originally posted by Kazan
extending the sexpression system would be less code, less memory overhead, faster execution, etc


Maintenance and readability would be issues, however. In any case, other resource intensive games have used scripting languages and still run well.

Anyhow, lots of people seem to be unhappy about Python. What do you propose as an alternative? It's possible to embed C into Python directly if the indenting is so horrible to you.
Science alone of all the subjects contains within itself the lesson of the danger of belief in the infallibility of the greatest teachers in the preceding generation . . .Learn from science that you must doubt the experts. As a matter of fact, I can also define science another way: Science is the belief in the ignorance of experts. - Richard Feynman

 

Offline mikhael

  • Back to skool
  • 211
  • Fnord!
    • http://www.google.com/search?q=404error.com
Quote
Originally posted by Goober5000
That does nothing to resolve the whitespace issue and in fact makes it worse by sticking a band-aid on it.  Suppose a C programmer is using #{ and #} and encounters an indentation problem.  He's going to debug his code based on the braces, not the indentations.  The result will be even more frustration.

This is not a matter of making people more comfortable with the code.  This is a fundamental design flaw of the language itself.


I see you failed to grok the humor. It was a joke.

Kaz, be silent. You're be Kazan again. Its annoying.

If Python is out, I recommend Perl. Its small, fast, and freeform. Structure is nearly completely unimportant. Its got braces. Its got blocks. Its got all the stuff Python has going for it syntactically. Even a monkey can use it.
« Last Edit: October 18, 2005, 08:40:27 pm by 440 »
[I am not really here. This post is entirely a figment of your imagination.]

 

Offline Kazan

  • PCS2 Wizard
  • 212
  • Soul lives in the Mountains
    • http://alliance.sourceforge.net
mikhail: you mean i'm being CORRECT? I'm trying ot make sure code runs fast?

as for "readability" - we can simply extend the FRED SEXP editor and you can do all your SEXP-building in a nice GUI.

piece-of-cake
PCS2 2.0.3 | POF CS2 wiki page | Important PCS2 Threads | PCS2 Mantis

"The Mountains are calling, and I must go" - John Muir