Coder Social home page Coder Social logo

clean-code-python's People

Contributors

abbas980301 avatar airbusdriver avatar arpanetus avatar cassiosantos avatar connorvg avatar eddymens avatar emnsen avatar fredsonchaves07 avatar guilhermeportela avatar jnyjny avatar litvinchuk avatar mandarvaze avatar martinthoma avatar migonzalvar avatar mpavlase avatar mstruebing avatar naffiq avatar pavel-ekt avatar peter-gribanov avatar piotrplenik avatar rigeldiscala avatar rigelds avatar shahrukhx01 avatar solival avatar vlassiuk avatar zacharyaanglin avatar zayon avatar zedr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clean-code-python's Issues

the DIP example seems wrong to me

hi,

I would have expected, that in the ‘good’ example, the function will take a parameter of type ‘EchoIf’

You could have showed that there is an ‘Echo’ class with the actual implementation, and an ‘EchoIf’ interface class that abstracts the ‘write’ method.

this is basically the whole point, your function depends on an abstraction. it is clear that in order for that function to work, it is required an object that implements the ‘write’ method.

as it is done now, the function hides a dependency on the Echo class. you are building the object inside the function, instead of delegating this responsibility to a different function.

Also, same function builds ‘rows’ object with a default value, a thing that you have said in previous example that should be done using parameters with default values.

Translate to Korean

Hello @zedr!, I learned a lot from this repo, so I translated this repo to korean.
Can you please add my translated repo link to your repo?

Thank you for making a great document😊

Using `str` instead of `Text`

Hi! Thanks so much for your efforts, well done, excited for more!

One thought...
you have used the Text typing instead of str in your functions. Take a look at this link.
I think it's better to use str instead of Text unless we want backward compatibility for python2 code.

Translation - PT-BR

Hi guys! How about translating this project to other languages? I believe I can contribute with the PT-BR translation 👍

MenuConfig example mutating/setting class variables listed as Good

I am surprised to see this example listed as "Good".

class MenuConfig:
    """A configuration for the Menu.

    Attributes:
        title: The title of the Menu.
        body: The body of the Menu.
        button_text: The text for the button label.
        cancellable: Can it be cancelled?
    """
    title: str
    body: str
    button_text: str
    cancellable: bool = False


def create_menu(config: MenuConfig):
    title = config.title
    body = config.body
    # ...


config = MenuConfig
config.title = "My delicious menu"
config.body = "A description of the various items on the menu"
config.button_text = "Order now!"
# The instance attribute overrides the default class attribute.
config.cancellable = True

create_menu(config)

I think there might be some misunderstand of how classes work in Python or there's perhaps a typo yielding a confusion on instance vs class.

Any key:type annotation on a class gets added to __annotations__. If the key:type has a default then it will be set as the default class variable. Any setter on the class will set any value (e.g., config.dragons = 34). I believe this practice should be discouraged.

Here's an example:

In [13]: class Record:
    ...:     alpha:int
    ...:     beta:int
    ...:     gamma:int = 1234
    ...:     
    ...:             

In [14]: r = Record

In [15]: r.alpha
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-15-b43492ebc57e> in <module>()
----> 1 r.alpha

AttributeError: type object 'Record' has no attribute 'alpha'

In [16]: r.__annotations__
Out[16]: {'alpha': int, 'beta': int, 'gamma': int}

In [17]: r.gamma
Out[17]: 1234

In [18]: r.dragons = 27

In [19]: r.more_dragons = 48

I would suggest that this Menu example should use an instance, not class, or the example should be marked as "Bad" in the text.

Possibly incorrect: "Zero arguments is the ideal case"

In the section "Function arguments (2 or fewer ideally)" it says:
"Zero arguments is the ideal case. One or two arguments is ok, and three should be avoided."
However, I think it's typically best to have at least 1 argument, as most functions with zero arguments aren't pure functions and aren't easily testable

Personally I prefer the wording in Clean Code JavaScript:
"One or two arguments is the ideal case, and three should be avoided if possible" (https://github.com/ryanmcdermott/clean-code-javascript#function-arguments-2-or-fewer-ideally)

Wraping parameters into dictionary in "Function arguments (2 or fewer ideally)"

class Menu:
    def __init__(self, config: dict):
        title = config["title"]
        body = config["body"]
        # ...

menu = Menu(
    {
        "title": "My Menu",
        "body": "Something about my menu",
        "button_text": "OK",
        "cancellable": False
    }
)

From my experience, using a dictionary as a structure for holding data can lead to a big mess, when you have several complex structures like that. It is not typed checked and can't be annotated. I would use TypedDict instead.

Also, I think, it is not completely clear, how it solves the stated problem. The function still has the same amount of parameters. I think the more proper solution is to refactor the function/class into several smaller functions/classes and compose them (e.g. make_menu_content, make_button, etc.).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.