Python-OO-development: lessions and classes: how to name the arguments?
Results 1 to 1 of 1

Thread: Python-OO-development: lessions and classes: how to name the arguments?

  1. #1
    Member
    Join Date
    Sep 2010
    Posts
    40

    Python-OO-development: lessions and classes: how to name the arguments?

    hello dear PHP-Freaks,


    well this seems to be a bit out of topic - but i want to dive into python so i have some beginner questions:

    in oo-development - lession classes and instances i have learned


    in this video: at in 6:58 ff the developer says:


    https://www.youtube.com/watch?v=ZDa-...hwlXsIBIdSeYtc

    the author says:
    now these donīt need to be the same as our arguments, so for example i could make this
    self dot fname equals first, but usually i like to keep these similar if possible.
    so i am going to go ahad and set that back to self dot first equals first, okay? . end of citation.
    well i wonder if it would be possible - to use other arguments than declarded

    Code:
    class Employee:
    
        def __init__(self, first, last, pay):
            self.first = first
            self.last = last
            self.email = first + '.' + last + '@email.com'
            self.pay = pay
    
        def fullname(self):
            return '{} {}'.format(self.first, self.last)
    
            
    emp_1.first = `Corey`
    emp_1.last  = `Schafer`
    emp_1.email  = `corey.schafer@company.com `
    
    
    so te question is. Can we really go and write like so:
    
    emp_1.fname = `Corey`
    emp_1.lname = `Schafer`
    emp_1.email  = `corey.schafer@company.com `
    but isn t this a lack of consistency?


    love to hear from you.

    greetings
    dilbert 2010 :: overwhelming wordpress-toolkits http://wpgear.org/

  2. #2
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    14,909
    I suspect they're talking about the argument list names not having to match the object variable names you store them under, e.g. it could be:
    Code:
    class Employee:
    
        def __init__(self, first, last, pay):
            self.first_name = first  # <-----
            self.last_name = last    # <-----
            self.email = first + '.' + last + '@email.com'
            self.pay = pay
    
        def fullname(self):
            return '{} {}'.format(self.first_name, self.last_name)
    But their recommendation is to keep them the same to enhance readability (and thus maintainability).
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •