6 comments

  • shoo7 minutes ago
    Mmm. Changing control flow based on introspection of the call stack is reasonably nasty.<p>I recall we found a neat use for call stack introspection in one project - not to change control flow but to improve logging. Inside an open_db_connection utility function, to auto-generate an informational name describing which part of the codebase had opened the connection:<p>E.g. some_backend_process: main -&gt; ... &gt; grandparent -&gt; parent -&gt; open_db_connection<p>We&#x27;d use information from the call stack generate a string &quot;some_backend_process grandparent.parent&quot; describing the call site which could be passed to postgres as the application_name [1] when establishing a connection. Then from the database side, if we had problematic queries at runtime, we had a lot more clues to figure out which part of the backend codebase was responsible [2].<p>There&#x27;d be a way to do something equivalent without peeking at the call stack, by requiring the caller to explicitly pass a descriptive &amp; unique name, but that makes things a bit more error-prone, especially since some devs would be prone to copy-pasting chunks of existing code &amp; reusing the same name everywhere.<p>[1] <a href="https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;libpq-connect.html#LIBPQ-CONNECT-APPLICATION-NAME" rel="nofollow">https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;libpq-connect.html#L...</a> [2] <a href="https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;monitoring-stats.html#MONITORING-PG-STAT-ACTIVITY-VIEW" rel="nofollow">https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;monitoring-stats.htm...</a>
  • aeturnum3 minutes ago
    I can&#x27;t provide any code samples, but this only strikes me as medium-cursed as far as python code goes. That stuff can get nasty! Once a team realizes they can modify anything at runtime things can go bad quite quickly.<p>Nice hack for maintaining old behavior tho!
  • ariebovenberg1 day ago
    Author here. I ran into this while comparing Pendulum with `whenever`, the datetime library I maintain. I sent a patch that removes the hack, but the post is about why the underlying design can&#x27;t be patched the same way. Happy to answer questions.
    • LoganDark59 minutes ago
      Did you use LLM to write parts of the article?<p>&gt; The trouble with guessing who’s calling is that you can’t anticipate every caller. Pendulum’s hard-coded check is fragile: it covers only one name, and relies on an exact call stack that Pendulum doesn’t control.<p>Edit: it looks like the later parts of the article show a <i>lot</i> of LLM tells, but not the beginning. I&#x27;ve been seeing this pop up more and more lately...
      • awildfivreld0 minutes ago
        Up until &quot;Each guess may look reasonable on its own. But guessing itself has four problems.&quot; I read the occasional tell, but not much.<p>By the end of that paragraph thereafter I started skimming as the rest turned blatantly LLM.<p>I should have caught the emdash in the first code block in &quot;Who else is calling&quot; though...
      • throwaway8920129 minutes ago
        &gt; but not the beginning<p>You didn&#x27;t stop reading after &quot;The hack itself is on its way out, but the design behind it still matters for your code&quot;? I did.
  • Philpax14 minutes ago
    must admit that my first association was with the drum and bass band
    • groestl12 minutes ago
      Same here, and I thought it was about their visuals or something
  • jonathaneunice56 minutes ago
    OMGeeeee!<p>I too have plumbed the call stack for hidden-maybe-forbidden knowledge from the caller, and it is always fraught. No matter how good one&#x27;s intentions. Forget dynamic type testing. Forget Perl&#x27;s `wantarray` dynamic introspection of &quot;what does the caller want?&quot; Those are small potatoes. This is full on &quot;who&#x27;s calling me and what do I want to send back as a result?&quot; The people who will never forgive you for type testing are going to straight-up excommunicate whoever wrote this! And yet...it makes complete sense. Based on the promises made, you have to do something... and you&#x27;re already in &quot;what is the least of the evils?&quot; territory, because you&#x27;re going to have to do something that someone—maybe a lot of someones—will call evil.<p>My admiration for Pendulum just increased. This is sin-eating.
    • leni53648 minutes ago
      It&#x27;s the promises that don&#x27;t make sense, although that might be obvious in hindsight.
  • david2ndaccount45 minutes ago
    &quot;In the face of ambiguity, refuse the temptation to guess.&quot;