I was trying to figure out, why do people like Python? I really _want_ to like it, but I haven't found its use for me. People say that it is a "beginners" language, while still being a "grown-up" language. I guess I also don't get why one should use it instead of some other language. Can you give examples of what you do in Python and/or why it is expressed so well in Python?
There are certainly things I don't like about Python, but it is quite a nice language. It can be quite handy for writing quick scripts, and is, I think, a very good language to teach people how to program. It's basically like writing pseudo-code. It's not so great, in my opinion, for writing large projects, and I hate the object syntax, but it's nice for quick scripts that you want to work just about everywhere. I do find myself sometimes starting a Python program, and then giving up because I can write faster in C#. It's really all a matter of preference. I suggest picking it up and giving it a whirl, if at least to say you kinda know it. I guess an example I see a lot of why Python is so great is Hello World:

Code:
print "Hello World"

vs. say, C#:

Code:
class HelloWorld {
    static void Main() {
        System.Console.WriteLine("Hello, World!");
    }
}

It's expressed very simply in Python, as are most things, whereas other languages tend to have a more "complicated" syntax. For example, I used to show my mom my programming projects to see if she could figure it out. She could read the Python programs a lot more easily than my C# ones. I also used to TA the intro to programming classes at Denison. When I started they were in Java, and then they were in Python. People picked up Python a lot quicker, and we were able to do more complicated projects because the barrier to entry was much lower.

All this being said, I still prefer C#.
Because of all the built-in functions, http://docs.python.org/library/functions.html.

Because of all the built-in modules, http://docs.python.org/modindex.html.

Because it makes coding super fast and easy, it's the language for prototyping projects and functions because it doesn't have many syntax rules and structuring rules, it's just clean and simple to code and makes coding really fast.
Shaun,
I suppose that is one of the things that I have trouble with: I can think of code in terms of a specific language, and remember it, but if I try to think of it from a more pseudo-code view, I have trouble remembering it. In a way, I prefer to stay in the "curly-brackets" languages, not sure why. In terms of quick scripts, I would typically just use Bash scripting, because I don't really have too much of a preference for working on all OSes-- just Fedora, and my install, specifically.

