Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

After 5 years of Python, I don't even see self anymore (how zen).

Author could have written

    class Window(object):
        def __init__(self, min, max):
            if min > max:
                min, max = max, min
            self.min = min
            self.max = max
to avoid repetition. If many args are needed,

    def __init__(self, a,b,c,d,e,f,...):
        for k, v in locals().items():
            setattr(self, k, v)
Etc etc there are endless idiomatic ways to avoid boilerplate in Python


Or this:

    class Window(object):
        def __init__(self, minimum, maximum):
            self.minimum = min(minimum, maximum)
            self.maximum = max(minimum, maximum)
Why set attributes twice? AFAIAC you only need to write "self." once for each attribute in the constructor.


    class Window(object):
        def __init__(self, minimum, maximum):
            self.min_func = min
            self.max_func = max
            self.tuple_type = tuple
            self.minimum = minimum
            self.maximum = maximum
            self.minimum, self.maximum = self.tuple_type([self.min_func(*self.tuple_type([self.minimum, self.maximum])), self.max_func(*self.tuple_type([self.minimum, self.maximum]))])
    
        def __call__(self, x):
            self.x = x
            result = self.minimum <= self.x <= self.maximum
            del self.x
            return result


I agree, there is hardly any need for OPs post.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: