Re: Love to get some feedback on my first python app!!!
One thing I noticed with that code was the size of your function, and excessive comments. It reminds me of my bubble_sort.c program in school/college - everything plonked into 'main'. Try writing it like this: 1. #!/usr/bin/python or #!/usr/bin/env python The leading #! is read by the kernel when it has to start the interpreter (exec), so don't stick your comment in there. 2. Try to align the imports so they look pretty 3. Don't use whacking big functions and then stick endless explanatory comments Use the function name as a comment instead - divide your program up into little tasks. Try to make the stuff generic - def url_extract(content, pattern): def extract_url def extract_title def tk_init Use #--- to demarcate sections, very common functions go into a utility-library, not so common functions at the section at start of the file, and so on.. 4. Don't skimp on the sys.exit() or def debug (which should be in your utilities lib) 5. Don't do :x = foo('.') instead: var_name = '..' # make it global x = foo(var_name) 6. To build a string do: param1 = xyz1 + xyz2 x = foo(param1) -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Mon, Sep 22, 2014 at 7:00 PM, vek.m1...@gmail.com wrote: One thing I noticed with that code was the size of your function, and excessive comments. It reminds me of my bubble_sort.c program in school/college - everything plonked into 'main'. Try writing it like this: I'd like to see justifications for some of the advice you're giving here. Quite a bit of it I disagree with :) 1. #!/usr/bin/python or #!/usr/bin/env python The leading #! is read by the kernel when it has to start the interpreter (exec), so don't stick your comment in there. Very much optional. Even on Unix systems, it's not necessary unless you want it to be executable. 2. Try to align the imports so they look pretty You mean adding extra spaces? Not advised. Or something else? Definitely needs more explanation (maybe an example) and justification (why do it?). 3. Don't use whacking big functions and then stick endless explanatory comments Use the function name as a comment instead - divide your program up into little tasks. Try to make the stuff generic - def url_extract(content, pattern): def extract_url def extract_title def tk_init Use #--- to demarcate sections, very common functions go into a utility-library, not so common functions at the section at start of the file, and so on.. If functions are defined and then called from exactly one place, there's no need to put them anywhere else. Just inline them. It's not as if the indentation is getting out of hand here - getinfo() tops out at just three tabs in, which is nothing. I've gone to seven a number of times, and there's one particular piece of code I have that goes as far as nine - though that's not something I'd recommend! Different people will put the limit at different points, but three is never going to be excessive. (Cue someone pointing out to me a situation in which three really is excessive, but sure, that'll be a fun spin-off thread.) 4. Don't skimp on the sys.exit() or def debug (which should be in your utilities lib) More explanation needed, please. What are you trying to do here? What would be different? 5. Don't do :x = foo('.') instead: var_name = '..' # make it global x = foo(var_name) Uhhh, why??!? 6. To build a string do: param1 = xyz1 + xyz2 x = foo(param1) Ditto. Why?!? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
1. It's feedback not a mathematical proof. 2. I hope the OP tries what I suggested - it's all entirely optional. @OP I have no idea what that program does because it's well commented. You aren't using variable and function names to good effect and are resorting to excessive comments. Additionally, I think you are mangling your display text but I'm not sure. textDisplay.insert should be a function that you pass args to. def spit_msg(text): textDisplay.insert(text) spit_msg(go away doo doo bird) Any time you see repeated text in your program, wrap it in a single func and simplify. try: def create_root_window(): rather than letting all your funny parts dangle around naked. -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
https://github.com/Veek/Python/blob/master/IRC/Hexchat/fake_ctcp.py that's not too bad as far as readability is concerned and it's bereft of all comments {:p -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Mon, Sep 22, 2014 at 9:47 PM, vek.m1...@gmail.com wrote: 1. It's feedback not a mathematical proof. 2. I hope the OP tries what I suggested - it's all entirely optional. Doesn't change the fact that you need to justify your recommendations, at least when they're not obvious. You're suggesting a number of things which are definitely not the same as I'd recommend, and I can't evaluate them because you haven't explained *why* you give that advice. @OP I have no idea what that program does because it's well commented. You aren't using variable and function names to good effect and are resorting to excessive comments. Comments are not bad. His variable names aren't nearly as bad as you imply. I can read the code *just fine*. Either you're exaggerating, or you're trolling, or you're extremely dim. I'm not sure which. Additionally, I think you are mangling your display text but I'm not sure. textDisplay.insert should be a function that you pass args to. def spit_msg(text): textDisplay.insert(text) spit_msg(go away doo doo bird) Any time you see repeated text in your program, wrap it in a single func and simplify. Not every one-liner needs to be a function. Not all repeated text needs to be wrapped up. You can always add another level of indirection, and it's frequently not necessary. try: def create_root_window(): rather than letting all your funny parts dangle around naked. This seems incomplete. What's this try block for? What's the function for? Will it be called from more than one place? If not, why wrap it up? Again, you need to explain *why* something needs to be changed. Telling someone do this, this, this, and this is almost completely useless, because it doesn't teach any better programming practices - in fact, it may teach a black-box programming style that's good only for novices (like saying always put 'from __future__ import print_function' at the top of your Python files, which might be a perfectly good thing to do, but at some point you need to explain why). Also, you're posting on a mailing list and newsgroup. Please include context in your posts so we know what you're talking about. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Mon, Sep 22, 2014 at 10:00 PM, vek.m1...@gmail.com wrote: https://github.com/Veek/Python/blob/master/IRC/Hexchat/fake_ctcp.py that's not too bad as far as readability is concerned and it's bereft of all comments {:p Sure, I can work out what it's doing without comments. Doesn't mean comments are bad, though. Also, without comments, I have no idea *why* it's doing what it does. For instance, this: def debug(msg): hexchat.prnt('{}'.format(msg)) Why not just do this: debug = hexchat.prnt Or, better still, just use hexchat.prnt() everywhere, instead of having a local name? (You happily use hexchat.* in other places.) Is it meant to be monkey-patched externally? Is it meant to be a one-place edit? What's the purpose of this one-line function? date = str(date_s) + ' ' + str(hour) + ':' + str(min) + ':' + str(sec) You use .format() in places where it's completely unnecessary, but eschew it when it would make your code more readable. date = %s %s:%s:%s % (date_s, hour, min, sec) date = {} {}:{}:{}.format(date_s, hour, min, sec) So, comments would definitely help. In some cases, would help a lot. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Mon, Sep 22, 2014 at 8:23 AM, Chris Angelico ros...@gmail.com wrote: So, comments would definitely help. In some cases, would help a lot. This is me: http://xkcd.com/1421/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
Ok I'm confused. Do I need to do better comments? I know the text is not that great but that is my next obstacle I am going to tackle. I mostly need to know where I am going wrong such as what is expectable readable code and what is not and how to fix this. This is good feedback thanks to all of you guys. All I want to do is learn and become better and neater! -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
Also I have just been coding for about and hour and a half and added a lot more code to it but it is not fully finished yet so it is not on github yet. -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Mon, Sep 22, 2014 at 11:02 PM, Larry Martell larry.mart...@gmail.com wrote: On Mon, Sep 22, 2014 at 8:23 AM, Chris Angelico ros...@gmail.com wrote: So, comments would definitely help. In some cases, would help a lot. This is me: http://xkcd.com/1421/ Also me. I have apologized to my future selves on a number of occasions. And of course, very VERY frequently, I have answered my future selves' questions. That, I think, is the primary purpose of code comments. It's a kind of limited-range time travel: I can travel back in time, ask myself a question, and get an answer. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Mon, Sep 22, 2014 at 11:17 PM, Nicholas Cannon nicholascann...@gmail.com wrote: Ok I'm confused. Do I need to do better comments? I know the text is not that great but that is my next obstacle I am going to tackle. I mostly need to know where I am going wrong such as what is expectable readable code and what is not and how to fix this. This is good feedback thanks to all of you guys. All I want to do is learn and become better and neater! Your comments aren't terrible. Just imagine yourself reading this code six months from now, having not touched it in between, and imagine all the questions you'd ask yourself. Then answer them. Conversely, if something would be patently obvious to your future self, don't bother commenting it. Have a read of some of the tips here. You may find them helpful. http://www.catb.org/esr/faqs/hacker-howto.html ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
@Chris, Hi, I don't like your style of posting - please kill file me. @Everybody else - I don't like Chris and his style of posting (overuse of the 'troll' word and perceived aggression). I shall be ignoring him for a year (barring an emergency). Good communication demands that I announce this. Please don't misconstrue this as rudeness on my part. If you feel that he is asking something of pertinence, feel free to include it in your posts for a reply. -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
I wouldn't take it personally, just defend your position. I think that is what he is looking for. We are all adults here (maybe?). You guys should be able to work it out. A tangential skill to programming is being able to give and take criticism well, even if you think it crosses the line. On Mon, Sep 22, 2014 at 6:35 AM, vek.m1...@gmail.com wrote: @Chris, Hi, I don't like your style of posting - please kill file me. @Everybody else - I don't like Chris and his style of posting (overuse of the 'troll' word and perceived aggression). I shall be ignoring him for a year (barring an emergency). Good communication demands that I announce this. Please don't misconstrue this as rudeness on my part. If you feel that he is asking something of pertinence, feel free to include it in your posts for a reply. -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Mon, Sep 22, 2014 at 11:48 PM, C Smith illusiontechniq...@gmail.com wrote: I wouldn't take it personally, just defend your position. I think that is what he is looking for. We are all adults here (maybe?). You guys should be able to work it out. A tangential skill to programming is being able to give and take criticism well, even if you think it crosses the line. Precisely. Asking for justification isn't meant to imply that there is none. But it's like back in my high school maths lessons: if you don't show your working, there's no way to discuss the details, and if the conclusion is wrong (or in this case, is disagreed with), you can't do anything with it. With the intermediate steps given, we can discuss, explain, and maybe find that we mostly agree. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
- Original Message - From: Chris Angelico ros...@gmail.com Cc: python-list@python.org Sent: Saturday, 20 September, 2014 4:58:44 PM Subject: Re: Love to get some feedback on my first python app!!! [snip] #search API rawData = urllib.urlopen('http://ajax.googleapis.com/ajax/services/search/web?v=1.0q='+encodedQuery).read() #loads data from API into json jsonData = json.loads(rawData) #extracts the results from API searchResults = jsonData['responseData']['results'] The more normal way to write these would be in present tense, in a more imperative style: Fix some bugs, Load data, Extract results. (Although these comments are actually quite redundant - all they do is tell you what the single next line of code does.) I used to belong to the cult don't repeat yourself in the comments, being angry against people who thought I couldn't understand by myself the simplest line of code. But I changed my mind. I've read some code comments over the years and best ones (imo) where those which where actually repeating themselves. Golden rules of comments: # state what you plan to do doIt() For instance: cells = ['a', 'b' 'c'] # print the first cell print cell[1] A bug that is easily spotted thanks to the comment. It's all about implementation versus intentions. Also note that comment should be written for the future self, and most importantly, for the current others. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Mon, Sep 22, 2014 at 10:32 AM, Jean-Michel Pichavant jeanmic...@sequans.com wrote: - Original Message - From: Chris Angelico ros...@gmail.com Cc: python-list@python.org Sent: Saturday, 20 September, 2014 4:58:44 PM Subject: Re: Love to get some feedback on my first python app!!! [snip] #search API rawData = urllib.urlopen('http://ajax.googleapis.com/ajax/services/search/web?v=1.0q='+encodedQuery).read() #loads data from API into json jsonData = json.loads(rawData) #extracts the results from API searchResults = jsonData['responseData']['results'] The more normal way to write these would be in present tense, in a more imperative style: Fix some bugs, Load data, Extract results. (Although these comments are actually quite redundant - all they do is tell you what the single next line of code does.) I used to belong to the cult don't repeat yourself in the comments, being angry against people who thought I couldn't understand by myself the simplest line of code. But I changed my mind. I've read some code comments over the years and best ones (imo) where those which where actually repeating themselves. Golden rules of comments: # state what you plan to do doIt() For instance: cells = ['a', 'b' 'c'] # print the first cell print cell[1] A bug that is easily spotted thanks to the comment. It's all about implementation versus intentions. Also note that comment should be written for the future self, and most importantly, for the current others. JM Docstrings -- look them up. Then you can run pydocs (and help!) on your code and see excellent documentation I would break up the big function into a few smaller ones that are easier to describe. Unless there is something very weird in the code, I don't think #inline comments saying the obvious are useful, but a summary at the top of the module, function, class, etc. is important -- Joel Goldstick http://joelgoldstick.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Tue, Sep 23, 2014 at 12:32 AM, Jean-Michel Pichavant jeanmic...@sequans.com wrote: For instance: cells = ['a', 'b' 'c'] # print the first cell print cell[1] A bug that is easily spotted thanks to the comment. It's all about implementation versus intentions. Also note that comment should be written for the future self, and most importantly, for the current others. I do see your point, but there's a serious problem here of code edits. It's really easy to zip through and find all occurrences of some name and change them - and miss the one in the comment. In this particular case, I'm not actually sure where the bug is: is it in the first line (should be cell = ...) or the third (print cells[1])? Either way, the comment doesn't make it any clearer, because the plural rule in English doesn't always match naming of variables. Also, it's common in English to count from 1, but in code to count from 0; so there's another bug (and this might be the one you thought easily spotted) - it should either be cell[0] in the third line, or print the 1th cell in the second. (Plus, there's a comma omitted. That list has two elements, but I think it's meant to have three. However, I'm guessing that's a transcription error, or a construction-in-email error, and nothing to do with what you're saying.) Now, compare this similar code: cells = ['Chris Angelico', 'ros...@gmail.com', 142857] # print the email address print(cells[2]) This says *why* it's doing what it does - what the meaning of the index is. And it, too, has a clearly visible bug, because when it prints out an integer, the comment makes it obvious that it's done the wrong thing. This is, IMO, much more useful. If the code gets edited (maybe the name used to be in two fields for First Name and Last Name, and then someone realized how bad an idea that is - but forgot to update the index), the original intention is visible; if it just says print out cell #2, it's not so helpful. So basically, don't *purely* repeat yourself, but give some info that's a level behind the code. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
@CSmith Hi, I'm sorry, I wish I could acquiesce but I think it's better for me to stay clear. There's criticism, and there's name calling ('dim' 'troll'). Reiterating what I said earlier, if the OP wants clarification he can ask for it. -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Mon, 22 Sep 2014 16:32:27 +0200, Jean-Michel Pichavant wrote: - Original Message - From: Chris Angelico ros...@gmail.com Cc: python-list@python.org Sent: Saturday, 20 September, 2014 4:58:44 PM Subject: Re: Love to get some feedback on my first python app!!! [snip] #search API rawData = urllib.urlopen('http://ajax.googleapis.com/ajax/services/search/ web?v=1.0q='+encodedQuery).read() #loads data from API into json jsonData = json.loads(rawData) #extracts the results from API searchResults = jsonData['responseData']['results'] The more normal way to write these would be in present tense, in a more imperative style: Fix some bugs, Load data, Extract results. (Although these comments are actually quite redundant - all they do is tell you what the single next line of code does.) I used to belong to the cult don't repeat yourself in the comments, being angry against people who thought I couldn't understand by myself the simplest line of code. But I changed my mind. I've read some code comments over the years and best ones (imo) where those which where actually repeating themselves. Golden rules of comments: # state what you plan to do doIt() For instance: cells = ['a', 'b' 'c'] # print the first cell print cell[1] That is not too bad, Print Customer name from cell 1 may be better as it would stick out if the data structure changed what is meant by don't state the obvious in comments is stating something like Increment x without explaining why. -- It is hard to overstate the debt that we owe to men and women of genius. -- Robert G. Ingersoll -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
- Original Message - From: Chris Angelico ros...@gmail.com Cc: python-list@python.org Sent: Monday, 22 September, 2014 4:50:15 PM Subject: Re: Love to get some feedback on my first python app!!! On Tue, Sep 23, 2014 at 12:32 AM, Jean-Michel Pichavant jeanmic...@sequans.com wrote: For instance: cells = ['a', 'b' 'c'] # print the first cell print cell[1] A bug that is easily spotted thanks to the comment. It's all about implementation versus intentions. Also note that comment should be written for the future self, and most importantly, for the current others. I do see your point, but there's a serious problem here of code edits. It's really easy to zip through and find all occurrences of some name and change them - and miss the one in the comment. In this particular case, I'm not actually sure where the bug is: is it in the first line (should be cell = ...) or the third (print cells[1])? Either way, the comment doesn't make it any clearer, because the plural rule in English doesn't always match naming of variables. Also, it's common in English to count from 1, but in code to count from 0; so there's another bug (and this might be the one you thought easily spotted) - it should either be cell[0] in the third line, or print the 1th cell in the second. (Plus, there's a comma omitted. That list has two elements, but I think it's meant to have three. However, I'm guessing that's a transcription error, or a construction-in-email error, and nothing to do with what you're saying.) Now, compare this similar code: cells = ['Chris Angelico', 'ros...@gmail.com', 142857] # print the email address print(cells[2]) This says *why* it's doing what it does - what the meaning of the index is. And it, too, has a clearly visible bug, because when it prints out an integer, the comment makes it obvious that it's done the wrong thing. This is, IMO, much more useful. If the code gets edited (maybe the name used to be in two fields for First Name and Last Name, and then someone realized how bad an idea that is - but forgot to update the index), the original intention is visible; if it just says print out cell #2, it's not so helpful. So basically, don't *purely* repeat yourself, but give some info that's a level behind the code. ChrisA Damn you didn't fall into my trap :D. The code I posted had many bugs but one could not be fixed without the comment. Or at least there's an obvious discrepancy between the comment and the code that should catch the reader's attention. Anyway it's seems we agree anyway because your example perfectly illustrate what I was trying to demonstrate: print(cells[2]) is very easy to understand, most of people would say 'no need of any comment'. I think it does require a comment. I find myself writing a comment every 3 or 4 line of code, at least, for what I've read, that's way too much. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Tue, Sep 23, 2014 at 1:52 AM, Jean-Michel Pichavant jeanmic...@sequans.com wrote: The code I posted had many bugs but one could not be fixed without the comment. Or at least there's an obvious discrepancy between the comment and the code that should catch the reader's attention. The obvious discrepancy, sadly, doesn't tell you which one is right. It's like the old days of FAT file systems - DOS would maintain two copies of the eponymous File Allocation Table, but in the event of corruption, it had no way of knowing which was to be trusted. (And I'm not sure anything would ever actually notice differences, other than an explicit CHKDSK.) When you have an intention comment, rather than simply replicating the functionality in human-readable form, you can more easily check that the intention matches the rest of the design. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On 22/09/2014 12:47, vek.m1...@gmail.com wrote: 1. It's feedback not a mathematical proof. What is? 2. I hope the OP tries what I suggested - it's all entirely optional. Which is? @OP I have no idea what that program does because it's well commented. You aren't using variable and function names to good effect and are resorting to excessive comments. Additionally, I think you are mangling your display text but I'm not sure. textDisplay.insert should be a function that you pass args to. def spit_msg(text): textDisplay.insert(text) spit_msg(go away doo doo bird) Any time you see repeated text in your program, wrap it in a single func and simplify. try: def create_root_window(): rather than letting all your funny parts dangle around naked. Google groups rides again? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Tue, Sep 23, 2014 at 2:10 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: Google groups rides again? Yeah. And now someone from Google Groups has killfiled me. So it's up to you to request/recommend alternatives, s/he won't see me saying so. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On 22/09/2014 14:35, vek.m1...@gmail.com wrote: @Chris, Hi, I don't like your style of posting - please kill file me. @Everybody else - I don't like Chris and his style of posting (overuse of the 'troll' word and perceived aggression). I shall be ignoring him for a year (barring an emergency). Good communication demands that I announce this. Please don't misconstrue this as rudeness on my part. If you feel that he is asking something of pertinence, feel free to include it in your posts for a reply. Laughable as you never give any context. Please equip yourself with a decent tool, there are plenty to choose from. And ignore Chris at your peril, he knows a fair bit about Python. Sure he gets things wrong, but the only person who never gets things wrong is the person who never does anything. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On 22/09/2014 14:48, C Smith wrote: I wouldn't take it personally, just defend your position. I think that is what he is looking for. We are all adults here (maybe?). You guys should be able to work it out. A tangential skill to programming is being able to give and take criticism well, even if you think it crosses the line. On Mon, Sep 22, 2014 at 6:35 AM, vek.m1...@gmail.com wrote: @Chris, Hi, I don't like your style of posting - please kill file me. @Everybody else - I don't like Chris and his style of posting (overuse of the 'troll' word and perceived aggression). I shall be ignoring him for a year (barring an emergency). Good communication demands that I announce this. Please don't misconstrue this as rudeness on my part. If you feel that he is asking something of pertinence, feel free to include it in your posts for a reply. -- https://mail.python.org/mailman/listinfo/python-list Hells bells if it's not googlegroups it's top posting. What did I do in a past life to deserve this? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Tue, Sep 23, 2014 at 2:17 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: And ignore Chris at your peril, he knows a fair bit about Python. Sure he gets things wrong, but the only person who never gets things wrong is the person who never does anything. Thanks :) I don't mind being wrong, or being told I'm wrong. Those are some of the best threads we've ever had - lengthy debates by intelligent people who start out with different views, figuring out exactly what the differences are and why there are those differences. Those are the threads that differentiate c.l.p/python-list from Facebook - there's solid content, serious discussion, and stuff that's worth going back to. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On 22/09/2014 13:00, vek.m1...@gmail.com wrote: https://github.com/Veek/Python/blob/master/IRC/Hexchat/fake_ctcp.py that's not too bad as far as readability is concerned and it's bereft of all comments {:p Definitely googlegroups rides again. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On 22/09/2014 14:17, Nicholas Cannon wrote: Ok I'm confused. Do I need to do better comments? I know the text is not that great but that is my next obstacle I am going to tackle. I mostly need to know where I am going wrong such as what is expectable readable code and what is not and how to fix this. This is good feedback thanks to all of you guys. All I want to do is learn and become better and neater! So am I. To whom are you replying and about what? I'm not spending my time trying to find out just because you can't be bothered to use a decent tool when posting here. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Mon, Sep 22, 2014 at 8:52 AM, Jean-Michel Pichavant jeanmic...@sequans.com wrote: Anyway it's seems we agree anyway because your example perfectly illustrate what I was trying to demonstrate: print(cells[2]) is very easy to understand, most of people would say 'no need of any comment'. I think it does require a comment. But the thing that requires the comment is the 2, not the print or the cells. And that comes to a more common issue: any number other than 0 or 1 in code most likely needs a comment (that comment could be merely a variable name). Values of 0 or 1 may need a comment, but there are plenty of cases where they are used quite clearly - its much less likely that other numbers have obvious meaning. Chris -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Tue, Sep 23, 2014 at 4:24 AM, Chris Kaynor ckay...@zindagigames.com wrote: On Mon, Sep 22, 2014 at 8:52 AM, Jean-Michel Pichavant jeanmic...@sequans.com wrote: Anyway it's seems we agree anyway because your example perfectly illustrate what I was trying to demonstrate: print(cells[2]) is very easy to understand, most of people would say 'no need of any comment'. I think it does require a comment. But the thing that requires the comment is the 2, not the print or the cells. And that comes to a more common issue: any number other than 0 or 1 in code most likely needs a comment (that comment could be merely a variable name). Values of 0 or 1 may need a comment, but there are plenty of cases where they are used quite clearly - its much less likely that other numbers have obvious meaning. Or in this case, replacing the list with a namedtuple is probably more useful. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
Original Message - From: Chris Angelico ros...@gmail.com Cc: python-list@python.org Sent: Monday, 22 September, 2014 6:04:43 PM Subject: Re: Love to get some feedback on my first python app!!! On Tue, Sep 23, 2014 at 1:52 AM, Jean-Michel Pichavant jeanmic...@sequans.com wrote: The code I posted had many bugs but one could not be fixed without the comment. Or at least there's an obvious discrepancy between the comment and the code that should catch the reader's attention. The obvious discrepancy, sadly, doesn't tell you which one is right. [snip] ChrisA You're right but that's fine and the comment's still doing its job. Either the comment is wrong, or the code is. It doesn't really matter which one, It needs to be investigated and fixed. Otherwise you could say that writing specifications is pointless since specifications can be wrong and when a problem occur you need to figure out if either the code or the specification is responsible. Like a CRC check, sometimes the payload is correct and the error is on the CRC, it's still damn useful. JM -- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On 23/09/2014 4:25 AM, Chris Angelico wrote: On Tue, Sep 23, 2014 at 4:24 AM, Chris Kaynor ckay...@zindagigames.com wrote: But the thing that requires the comment is the 2, not the print or the cells. And that comes to a more common issue: any number other than 0 or 1 in code most likely needs a comment (that comment could be merely a variable name). Values of 0 or 1 may need a comment, but there are plenty of cases where they are used quite clearly - its much less likely that other numbers have obvious meaning. Or in this case, replacing the list with a namedtuple is probably more useful. Depending on the use case, binding a slice to a name can also help clarify things. -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Saturday, September 20, 2014 9:17:27 PM UTC+8, Nicholas Cannon wrote: I have created my first python program and I have learnt a lot about python from this group and wanted some feedback. I am still improving it and trying to tackle some performance and GUI stuff so keep that in mind. I don't think it is the best program but is a good product of 3 months of python. link: https://github.com/nicodasiko/Article-Grab I just updated the whole app to include a scroll bar, loading bar and I used multi threading to update the scroll bar whilst scraping the data from the web. I need to work on performance though but I have defiantly improved it now! -- https://mail.python.org/mailman/listinfo/python-list
Love to get some feedback on my first python app!!!
I have created my first python program and I have learnt a lot about python from this group and wanted some feedback. I am still improving it and trying to tackle some performance and GUI stuff so keep that in mind. I don't think it is the best program but is a good product of 3 months of python. link: https://github.com/nicodasiko/Article-Grab -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Sat, Sep 20, 2014 at 11:16 PM, Nicholas Cannon nicholascann...@gmail.com wrote: I have created my first python program and I have learnt a lot about python from this group and wanted some feedback. I am still improving it and trying to tackle some performance and GUI stuff so keep that in mind. I don't think it is the best program but is a good product of 3 months of python. link: https://github.com/nicodasiko/Article-Grab Sure! But first, a couple of points that aren't specifically Python... Firstly, you're using Google Groups. Until someone gets inside Google and fixes up the code, it will make a mess of every post made through it. Please use something better... either subscribe to the mailing list and do everything through email, or access the newsgroup comp.lang.python via a better client, or something of the sort. Secondly, a note about verb tenses in English. You have this commit message on the (as of 20140921) latest commit: Fixed some bugs and did some GUI changes And these comments in the code: #search API rawData = urllib.urlopen('http://ajax.googleapis.com/ajax/services/search/web?v=1.0q='+encodedQuery).read() #loads data from API into json jsonData = json.loads(rawData) #extracts the results from API searchResults = jsonData['responseData']['results'] The more normal way to write these would be in present tense, in a more imperative style: Fix some bugs, Load data, Extract results. (Although these comments are actually quite redundant - all they do is tell you what the single next line of code does.) You may also notice that the camelCase variable names you're using are in stark contrast to the rest of the language. It's normal to use lower_case_with_underscores instead. Now, let's have a look at the code itself. query = queryVar.get() ... and further down ... global queryVar queryVar = StringVar() You don't need to say global at top level. Everything at top-level is global. However, I generally like to, as much as possible, define things higher in the file than their usages - so that as you read the file, the first reference to anything is the one that tells you what it is. That may not be practical here, but it's something to keep in mind. (This is why import statements generally go at the top of the file, for instance.) The language doesn't require it, but it does make the code easier for a human to read. links = [] for result in searchResults: #loops through the searchResults data to find the title and URL of the pages #and then add the links to the links list title = result['title'] link = result['url'] links.append(link) print links You're not doing anything with the title, so what you have here is a loop that builds up a list from empty, by repeated appends. That's a perfect job for a list comprehension: links = [result['url'] for result in searchResults] I'm not sure why you print the links to stdout there - is that some left-over debugging code? Although, the only thing you do with the list of URLs is to iterate over it, once. You could simply merge the two loops into one: for result in searchResults: url = result['url'] pageData = urllib.urlopen(url).read() ... etc ... Your text insertion is a little inconsistent: you put the URL and title at the cursor position, then the body at the end. Is that intentional? If so, that deserves a comment - which would be much more useful than the comments that say what we can read in the code already. textDisplay.insert(INSERT, 'This spider searches for information on your query and will display it here!') You haven't written a spider here :) You're just calling on Google's spider and showing some information. Similarly, the verb CRAWL on your button isn't really accurate - and isn't particularly helpful to the user either. I'd just word it in terms of how the user will value it, and say Search on the button. Keep it simple. queryWidgit = Entry(frame, textvariable=queryVar, fg='Blue', bd=5, width=50) It's normally Widget, not Widgit. Not significant, but you seem to have consistently used two i's, including in your comments. Well, you asked for feedback. That's normally going to consist of people pointing out where they think you did badly. But ultimately, this is all relatively minor, so if the program works, consider yourself to have broadly succeeded. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On 20/09/2014 15:58, Chris Angelico wrote: On Sat, Sep 20, 2014 at 11:16 PM, Nicholas Cannon nicholascann...@gmail.com wrote: You may also notice that the camelCase variable names you're using are in stark contrast to the rest of the language. It's normal to use lower_case_with_underscores instead. That may be the PEP 8 guideline but I don't regard it as normal, I find camelCase far easier to read. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Saturday, September 20, 2014 9:17:27 PM UTC+8, Nicholas Cannon wrote: I have created my first python program and I have learnt a lot about python from this group and wanted some feedback. I am still improving it and trying to tackle some performance and GUI stuff so keep that in mind. I don't think it is the best program but is a good product of 3 months of python. link: https://github.com/nicodasiko/Article-Grab Yeah this is exactly what I was looking for I know the comments are horrible and I had no idea about the camelCase stuff. Should I use ''' Use this commenting on my functions or not. I think they are called docStrings or something ''' I have a free day today and I am going to fix up some GUI stuff and try and slim down the processing and amount of variables because it doesnt really run as fast. Thanks for the help Chris Angelico! -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
On Sun, Sep 21, 2014 at 11:33 AM, Nicholas Cannon nicholascann...@gmail.com wrote: Yeah this is exactly what I was looking for I know the comments are horrible and I had no idea about the camelCase stuff. Should I use ''' Use this commenting on my functions or not. I think they are called docStrings or something ''' Yes, they're called docstrings (without the capital S - again, Python doesn't tend to work that way). You can find info and advice all over the web about how to write good, useful docstrings. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Love to get some feedback on my first python app!!!
I have just committed a new main.py file on github. I added alot more comments and slimmed down the getinfo() function. -- https://mail.python.org/mailman/listinfo/python-list