• JATth@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    7 hours ago

    I once wrote bind_front() and move_only_function likes in C++17. This nearly drove me mad because you cannot refer to a overload set by a name.

    On the otherhand, I can now decipher the template error mess that the (g++) C++ compiler spews out.

  • brucethemoose@lemmy.world
    link
    fedilink
    arrow-up
    134
    arrow-down
    2
    ·
    edit-2
    2 days ago

    Meanwhile, Rust punches you in the face for the mere suggestion. Again. And again.

    Python happily nods, runs it one page at a time, very slowly, randomly handing things off to a C person standing to the side, then returns a long poem. You wanted a number.

    Assembly does no checking, and reality around you tears from an access violation.

    EDIT: Oh, and the CUDA/PyTorch person is holding a vacuum sucking money from your wallet, with a long hose running to Jensen Huang’s kitchen.

    • stingpie@lemmy.world
      link
      fedilink
      arrow-up
      12
      arrow-down
      2
      ·
      1 day ago

      I refuse to believe the python one ever happens. Unless you are importing libraries you don’t understand, and refuse to read the documentation for, I don’t see how a string could magically appear from numeric types.

      • expr@programming.dev
        link
        fedilink
        arrow-up
        3
        ·
        8 hours ago

        You don’t see how type mismatch errors can happen in a dynamically-typed language? Then why do they happen all the time? Hell, I literally had a Python CLI tool crash with a TypeError last week.

        • stingpie@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          5 hours ago

          That’s not what I’m saying at all. What I’m trying to say is that I can’t think of any way a program working with numeric types could start outputting string types. I could maybe believe a calculator program that disables exceptions could do that, but even then, who would do that?

  • count_dongulus@lemmy.world
    link
    fedilink
    arrow-up
    63
    arrow-down
    1
    ·
    2 days ago

    This is why I will never touch Javascript again. Long ago when I worked on web stuff, half my workflow was spent in the debugger tracing garbage to find where a typo was. The industry moved to Typescript, and now assuming the strictness checks are enabled, if some Typescript transpiles successfully, I can be 95% sure whatever fuckup I observe at runtime is a logic problem.

    Weakly typed languages were an awful idea. But in general, if the compiler isn’t able to detect most runtime issues (like with C++ here), it’s not going to be the most productive language to use for building solutions compared to smarter alternatives.

    • Gladaed@feddit.org
      link
      fedilink
      arrow-up
      4
      arrow-down
      3
      ·
      1 day ago

      If you tell the Compiler to be careful and avoid writing c code c++ does not segfault. This is a user error.

      You can technically even write Assembler code and compile with gpp.

      • T156@lemmy.world
        link
        fedilink
        English
        arrow-up
        5
        ·
        23 hours ago

        Does it count as user error if the user has to micromanage the compiler?

        • Gladaed@feddit.org
          link
          fedilink
          arrow-up
          1
          ·
          12 hours ago

          Yes. Unless you have a really good reasons there are safe and portable versions you should use instead.

      • ShortFuse@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        10 hours ago

        I suggest against it. Just use JSDocs syntax and typescript (the CLI and VSCode checker) will check it. No need to use transcompiler anymore. It was more useful when JS itself was more ES5 based and CommonJS.

        Using something like esbuild will get you minification if you want it, but it’s only for deployment, not actually needed for runtime. Having pure JS code is much easier to work with and debug.

      • count_dongulus@lemmy.world
        link
        fedilink
        arrow-up
        16
        arrow-down
        1
        ·
        2 days ago

        Try porting a very small bit of behavior into a new tiny library or module that is Typescript based and independently published. Enable the strictness checks in tsconfig - really, really resist the urge to use any, and enforce that any is disallowed in tsconfig. Familiarize yourself with its utility types that really trip new authors up. “Record” comes to mind here, and others that involve generics if you haven’t before worked with generics. Some of the type error messaging can be pretty obtuse - don’t be afraid to paste them into an LLM (or use Copilot enhanced Intellisense) to explain what it actually means. IMO the type violation messaging is a weak dev experience point for new authors, so don’t sweat it if you occasionally “struggle to make the squiggles go away”.

      • SorryQuick@lemmy.ca
        link
        fedilink
        arrow-up
        4
        arrow-down
        3
        ·
        edit-2
        2 days ago

        The whole point of a segfault is that you can’t really know anything about it. Even in rust, when you get a segfault there is no meaningful error.

        • RoyaltyInTraining@lemmy.world
          link
          fedilink
          arrow-up
          3
          ·
          24 hours ago

          The worst thing you can do in non-unsafe Rust is perform an out-of-bounds indexing operation, or anything else that panics. The error you get tells you the panic’s exact location in the source code, down to the line and column. Meanwhile, C and C++ either don’t produce an error at all when accessing uninitialized memory (which is arguably the worst behavior), or it segfaults with zero extra info.

          The only way to make Rust segfault is by performing unsafe operations, and those must always be clearly marked.

          • weker01@sh.itjust.works
            link
            fedilink
            arrow-up
            1
            ·
            edit-2
            8 hours ago

            The only way to make Rust segfault is by performing unsafe operations.

            Challange accepted. The following Rust code technically segfaults:

            fn stackover(a : i64) -> i64 {
                return stackover(a);
            }
            
            
            fn main() {
                println!("{}", stackover(100));
            }
            

            A stack overflow is technically a segmentation violation. At least on linux the program recives the SIGSEGV signal. This compiles and I am no rust dev but this does not use unsafe code, right?

            While the compiler shows a warning, the error message the program prints when run is not very helpfull IMHO:

            thread 'main' has overflowed its stack
            fatal runtime error: stack overflow
            [1]    45211 IOT instruction (core dumped)  ../target/debug/rust
            

            Edit: Even the compiler warning can be tricked by making it do recusion in pairs:

            fn stackover_a(a : i64) -> i64 {
                return stackover_b(a);
            }
            
            fn stackover_b(a : i64) -> i64 {
                return stackover_a(a);
            }
            
            fn main() {
                println!("{}", stackover_a(100));
            }
            
        • WhyJiffie@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          9
          arrow-down
          2
          ·
          1 day ago

          point is, Rust manages to give you not a segfault but a meaningful error almost all the time until you use unsafe

          • SorryQuick@lemmy.ca
            link
            fedilink
            arrow-up
            3
            arrow-down
            5
            ·
            1 day ago

            If you’re getting a segfault in C++, it’s also cause you used unsafe code. It’s just not officially enclosed in an “unsafe” block.

            • WhyJiffie@sh.itjust.works
              link
              fedilink
              English
              arrow-up
              4
              ·
              edit-2
              23 hours ago

              the point was not on the unsafe word, but a very specific feature of Rust that helps enclosing unsafe code where the compiler wouldn’t be able to 100% verify your logic. no such thing in C++. C++ does not even attempt to verify safety

              your response is basically “get better at coding dumbass, I am the safety validator”

    • asdfasdfasdf@lemmy.world
      link
      fedilink
      arrow-up
      20
      ·
      2 days ago

      I mean, this is correct in many cases, unironically.

      It should be one of the core purposes of a programming language to help humans to write the code they intend. If a language doesnt do that then it’s bad.

      • Shanmugha@lemmy.world
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        10 hours ago

        I tend to disagree. The language should allow me to do things, and what is simple and obvious logically should be simple and obvious in the language (I am looking at you, JavaScript with [] != [])

        What I intend - well, more than half my work is figuring out what I intend, language should have no say in this, save things like “we do this kind of trick like this here” (for example, C++ has no concept of “interface” entity. Ok, looks like I can use virtual class instead)

        It is when languages start trying to be “helpful” they become an ugly mess: meaningful white spaces in Python? The whole shit with prototypes and objects in JS(see above)? Fuck this shit, I am not going to call those two good programming languages

        • asdfasdfasdf@lemmy.world
          link
          fedilink
          arrow-up
          3
          ·
          edit-2
          9 hours ago

          I think you’re saying the same thing as what I am. If it’s more complex than what you may think, the language should guard against it. If not, it should make it simple.

          Rust, for example, is the only mainstream language where it isn’t possible to read from a file handle after it’s been closed. Doing so is a compilation failure. This is just a general invariant of “how to use files”.

          But you also don’t need to think about allocating or deallocating memory in Rust. It does that fke you automatically, even though it’s not GC.

          JS can also be complicated when it tries to hide realities about the world. E.g. is a const array or object immutable? No, the pointer is. But pointers don’t exist! /s

          • Shanmugha@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            9 hours ago

            Looks like we still differ. If something is more complicated than what I may think, then there are some possibilities:

            • I have not learned to language properly yet (this is where I stand with C++, so no matter how many times I’ve got segfaults, now is not the time for me to say language is bad)
            • I have chosen the wrong tool (writing a videoplayer in assembler? something went way wrong here)
            • tool is actually bad (my rant above goes here. in the sake of making some things easy and simple, something basic in the language got screwed up irrevocably)

            And if I managed to try reading from a closed handle, or to access a memory that I am not actually allowed to use, or… (could not get more examples out of the top of my head), it is not the job of the language to slap my hands, as long as I follow the syntax. Most of the time (if not all the time) this means I have not accounted for something that my code allowed to happen - so my responsibility to deal with that

            What I keep hearing about Rust is still in the lines of too-much-fucking-care (that’s besides obviously dumb rule of “no more than one owner of a variable at any moment” which then had to be worked around because not everything can be done this way. please correct me if I am wrong here)

            • asdfasdfasdf@lemmy.world
              link
              fedilink
              arrow-up
              2
              ·
              8 hours ago

              Yep, we disagree. The world and technology especially is an extremely complicated place. IMO any complex system that is built upon “humans should just know all this complexity and keep it in mind all the time” is fundamentally broken.

              • Shanmugha@lemmy.world
                link
                fedilink
                arrow-up
                1
                ·
                edit-2
                8 hours ago

                It depends. We may have our differences in weighing things, but yes, complexity of the system must correlate with complexity of the task it is used for. A system allowing to do things without any complexity means either no complex things to be done or straight up magic

  • henfredemars@infosec.pub
    link
    fedilink
    English
    arrow-up
    68
    ·
    2 days ago

    Ah, C++. An endless supply of footguns where the difference between a junior and a senior dev is knowing what parts of the language to never use.

      • henfredemars@infosec.pub
        link
        fedilink
        English
        arrow-up
        13
        ·
        edit-2
        2 days ago

        You can also make everything a smart pointer and be done with it.

        I can count on more than one hand the number of large scale projects where converting everything to smart pointers fixed major memory issues. Even if smart pointers can’t handle circular references, the number of projects that just don’t manage their memory correctly at all and were fixed by introducing these tools is way too high.

        • xmunk@sh.itjust.works
          link
          fedilink
          arrow-up
          3
          ·
          2 days ago

          This is a bit embarrassing but the last time I actively worked in C++ it was with Qt and pre C++11.

          • henfredemars@infosec.pub
            link
            fedilink
            English
            arrow-up
            2
            ·
            2 days ago

            Almost the same as me. All kinds of programming jobs. I usually end up working in Python or C, for embedded systems work.

            Of course, if you’re talking hobby, it could be anything.

        • CanadaPlus@lemmy.sdf.org
          link
          fedilink
          arrow-up
          2
          ·
          2 days ago

          Which kind of smart pointer, with which kind of footgun? I mean, it’s better than not even trying I guess, but if it was actually a full solution you’d just have Rust.

          • henfredemars@infosec.pub
            link
            fedilink
            English
            arrow-up
            7
            ·
            2 days ago

            You’re right. It’s a stop gap, but when you’re talking about a code base that has been maintained for 20 years plus you can’t really sell re-implementation.

            Most recently it was with an older version of C++ using shared pointers.

  • I Cast Fist@programming.dev
    link
    fedilink
    arrow-up
    24
    ·
    2 days ago

    What surprised me the most was the speed of the compilation, must be a very small program. I tried to compile Godot from source once. Force-stopped it after 3 hours

    • Sylvartas@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      10
      ·
      2 days ago

      How many cores do you have and what compiler was it ? Also RAM can help with huge codebases iirc. When I was working with UE5 I had the best Ryzen available with 128 Go of RAM, could compile the engine (which is much bigger than Godot) from source in less than 2 hours iirc (yes that is a full clean+rebuild, not just compiling recent changes)

    • Psythik@lemmy.world
      link
      fedilink
      arrow-up
      4
      arrow-down
      18
      ·
      2 days ago

      Why are you trying to compile an actress? What is a human’s “source”? Their DNA? I’m surprised that the compiler even tried.

  • Lemmist@lemm.ee
    link
    fedilink
    arrow-up
    56
    arrow-down
    9
    ·
    2 days ago

    So? Do you really expect the compiler to UNDERSTAND the code?

    Here is a grammatically correct phrase for you to think:

    Compilers don’t paint tangential apostrophes unless the storm value is deeper than radish. Fraggles love radish.

      • CanadaPlus@lemmy.sdf.org
        link
        fedilink
        arrow-up
        10
        ·
        2 days ago

        C/C++ is mildly obsolete now, basically. Breaking the memory model is not really a small defect that’s a matter of taste.

      • kiri@ani.socialOP
        link
        fedilink
        arrow-up
        6
        arrow-down
        1
        ·
        2 days ago

        There are C++ analyzers like this which are also designed to prevent it (if you have no choice between languages).

        • CanadaPlus@lemmy.sdf.org
          link
          fedilink
          arrow-up
          6
          ·
          edit-2
          2 days ago

          I’ve seen things like this posted several times on here. It always turns out it doesn’t actually catch all the possible problems, or it’s garbage collected, or it’s non-usable for real code.

          If it was that easy, the people who wrote Rust with all it’s complexity and divergence from the norm were idiots, and I really don’t think they were.

          • kiri@ani.socialOP
            link
            fedilink
            arrow-up
            7
            ·
            2 days ago

            It’s pleasure for me to write in rust, I really like how fast I can deploy a working solution (including debug time). As I mentioned, there are situations when, for some reason, you cannot do without C++. But you are right cpp-analyzers do not solve all possible problems.

      • Lemmist@lemm.ee
        link
        fedilink
        arrow-up
        10
        arrow-down
        22
        ·
        2 days ago

        Prevent what? UNDERSTANDING the code?

        Yeah, Rust is quite successful in that :)

          • Lemmist@lemm.ee
            link
            fedilink
            arrow-up
            5
            arrow-down
            13
            ·
            2 days ago

            That’s a rather old joke. Modern compilers print more adequate things on STL/templates related things.

            And it doesn’t make Rust any better.

            • kiri@ani.socialOP
              link
              fedilink
              arrow-up
              7
              ·
              2 days ago

              Yeah, I know, that all just a humour. I almost always use C++, inspite of knowing rust (cz no jun vacncies for rust, but still). There is no modern language which is absolutely better than other one — compromises are everywhere, that’s why it’s a silly topic to argue about.

        • bitcrafter@programming.dev
          link
          fedilink
          arrow-up
          7
          arrow-down
          1
          ·
          2 days ago

          You do not come across as clever as you think that you are when your central point is that you personally are not capable of understanding code written in a different programming language.

        • CanadaPlus@lemmy.sdf.org
          link
          fedilink
          arrow-up
          1
          ·
          2 days ago

          I feel like a really bad job has been done of making it simple, honestly. Or at least was last I checked.

          Pointers allow aliasing XOR mutability. There’s all kinds of nuance layered on top of that if you look in the compiler developers resources, but that’s just to allow for all the different kinds of sugar people want in a modern language.

        • AngryCommieKender@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          2 days ago

          I kinda want to look up Fraggle Rock to see what that show was about, but I’m worried I’ll be disappointed in my former self’s taste. I know I watched it when I was like 4-6 y/o.

          • Lemmist@lemm.ee
            link
            fedilink
            arrow-up
            5
            ·
            2 days ago

            I watched it when I was 30 as a method of learning English. It wasn’t too childish.

    • Thinker@lemmy.world
      link
      fedilink
      arrow-up
      20
      ·
      2 days ago

      Congratulations, you’ve illustrated the difference between syntax and semantics. But any competent compiler also handles semantics (just in a separate phase of compilation), because that’s necessary for any useful conversion to machine code, not to mention optimizations.

      • CanadaPlus@lemmy.sdf.org
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        2 days ago

        It’s more like they handle a smaller, toy version of semantics that you can actually code a compiler for. In OP, something semantically correct in that version but not by common sense was accidentally written.

        Maybe an early LLM that talks about picking up fire would be a better analogy.

    • Jyek@sh.itjust.works
      link
      fedilink
      arrow-up
      9
      ·
      2 days ago

      It makes sense to me. You start in the top left like how you read and then you get a direction for the order of the conversation. I read it naturally at intended the first time through.

        • Jyek@sh.itjust.works
          link
          fedilink
          arrow-up
          1
          ·
          1 day ago

          The connection between the bubbles guides you to the next bubble in order of dialogue. Without it it would read as if the man says everything first before the woman speaks which is incorrect.

            • Jyek@sh.itjust.works
              link
              fedilink
              arrow-up
              1
              ·
              1 day ago

              When convention doesn’t convey the proper flow of the conversation then you have to improvise. I’ve seen this in western comics before, though I don’t have any examples on hand. The bubbles have a tail indicator to show who is speaking and a flow indicator to show the order in which the bubbles are spoken. It is a little strange in this case but it’s not unheard of and it does the job it was drawn to do.

  • Thorry84@feddit.nl
    link
    fedilink
    arrow-up
    36
    arrow-down
    1
    ·
    2 days ago

    Typescript on the other hand: Exwuse me sir, you seem to have a little oopsie right here. Oh right! Let me just fix that right up.

    HERE ARE TWO THOUSAND ERRORS! YOUR PUNY LITTLE BUFFER CAN’T EVEN SCROLL BACK TO READ THEM ALL! AND YOU CALL YOURSELF A PROGRAMMER?

  • heavy@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    15
    ·
    2 days ago

    I mean, the comic is fine I guess, but if it implies the Cpp lady is hitting you, it’s not. That would be the kernel, the lady did what you told her to do.