Similar Posts

Subscribe
Notify of
14 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
cleanercode
9 months ago

Clean code or clean architecture makes your code more readable and predictable.

In this context, comments may also be dispensed with – unless these comments serve a legal purpose. If someone claims he writes a good code and uses comments, then the code is not good.

What would you like better?

import re

class PasswordValidator:
    def __init__(self, password):
        self.password = password

    def __validate_password(self):
        pattern = r"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$"
        result = re.match(pattern, self.password)
    
        return result.group()

    def validate(self):
        try:
            self.__validate_password()

            print("Password is valid!")
        except AttributeError:
            print("Password validation failed.")

o_validator = PasswordValidator("aTest1337!")
o_validator.validate()

or

class PasswordValidator:
    def __init__(self, password):
        self.password = password

    def __validate_password_length(self):
        ...

    def __validate_upper_case(self):
        ...

    def __validate_lower_case(self):
        ...

    def __validate_digits(self):
        ...

    def __validate_special_chars(self):
        ...

    def validate(self):
        try:
            self.__validate_password_length(self):
            self.__validate_upper_case(self):
            self.__validate_lower_case(self):
            self.__validate_digits(self):
            self.__validate_special_chars(self):
            
        except AttributeError:
            print("Password validation failed.")

o_validator = PasswordValidator("aTest1337!")
o_validator.validate()

At this point, taste and experience are crucial. Would you know what’s happening? Or would comments be necessary?

ntechde
9 months ago

“Beauty and Power” have never been interested in me.

I write code so he does what he wants and I write it so that I can read it after a few years. Especially with a more frequent use of class, this is very important because comment lines must not be missing, especially in places that are not self-explanatory. In addition, I insert comment lines as a kind of headlines (“here blablabla begins”)

But we’re at work, not at a beauty contest.

CatsEyes
9 months ago

I was, because efficiency, ease of use and benefit is most important, and wartability. That has little to do with me beauty and power.

This is a continuous process without ending. 😉

CatsEyes
9 months ago
Reply to  Kimanon

I use, but this does not replace a complete documentation of the processes, etc.

Fab1anDev
9 months ago

I started with Python and already from

made initially at line breaks. Then I continued with C and then zb instead

int main {
}

I have done this:

int main
{
}

But I always have the beauty of the code ne role.

And then other languages came underanderen C# and JS

Pixelated
9 months ago

until you started to see beauty and strength in your code

This has not happened yet

Pixelated
9 months ago
Reply to  Kimanon

What now?

CatsEyes
9 months ago
Reply to  Pixelated

I was, because efficiency, ease of use and benefit is most important, and wartability. That has little to do with me beauty and power

Pixelated
9 months ago
Reply to  CatsEyes

Right. Code must be functional, legible and efficient. And not nice.

And sometimes the unsightly solutions are the more efficient.

Pixelated
9 months ago

All right. I’m just at the first coffee.

CatsEyes
9 months ago

Shouldn’t come in here as an answer. Coffee doesn’t work yet…