News for hackers. Stuff that matters.
Re:Care is needed to use C++ std:optional with non-trivial o... by jstimpfle on Friday January 13, 2023 @01:26PM (#34371814)
Have you made any effort trying to understand what I'm saying? Because you're almost making all my points. How does your definition of "in plain sight" not make a difference between "I can see which functions are called from a piece of code printed out on paper" and "I need to look up the type to see if there's an overloaded operator or method or a non-default constructor/destructor, and to get there I might need an advanced code browser, probably based on compiler infrastructure -- and I must like actually hit go-to-definition to navigate to the site"?

> The fun part is that you can still use plain old objects if you really really want to deal with C-Strings.

It's easy to see you've never seriously programmed C, because strings are like 0.1% of my concerns. They just work where they have to, and otherwise string manipulation is 99% done in places and where a C programmer wouldn't even do it.

> The fun part is that you can still use plain old objects if you really really want to deal with C-Strings.

yawn... But how exactly do I know that anything is a POD structure? And if everything is, so I can assume that anything is, where's all the advantages gone?

Re:Care is needed to use C++ std:optional with non-trivial o... by josefx on Friday January 13, 2023 @08:13PM (#34376169)
> and I must like actually hit go-to-definition to navigate to the site"?

If you feel like it is too much effort you can just not do it? I can't remember the last time I checked, ctors and dtors should do basic setup and teardown. Counterquestion, how do you know a specific C struct wont overflow your stack without looking? We are assuming that everything important is visible inline, right?

> Strings are just buffers like any other, nothing special. It's easy to see you've never seriously programmed C

I have seen way too many hand rolled parsers on C, they may have been only 0.1% of the total code but they amounted for at least 50% of the bugs, along with the constant manual memory management and badly initialized variables.

> If string manipulation in C becomes annoying, you should have written a Python script.

That is an interesting statement to make for someone who claims to almost never write C string handling code. As someone who has to deal with strings, std::string is simply supperior in most cases so I prefer to use C++ where I have the choice.

> where's all the advantages gone?

That was in response to the "locked into a framework" claim.

Re:Care is needed to use C++ std:optional with non-trivial o... by jstimpfle on Saturday January 14, 2023 @05:27AM (#34379084)
> I have seen way too many hand rolled parsers on C, they may have been only 0.1% of the total code but they amounted for at least 50% of the bugs, along with the constant manual memory management and badly initialized variables.

It's all about creating the right abstractions. A parser is not about string handling! The typical (lexical) parser scans input from left to right and builds up (identifier and string literal) tokens by appending. So basically, you need a function input_read_char() and string_push_char(). You're done, there is no other string indexing or string allocation in a parser.

> That is an interesting statement to make for someone who claims to almost never write C string handling code

What I want to say is that if you're dealing with a lot of strings, you're working in a high-level glue domain. And there is no point in using either C or C++. You're probably making a web API, or an ad-hoc throwaway thing. It need not be python, possibly it should even be a shell or awk script. I write lots of those, typically they live and die in my command-line history, or as a 5-line script in my /tmp folder. Using C++ for these tasks would slow me down by 10x.