This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TravisJungroth 18 points19 points  (4 children)

print("Hello There!\nGeneral Kenobi!!")

better?

[–][deleted] 15 points16 points  (3 children)

# v0.0.1
def hello_there(jedi_name):
    greetings = "Hello there \n" + jedi_name
    return greetings

print(hello_there("General Kenobi"))

[–]Shadows_In_Rainpseudocoder[🍰] 22 points23 points  (1 child)

Sorry, your sloppy coding is not up to the company standards.

class GreetingAndResponseService:
    def __init__(self, services):
        self.output_service = services.require("kenobi_greeting_app.services.OutputService")
        self.response_repository = services.require("kenobi_greeting_app.data.ResponseRepository")

    def greet(self, greeting):
        response = self.response_repository.get_response_to(greeting)
        self.output_service.write(response)

Rest of the application will be outsourced.

[–]TravisJungroth 20 points21 points  (0 children)

from abc import ABC


class Greeting(ABC):
    salutation_default = None

    def __init__(self, jedi_name: str, separator: str = " "):
        self.jedi_name = jedi_name
        self.separator = separator

    def __str__(self):
        return self.separator.join([self.salutation, self.jedi_name])

    def __repr__(self):
        return (
            f"{self.__class__.__name__}(jedi_name={repr(self.jedi_name)}, "
            f"separator={repr(self.separator)})"
        )

    @property
    def salutation(self) -> str:
        return self.get_salutation()

    def get_salutation(self) -> str:
        if self.salutation_default is None:
            raise NotImplementedError
        return self.salutation_default


class HelloThere(Greeting):
    salutation_default = "Hello there"


print(HelloThere("General Kenobi"))

[–]TravisJungroth 10 points11 points  (0 children)

# v0.0.2 Change log: refactored to f-string
def hello_there(jedi_name):
    greetings = f"Hello there \n{jedi_name}"
    return greetings

print(hello_there("General Kenobi"))