all 14 comments

sorted by: hot top controversial new old
[–] 34 points 1 year ago (11 children)

I don't get it. What's wrong with constexpr? It's vastly preferable to macros due to type safety, and const due to compile-time optimization.

  • source
  • hideshow 11 child comments
  • [–] 14 points 1 year ago (10 children)

    I don't get it either. OP might be angry at compile time (Couldn't be worse than rust)

  • source
  • parent
  • hideshow 10 child comments
  • [–] 6 points 1 year ago (3 children)

    Rust doesn't allow type inference in function signatures, c++ does with auto. IIRC, they recommended against using it, because of -you guessed it- compile time.

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

    Not fair to compare it to the very immature Rust.

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

    I do love rust. But I do like making fun of it too.

    Although I don't see how rust is immature? Unless I missed the joke?

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

    It's very young for a programming language, and is still rapidly evolving.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 2 points 1 year ago

    It's more than 10 years old. It has stable syntax, big standard library, big library ecosystem, plenty of rust programs already in production.

    If by "evolving" you mean "changing", I don't think that is an issue at all. At most, they add features. They don't change or remove. And with the editions system, it should be no issue.

    If by "evolving" you mean "improving", then I don't see how that could ever be an issue.

  • source
  • parent
  • [–] 4 points 1 year ago*

    Wdym? They're so good they even got backported to C in C23

    You know how often C gets big features like that? I mean to get auto they had to basically deprecate a keyword (well, sort of)

  • source
  • [–] 1 point 1 year ago*

    I much prefer for (auto map : hashMaps) ... over for(unordered_map<string, unordered_set<string>> map : hashMaps) though. Shame they didn't name it "var" like in many other languages, auto just reminds me of cars.

  • source
  • 8 comments in c/programmerhumor@lemmy.ml view that post
    [–] 11 points 1 year ago (6 children)

    What's wrong with constexpr?

  • source
  • hideshow 6 child comments
  • [–] [S] 10 points 1 year ago* (5 children)

    Back when I made this, GCC/clang were crashing left and right while compiling my project because of constexpr and auto usage with nested lambdas. It got worse with every template being evaluated until the compiler and my IDE started crashing.

    I was making a react-like UI component library with all the new bells and whistles of modern C++. It was fun at first then the issues cropped up and it kinda killed my passion for the language and drove me away entirely.

    Not sure about its state nowadays though.

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

    I see. I think auto gets overused a lot by people just being lazy about writing out the full type, but constexpr is good practice in my opinion. Never had a compiler issue with them, but then I don't think I've ever used a nested lambda either.

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

    I really like C++ (I know, shoot me), and I think auto should be avoided at (almost) all costs.

    One of the things I love about a language like C++ is that I can take one glance at the code and immediately know what types I'm working with. auto takes that away while adding almost no benefit outside of a little convenience while writing.

    If I'm working with some very big template type that I don't want to write out, 99/100 times I'll just have a using somewhere to make it more concise. Hell, I'll have using vectord = std::vector<double> if I'm using a lot of them, because I think it makes the code more readable. Just don't throw auto at me.

    Of course, the worst thing ever (which I've seen far too often) is the use of auto in examples in documentation. Fucking hell! I'm reading the docs because I don't know the library well! When you first bother to write examples, at least let me know the return type without needing to dig through your source code!

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

    Thanks, that was a good read :)

    However, my impression is that he's largely using the existence of templates and polymorphism as arguments that "we don't really care about type". I disagree: A template is essentially a generic type description that says something about what types are acceptable. When working with something polymorphic, I'll prefer ParentClass&, to indicate what kind of interface I'm working with.

    Sure, it can be very useful to hide exact type information in order to generalise the code, but I think that's a weak argument for hiding all type information by default, which is what auto does.

  • source
  • parent
  • hideshow 1 child comment
  • [+] 1 point 1 year ago (1 child)
  • [–] 1 point 1 year ago*

    Similarly, what would you gain by saying uint32_t const* x = my_var.get<uint32_t>();

    To be frank: You gain the information that MyConcreteType::get<uint32_t> returns a uint32_t, which I otherwise couldn't infer from the docs. Of course, I could assume it, based on the template parameter, but I don't want to go around assuming a bunch of stuff in order to read docs.

    Take an example like auto x = my_var.to_reduced_form(), it's very clear that x is the "reduced form" of my_var, which could be meaningful in itself, but what type is it? I need to know that if I want to do anything with x. Can I do x += 1? If I do, will that modify my_var? Let's say I want to make a vector of whatever to_reduced_form returns... and so on.

    All these questions are very easily answered by MyConcreteType x = my_var.to_reduced_form(). Now I immediately know that everything I can do with my_var, I can also do with x. This makes me happy, because I need to do less digging, and the code becomes clearer to read.

  • source
  • parent
  • load more comments (-1 replies)
  • load more comments (-1 replies)
  • [–] [S] 2 points 1 year ago* (last edited 1 year ago)

    The problem is that lambdas with a capture aren’t strongly typed are uniquely typed, so you have to use decltype/auto. And if you pass such a lambda to a function you’ll have to use auto as well.

    If you write a lambda with a capture that calls itself recursively you’ll have to pass it to itself as an auto argument as part of the call signature.

    I think this article explains it better: https://artificial-mind.net/blog/2020/09/12/recursive-lambdas

    Edit: fixed wrong terminology

  • source
  • parent
  • [–] 3 points 1 year ago

    Integrated divinity environment

  • source