Python Forum
Coding style questions -- variables
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding style questions -- variables
#11
(Apr-23-2017, 11:13 PM)wavic Wrote:
(Apr-23-2017, 11:09 PM)volcano63 Wrote: Speaking of continuity - I think you meant consistency ?!
Don't know. The English is not my native language. :)
Just follow as close as you can PEP 8 :D

Mine neither  Hand. Is yours Spanish - as you imply? I would vouch for Russian  Think

And I was known to boldly go against pylintNaughty - especially the part that forbids using mutable as default value (caching, you know).
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply
#12
(Apr-23-2017, 02:51 AM)Luke_Drillbrain Wrote: I could stick with Hungarian if there's enough of an advantage to doing so.  On the other hand, if it would be an advantage to working with other GNU freeware authors, I could junk it.  The code, of course, runs regardless of how you name your variables. 

I don't see the value of declaring everything at the top of a function, nor do I see value in hungarian notation.  But I DO see value in functions that are very short, 15 lines or less, with a fairly hard maximum at roughly however big your editor is, so you can see all of the function all at once. 

The best place to find out what recommended conventions are, is PEP8: https://www.python.org/dev/peps/pep-0008/

But as for open source projects, the best thing you can do is learn that different people like code that looks however they like looking at it.  Whichever project you find interesting might have a different convention than other things, and it's more important for you to stick with whatever that project is already doing.
Reply
#13
(Apr-23-2017, 11:19 PM)volcano63 Wrote:
(Apr-23-2017, 11:13 PM)wavic Wrote: Don't know. The English is not my native language. :)
Just follow as close as you can PEP 8 :D

Mine neither  Hand. Is yours Spanish - as you imply? I would vouch for Russian  Think

And I was known to boldly go against pylintNaughty - especially the part that forbids using mutable as default value (caching, you know).

If you guys are non-native English speakers, you're both doing great.  I can understand you perfectly.  As I get more skilled in Python, I'm going to be looking for ways to add support for multiple languages to the utilities that I write.  In addition to English (my native language), I speak German and French.  Those are two languages I certainly want to support in my applications, but I would also like to support languages I don't speak, especially Spanish, simply because so many people speak it.  Therefore, I'll be looking for ways to code that make supporting multiple languages efficient.  Thanks for learning English.  

(Apr-29-2017, 05:35 PM)nilamo Wrote:
(Apr-23-2017, 02:51 AM)Luke_Drillbrain Wrote: I could stick with Hungarian if there's enough of an advantage to doing so.  On the other hand, if it would be an advantage to working with other GNU freeware authors, I could junk it.  The code, of course, runs regardless of how you name your variables. 

I don't see the value of declaring everything at the top of a function, nor do I see value in hungarian notation.  But I DO see value in functions that are very short, 15 lines or less, with a fairly hard maximum at roughly however big your editor is, so you can see all of the function all at once. 

The best place to find out what recommended conventions are, is PEP8: https://www.python.org/dev/peps/pep-0008/

But as for open source projects, the best thing you can do is learn that different people like code that looks however they like looking at it.  Whichever project you find interesting might have a different convention than other things, and it's more important for you to stick with whatever that project is already doing.

I did find some value in Hungarian notation for keeping track of what data type and scope my variables were, but I don't think it's so essential that I couldn't live without it.  Your advice about coding as much as possible in the style of the original GNU freeware author seems reasonable to me.  If I can create a feature that improves a piece of software, I would hope that the original author would adopt my code so that all can benefit. 

In any event, this is a great forum.  I really appreciate everyone's helpful input.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Style and Naming Variables rsherry8 3 2,219 Jun-07-2021, 09:30 PM
Last Post: deanhystad
  Discord bot that asks questions and based on response answers or asks more questions absinthium 1 40,147 Nov-25-2017, 06:21 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020