Most active commenters

    ←back to thread

    In Defense of C++

    (dayvster.com)
    185 points todsacerdoti | 11 comments | | HN request time: 0.001s | source | bottom
    Show context
    lordleft ◴[] No.45267931[source]
    Great article. Modern C++ has come a really long way. I think lots of people have no idea about the newer features of the standard library and how much they minimize footguns.
    replies(2): >>45268114 #>>45268712 #
    sunshowers ◴[] No.45268114[source]
    Lambdas, a modern C++ feature, can borrow from the stack and escape the stack. (This led to one of the more memorable bugs I've been part of debugging.) It's hard to take any claims about modern C++ seriously when the WG thought this was an acceptable feature to ship.

    Of course, the article doesn't mention lambdas.

    replies(4): >>45268264 #>>45268485 #>>45268512 #>>45274413 #
    1. im3w1l ◴[] No.45268264[source]
    Why wouldn't it be acceptable to ship? This is how everything works in C++. You always have to mind your references.
    replies(2): >>45268326 #>>45269016 #
    2. sunshowers ◴[] No.45268326[source]
    Exactly! This is my problem with the C++ community's culture. At no point is safety put first.
    replies(2): >>45268649 #>>45268867 #
    3. Yoric ◴[] No.45268649[source]
    Yeah, it's great that the C++ community starts to take safety in consideration, but one has to admit that safety always comes as the last priority, behind compatibility, convenience, performance and expressiveness.
    4. StillBored ◴[] No.45268867[source]
    Its worse. The day I discovered that std::array is explicitly not range/bounds checked by default I really wanted to write some angry letters to the committee members.

    Why go through all the trouble to make a better array, and require the user to call a special .at() function to get range checking rather than the other way around? I promptly went into my standard library and reversed that decision because if i'm going to the trouble to use a C++ array class, it better damn well give me a tiny bit of additional protection. The .at() call should have been the version that reverted to C array behavior without the bounds checking.

    And its these kinds of decisions repeated over and over. I get its a committee. Some of the decisions won't be the best, but by 2011 everyone had already been complaining about memory safety issues for 15+ years and there wasn't enough politics on the comittee to recognize that a big reason for using C++ over C was the ability of the language to protect some of the sharper edges of C?

    replies(3): >>45271657 #>>45271670 #>>45271759 #
    5. BeetleB ◴[] No.45269016[source]
    This is like writing an article entitled "In Defense of Guns", and then belittling the fact it can kill by saying "You always have to track your bullets".[1]

    [1] Not me making this up - I started getting into guns and this is what people say.

    replies(1): >>45273610 #
    6. mbac32768 ◴[] No.45271657{3}[source]
    Good news! Contracts were approved for c++26 so they should be in compilers by like 2031 and then you can configure arrays and vectors to abort on out-of-bounds errors instead of corrupting your program.

    Let no one accuse the committee of being unresponsive.

    7. fluoridation ◴[] No.45271670{3}[source]
    >Why go through all the trouble to make a better array, and require the user to call a special .at() function to get range checking rather than the other way around?

    Because the point was not to make an array type that's safe by default, but rather to make an array type that behaves like an object, and can be returned, copied, etc. I mean, I agree with you, I think operator[]() should range-check by default, but you're simply misunderstanding the rationale for the class.

    replies(1): >>45277847 #
    8. TinkersW ◴[] No.45271759{3}[source]
    std::array [] is checked if you have the appropriate build settings toggled, which of course you should during development.

    The same applies to many of the other baseless complaints I'm seeing here, learn to use your tools fools.

    9. im3w1l ◴[] No.45273610[source]
    To me it's as if someone releases a new gun model and people single that gun out and complain that if you shoot someone with it they may die. Like it's a critique of guns as a concept not of that particular one.

    In a complete tangent I think that "smart guns" that only let you shoot bullseye targets, animals and designated un-persons are not far off.

    10. StillBored ◴[] No.45277847{4}[source]
    Which goes to the GP's point, which is that security and robustness are not on the radar.

    And my point in providing a concrete example, where a decision was made to prioritize unsafe behavior in a known problematic area, when they could just as well have made a half dozen other decisions which would have solved a long standing problem rather than just perpetuating it with some new syntactic sugar.

    replies(1): >>45278081 #
    11. fluoridation ◴[] No.45278081{5}[source]
    I didn't dispute that, I was simply addressing the point about std::array. The class is not meant to be "arrays, but as good as they could possibly be". It's "arrays, but as first-class objects instead of weird language constructs".

    That said, making std::array::operator[]() range-checking would have been worse, because it would have been the only overload that did that. Could they have, in the same version, made all the overloads range-checking? Maybe, I don't know.