Naming Conventions, Where's the Convention Waldo?

Discussion in 'Python' started by rantingrick, Jul 11, 2010.

  1. rantingrick

    rantingrick Guest

    Another source of asininity seems to be the naming conventions of the
    Python language proper! True/False start with an upper case and i
    applaud this. However str, list, tuple, int, float --need i go
    on...?-- start with lowercase.

    Q: Well what the hell is your problem Rick. Who cares right?

    WRONG, I tell you what my problem is. Now i cannot "wisely" use
    variables like...

    str="this is a string"
    list = [1,2,3]
    def make_random_objs(range=10)
    def show_message(str)
    int = 12

    If we would have adopted proper naming conventions from dios numero
    uno all this nonsense would be rectified! Str, Float, List, Range,
    etc, etc. You think Python 3000 was a hump to climb over just wait for
    Python 4000.

    Just thoughts.
     
    rantingrick, Jul 11, 2010
    #1
    1. Advertising

  2. * rantingrick, on 11.07.2010 09:26:
    >
    > Another source of asininity seems to be the naming conventions of the
    > Python language proper! True/False start with an upper case and i
    > applaud this. However str, list, tuple, int, float --need i go
    > on...?-- start with lowercase.
    >
    > Q: Well what the hell is your problem Rick. Who cares right?
    >
    > WRONG, I tell you what my problem is. Now i cannot "wisely" use
    > variables like...
    >
    > str="this is a string"
    > list = [1,2,3]
    > def make_random_objs(range=10)
    > def show_message(str)
    > int = 12
    >
    > If we would have adopted proper naming conventions from dios numero
    > uno all this nonsense would be rectified! Str, Float, List, Range,
    > etc, etc. You think Python 3000 was a hump to climb over just wait for
    > Python 4000.
    >
    > Just thoughts.


    Just do

    Str = str
    List = list
    Float = float

    and so on in module "myBasicTypes", and import that.

    :)

    Cheers & hth.,

    - Alf

    --
    blog at <url: http://alfps.wordpress.com>
     
    Alf P. Steinbach /Usenet, Jul 11, 2010
    #2
    1. Advertising

  3. rantingrick <> wrote:

    >Another source of asininity seems to be the naming conventions of the
    >Python language proper! True/False start with an upper case and i
    >applaud this. However str, list, tuple, int, float --need i go
    >on...?-- start with lowercase.
    >
    >Q: Well what the hell is your problem Rick. Who cares right?
    >
    >WRONG, I tell you what my problem is. Now i cannot "wisely" use
    >variables like...
    >
    >str="this is a string"
    >list = [1,2,3]
    >def make_random_objs(range=10)
    >def show_message(str)
    >int = 12


    Someone who wants to write readable and maintainable code would
    (practically) never want to use variables named in this way. Why?
    Because these names don't tell anything about the purpose of the
    variables.
    So, it is not a disadvantage that the functions you listed above are
    named in this way. In the contrary, it is an advantage, as it keeps
    newcomers from using stupid variable names.


    >If we would have adopted proper naming conventions from dios numero
    >uno all this nonsense would be rectified! Str, Float, List, Range,
    >etc, etc. You think Python 3000 was a hump to climb over just wait for
    >Python 4000.


    Additionally to what I mention above, there is PEP 0008. Read it, you
    can learn from it. What you listed above, are functions, and their names
    comply completely with PEP 0008.



    Regards,

    Günther




    PS: Even though I suspect that you are simply an agitator rsp. troll
    (based on what you posted in this group so far), and normally I refuse
    to feed trolls, I make an exception in this case, so newcomers ar not
    mislead by your half-baked ideas.
     
    Günther Dietrich, Jul 11, 2010
    #3
  4. rantingrick

    rantingrick Guest

    On Jul 11, 3:03 am, "Günther Dietrich" <>
    wrote:

    > So, it is not a disadvantage that the functions you listed above are
    > named in this way. In the contrary, it is an advantage, as it keeps
    > newcomers from using stupid variable names.


    "int" for an Integer is stupid?
    "list" for a List is stupid?
    "str" for a String is stupid?

    What am i missing?
     
    rantingrick, Jul 11, 2010
    #4
  5. On 07/11/2010 10:30 AM, rantingrick wrote:
    > On Jul 11, 3:03 am, "Günther Dietrich" <>
    > wrote:
    >
    >> So, it is not a disadvantage that the functions you listed above are
    >> named in this way. In the contrary, it is an advantage, as it keeps
    >> newcomers from using stupid variable names.

    >
    > "int" for an Integer is stupid?
    > "list" for a List is stupid?
    > "str" for a String is stupid?
    >
    > What am i missing?


    You are missing (from PEP 8):

    --- 8< --- 8< ---
    Class Names

    Almost without exception, class names use the CapWords convention.
    Classes for internal use have a leading underscore in addition.

    --- 8< --- 8< ---

    You may want to think of list, int, str, object, ... as classes that
    don't follow this advice with their class name.

    But besides that, shouldn't a variable name reflect it's purpose instead
    of it's type? E.g.

    name = 'rantingrick'
    counter = 1
    ....

    as compared to

    str = 'rantingrick'
    int = 1?

    Regards


    Andre
     
    Andre Alexander Bell, Jul 11, 2010
    #5
  6. rantingrick

    News123 Guest

    Andre Alexander Bell wrote:
    > On 07/11/2010 10:30 AM, rantingrick wrote:


    >>> So, it is not a disadvantage that the functions you listed above are
    >>> named in this way. In the contrary, it is an advantage, as it keeps
    >>> newcomers from using stupid variable names.

    >> "int" for an Integer is stupid?
    >> "list" for a List is stupid?
    >> "str" for a String is stupid?
    >>
    >> What am i missing?

    >
    > You are missing (from PEP 8):
    >
    > --- 8< --- 8< ---
    > Class Names
    >
    > Almost without exception, class names use the CapWords convention.
    > Classes for internal use have a leading underscore in addition.
    >
    > --- 8< --- 8< ---
    >
    > You may want to think of list, int, str, object, ... as classes that
    > don't follow this advice with their class name.
    >
    > But besides that, shouldn't a variable name reflect it's purpose instead
    > of it's type? E.g.


    hm, well sometimes I do write generic functions, that do something with
    a list or a string or an int.

    However a simple way around this is to use following naming style.

    to replace
    def process_list(list):
    dostuff_with(list)

    with
    def process_list(alist):
    dostuff_with(alist)

    or with
    def process_list(a_list):
    dostuff_with(a_list)

    I must admit, that I have still problems
    to not use the variables range or id
     
    News123, Jul 11, 2010
    #6
  7. On Sun, 11 Jul 2010 15:46:40 +0200 News123 <> wrote:

    > Andre Alexander Bell wrote:
    > > On 07/11/2010 10:30 AM, rantingrick wrote:

    >
    > >>> So, it is not a disadvantage that the functions you listed above
    > >>> are named in this way. In the contrary, it is an advantage, as it
    > >>> keeps newcomers from using stupid variable names.
    > >> "int" for an Integer is stupid?
    > >> "list" for a List is stupid?
    > >> "str" for a String is stupid?
    > >>
    > >> What am i missing?

    > >
    > > [snip]

    >
    > hm, well sometimes I do write generic functions, that do something
    > with a list or a string or an int.
    >
    > [snip]
    >
    > I must admit, that I have still problems
    > to not use the variables range or id
    >


    There are several approaches:

    - Use range_, id_, and so on. I think this is the proposed convention.
    Slightly ugly, though.
    - Use abbreviations, or misspellings like lst, Set, klass, ... Less
    ugly, but can get weird.
    - Prepend 'a' to a type name: alist, aset, astr. Similar weirdness
    potential as above, but more consistent in terms of style. I
    sometimes take this to the extreme and prepend 'some_'.

    So really, this is a non issue, at least for me.

    Having capitalized boolean values ... that is a bit odd, but as long as
    children are starving in Africa, this isn't very high on my gripe-list.

    /W

    --
    INVALID? DE!
     
    Andreas Waldenburger, Jul 11, 2010
    #7
  8. rantingrick

    News123 Guest

    Andreas Waldenburger wrote:
    >
    > Having capitalized boolean values ... that is a bit odd, but as long as
    > children are starving in Africa, this isn't very high on my gripe-list.
    >

    +1
     
    News123, Jul 11, 2010
    #8
  9. rantingrick

    MRAB Guest

    rantingrick wrote:
    > Another source of asininity seems to be the naming conventions of the
    > Python language proper! True/False start with an upper case and i
    > applaud this. However str, list, tuple, int, float --need i go
    > on...?-- start with lowercase.
    >
    > Q: Well what the hell is your problem Rick. Who cares right?
    >
    > WRONG, I tell you what my problem is. Now i cannot "wisely" use
    > variables like...
    >
    > str="this is a string"
    > list = [1,2,3]
    > def make_random_objs(range=10)
    > def show_message(str)
    > int = 12
    >
    > If we would have adopted proper naming conventions from dios numero
    > uno all this nonsense would be rectified! Str, Float, List, Range,
    > etc, etc. You think Python 3000 was a hump to climb over just wait for
    > Python 4000.
    >
    > Just thoughts.


    If you're so unhappy with Python, why don't you create your own
    language. I suggest the name "Rantthon".
     
    MRAB, Jul 11, 2010
    #9
  10. rantingrick

    rantingrick Guest

    On Jul 11, 12:23 pm, MRAB <> wrote:

    > If you're so unhappy with Python, why don't you create your own
    > language. I suggest the name "Rantthon".


    Ah yes, then i can finally assume my worthy title of the "Ranting
    Dictator For Life"! ;-)
     
    rantingrick, Jul 11, 2010
    #10
  11. On Sun, 11 Jul 2010 01:30:36 -0700, rantingrick wrote:

    > On Jul 11, 3:03 am, "Günther Dietrich" <> wrote:
    >
    >> So, it is not a disadvantage that the functions you listed above are
    >> named in this way. In the contrary, it is an advantage, as it keeps
    >> newcomers from using stupid variable names.

    >
    > "int" for an Integer is stupid?
    > "list" for a List is stupid?
    > "str" for a String is stupid?
    >
    > What am i missing?


    If you're going to use generic names, why type three or four letters when
    one will do?

    i, j, k, m, n, p, q for ints.
    L, a, b, x for lists
    s, t, a, b for strings.

    If you don't want to use generic names, then int, list, str are useless
    because they don't mean anything. You need something like:

    count_of_widgets
    list_of_widgets
    description




    --
    Steven
     
    Steven D'Aprano, Jul 12, 2010
    #11
  12. On Sun, 11 Jul 2010 00:26:36 -0700, rantingrick wrote:

    > Another source of asininity seems to be the naming conventions of the
    > Python language proper! True/False start with an upper case and i
    > applaud this. However str, list, tuple, int, float --need i go on...?--
    > start with lowercase.
    >
    > Q: Well what the hell is your problem Rick. Who cares right?
    >
    > WRONG, I tell you what my problem is. Now i cannot "wisely" use
    > variables like...
    >
    > str="this is a string"
    > list = [1,2,3]
    > def make_random_objs(range=10)
    > def show_message(str)
    > int = 12



    Yes. So what? You can't wisely use variables like:

    True = "rantingrick is an obnoxious loudmouth"
    None = "the problem he is describing"

    Nor can you wisely use variables like:

    len = len("something")
    chr = chr(48)


    [...]
    > Just thoughts.


    But not deep thoughts.



    --
    Steven
     
    Steven D'Aprano, Jul 12, 2010
    #12
  13. On 12/07/2010 01:06, Steven D'Aprano wrote:
    > On Sun, 11 Jul 2010 00:26:36 -0700, rantingrick wrote:
    >
    >> Another source of asininity seems to be the naming conventions of the
    >> Python language proper! True/False start with an upper case and i
    >> applaud this. However str, list, tuple, int, float --need i go on...?--
    >> start with lowercase.
    >>
    >> Q: Well what the hell is your problem Rick. Who cares right?
    >>
    >> WRONG, I tell you what my problem is. Now i cannot "wisely" use
    >> variables like...
    >>
    >> str="this is a string"
    >> list = [1,2,3]
    >> def make_random_objs(range=10)
    >> def show_message(str)
    >> int = 12

    >
    >
    > Yes. So what? You can't wisely use variables like:
    >
    > True = "rantingrick is an obnoxious loudmouth"

    +1 QOTW
    > None = "the problem he is describing"
    >
    > Nor can you wisely use variables like:
    >
    > len = len("something")
    > chr = chr(48)
    >
    >
    > [...]
    >> Just thoughts.

    >
    > But not deep thoughts.
    >

    Well said Steven, or is it Stephen, or Stephan, or Stefen, or what?
    Kindest regards.

    Mark Lawrence.
     
    Mark Lawrence, Jul 12, 2010
    #13
  14. On Mon, 12 Jul 2010 01:31:14 +0100, Mark Lawrence wrote:

    > Well said Steven, or is it Stephen, or Stephan, or Stefen, or what?


    For some reason, when I answer the phone and say "Hello, Steven
    speaking?" I often get called Peter.


    --
    Steven
     
    Steven D'Aprano, Jul 12, 2010
    #14
  15. On Mon, 12 Jul 2010 02:40:07 +0000, Steven D'Aprano wrote:

    > On Mon, 12 Jul 2010 01:31:14 +0100, Mark Lawrence wrote:
    >
    >> Well said Steven, or is it Stephen, or Stephan, or Stefen, or what?

    >
    > For some reason, when I answer the phone and say "Hello, Steven
    > speaking?" I often get called Peter.


    Er, without the question mark.

    --
    Steven
     
    Steven D'Aprano, Jul 12, 2010
    #15
  16. rantingrick

    Terry Reedy Guest

    On 7/11/2010 3:26 AM, rantingrick wrote:
    >
    > Another source of asininity seems to be the naming conventions of the
    > Python language proper! True/False start with an upper case and i
    > applaud this. However str, list, tuple, int, float --need i go
    > on...?-- start with lowercase.


    This is an anomaly, known to all long-time Pythoneers, due the the
    history of Python. Before 2.2 and unification of types and classes as
    new-style classes, those were all type constructor *functions*, not
    class names. The idea of breaking most every serious Python program on
    the planet by upper-casing them has been considered and so far rejected.

    --
    Terry Jan Reedy
     
    Terry Reedy, Jul 12, 2010
    #16
  17. On 12Jul2010 02:43, Steven D'Aprano <> wrote:
    | On Mon, 12 Jul 2010 02:40:07 +0000, Steven D'Aprano wrote:
    | > On Mon, 12 Jul 2010 01:31:14 +0100, Mark Lawrence wrote:
    | >> Well said Steven, or is it Stephen, or Stephan, or Stefen, or what?
    | >
    | > For some reason, when I answer the phone and say "Hello, Steven
    | > speaking?" I often get called Peter.
    |
    | Er, without the question mark.

    Ah, so you get differing results when you use the question mark?
    Phonetic punctuation; Victor Borge would be proud.
    --
    Cameron Simpson <> DoD#743
    http://www.cskk.ezoshosting.com/cs/

    A lot of people don't know the difference between a violin and a viola, so
    I'll tell you. A viola burns longer. - Victor Borge
     
    Cameron Simpson, Jul 12, 2010
    #17
  18. rantingrick wrote:
    > On Jul 11, 3:03 am, "Günther Dietrich" <>
    > wrote:
    >
    >
    >> So, it is not a disadvantage that the functions you listed above are
    >> named in this way. In the contrary, it is an advantage, as it keeps
    >> newcomers from using stupid variable names.
    >>

    >
    > "int" for an Integer is stupid?
    > "list" for a List is stupid?
    > "str" for a String is stupid?
    >
    > What am i missing?
    >

    def func154():
    int32 = 24
    list18 = [int32, 14]
    str14 = ""
    for int89 in list18:
    if int89 == int32 or int89 == 88:
    str14 = "I am missing everything"
    if str14:
    print str14

    >>> func154()
    >>> "I am missing everything"



    JM
     
    Jean-Michel Pichavant, Jul 12, 2010
    #18
  19. rantingrick

    Neil Cerutti Guest

    On 2010-07-12, Steven D'Aprano <> wrote:
    > On Sun, 11 Jul 2010 01:30:36 -0700, rantingrick wrote:
    >
    >> On Jul 11, 3:03??am, "G??nther Dietrich" <> wrote:
    >>
    >>> So, it is not a disadvantage that the functions you listed above are
    >>> named in this way. In the contrary, it is an advantage, as it keeps
    >>> newcomers from using stupid variable names.

    >>
    >> "int" for an Integer is stupid?
    >> "list" for a List is stupid?
    >> "str" for a String is stupid?
    >>
    >> What am i missing?

    >
    > If you're going to use generic names, why type three or four letters when
    > one will do?
    >
    > i, j, k, m, n, p, q for ints.
    > L, a, b, x for lists
    > s, t, a, b for strings.
    >
    > If you don't want to use generic names, then int, list, str are useless
    > because they don't mean anything. You need something like:
    >
    > count_of_widgets
    > list_of_widgets
    > description


    def map(function, list):
    # etc.

    It's a slight annoyance, nothing more.

    In the data I deal with, I get annoyed at needing to write
    student_id instead of id, but it's not a huge issue. The big
    consolation is that Python really doesn't care if I happen to
    shadow a builtin name that I've never heard of. I forget, and use
    id as a variable all the time, and nothing bad happens to me,
    because I don't need the builtin function.

    To see a really odd example of a similar name clash, create a tab
    separated values file with a header line starting with ID (I get
    lots of them in my work), and then open it with Excel (I don't
    know which version has the most bizarre error message).

    --
    Neil Cerutti
     
    Neil Cerutti, Jul 13, 2010
    #19
  20. rantingrick

    Aahz Guest

    In article <4c3a8087$0$28662$>,
    Steven D'Aprano <> wrote:
    >
    >For some reason, when I answer the phone and say "Hello, Steven
    >speaking?" I often get called Peter.


    That's the Peter Principle in action.
    --
    Aahz () <*> http://www.pythoncraft.com/

    "....Normal is what cuts off your sixth finger and your tail..." --Siobhan
     
    Aahz, Jul 16, 2010
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =B=
    Replies:
    4
    Views:
    9,349
  2. Floppy Jellopy

    Namespaces and Naming conventions

    Floppy Jellopy, Jul 20, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    543
    Kevin Spencer
    Jul 21, 2005
  3. Josh  Wolf
    Replies:
    2
    Views:
    3,298
    Martin Robins
    Mar 31, 2006
  4. Roy  Assaly
    Replies:
    1
    Views:
    482
    Roy Assaly
    Apr 10, 2006
  5. Roedy Green

    naming conventions

    Roedy Green, Jun 29, 2004, in forum: Java
    Replies:
    4
    Views:
    497
    Christophe Vanfleteren
    Jun 30, 2004
Loading...

Share This Page