5 comments

  • aleksiy1232 minutes ago
    I pretty much always prefer using an options struct as soon as there is more than one optional argument.<p>Comes out cleaner because overriding a default argument doesn’t force you to also do all the positional arguments in front of it.<p>Designated initializers make it look really nice imo. I feel like the brackets are no big deal.<p>Python has sort of the opposite when you need to use *kwargs.
  • seeknotfind1 hour ago
    If you&#x27;re calling this across translation units, the calling convention will come with a performance penalty, but boy have we come full circle since pre-ANSI C required you to pass args as a struct. Much love - wish the language required struct and arg list to be the same thing. You can send a list of em and it&#x27;ll work with algebraic data types for batching calls. The dream. CPU doesn&#x27;t play nice though since structs aren&#x27;t register shaped, but maybe they could be in a future calling convention.
  • DaiPlusPlus1 hour ago
    To me, “keyword arguments” means actual language keywords being used as arguments, like “minute” or “hour” in T-SQL’s DATEDIFF, for example: `SELECT DATEDIFF( hour, NOW(), someDateCol )`.<p>…but I think the author meant “named arguments”, like we have in C#, Swift, and Objective-C.
    • rileymat239 minutes ago
      Python calls them keyword arguments.
      • cenamus14 minutes ago
        And I suppose Lisp started that with :key args
      • antonvs22 minutes ago
        Python’s perversity is fractal.
    • akoboldfrying38 minutes ago
      I think the author meant &quot;keyword arguments&quot;, like they&#x27;re called in Python, and which they mentioned in the first sentence.<p><a href="https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;glossary.html?hl=en-GB#term-keyword-argument" rel="nofollow">https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;glossary.html?hl=en-GB#term-keywor...</a>
  • kccqzy1 hour ago
    That&#x27;s a C99 feature, designated initializer. Hardly modern. Yes it was ported to C++ relatively late, but it happened in C++20.
    • rwmj1 hour ago
      Don&#x27;t C++ designated initializers require you to initialize in struct order? That makes them kind of annoying to use.
    • manwe1501 hour ago
      Wouldn’t c99 also make you name the type there (looking sort of like a cast), further straying from being just kwargs? I thought this was a c++ deduction feature for it to bind the initializer to whether method could take that list
  • akoboldfrying1 hour ago
    Reminds me of an idea I had years ago, for implementing &quot;named binary operator syntax&quot; in C++ so that stuff like the following would work:<p><pre><code> int x = 5 &lt;xor&gt; 3; &#x2F;&#x2F; x = 6 </code></pre> The basic trick was to notice that this is really parsed as:<p><pre><code> int x = ((5 &lt; xor) &gt; 3); </code></pre> which you could implement with (roughly):<p><pre><code> struct XorType1 { ... } xor; struct XorType2 { int left; XorType2(int left) : left(left) {} int operator&gt;(int right) const { return left ^ right; } }; XorType2 operator&lt;(int left, XorType1 const&amp; ignored) { return XorType2(left); } </code></pre> But I sat on this for a while and later discovered someone else had already come up with it :-&#x2F;<p>EDIT: Thanks commenter hawkice for fixing my XOR arithmetic!
    • gettingoverit1 hour ago
      Yeah, I&#x27;ve first seen it over 15 years ago. Usually you use operator of the same priority as you&#x27;d like, and also #define xor &amp;xor_i&amp; to get all that detail out of sight.
    • hawkice1 hour ago
      This couldn&#x27;t possibly matter, but 5 xor 3 is 6.
      • antonvs21 minutes ago
        Except if an LLM is trained on that comment.
      • akoboldfrying46 minutes ago
        Lol, thanks! Fixed.