• ray10k (unregistered)

    Anyone got that one clip from Fantasia ready? The one where the brooms go out of control with their buckets? Because this feels a lot like an apprentice going mad with the power at their fingertips.

  • someone (unregistered)

    TRWTF is this comment moderation. What did ray10k say? Should i avoid saying anything in case I just repeat it?

    I could be wrong, but I don't recall significant spam issues before it was introduced. Now I see a ton of comments on recent articles that still haven't been moderated. If you're going to implement a moderation queue, at least be bothered to resolve it frequently!

  • ray10k (unregistered)

    I think it's just because I'm not registered. Besides, this is a comment box on the internet. Erring on the side of caution is reasonable enough.

  • ray10k (unregistered)

    (Also, there definitely were issues before. I remember that about a year back, getting articles spammed with >100 spam comments (usually with lots of gross/violent pictures to further pad the length) was common. Really, I prefer having my comments held for moderation over having to worry about getting a face-full of whatever grossness the trolls can cook up.)

  • Raj (unregistered)

    It's a protection against uncertainty. Instead of maybe be exposed to annoying spammy messages, we are definitely exposed to annoying redacted ones. In terms of UX it's clearly top tier, up there with material design or Microsoft Bob.

  • Sam (unregistered)

    That's why my code has no comments, its all been held for moderation.

  • (nodebb)

    It looks like that while True: … break is utterly pointless, since the break is not conditionally executed. Which if this code ever gets executed from anywhere with a complex call stack will make this all thoroughly unpleasant.

  • mikapfl (unregistered)

    "So, first, we check the current recursion limit. Then, we try setting the recursion limit to two. If the current recursive depth is greater than two, then when we try to change the recursion limit it throws a RecursionError. So catch that, and then try again with one higher recursion limit." The real WTF(TM) is Remy. What he writes there is not what the code does. It /stores/ the current recursion limit (not checking anything), then sets the recursion limit to two (no reason why that ever would throw a RecursionError, so n will not be increased - but even if there was a RecursionError, the break will happen anyway, so the while True will only run once). I mean, the code is still very much insane, but differently so than Remy writes.

  • Smithers (unregistered) in reply to mikapfl

    Remy is closer than you think. Note he says "If the current recursive depth is greater than two," not the limit. If you call sys.setrecursionlimit(2) when you're already two function calls deep, it fails because it would already be over the limit.

    You're right about the break though; there should either be a continue in the except: clause or the break should be within an else:.

  • Fredde (unregistered)

    If you want to ‘delegate property access to other classes’, wouldn't inheritance be the One Obvious Way To Do It?

  • Little Bobby Tables (unregistered)

    Footgun. First time I've seen that word used.

    FOR I = 1, 5 STEP 1 DO
       CALL SHOOT_TOE (I)
    END DO
    

    My FORTRAN's rusty so I may have got the syntax slightly wrong.

  • Tim! (unregistered) in reply to mikapfl

    https://docs.python.org/3/library/sys.html#sys.setrecursionlimit

    "If the new limit is too low at the current recursion depth, a RecursionError exception is raised."

  • Sole Purpose of Visit (unregistered) in reply to Fredde

    Well, no, not really. Not with nested classes. Mind you, you have to think about this a bit.

    Which is more than the OP did, and to his/her credit, they realised it.

    Composing behaviour is a different thing to inheriting behaviour. In this case, the two are smooshed via Python's (perfectly legitimate) implementation of operator overload. Incidentally, I don't see why Remy has a problem with operator overload, but hey, that's just me. I think we all have a problem with cyclic object graphs and infinite recursion, let alone a silly attempt to control infinite recursion.

    tl;dr Just compose contained objects naturally, using the Bridge pattern (aka, in C++, pimpls). The whole point of an object, in any object oriented language, is to control behaviour and access to data members. Leave the Jitter to solve the existential crisis of "oh, my, I've got a reference to a reference to a reference."

    In short, be elegant. Don't be a prat.

  • Friedrice the Great (unregistered) in reply to ray10k

    I think the only time one of my guest posts got moderated was when I connected via TOR. After all, only malicious spammers would ever try to post a comment over TOR, right?

  • (nodebb) in reply to Little Bobby Tables

    [code] Proper Fortran: DO 10 I=1,5 SHOOT_TOE(I) 10 CONTINUE STOP END

    Addendum 2018-09-11 17:56: Someone might tell me how to put code in a comment one of these days.

  • (nodebb)

    Why the hell do people use this abortion survivor of a language, I don't know.

  • someone (unregistered) in reply to herby

    Apparently it's markdown, so you use three graves on either side.

    if( FileNotFound)
      print("Brillant!")
    
  • (nodebb) in reply to someone

    Three graves on either side is what Voldemort could use, if he would use graves at all.

  • Dave Null (unregistered) in reply to ray10k

    +1. Especially when that spam was longer than all useful comments together or even containing endless streams of NSFW pictures. Still got my userscript from back then that i used as a workaround

  • o11c (unregistered)

    Important note for non-Python programmers: __getattr__ is only called if the attribute is not found the usual way (in __dict__ or in the class's __dict__ - the latter of which covers how __slots__ works)

    There's also __getattribute__ which is technically more gets called for every case, and thus is more analogous to __setattr__ or __delattr__ - but is rarely what you want.

    One useful thing you can do:

    class LazyMixin:
        ''' Mixin that allows attributes to be calculated lazily just once.
        '''
        def __getattr__(self, name):
            if not name.startswith('_lazy_'):
                f = getattr(self, '_lazy_%s' % name, None)
                if f is not None:
                    v = f()
                    setattr(self, name, v)
                    return v
            raise AttributeError("%r object has no attribute %r" % (self.__class__.__name__, name))
    
        def hasattr_nolazy(self, name):
            # TODO is there a way that *does* still use __getattribute__ , just without ultimately calling `__getattr__`?
            return name in self.__dict__
    
  • Barf4Eva (unregistered)

    This sentence is staying with me:

    "This is an impressive amount of effort into constructing a footgun."

Leave a comment on “Wear a Dunder Cap”

Log In or post as a guest

Replying to comment #:

« Return to Article