9 comments

  • alankarmisra7 hours ago
    Ooo I love these things. I wrote a C++ -&gt; Clang -&gt; JS transpiler so I could show value change states on top of the C++ source code in html and allow people to step through the whole state change. They can also vary the input and see the values change cause the JS layer could recompute the values - which is why I bothered with the transpiling - otherwise I could have just output the state changes and parsed them as CSV for the steps. Fun project!<p><a href="https:&#x2F;&#x2F;youtu.be&#x2F;ZPGysUX62OY" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;ZPGysUX62OY</a>
  • kvemkon56 minutes ago
    &gt; See your source code ...<p>What I&#x27;d like to see, is how much time is spent to compile each block of C++ code (sliced as fine as possible).
  • jsrcout5 hours ago
    Definitely trying this out. I&#x27;ve always had the problem of &quot;but what is the compiler thinking?&quot; with C++ in particular.
  • StilesCrisis8 hours ago
    I wish the readme example showed a lambda capture. Now that&#x27;s where compiler magic REALLY shows up.
    • sltkr1 hour ago
      C++ lambdas are just structs that overload operator(); once you realize that they become a lot less mysterious. But it&#x27;s a great example of how this tool is useful to learn about those things (of course you could also read the C++ standard but who has time for that?)<p>Here&#x27;s an example: <a href="https:&#x2F;&#x2F;cppinsights.io&#x2F;s&#x2F;f04b6896" rel="nofollow">https:&#x2F;&#x2F;cppinsights.io&#x2F;s&#x2F;f04b6896</a><p>(That also shows how C++&#x27;s range-based for-loops work, which is similarly some syntactic suger for a fairly mundane for-loop, but details are interesting: unlike a typical for-loop, the loop variable is declared inside the loop body.)
      • StilesCrisis3 minutes ago
        I said shows a lambda _capture_. This involves the compiler automatically determining which variables cross the scope boundary, and injecting code for each one.
    • rramadass6 hours ago
      You can see it by typing in the sample code in the tool here - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=49928362">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=49928362</a>
    • mrlonglong6 hours ago
      I second this.
      • rramadass6 hours ago
        <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=49945197">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=49945197</a>
    • WalterBright4 hours ago
      [dead]
  • f1shy5 hours ago
    I must be the only one who (while I like the tool) feel a little strange, somewhere between sad, angry, annoyed and disappointed (can’t really express it), that a language needs (or at least is of good use) such a tool.<p>Like: I wish what is the first interpretation of my code to be obvious. Is not about advanced optimization, or nitty gritty compiler tricks, is about the language. This tool is useful in <i>any</i> C++ compiler. How did we end with such a complex language?<p>I mean (sorry, very personal take) the programming language is for me a tool to help me think about a problem and its solution. In this era of LLM more than before, is not a tool to get the machine to do something, is a language for formalizing ideas, problems and solutions, like math. Should not be so obscure, that you need to be a lawyer to understand it, right? Or I am very much old and totally in the weeds with my ideas?
    • kccqzy5 hours ago
      No a language doesn’t <i>need</i> it. It’s an educational tool for those new to the language or new to a particular language feature. With practice language features just become automatic so you don’t think about them when thinking about a problem.<p>In the README example, the C++ practitioner just doesn’t think about those automatically synthesized copy constructors and such for POD types, nor do they think about the fact that assignment is desugared to operator= or that an assignment can involve a static_cast.
      • f1shy4 hours ago
        &gt;&gt; needs (or at least is of good use) such a tool.<p>Of course there are people who do not need that tool. The thing is, other languages doesn’t need such an explanation tool at all, is very much enough with reading a small book. I personally would like C++ to not really need it, but clearly as I stated: maybe “the only one”
        • kccqzy1 hour ago
          &gt; other languages doesn’t need such an explanation tool at all<p>Plain old C has -E to expand macros. Rust has cargo expand. Haskell has -ddump-simpl. Common Lisp has macroexpand. Any language that has a complicated syntax or allows the user to customize the syntax needs such a tool. Whether such a tool actually exists reflects more on popularity and community desire.
        • drysine2 hours ago
          &gt;other languages doesn’t need such an explanation tool at all<p>Are you sure about that?
    • esikich5 hours ago
      In what language is compiling simple? Do you not like compiled languages? I&#x27;m not sure what you&#x27;re complaining about here.
      • f1shy4 hours ago
        Lisp is simple to compile. Even C (at the level this tool works anyway), also basic, and maybe other 100 languages (again, not the whole compiler, but what this tool shows).<p>Compilation per se is not difficult. Doing it with good error recovery, good feedback in case of error, and the optimization is difficult.<p>This tool does not tell me those parts (for that is gotbolt) this is about how the first layer of interpretation works, and not for making compilers, but for understanding what the code <i>actually</i> means, because is not obvious at first sight.
        • dasyatidprime2 hours ago
          I agree with an overall thrust of “C++ is overcomplicated and has many moving parts and a lot of implicit stuff happening in the background that makes it difficult to understand”. But I do want to briefly note that Lisp environments have macro expansion steppers for a reason too.
        • pjmlp2 hours ago
          Classical Lisp 1.5 yeah, modern Lisps not so much, hence why there are famous publications like Lisp In Small Pieces.<p>Only if you mean K&amp;R C or the early C89&#x2F;90 compilers, before the extension explosion, newer language standards, and modern ISAs.
    • rramadass3 hours ago
      You have misunderstood the language and the tool.<p>Compilers for all languages have the concept of &quot;lowering&quot; the level of source-language abstractions from high-level to low-level viz. Written Source -&gt; Simpler Source -&gt; AST -&gt; IR -&gt; Machine Code. One type is &quot;desugaring&quot; i.e. transforming complex syntax to simpler ones so that the following stages of compilation have to operate only on a smaller and hence more manageable language subset.<p>This tool shows both desugaring and other lowering (eg. implicit transformations, type deductions etc.) within the C++ source language by regenerating the source from the AST thus giving you full visibility until that stage in the compilation process.<p>PS: Explanatory video presentation by the author - <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=VJ6ZvDRYzNE&amp;t=558s" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=VJ6ZvDRYzNE&amp;t=558s</a>
    • rs5458375 hours ago
      I don&#x27;t think it&#x27;s only C++ though, Python decorators, Rust macros, almost every language&#x27;s compiler write code you never see. C++ just does more of it and makes it harder to guess. Being able to look at the expanded version is useful in any language that does this.
  • rramadass1 day ago
    The tool can be found at - <a href="https:&#x2F;&#x2F;cppinsights.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;cppinsights.io&#x2F;</a>
  • IshKebab5 hours ago
    This is what let me understand lambdas. Great tool.
    • drysine2 hours ago
      Good for C++&#x27;s coroutines too
      • pjmlp2 hours ago
        It also helps to know the .NET model, as C++20 co-routines were inspired by how they work and related magic methods on awaitable types.
  • tweedler2904 hours ago
    thats crazy. i made this <a href="https:&#x2F;&#x2F;github.com&#x2F;oooscoos&#x2F;Benzi" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;oooscoos&#x2F;Benzi</a> which does the same thing but is language agnostic (supports 9 other languages). urs probs goes in deeper into c++ than mine tho
    • abbefaria273 hours ago
      This is very different and doesn’t relate to what the linked repo does.