Skip to main content
added 5 characters in body
Source Link
alecxe
  • 17.5k
  • 8
  • 52
  • 93

I think there is this code organization issue - you have a class named Customer, but it, aside from the .name attribute, consists of credit-card related logic only.

I would also pass the obtained attributes to the class constructor instead of asking for them inside it:

def __init__(self, name, post_code, card_date, card_code):
    self.name = name
    self.post_code = post_code
    self.card_date = card_date
    self.card_code = card_code

It is a little bit cleaner to do this way since now our class is more generic, it is agnostic of where the attributes are coming from.

Some other code-style related notes:

  • consistent naming: rename postcode to post_code

  • revise the quality and necessity of comments: there is probably not much sense in having a comment # Constructor

  • you can simplify the way you return a boolean result from your methods. For instance, you can replace:

     if datetime.date.today() < card:
         return True
     else:
         return False
    

with:

    return datetime.date.today() < card

And, it's worth mentioning that, generally speaking, if you doing this for production, you should not be reinventing the wheel and switch to a more mature, well-used and tested package like pycard package.

I think there is this code organization issue - you have a class named Customer, but it, aside from the .name attribute, consists of credit-card related logic only.

I would also pass the obtained attributes to the class constructor instead of asking for them inside it:

def __init__(self, name, post_code, card_date, card_code):
    self.name = name
    self.post_code = post_code
    self.card_date = card_date
    self.card_code = card_code

It is a little bit cleaner to do this way since now our class is more generic, it is agnostic of where the attributes are coming from.

Some other code-style related notes:

  • consistent naming: rename postcode to post_code

  • revise the quality and necessity of comments: there is probably not much sense in having a comment # Constructor

  • you can simplify the way you return a boolean result from your methods. For instance, you can replace:

     if datetime.date.today() < card:
         return True
     else:
         return False
    

with:

    return datetime.date.today() < card

And, it's worth mentioning that, generally speaking, if you doing this for production, you should not be reinventing the wheel and switch to a more mature, well-used and tested pycard package.

I think there is this code organization issue - you have a class named Customer, but it, aside from the .name attribute, consists of credit-card related logic only.

I would also pass the obtained attributes to the class constructor instead of asking for them inside it:

def __init__(self, name, post_code, card_date, card_code):
    self.name = name
    self.post_code = post_code
    self.card_date = card_date
    self.card_code = card_code

It is a little bit cleaner to do this way since now our class is more generic, it is agnostic of where the attributes are coming from.

Some other code-style related notes:

  • consistent naming: rename postcode to post_code

  • revise the quality and necessity of comments: there is probably not much sense in having a comment # Constructor

  • you can simplify the way you return a boolean result from your methods. For instance, you can replace:

     if datetime.date.today() < card:
         return True
     else:
         return False
    

with:

    return datetime.date.today() < card

And, it's worth mentioning that, generally speaking, if you doing this for production, you should not be reinventing the wheel and switch to a more mature, well-used and tested package like pycard.

Source Link
alecxe
  • 17.5k
  • 8
  • 52
  • 93

I think there is this code organization issue - you have a class named Customer, but it, aside from the .name attribute, consists of credit-card related logic only.

I would also pass the obtained attributes to the class constructor instead of asking for them inside it:

def __init__(self, name, post_code, card_date, card_code):
    self.name = name
    self.post_code = post_code
    self.card_date = card_date
    self.card_code = card_code

It is a little bit cleaner to do this way since now our class is more generic, it is agnostic of where the attributes are coming from.

Some other code-style related notes:

  • consistent naming: rename postcode to post_code

  • revise the quality and necessity of comments: there is probably not much sense in having a comment # Constructor

  • you can simplify the way you return a boolean result from your methods. For instance, you can replace:

     if datetime.date.today() < card:
         return True
     else:
         return False
    

with:

    return datetime.date.today() < card

And, it's worth mentioning that, generally speaking, if you doing this for production, you should not be reinventing the wheel and switch to a more mature, well-used and tested pycard package.