Is my fear of C/++ justified?, -cursed `e` coding-, The Engima of Segmentation Fault

all 35 comments

sorted by: hot top controversial new old
[–] 93 points 1 week ago (20 children)

Less fucked-up than Javascript.

  • source
  • hideshow 20 child comments
  • [–] 45 points 1 week ago (18 children)

    This diagram is nonsense. JavaScript programmers know to simply never use == but to use === instead. Half of JavaScript is like this. Oh, there's a feature, but it behaves in a super weird way so we don't use it to avoid the weirdness.

  • source
  • parent
  • hideshow 18 child comments
  • [–] 13 points 1 week ago (5 children)

    The recommended ESLint rules catch most of the bad stuff, and these days this is all you need in your ESLint config to enable them:

    import {defineConfig} from 'eslint/config';
    import js from '@eslint/js' 
    
    export default defineConfig([
      js.configs.recommended,
    ]; 
    

    There's one use case where == is still commonly used: == null matches both null and undefined. Lint rules that block == usually allows the null case as an exception.

  • source
  • parent
  • hideshow 5 child comments
  • [–] 4 points 1 week ago (3 children)

    I wonder how much bandwidth is wasted on the extra =, since it survives minification 😅

  • source
  • parent
  • hideshow 3 child comments
  • [–] 7 points 1 week ago

    But if every single comparison used in a file is a triple =, then any compression algo worth its weight in salt will compress that bloat away during transmission

    The real issue is all the precious precious RAM those extra = use on the client device once received and unpacked!

  • source
  • parent
  • [–] 3 points 1 week ago (1 child)

    Gzip (any properly configured static server will serve compressed assets) probably compresses them down so probably a single extra byte per file

  • source
  • parent
  • hideshow 1 child comment
  • [–] 3 points 1 week ago*

    Gzip is old-school. The majority of modern sites use Brotli now. It's slower to compress, but that's not normally an issue for static resources (CSS, JS, etc) because they can be pre-compressed during the build and the web server serves the pre-compressed files instead of dynamically compressing them.

  • source
  • parent
  • [–] 12 points 1 week ago (3 children)

    As someone trying to learn Javascript, it just makes me mad that at this garbage heap of a language is so widely used.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 3 points 1 week ago (2 children)

    The problem is that you can't break compatibility.

    Only in some exceptional cases. 🙃

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 1 week ago (4 children)

    == has never, ever caused me a single issue. Parsing all server input with type-safe schemas makes sure that where I expect a string, I get a string; where I expect a number, I get a number. Bad data must result in an error before it reaches logic.

  • source
  • parent
  • hideshow 4 child comments
  • [–] 14 points 1 week ago (3 children)

    "I have no problem living in a house of cards as I make sure to never bump against the walls."

  • source
  • parent
  • hideshow 3 child comments
  • [–] 3 points 6 days ago

    I wonder how many millions of programmer man-hours have been wasted working around JavaScript's design mistakes that could've been saved simply by putting Scheme or Python (which were actually being considered) in the browser instead.

  • source
  • parent
  • [–] 1 point 6 days ago (1 child)

    Opposite, living in a house of cards is when you blindly trust data that comes from user. Regardless of the language. eqeqeq isn't in the recommended linting presets because if you end up needing it, you're probably already in big trouble because of insecure software design.

  • source
  • parent
  • hideshow 1 child comment
  • When I had to use JS I wrote JS 1.2 because why not. Fun how I had strings of numbers instead of actual numbers in some for loops, yet it all sort of functioned until something didn't. I then decided to add Number() to random values just in case.

  • source
  • parent
  • [–] 26 points 1 week ago* (1 child)

    For those needing help the code is:

    using namespace std;
    int main()
    {
    while (true)
    {
    cout << 'e';
    cerr << 'e';
    }
    return 'e';
    }
    

    Anyway, my opinion: c is the best thing to ever exist, and c++ is evil

  • source
  • hideshow 1 child comment
  • [–] 4 points 1 week ago

    Yeah. I kept reducing my sane "C with classes" subset until I just ended up back writing C99 too, and just about the only difference that made for my use case was better compilation times. If I ever need more than that, I'll likely reach for Zig or C3 before C++.

  • source
  • parent
  • [–] 15 points 1 week ago

    No, the C++ should fear you!

  • source
  • [–] 28 points 1 week ago (1 child)

    No. I don't find it a particularly nice language to work with, but there's no reason to fear it. Just make sure you know what you're doing if/when you use it.

  • source
  • hideshow 1 child comment
  • [–] 11 points 1 week ago

    Of C? No

    Of C++? Yes

  • source
  • [–] 16 points 1 week ago (5 children)

    If anyone is starting to learn C++, make sure to use books or training materials based on C++11 or later.

  • source
  • hideshow 5 child comments
  • [–] 9 points 1 week ago (4 children)

    Even C++11 is pretty old. I would recommend at least C++17

  • source
  • parent
  • hideshow 4 child comments
  • [–] 5 points 1 week ago (3 children)

    As someone who last touched any C++ books when C++11 was very new and has only written like 20-30 lines of non-tutorial C++ since then, what are some significant changes to the language that I should be aware of if I wanted to give it a try now?

  • source
  • parent
  • hideshow 3 child comments
  • [–] 11 points 1 week ago (1 child)

    A few examples:

    • CTAD: Instead of std::pair<int, int> myPair{ 1, 2 }, you just write std::pair myPair{ 1, 2 }
    • std::optional, std::variant and std::any
    • Guaranteed copy elision in some cases, making it more feasible to apply the rule of 5 everywhere
    • Attributes like [[nodiscard]] (compiler warning if an object or return value is discarded) and [[fallthrough]] (suppress a switch fallthrough warning)
    • Generic lambdas ([](auto it){ /* do something */ })
    • std::string_view, which is much safer as a function parameter than const char*
  • source
  • parent
  • hideshow 1 child comment