Live data from Hacker News

Writing New System Software

borud.no

141–150 of 158 posts

Re: Writing New System Software

#141
post #112

Earlier quoted context omitted.

> unlike everybody else, they actually have the combination of wisdom, skills, and discipline to not fall into this trap I'm constantly reminded of the NPC in Half Life 1 who says something like "Take me with you, I'm the one man who knows everything!" I know many programmers who think their one way of writing C++ will not cause any issues. None of them are 100% correct as I can always find a bug that a higher level…

And, you only know programmers who know no more than you.

This isn't a "know more" or "know less" than me thing. This is being-a-human thing. I've never written a large amount of C++ without a similar mistake creeping in. Humans make mistakes.

Re: Writing New System Software

#142

Earlier quoted context omitted.

Never contain programs so few bugs, as when no debugging tools are available - Niklaus Wirth Fuzzers and testing can detect bugs but I don't see how they can make a contribution to a reasonable software structure (I believe that bad structure is the prime cause of bugs).

The other tools being talked about are static analysis tools or runtime instrumentation both designed specifically to try to find bad memory use patterns. I don’t mean this in a rude way, but I don’t care what you believe, because the thing I care about is evidence. If you have some actual evidence for your claim, I would be interested. (I also believe there can be improvements from better code structure in a rewrite…

I think the burden is on you to show how fuzzers can show bad code structure and suggest better organization, instead of just finding bugs.

I would be interested what is the evidence that you're talking about. If my experience doesn't speak to your experience, so be it.

Re: Writing New System Software

#143
post #80

Earlier quoted context omitted.

I do not have single explicit memory management call in my product of very decent size written in modern C++. So no , I have no idea where did you fish your "evidence" from.

I don’t understand what you’re trying to say? Do you mean that you don’t call malloc? Because that is totally not the point. For example, you could create a new object, pass a reference to it to some function that stores it in a hash table, reach the end of your function where the object is automatically deleted, and then have something try to read the object out of the hashtable. Nowhere do you need to call malloc o…

In your example, storing a pointer to an item in the hashtable in a context that potentially outlives the hashtable items could qualify as "bad memory management". Long-lived cross-context pointers in general I frown upon (most pointers I use have their lifetime bound to a function call), although there are no hard rules of course, and you have a point in that these errors are not detected by most type systems or probably even static analyzers. Well, it's still a smell, because we know these types of problems and we know many ways to avoid most of them. I'm saying this all to support the claim that memory management needn't be hard, not to claim that there aren't any exploitable memory bugs out there, which would be an insane claim.

Re: Writing New System Software

#144
post #131
post #119

Earlier quoted context omitted.

Yes. Legacy in every sense, including "abandonware".

Educate yourself on Android source code. You can even start by the new entries related to Rust. https://source.android.com/setup/build/rust/building-rust-mo...

Why would I care about anything on that page?

I have no need to read hype about Rust, regardless of where it might run. And, I have no desire to build Android apps, in any language.

Re: Writing New System Software

#146
post #105

Earlier quoted context omitted.

> Basically, non-local control flow is dangerous (...) This is the crux of the error you're making. Exceptions are not about control flow. Exceptions are a transparent and clean way to handle exceptional events. Exceptions are not intended to, say, handle the status code of a HTTP requests. Exceptions are intended to handle exceptional and potentially unrecoverable errors in a safe and controlled manner, such as fail…

> Exceptions are a transparent and clean way to handle exceptional events. I'd sum up this argument as: Exceptions are syntax sugar that allow callers of a function to ignore the error cases of something they are calling and depend on something that calls into them to handle the error case. An example: void HandleRequest(const Request &request, KV &kv) { ... kv.set("a", 10); ... } In this example KV.set will raise an…

No.

Exceptions are a way to ensure that failures are directed immediately to a place designated to deal with such a failure.

They are, in particular, not any sort of "syntax sugar", unlike "?" in certain other languages, or your StatusOr thing. A function that throws an exception does not, in any sense, return to its caller. It does not construct any sort of return value. It does not consult the stack to see where it came from and resume running there.

And, exceptions are totally auditable. There is never any hint of ambiguity or uncertainty about where an exception will take you.

You can be confident that if a function was thrown from, it was because it could not perform the requested action. And, you can be confident that if an exception was not thrown the function called satisfied whatever postconditions it promised.

So, you don't need to know if a function might throw. You may instead assume any function might throw. If it doesn't, then it has satisfied its documented postconditions. Your obligation is only to ensure that destructors clean up any intermediate state on the way out. These identical destructors get exercised every time through the code, so are exercised frequently.

Error-handling code at places where the error cannot actually be dealt with properly, that just tries to propagate the failure up the call chain, is typically not well tested, and often cannot even be triggered in testing.

Re: Writing New System Software

#147
post #102

Earlier quoted context omitted.

> 2. I basically don’t believe that memory management is not hard. If you try to write Java in C++ then probably the result is verbose. With some practice though, memory management needn't be hard - if memory management is hard that hints lack of organization. Smaller, script-like programs where there is no place for large-scale organization, are a different story (especially in C and C-like C++) and GC'ed languaged…

Also known as MFC, PowerPlant, Turbo Vision, CSet++, Taligent, OWL, ATL, Symbian, Motif++,... all on average 5 years old when Java came into the world.

Well, they knew how to write Java in C++ even before Java came out...

Re: Writing New System Software

#148
post #134
post #117

Earlier quoted context omitted.

Measuring overhead of debug builds is a rookie mistake.

I'm not talking about code performance, I'm talking about human time of having to step through extra things while using a debugger to work out what's going on.

OK. I rely on "fin" a fair bit, at such times.

Re: Writing New System Software

#149
post #113

Earlier quoted context omitted.

Chrome is not coded in anything even slightly resembling modern C++. So, no conclusions about modern C++ can be drawn from it. Except, maybe, that it takes a long time to modernize old code.

I’m merely trying to respond to a comment that claims that chrome should have few memory management bugs. I don’t really have an opinion about whether it is modern. I don’t care enough about the distinction between C++ styles to know where to find evidence of the rate of memory management problems in modern C++ codebases. Perhaps I would just find that the definition of modern C++ is ‘the style of C++ where you don’t…

We all know Chrome is buggy as hell, and coded in the crabbed Google language subset.

You may read in numerous places what modern C(+ code looks like. There is no need to guess.

Re: Writing New System Software

#150
post #112

Earlier quoted context omitted.

And, you only know programmers who know no more than you.

This isn't a "know more" or "know less" than me thing. This is being-a-human thing. I've never written a large amount of C++ without a similar mistake creeping in. Humans make mistakes.

There are people who say engineers are not human. But they are just more careful.
Post reply on HN