David, if you don't mind me debating back, Lisp also has a large collection of ANSI standardized functions as well as having next-to-no defined syntax. I don't see Python as really having a lesser level of styling rules (IMHO, it has more because you can't just use any number of spaces to style it, it has to be correct, or your code is incorrect).

Also, I know that Kerm has good experience with Python, so hopefully he will reply soon. And I have tried to read, and re-read, and re-re-read thr Python tutorial among others to like it. I suppose a kind-of large problem is that I've never written anything in it, except small little examples. I think I tried multithreading in it, but it didn't really seem like I accomplished much. I also tried to write an IRC bot in it, but it seemed like more work than it was worth.
_player1537, it seems to me you're trying to make an RPG in TI-Basic without knowing TI-Basic.

IRC Bots and Multithread require reading some documentation, which Python by the way has a lot. You should try making simpler programs if you're starting on it.
ephan wrote:
_player1537, it seems to me you're trying to make an RPG in TI-Basic without knowing TI-Basic.

IRC Bots and Multithread require reading some documentation, which Python by the way has a lot. You should try making simpler programs if you're starting on it.


I would agree with that; like Ruby, Python has a lot of needed documentation; there are a million ways to do a single thing, but there's always that little known method that shortens the code by 90%. An IRC bot is a bit much to start with, without knowing all the tricks that will keep the snake from cracking your back with excessive code.
To me, what I seem to like is the simplicity, the lack of unnecessary syntactical cruft, and the consistency, yet without sacrificing functionality and potential: The available libraries and extra features that make the language really do a lot for you with little code are very attractive. I feel like a lot of thought went into the design of the language, and many of the design decisions make sense to me. Some people hate the compulsory indentation, though it personally has never bothered me much. I will admit, though, that it can be a bit of a pain when editing source files from other sources; I have to remember to set my editor's indentation/space vs. tab settings appropriately or the interpreter complains and refuses to have anything to do with the code.
Travis wrote:
To me, what I seem to like is the simplicity, the lack of unnecessary syntactical cruft, and the consistency, yet without sacrificing functionality and potential: The available libraries and extra features that make the language really do a lot for you with little code are very attractive. I feel like a lot of thought went into the design of the language, and many of the design decisions make sense to me. Some people hate the compulsory indentation, though it personally has never bothered me much. I will admit, though, that it can be a bit of a pain when editing source files from other sources; I have to remember to set my editor's indentation/space vs. tab settings appropriately or the interpreter complains and refuses to have anything to do with the code.
Yeah, I don't see why people mind it being white-space aware--that's how I code anyway. But, as you say, people using spaces instead of tabs always mucks everything up. My biggest issues with python are the "easier to ask forgiveness than permission" paradigm, and how ugly it is to make your own classes. For such a pretty language, they really screwed that up.
David, I understand what you are trying to say, but here are the differences that I see that make that invalid (in my eyes): TI Basic is more of a "first" language, it is what people on this forum tend to start off with. That means that they tend to not even know the basics of programming, so we will tell them that an RPG (for instance) is a big project that they typically won't finish. For me, I already have some (arguably) good experience with programming, so all I really need to do is understand what a language is good for and translate the basic programming concepts to it. Another thing is, I might not have said it correctly, but I have already written a multithreaded program as well as an IRC bot. It was just really weird, and became hard to maintain (the IRC bot). I encourage someone to tell me that that is an incorrect view of what you said.

Ashbad, see what I said to David. I agree with what you say that there is always that one little design choice that changes everything from being 5 lines to being 100 lines, but IMHO, I could just go back and fix it as I am learning the language. I have noticed that I don't truly learn a language until I have written a semi-large project in it-- like an IRC bot. So that is what I did (and why).

Travis, a note about how I keep my code, I am quite (in my eyes) OCD about my code being styled. I could spend an hour trying to make a certain piece of code styled (be it: writing an emacs extension to do it for me, or if push comes to shove, manually tabbing something correctly. The thing that I don't like in Python is: there is pretty much no way to tell what should and should not be tabbed out. No way to really write an extension to tab it out for me. And when I change how I like styling once a week, it is kind of frustrating when I can't do so with Python (Also, ask others about how I styled my C-like code up until I got to where I am happy with it now, though everyone else hates it to death). I believe that adds on to something, typically when I am learning, I'll just copy-paste code to edit it and learn what parts do. Python makes it beyond difficult. Not only can I not just tell my editor to style it for me, I typically have to remove the whitespace at the front because whatever site I got it from doesn't like to use tabs, whereas I do.

Merth, as I said above, I also keep my code tabbed out. Assuming that's what you mean by your first sentence. I also like your comparison to asking forgiveness-- not one that I have heard before. Would you mind explaining it a bit more? Do you mean like: it is easier to ask Python to let you try something over (re-styling) instead of asking it to just imagine that everything is the same? Or am I missing it?
Quote:
David, I understand what you are trying to say, but here are the differences that I see that make that invalid (in my eyes): TI Basic is more of a "first" language, it is what people on this forum tend to start off with. That means that they tend to not even know the basics of programming, so we will tell them that an RPG (for instance) is a big project that they typically won't finish. For me, I already have some (arguably) good experience with programming, so all I really need to do is understand what a language is good for and translate the basic programming concepts to it. Another thing is, I might not have said it correctly, but I have already written a multithreaded program as well as an IRC bot. It was just really weird, and became hard to maintain (the IRC bot). I encourage someone to tell me that that is an incorrect view of what you said.


I tried making an IRC Client. Believe me, it's not hard, but you need to understand two important things, Twisted and wxPython (you may not use Twisted, you can use pure sockets, but it makes it easier) and you are also not forced to use wxPython but then again it makes it easier.

So you set a reactor that allows multiprocessing (GUI & IRC Connection).

http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.wxreactor.html

It is complicated for a Python beginner, it's a language-specific thing. You can port a lot of console programs easily, but I'd recommend you to rewrite them Razz But things that involve language-specific things are obviously gonna be hard, even if you have made it in hundreds of other languages.

Also:
You us-s-s-e-e-e t-t-t-t-a-b-b-s? 4 spaces is the one and true way to go on Python, perhaps you should read PEP-8 Smile You're not forced to I know, but it makes the code much easier to read by other people and well following the standard makes it easier to ask questions and get help.
_player1537 wrote:
I also like your comparison to asking forgiveness-- not one that I have heard before. Would you mind explaining it a bit more? Do you mean like: it is easier to ask Python to let you try something over (re-styling) instead of asking it to just imagine that everything is the same? Or am I missing it?
It's the idea that you should use exception handling instead of checking if you're able to do something. For example, this:

Code:
try:
    ham = spam.eggs
except AttributeError:
    handle_error()

is preferred over:

Code:
if hasattr(spam, 'eggs'):
    ham = spam.eggs
else:
    handle_error()

So it's easier to ask forgiveness (that is, catch an exception and recover) than permission (check if it's possible and handle if it's not). I don't really like that.

ephan wrote:
You us-s-s-e-e-e t-t-t-t-a-b-b-s? 4 spaces is the one and true way to go on Python, perhaps you should read PEP-8 Smile You're not forced to I know, but it makes the code much easier to read by other people and well following the standard makes it easier to ask questions and get help.
What's with the repeated letters? As for tabs vs. spaces, I say screw PEP-8 and use tabs, but it's all preference. It does get in the way of stuff when different people use different things, though. Wikipedia has some good things to say about it:
Quote:
Both space characters and tab characters are currently accepted as forms of indentation in Python. Since many tools do not visually distinguish them, mixing spaces and tabs can create bugs that take specific efforts to find (a perennial suggestion among Python users has been removing tabs as block markers — except, of course, among those Python users who propound removing spaces instead). Moreover, formatting routines which remove whitespace — for instance, many Internet forums — can destroy the syntax of a Python program, whereas a program in a bracketed language would merely become more difficult to read.
ephan wrote:
Also:
You us-s-s-e-e-e t-t-t-t-a-b-b-s? 4 spaces is the one and true way to go on Python, perhaps you should read PEP-8 Smile You're not forced to I know, but it makes the code much easier to read by other people and well following the standard makes it easier to ask questions and get help.


I wouldn't start bickering over this here, but...

It doesn't matter what you use. What matters is that you don't mix spaces and tabs.

Readability barely changes, as long as you have a decent editor. Notepad++, for instance, shows the same spacing block for 4 spaces and tabs. I'm not sure how it would make it harder to get help either: unless people post code with spaces and you have to convert it to tabs.

Also, PEP 8 suggests that you limit code lines to 79 characters. Do you do that, too?
merthsoft wrote:
Yeah, I don't see why people mind it being white-space aware--that's how I code anyway. But, as you say, people using spaces instead of tabs always mucks everything up. My biggest issues with python are the "easier to ask forgiveness than permission" paradigm, and how ugly it is to make your own classes. For such a pretty language, they really screwed that up.


Uh, how is making your own classes ugly? Python classes are simple and straightforward. They even managed to avoid falling into the syntactic tarpit that usually results when dealing with operator overloads (look at the syntax to overload an operator in C++, it's ridiculous - and C# isn't much better)

As for "easier to ask forgiveness than permission", that really doesn't come up much at all. I've written several medium-sized python projects, and I never had to catch any exceptions. In fact, I use it so rarely I find I often have to lookup error handling in Python. I would go so far as to say that that really isn't a "Python" thing at all - seeing as things like dict have a get method that allows you to pass in the value to return if none exists.

As for why people use Python, it's because you can do a *TON* with very little code. Things like slices, negative indexing, etc... make string and array manipulation a breeze. There is a huge builtin library that has tons of high level stuff, with libraries to do just about anything you want. There is fairly easy C extension mechanisms if you want to get down and dirty. There is awesomely powerful reflection and run time modification abilities.
Kllrnohj wrote:
merthsoft wrote:
Yeah, I don't see why people mind it being white-space aware--that's how I code anyway. But, as you say, people using spaces instead of tabs always mucks everything up. My biggest issues with python are the "easier to ask forgiveness than permission" paradigm, and how ugly it is to make your own classes. For such a pretty language, they really screwed that up.


Uh, how is making your own classes ugly? Python classes are simple and straightforward. They even managed to avoid falling into the syntactic tarpit that usually results when dealing with operator overloads (look at the syntax to overload an operator in C++, it's ridiculous - and C# isn't much better)
The underscores, man:

Code:
class Whatever:
    def __init__ (self, a, b):
        ...
    def __add__ (self, other):
        ...
    def __sub__ (self, other):
       ...
    def __mul__ (self, other):
       ...
    def __div__ (self, other):
        ..
    def __str__ (self):
        ...
    def __float__ (self):
       ...
That's ugly. I think I much prefer:

Code:
public class Whatever {
   public Whatever(int a, int b) { ... }
   
   public override string ToString() { ... }
   
   public static operator +(Whatever x, Whatever y) { ... }
   public static operator -(Whatever x, Whatever y) { ... }
   public static operator *(Whatever x, Whatever y) { ... }
   public static operator /(Whatever x, Whatever y) { ... }
   
   public static explicit operator float(Whatever x) { ... }
}
Granted it's more verbose, but I don't think that's a bad thing. I think this is a rare case where my Mum would've understood the C# better than the Python. Others may think otherwise, though. It's all a matter of preference.

Ibid. wrote:
As for "easier to ask forgiveness than permission", that really doesn't come up much at all. I've written several medium-sized python projects, and I never had to catch any exceptions. In fact, I use it so rarely I find I often have to lookup error handling in Python. I would go so far as to say that that really isn't a "Python" thing at all - seeing as things like dict have a get method that allows you to pass in the value to return if none exists.
Fair enough. I haven't done a whole lot of python-ing myself, and when I have I've avoided exception handling if I could. I just read that it was the "Pythonian" way to do it, and figured I was just doing it un-Pythonianly. If it is, indeed, the case that I'm mistaken, I retract this point.

Ibid. wrote:
As for why people use Python, it's because you can do a *TON* with very little code. Things like slices, negative indexing, etc... make string and array manipulation a breeze. There is a huge builtin library that has tons of high level stuff, with libraries to do just about anything you want. There is fairly easy C extension mechanisms if you want to get down and dirty. There is awesomely powerful reflection and run time modification abilities.
I am too lazy to actually make my own post so instead I quote people and then don't say anything new
I enjoy Python for a whole variety of reasons, most of which boil down to fast code prototyping plus powerful functionality in relatively few lines. I threw together the meat of something like BinPac8x in a few dozen lines in an hour or less, for instance, and interfacing with a whole bunch of different things for the ongoing FeedScreamer/Scouter 2 project is a breeze. I wish that Python had been around when I was building Simms (or rather, that I knew about it), because it would have been a far better option than what I used. Of course, strict whitespacing is often cited as a disadvantage, but I like rigorously indented code anyway, so it's really not a hardship at all for me. I'd say my biggest gripe with it is the 2.x/3.x difference, especially when you want to make the same script compatible with both. Summary: straightforward, pseudocode-like code, fast prototyping, powerful yet simple.
merthsoft wrote:
The underscores, man:

Code:
class Whatever:
    def __init__ (self, a, b):
        ...
    def __add__ (self, other):
        ...
    def __sub__ (self, other):
       ...
    def __mul__ (self, other):
       ...
    def __div__ (self, other):
        ..
    def __str__ (self):
        ...
    def __float__ (self):
       ...
That's ugly.


I think it works pretty well. It removes the ambiguity that it is just another function and not something "special" - makes the rules pretty simple. Those are mostly only needed if you are doing operator overloading anyway. Prefixing an underscore also imply that it is private, btw.
Quote:
so, PEP 8 suggests that you limit code lines to 79 characters. Do you do that, too?


I'd link you to one of my finished Python projects:

http://code.google.com/p/hex-baker/source/browse/main.py

Everything in there is according to PEP-8, and I look at the code and think it looks just perfect and easy-to-rude.

Oh and that's yet another Python advantage, code is easy to read and it's "sexy".
Hey, that's actually not bad-looking code at all! Although I'm entertained that your latest commit is a line break to fix that very problem. Very Happy
KermMartian wrote:
Hey, that's actually not bad-looking code at all! Although I'm entertained that your latest commit is a line break to fix that very problem. Very Happy


I had one line with 83 columns, but the rest of the code was PEP-8 Fixed.
ephan wrote:
Quote:
so, PEP 8 suggests that you limit code lines to 79 characters. Do you do that, too?


I'd link you to one of my finished Python projects:

http://code.google.com/p/hex-baker/source/browse/main.py

Everything in there is according to PEP-8, and I look at the code and think it looks just perfect and easy-to-rude.

Oh and that's yet another Python advantage, code is easy to read and it's "sexy".


If you want to spend time making your code "standardized" according to PEP 8, good for you.

But the point I was trying to make was that it doesn't really matter. See, that Python code is no more or less readable to me than any of my own projects, which use tabs and generally have all code on one line. I grant that it's very readable, but I don't think that's because it's PEP 8 formatted: that's just because it's Python. Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 3
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement