From abriggs at westnet.com.au Tue Oct 18 12:58:08 2005 From: abriggs at westnet.com.au (Anthony Briggs) Date: Tue, 18 Oct 2005 20:58:08 +1000 Subject: [melbourne-pug] Thursday's Meeting Message-ID: <4354D540.4060607@westnet.com.au> Hi All, A bit late I know - sorry. I've been in the middle of trying to release at work, and I lost track of what week it was :\ Anyway, the topic for Thursday will be "Python coding style". I'm trying to avoid the standard "stand up and talk at people" format, so it's more of a series of "how the hell do you make this Python code look good?" snippets :) If you want to bring (or forward) snippets that you consider either particularly good or particularly bad style (I guess in between is ok too), you can see how other people would deal with your code. Try and keep it reasonably short though - 20 lines or so, or a single class. Again - sorry - it doesn't give you a lot of time to prepare. If you can't think of anything, how about the most recent piece of code that you've written? Thanks, Anthony From tennessee at tennessee.id.au Tue Oct 18 13:49:48 2005 From: tennessee at tennessee.id.au (Tennessee Leeuwenburg) Date: Tue, 18 Oct 2005 21:49:48 +1000 Subject: [melbourne-pug] Thursday's Meeting In-Reply-To: <4354D540.4060607@westnet.com.au> References: <4354D540.4060607@westnet.com.au> Message-ID: <4354E15C.7000202@tennessee.id.au> Sounds great. I'll bring some code. Cheers, -T Anthony Briggs wrote: >Hi All, > >A bit late I know - sorry. I've been in the middle of trying to release >at work, and I lost track of what week it was :\ > >Anyway, the topic for Thursday will be "Python coding style". I'm trying >to avoid the standard "stand up and talk at people" format, so it's more >of a series of "how the hell do you make this Python code look good?" >snippets :) If you want to bring (or forward) snippets that you consider >either particularly good or particularly bad style (I guess in between >is ok too), you can see how other people would deal with your code. Try >and keep it reasonably short though - 20 lines or so, or a single class. > >Again - sorry - it doesn't give you a lot of time to prepare. If you >can't think of anything, how about the most recent piece of code that >you've written? > >Thanks, > >Anthony >_______________________________________________ >melbourne-pug mailing list >melbourne-pug at python.org >http://mail.python.org/mailman/listinfo/melbourne-pug > > From miked at dewhirst.com.au Wed Oct 19 00:14:12 2005 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Wed, 19 Oct 2005 08:14:12 +1000 Subject: [melbourne-pug] Thursday's Meeting In-Reply-To: <4354D540.4060607@westnet.com.au> References: <4354D540.4060607@westnet.com.au> Message-ID: <435573B4.1020300@dewhirst.com.au> Anthony Briggs wrote: > Hi All, > Anyway, the topic for Thursday will be "Python coding style". I think the ... http://www.python.org/peps/pep-0008.html ... style guide seems to be a reasonable way forward and I would be more interested in learning where you think it may be improved on rather than covering what is already there. I'm especially interested in learning about module layout and project layout within directories and spanning directories. Maybe "coding style" can be stretched to cover that and __init__.py which is still a mystery for me. See you there What time again? Mike From stuart at stuartbishop.net Wed Oct 19 01:16:22 2005 From: stuart at stuartbishop.net (Stuart Bishop) Date: Wed, 19 Oct 2005 06:16:22 +0700 Subject: [melbourne-pug] Thursday's Meeting In-Reply-To: <435573B4.1020300@dewhirst.com.au> References: <4354D540.4060607@westnet.com.au> <435573B4.1020300@dewhirst.com.au> Message-ID: <43558246.5040302@stuartbishop.net> Mike Dewhirst wrote: > I think the ... > > http://www.python.org/peps/pep-0008.html > > ... style guide seems to be a reasonable way forward and I would be more > interested in learning where you think it may be improved on rather than > covering what is already there. We have about 16 developers all working on the same Python code base, which of course means about 16 subtly different Python coding styles. So we stick slavishly to PEP-8 to keep things consistant and maintainable. It also keeps the noise level down as it is easier to say 'PEP8 says two carriage returns after a class definition' rather than 'IMO, putting extra whitespace here makes the code more readable' and lets reviewers focus on meatier issues. > See you there > > What time again? I'm not in the country so won't be at meetings for at least the next tree months. -- Stuart Bishop http://www.stuartbishop.net/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: OpenPGP digital signature Url : http://mail.python.org/pipermail/melbourne-pug/attachments/20051019/428ec3b1/signature.pgp From abriggs at westnet.com.au Wed Oct 19 13:40:43 2005 From: abriggs at westnet.com.au (Anthony Briggs) Date: Wed, 19 Oct 2005 21:40:43 +1000 Subject: [melbourne-pug] Thursday's Meeting In-Reply-To: <435573B4.1020300@dewhirst.com.au> References: <4354D540.4060607@westnet.com.au> <435573B4.1020300@dewhirst.com.au> Message-ID: <435630BB.20005@westnet.com.au> Mike Dewhirst wrote: > Anthony Briggs wrote: > >>... the topic for Thursday will be "Python coding style". > > I think the ... > > http://www.python.org/peps/pep-0008.html > > ... style guide seems to be a reasonable way forward and I would be more > interested in learning where you think it may be improved on rather than > covering what is already there. Sure. It's a good starting point, particularly as there are a number of things in there that I don't agree with, such as writing "if not someList:..." rather than "if someList == []:". I also tend to prefer a style with more whitespace, etc. A lot of the style guides also tend to say 'what', rather than 'why', and in fairly rigid fashion too, which means that it's harder to know when to break the rules when you need to. > I'm especially interested in learning about module layout and project > layout within directories and spanning directories. Maybe "coding style" > can be stretched to cover that and __init__.py which is still a mystery > for me. We can probably manage to cover something along those lines - the more people that know how to package up python code, the more code we'll get released :) > See you there > > What time again? 6.30: Anthony From djc at object-craft.com.au Thu Oct 20 01:55:57 2005 From: djc at object-craft.com.au (Dave Cole) Date: Thu, 20 Oct 2005 09:55:57 +1000 Subject: [melbourne-pug] Thursday's Meeting In-Reply-To: <435630BB.20005@westnet.com.au> References: <4354D540.4060607@westnet.com.au> <435573B4.1020300@dewhirst.com.au> <435630BB.20005@westnet.com.au> Message-ID: <4356DD0D.4060609@object-craft.com.au> Anthony Briggs wrote: > Mike Dewhirst wrote: > >>Anthony Briggs wrote: >> >> >>>... the topic for Thursday will be "Python coding style". >> >>I think the ... >> >> http://www.python.org/peps/pep-0008.html >> >>... style guide seems to be a reasonable way forward and I would be more >>interested in learning where you think it may be improved on rather than >>covering what is already there. > > > Sure. It's a good starting point, particularly as there are a number of > things in there that I don't agree with, such as writing "if not > someList:..." rather than "if someList == []:". I also tend to prefer a > style with more whitespace, etc. I am not sure if you are arguing for or against "if someList == []:". I suggest that the above code is not good style. It is very fragile if you are testing the value of an argument because it will not detect when someList is (). When a care about the distinction between empty list and None I almost always do either "if len(some_list) == 0:" or "if some_list is None:". When using "if not some_list:" you trap both cases, which is not always what you want. >From a PEP-8 perspective, the variable name is even questionable. The mixedCase style is only condoned when you are maintaining existing code that already uses that convention. If you are writing new code you should be using some_list rather then someList. > A lot of the style guides also tend to say 'what', rather than 'why', > and in fairly rigid fashion too, which means that it's harder to know > when to break the rules when you need to. Reading a book like Code Complete might a be good start for people who want to know why you should do something rather than just be told to do it. While it does not discuss Python coding style, it does explore the reasons behind various code style conventions. >>I'm especially interested in learning about module layout and project >>layout within directories and spanning directories. Maybe "coding style" >>can be stretched to cover that and __init__.py which is still a mystery >>for me. This is something I still find myself getting wrong at times. Especially where you have multiple packages that you wish to share the same nested package namespace. - Dave -- http://www.object-craft.com.au From abriggs at westnet.com.au Thu Oct 20 06:56:13 2005 From: abriggs at westnet.com.au (Anthony Briggs) Date: Thu, 20 Oct 2005 14:56:13 +1000 Subject: [melbourne-pug] I won't be able to make the meeting tonight... (still on, though) Message-ID: <4357236D.3010903@westnet.com.au> Hi Guys, Sorry, but I can't make the meeting tonight. Peter, however, will be there at 6.30 to meet you all. I'm not sure how long he can stay - he's been sick this week, so he'll probably want to go home early, which will mean that he'll have to kick you out into the cold, dark streets of Fitzroy :) But since tonight is a discussion topic rather than a presentation, perhaps a cafe might be a better venue anyway. I'll let you guys discuss it amongst yourselves (either tonight when you get there or on the list now). Just let me know what the final decision is, so that I can get Pete to post it up on the Intrepid door for latecomers. I'll type out my notes for the meeting (mostly in my head at this stage) so that Pete can print them out and get the discussion going. It's a bummer, because I was really looking forward to it, but c'est la vie. Sorry, Anthony -- ------------------------------------------------------ HyPerACtIVe?! HEY, Who ArE yoU cAllInG HYPERaCTive?! abriggs at westnet.com.au ------------------------------------------------------ From abriggs at westnet.com.au Thu Oct 20 05:50:58 2005 From: abriggs at westnet.com.au (Anthony Briggs) Date: Thu, 20 Oct 2005 13:50:58 +1000 Subject: [melbourne-pug] Thursday's Meeting In-Reply-To: <4356DD0D.4060609@object-craft.com.au> References: <4354D540.4060607@westnet.com.au> <435573B4.1020300@dewhirst.com.au> <435630BB.20005@westnet.com.au> <4356DD0D.4060609@object-craft.com.au> Message-ID: <43571422.60603@westnet.com.au> Dave Cole wrote: > Anthony Briggs wrote: > >>Mike Dewhirst wrote: >>> >>>I think the ... >>> >>> http://www.python.org/peps/pep-0008.html >>> >>>... style guide seems to be a reasonable way forward and I would be more >>>interested in learning where you think it may be improved on rather than >>>covering what is already there. >> >>Sure. It's a good starting point, particularly as there are a number of >>things in there that I don't agree with, such as writing "if not >>someList:..." rather than "if someList == []:". I also tend to prefer a >>style with more whitespace, etc. > > I am not sure if you are arguing for or against "if someList == []:". In general, I'd argue for it, since it's more explicit. > I suggest that the above code is not good style. It is very fragile if > you are testing the value of an argument because it will not detect when > someList is (). But it'll also 'fire' when someList is None, "", 0, etc. > When a care about the distinction between empty list and None I almost > always do either "if len(some_list) == 0:" or "if some_list is None:". > When using "if not some_list:" you trap both cases, which is not always > what you want. Yep. In the case where you don't know what you're testing, you might be able to save some logic by just testing the variable. In a list mangling function though, I'd use the explict test - you'll catch broken programs much more quickly. Just a bit of background: I've had a few nasty debugging sessions over the past little where the culprit has turned out to be a function dropping out of the bottom and returning None (not my code, btw) instead of an integer or a list. With an implicit test, it's suprising how far you can get from that initial error before everything crashes :) Explicit testing catches those sorts of errors far faster. >>From a PEP-8 perspective, the variable name is even questionable. The > mixedCase style is only condoned when you are maintaining existing code > that already uses that convention. If you are writing new code you > should be using some_list rather then someList. Yeah, here we get into personal style issues, and risk starting a flame war :) Personally, I prefer someList to some_list. It's shorter, particularly when you start adding function arguments into the mix, but the main reason is that I find: someMethodName = aParticularFunction( longishArgument = ..., longerArgument = ..., longestArgumentOfAll = ... ) more readable than some_method_name = a_particular_function( longish_argument = ..., longer_argument = ..., longest_argument_of_all = ... ) perhaps because the caps jump up and make it more legible, whereas the underscores blend in a bit. It also depends on what you're used to - someone who reads code with underscores all day is going to find the latter more readable. Of course, camelCase has it's downsides - I've had quite a few errors where I've mistyped a capital and regretted it, but readability counts more than typability. IMHO the solution is to make naming case insensitive, but that's just me :) This is partly why I picked this particular topic, (other than that it's good for getting a discussion going :) ) -- I actually disagree with a lot of what PEP-8 has to say. It's not suprising I suppose, considering that it's essentially distilled from Guido's personal style, but I'm interested to explore some of the rationale behind it. >>A lot of the style guides also tend to say 'what', rather than 'why', >>and in fairly rigid fashion too, which means that it's harder to know >>when to break the rules when you need to. > > Reading a book like Code Complete might a be good start for people who > want to know why you should do something rather than just be told to do > it. While it does not discuss Python coding style, it does explore the > reasons behind various code style conventions. I'll have another look at it and see what it's got to say about camel case :) From memory though, it's largely geared towards the more static languages (C/C++ and Java), so there are some aspects (eg. being passed "", None or a list) that wouldn't necessarily come up as often. Anthony -- ------------------------------------------------------ HyPerACtIVe?! HEY, Who ArE yoU cAllInG HYPERaCTive?! abriggs at westnet.com.au ------------------------------------------------------ From tennessee at tennessee.id.au Thu Oct 20 07:05:59 2005 From: tennessee at tennessee.id.au (Tennessee Leeuwenburg) Date: Thu, 20 Oct 2005 15:05:59 +1000 Subject: [melbourne-pug] I won't be able to make the meeting tonight... (still on, though) In-Reply-To: <4357236D.3010903@westnet.com.au> References: <4357236D.3010903@westnet.com.au> Message-ID: <435725B7.6010105@tennessee.id.au> Hmmm, sounds like the numbers are thinning out. Who can make it, exactly? I can make it, but I don't want to be the only schmo standing around. Let's see if we can establish a group of 5 or 6 by COB? If we see a show of hands, we might be encourage a few more "maybes" to show. Cheers, -T >Hi Guys, > >Sorry, but I can't make the meeting tonight. Peter, however, will be >there at 6.30 to meet you all. I'm not sure how long he can stay - he's >been sick this week, so he'll probably want to go home early, which will >mean that he'll have to kick you out into the cold, dark streets of >Fitzroy :) > >But since tonight is a discussion topic rather than a presentation, >perhaps a cafe might be a better venue anyway. I'll let you guys discuss >it amongst yourselves (either tonight when you get there or on the list >now). Just let me know what the final decision is, so that I can get >Pete to post it up on the Intrepid door for latecomers. > >I'll type out my notes for the meeting (mostly in my head at this stage) >so that Pete can print them out and get the discussion going. It's a >bummer, because I was really looking forward to it, but c'est la vie. > >Sorry, > >Anthony > > > From abriggs at westnet.com.au Thu Oct 20 08:37:00 2005 From: abriggs at westnet.com.au (Anthony Briggs) Date: Thu, 20 Oct 2005 16:37:00 +1000 Subject: [melbourne-pug] I won't be able to make the meeting tonight... (still on, though) In-Reply-To: <435725B7.6010105@tennessee.id.au> References: <4357236D.3010903@westnet.com.au> <435725B7.6010105@tennessee.id.au> Message-ID: <43573B0C.8030504@westnet.com.au> Tennessee Leeuwenburg wrote: > Hmmm, sounds like the numbers are thinning out. Who can make it, exactly? > > I can make it, but I don't want to be the only schmo standing around. > Let's see if we can establish a group of 5 or 6 by COB? If we see a show > of hands, we might be encourage a few more "maybes" to show. I'd say that at this late stage, you'll probably get people turning up who won't have read their email. So a non-show of hands won't necessarily mean that nobody will be there. Anthony -- ------------------------------------------------------ HyPerACtIVe?! HEY, Who ArE yoU cAllInG HYPERaCTive?! abriggs at westnet.com.au ------------------------------------------------------ From cropleyb at yahoo.com.au Thu Oct 20 08:39:13 2005 From: cropleyb at yahoo.com.au (Bruce Cropley) Date: Thu, 20 Oct 2005 16:39:13 +1000 (EST) Subject: [melbourne-pug] I won't be able to make the meeting tonight... (still on, though) Message-ID: <20051020063913.76366.qmail@web60213.mail.yahoo.com> I'll be there if anyone else is; I'm very interested in discussing good and bad python style. Bruce ____________________________________________________ Do you Yahoo!? Find a local business fast with Yahoo! Local Search http://au.local.yahoo.com From tennessee at tennessee.id.au Thu Oct 20 09:06:05 2005 From: tennessee at tennessee.id.au (Tennessee Leeuwenburg) Date: Thu, 20 Oct 2005 17:06:05 +1000 Subject: [melbourne-pug] I won't be able to make the meeting tonight... (still on, though) In-Reply-To: <43573B0C.8030504@westnet.com.au> References: <4357236D.3010903@westnet.com.au> <435725B7.6010105@tennessee.id.au> <43573B0C.8030504@westnet.com.au> Message-ID: <435741DD.3080508@tennessee.id.au> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Just been called away myself. Apparently, my roleplaying group is meeting tonight after all. Thought I'd better inform people. Sorry!!! Cheers, - -T -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFDV0HdFp/Peux6TnIRArhBAJ0ZY+/TDxIiCBS73yDxX+8hJi6MQQCghAaB bEuH6rV0FFwiiw/vdlfYoV4= =X3tI -----END PGP SIGNATURE----- From peter at intrepidtravel.com Thu Oct 20 09:02:59 2005 From: peter at intrepidtravel.com (Peter Ogilvy) Date: Thu, 20 Oct 2005 17:02:59 +1000 Subject: [melbourne-pug] I won't be able to make the meeting tonight... (still on, though) In-Reply-To: <20051020063913.76366.qmail@web60213.mail.yahoo.com> References: <20051020063913.76366.qmail@web60213.mail.yahoo.com> Message-ID: <200510201702.59758.peter@intrepidtravel.com> I'll be here to start the meeting as Anthony said. Peter Ogilvy Web Developer Intrepid Travel Ph +61 (0)3 9473 2661 Real life experiences Travel for people who want to leave their world behind From djc at object-craft.com.au Sun Oct 23 05:02:08 2005 From: djc at object-craft.com.au (Dave Cole) Date: Sun, 23 Oct 2005 13:02:08 +1000 Subject: [melbourne-pug] Thursday's Meeting In-Reply-To: <43571422.60603@westnet.com.au> References: <4354D540.4060607@westnet.com.au> <435573B4.1020300@dewhirst.com.au> <435630BB.20005@westnet.com.au> <4356DD0D.4060609@object-craft.com.au> <43571422.60603@westnet.com.au> Message-ID: <435AFD30.5010105@object-craft.com.au> Anthony Briggs wrote: > Dave Cole wrote: >>I am not sure if you are arguing for or against "if someList == []:". > > In general, I'd argue for it, since it's more explicit. > >>I suggest that the above code is not good style. It is very fragile if >>you are testing the value of an argument because it will not detect when >>someList is (). > > But it'll also 'fire' when someList is None, "", 0, etc. I think you missed my point. Consider the following: def func(some_list): if some_list == []: print 'the list was empty' else: print 'there were things in the list' func(()) If the function is going to deal with something that implements the sequence protocol, why go out of your way to prevent other types that implement the sequence protocol. def func(some_list): if len(some_list) == 0: print 'the list was empty' else: print 'there were things in the list' So one of the following objects could be successfully passed to the function. class List: def __init__(self): ... def __len__(self): ... def __getitem(self, i): ... >>When a care about the distinction between empty list and None I almost >>always do either "if len(some_list) == 0:" or "if some_list is None:". >>When using "if not some_list:" you trap both cases, which is not always >>what you want. > > Yep. In the case where you don't know what you're testing, you might be > able to save some logic by just testing the variable. In a list mangling > function though, I'd use the explict test - you'll catch broken programs > much more quickly. I disagree with that. I think it is a lot better to test arguments by the protocols implemented rather than the type. > Just a bit of background: I've had a few nasty debugging sessions over > the past little where the culprit has turned out to be a function > dropping out of the bottom and returning None (not my code, btw) instead > of an integer or a list. With an implicit test, it's suprising how far > you can get from that initial error before everything crashes :) > Explicit testing catches those sorts of errors far faster. pychecker is your friend. >>>From a PEP-8 perspective, the variable name is even questionable. The >>mixedCase style is only condoned when you are maintaining existing code >>that already uses that convention. If you are writing new code you >>should be using some_list rather then someList. > > > Yeah, here we get into personal style issues, and risk starting a flame > war :) To paraphrase a friend. PEP-8 explains how a native "speaker" of Python writes code. If you want to write like a native and not a foreigner then you should follow PEP-8. Writing with an accent will mean that your code looks foreign to natives and will be unpleasant to look at. Each community has its own conventions and accent on the language. By developing your own accent you are (to a degree) isolating yourself from the larger community. It is hard to see how that helps you. If you want to write Java (for example) in Python, then maybe you should be developing in Java. > perhaps because the caps jump up and make it more legible, whereas the > underscores blend in a bit. It also depends on what you're used to - > someone who reads code with underscores all day is going to find the > latter more readable. Exactly my point. The wider community follows PEP-8. Why make it hard for new comers to your project by enforcing foreign style. > This is partly why I picked this particular topic, (other than that it's > good for getting a discussion going :) ) -- I actually disagree with a > lot of what PEP-8 has to say. It's not suprising I suppose, considering > that it's essentially distilled from Guido's personal style, but I'm > interested to explore some of the rationale behind it. I am not sure that there is any rationale to it. It just represents the way a native Python programmer does things. Guido is the founder of the language, so if he says "this is Python style" then that is the correct style. >>>A lot of the style guides also tend to say 'what', rather than 'why', >>>and in fairly rigid fashion too, which means that it's harder to know >>>when to break the rules when you need to. >> >>Reading a book like Code Complete might a be good start for people who >>want to know why you should do something rather than just be told to do >>it. While it does not discuss Python coding style, it does explore the >>reasons behind various code style conventions. > > I'll have another look at it and see what it's got to say about camel > case :) From memory though, it's largely geared towards the more static > languages (C/C++ and Java), so there are some aspects (eg. being passed > "", None or a list) that wouldn't necessarily come up as often. I did not mean that you should look to Code Complete for an explanation of Python style. I meant that if you want to see a discussion of "why" for many programming issues then Code Complete is a good read. - Dave -- http://www.object-craft.com.au From richardjones at optushome.com.au Mon Oct 24 03:56:44 2005 From: richardjones at optushome.com.au (Richard Jones) Date: Mon, 24 Oct 2005 11:56:44 +1000 Subject: [melbourne-pug] OSDC 2005 Registration Message-ID: <200510241156.44865.richardjones@optushome.com.au> G'day folks, This is a quick note to let you know that registrations for Australia's second Open Source Developers' Conference are now open. Last year's conference was a huge hit with 60 high quality talks running in three streams over three days. If you weren't able to join us last year make sure you don't miss out this year! If you register before EARLY BIRD DATE you will receive a conference t-shirt and financial discount. You can register at http://www.osdc.com.au/registration/index.html OSDC is a grass roots-style conference designed by developers for developers, covering open source languages, tools, libraries, operating systems, licences and business models. We're booking 3 lecture rooms each day for the 3 days to hold a new set 60 different talks. Talks topics range from the safety Perl's Safe.pm, to rapid game development in Python, to using PHP for unorthodox applications, to utilizing Java's Groovy in your next application. We also have talks on conference skills, database integration, digital forensics, Gumstix and Nagios. You can find the full list of speakers and talk titles at http://osdc2005.cgpublisher.com/session_descriptions.html Because there are so many good talks, you can be certain that there will be something that interests you in every talk session. Each day will start with a keynote by our excellent keynote speakers. These include Damian Conway, Jonathan Oxer, Richard Farnsworth (from the Australian Synchrotron) and Anthony Baxter. The rest of the day will be filled with up to 5 hours of talks and plentiful food breaks. Our catering choices should result in you being extraordinarily well fed throughout the days of the conference. There will also be several BOFs (yet to be organised), lots of opportunities to socialise, a semi-formal dinner, a partners' programme and other usual conference stuff. If you have any other questions about what is happening, please don't hesitate to ask: osdc-help at osdc.com.au -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/melbourne-pug/attachments/20051024/ef173006/attachment.pgp From abriggs at westnet.com.au Thu Oct 27 14:46:44 2005 From: abriggs at westnet.com.au (Anthony Briggs) Date: Thu, 27 Oct 2005 22:46:44 +1000 Subject: [melbourne-pug] Thursday's Meeting In-Reply-To: <435AFD30.5010105@object-craft.com.au> References: <4354D540.4060607@westnet.com.au> <435573B4.1020300@dewhirst.com.au> <435630BB.20005@westnet.com.au> <4356DD0D.4060609@object-craft.com.au> <43571422.60603@westnet.com.au> <435AFD30.5010105@object-craft.com.au> Message-ID: <4360CC34.2070802@westnet.com.au> Dave Cole wrote: > > I think you missed my point. Consider the following: > > def func(some_list): > if some_list == []: > print 'the list was empty' > else: > print 'there were things in the list' > > func(()) > > If the function is going to deal with something that implements the > sequence protocol, why go out of your way to prevent other types that > implement the sequence protocol. > > def func(some_list): > if len(some_list) == 0: The "len(some_list)" version is even better than mine, but the "if not some_list:" though, is distinctly dodgy, particularly if you're working with ex-C/C++/Java programmers who like to return None or 0 on error. >>Just a bit of background: I've had a few nasty debugging sessions over >>the past little where the culprit has turned out to be a function >>dropping out of the bottom and returning None > > pychecker is your friend. Yep, but it won't catch the other cases where someone's explicitly returned None :\ > To paraphrase a friend. PEP-8 explains how a native "speaker" of Python > writes code. If you want to write like a native and not a foreigner > then you should follow PEP-8. Writing with an accent will mean that > your code looks foreign to natives and will be unpleasant to look at. > > Each community has its own conventions and accent on the language. By > developing your own accent you are (to a degree) isolating yourself from > the larger community. It is hard to see how that helps you. Well, let's continue with the list example. PEP-8 says: - For sequences, (strings, lists, tuples), use the fact that empty sequences are false, so "if not seq" or "if seq" is preferable to "if len(seq)" or "if not len(seq)". which is not what I do, and is not what you do. It helps because it's a lot more rigorous than the PEP-8 style, and effectively gives you an assert statement to check that you have a sequence, catching a common error. The point I was trying to make is that sometimes the standard is wrong, either for a specific situation, or in general. >>I actually disagree with a >>lot of what PEP-8 has to say. It's not suprising I suppose, considering >>that it's essentially distilled from Guido's personal style, but I'm >>interested to explore some of the rationale behind it. > > I am not sure that there is any rationale to it. It just represents the > way a native Python programmer does things. Guido is the founder of the > language, so if he says "this is Python style" then that is the correct > style. There should always be a rationale to it, if you think hard enough. Most of PEP-8 is common sense, but there are times when you should break it. PEP-8 even says that explicitly. It's also a better way to discuss code style - if you can talk about why you do things a certain way, that often helps to work around any flamewars. > I did not mean that you should look to Code Complete for an explanation > of Python style. I meant that if you want to see a discussion of "why" > for many programming issues then Code Complete is a good read. Yes, but I found it to be aimed mainly at C/C++/Java code, rather than Python, so there are some parts which are not as relevant, and other parts which aren't covered. Not that it's not a good read, but that it doesn't cover dynamic languages as well, despite having quite a few Python examples. Anthony -- ------------------------------------------------------ HyPerACtIVe?! HEY, Who ArE yoU cAllInG HYPERaCTive?! abriggs at westnet.com.au ------------------------------------------------------