Skip to main content
GameDev.net gamedev.net
🔒 Locked

Python

Started by Russell Nov 29, 2002 at 10:54 PM 15 replies 500+ views
Original Post
Russell
Russell
Two questions... Does python still use indentation to determine scope? Can you write GUI''s in python? Are they portable?
mutex
mutex
Yes, indentation determines scope. Yes, you can write GUI''s in Python. There is a fully portable Tk/Tcl library for GUI''s that should run on Linux and any other system Tk/Tcl has been ported to, but you can also use MFC or raw the Win32 API if you want for a non-portable GUI.

SabreMan
SabreMan
quote:
Original post by Russell
Can you write GUI''s in python? Are they portable?

Yes and maybe. A GUI is as portable as you make it. The core Python distribution includes Tkinter, which is a Python binding to the Tk GUI. It''s incredibly easy to use. However, I find Tk wanting for native look-and-feel, so I use wxPython, which is a port of the wxWindows library. There''s also bindings available for MFC, Win32, FLTK, QT, OpenGL, SDL...

Whether or not they''re portable depends on what you do with them. For example, if you use Win32 calls, it''s obviously not portable. Even on the "portable" toolkits, you have to be careful. For example, Windows has problems with making GUI calls outside of the main GUI thread, which isn''t a problem on *nix. If you write a program that does that, it is likely to barf on Windows.
Arild Fines
Arild Fines
quote:
Original post by Russell
Does python still use indentation to determine scope?

I''ve never understood why people seem to object so much to this. You''d think this was the most natural way of them all. Is everybody brainwashed into thinking that curly braces(begin/end or whatever) is The One Way To Do It?
If you take out the braces from any C/C++/Java/C# source file, the structure will be exactly the same as if you had written it in Python. There really isn''t that many ways of formatting source code when you don''t have to decide where the braces go. Are people really that anal about having things to control?

Ok - there is one disadvantage. You get mysterious errors if you have a habit of mixing tabs and spaces. But no sane developer does that, right?




For those who believe in God, most of the big questions are answered. But for those of us who can''t readily accept the God formula, the big answers don''t remain stone- written. We adjust to new conditions and discoveries. We are pliable. Love need not be a command or faith a dictum. I am my own God. We are here to unlearn the teachings of the church, state, and our educational system. We are here to drink beer. We are here to kill war. We are here to laugh at the odds and live our lives so well that Death will tremble to take us -- Charles Bukowski
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Russell
Russell
I don''t object to it. I asked because I heard someone else say that it was no longer the case, and I couldn''t find it anywhere on the python site. I can''t believe some peopel are so anal that they complain when they think other people are complaining
stodge
stodge
quote:
I''ve never understood why people seem to object so much to this.


Because they/we/I can? Personally I find it a bit weird that a language won''t compile if the source indentation isn''t correct. It reminds me too much of Fortran''s weird column rules.
---------------------http://www.stodge.net
Arild Fines
Arild Fines
quote:
Original post by Russell
I can''t believe some peopel are so anal that they complain when they think other people are complaining

I wasn''t referring to you specifically - I''ve heard people complaining about this for a long time.

quote:

Personally I find it a bit weird that a language won''t compile if the source indentation isn''t correct.


What does it matter? Do you usually write code without indentation?



For those who believe in God, most of the big questions are answered. But for those of us who can''t readily accept the God formula, the big answers don''t remain stone- written. We adjust to new conditions and discoveries. We are pliable. Love need not be a command or faith a dictum. I am my own God. We are here to unlearn the teachings of the church, state, and our educational system. We are here to drink beer. We are here to kill war. We are here to laugh at the odds and live our lives so well that Death will tremble to take us -- Charles Bukowski
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Russell
Russell
Yes I indent my code. Actually I think indentation based code is less error prone. For example:

  
while(!done) {
update_stuff();
display_stuff();
if(error)
output_error();
done = true;
}

And then you have someone saying, "WTF my program only displays the first frame and then quits!!" I imagine if this were in the middle of a very large chunk of code you might skim right past it, or if you were new to the language, might not realize it. In python, that would behave as you expect it to. In C/C++ that''s just misleading and going to cause people headaches.
stodge
stodge
quote:
What does it matter? Do you usually write code without indentation?


Yes sometimes I do. Particularily when I find a snippet of code on the web. When I copy and paste into VC it sometimes has weird formatting. If I''m just experimenting or playing with ideas and paste some code, I don''t want to spend time formatting.


http://www.stodge.net - the powerhouse in personal commentary
---------------------http://www.stodge.net
Arild Fines
Arild Fines
quote:
Original post by stodge
Do you usually write code without indentation?
--
Yes sometimes I do.


It was a rhetorical question, really.
quote:

o When I copy and paste into VC it sometimes has weird formatting.
o I don''t want to spend time formatting.

Cool - I was afraid you''d have some real arguments



For those who believe in God, most of the big questions are answered. But for those of us who can''t readily accept the God formula, the big answers don''t remain stone- written. We adjust to new conditions and discoveries. We are pliable. Love need not be a command or faith a dictum. I am my own God. We are here to unlearn the teachings of the church, state, and our educational system. We are here to drink beer. We are here to kill war. We are here to laugh at the odds and live our lives so well that Death will tremble to take us -- Charles Bukowski
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
stodge
stodge
Arild, you are annoying.
---------------------http://www.stodge.net
krumms
krumms
now now, play nice
refrain_from_stupidity( &me );
Oluseyi
Oluseyi
quote:
Original post by Arild Fines
Ok - there is one disadvantage. You get mysterious errors if you have a habit of mixing tabs and spaces. But no sane developer does that, right?

No, but a sane group of developers (or a group of sane developers) might. If everyone agrees to use consistent indentation and interpret modules independently (ie, not cross-pollinate code), there should be no problems with it. If not.. chaos.

I''m always reminded of the story of the makefile programmer who unwittingly used tabs instead of spaces and couldn''t figure out how to solve the problem. He was fired.
Fruny
Fruny
quote:
Original post by Arild Fines
Ok - there is one disadvantage. You get mysterious errors if you have a habit of mixing tabs and spaces. But no sane developer does that, right?



"Sane developer" - oxymoron

Many coding standards already have to impose formatting explicitely to avoid chaos. The fact that the language itself imposes formatting is but a way to prevent deceptive indentations.

TABs are usually similarly targeted due to their variable-width nature. Code beautifiers that rely on language structure ( C, not Python, obviously ) indent with spaces, not tabs.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Kylotan
Kylotan
Personally I think it would be better if groups of developers standardised on a tab width rather than on using spaces. Tabs are so much more convenient to alter, take up less file space, and make more sense in the context. I do think the Python interpreter could be a bit more intelligent with guessing when the tab/space thing is a problem, though.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.