5 ms·
This article has a hint of "C-style memory management is good for you"—implying that you might want to write in something like JS and then go back and write in
by pcwalton 11y ago
This article has a hint of "C-style memory management is good for you"—implying that you might want to write in something like JS and then go back and write in C++ in order to "tighten the screws". I think that's wrong—by and large, it's been a very good thing that people have stopped caring about memory management in production. That's because correct C-style memory management never† scales up to large software projects in a way that doesn't result in crashes and, worse, vulnerabilities.
So, yes, we've traded performance for automatic memory management. But we've gained reliability, safety, and security. For the vast majority of server-side apps, that's a worthwhile trade.
† Unless you use the processes like NASA and the like use, which for most apps are infeasible from a cost point of view.
- ArkyBeagle 11y agoIt scales, and you don't have to use NASA-like process. The article fairly clearly says that making this work is a learned skill. And it is. If course it's possible to write stuff using manual memory management in a manner such that it's nearly impossible to do well. Doctor, doctor, it hurts when I do that... I wrote a 'C' based thing around 2012 that: - is about 50,000 lines; 50ish by 1000ish lines. - uses no dynamic memory. - does very "dynamic memory" things. Each type/shape/class has its own statically allocated 'C' array of structs that is declared to worst-case, and has a "new". Behind the "new" is a lot of behavior, including pointing to other such things/objects. A set of "delete" operations would be also relatively easy. But because it's an array and it is in 'C', this is relatively little code. Yes, there is duplication involved but the object creation code is probably 20% of the total thing and each object creation is darn near provably correct. It's built on RAII principles ( perhaps foolishly, since there's no deletion ). Dependencies between objects are completely explicit in the code. Object creation must be in the correct order to manage dependencies The magic happens because scripts* are used to create all things, once at startup. it also helps because by its very nature, the system is fully serialized - after a creation script, the state of the tables of objects can be written to a text file. *scripts are, in this case nothing but sequences of verbs which send text files full of XML to a service at a TCP port. It could have been JSON or attribute-value pairs, but instead it's XML. I do take extra care to make a very comprehensive test suite or it. but since the allocation scheme is 1) cheap and 2) fully exposed as state in the system, there's nothing actually opaque about it. I don't have to do "trust falls" with a garbage collector or even the heap. You can't have a malloc() or new() failure - it'll violate a constraint and quit/exit(). You then make the table larger. From the frame of reference of the other objects, it's abstracted and opaque - after the initial setup. From the "scripting" interface, it's fully transparent.
- pcwalton 11y agoI'm willing to believe you always write flawless C. I've never seen a large C or C++ codebase written by a large team that didn't have serious memory management problems.
- ArkyBeagle 11y agoI know. And it's stupid to think I always write flawless 'C'. I just know how; doesn't mean it's always correct. I just smell a lot of despair in these threads.
- nickpsecurity 11y agoI've seen this post many times under different names for the authors and projects. Later on, a CVE or bug report shows up with the project's name but a different author. Because the person who created the code just couldn't break their own code like someone else who wasn't mentally attached to it. What you're likely a victim of is the Dunning-Kruger effect or Schneier's Law depending on which you prefer: https://www.schneier.com/blog/archives/2011/04/schneiers_law.html https://www.schneier.com/blog/archives/2011/04/schneiers_law... On the other hand, you could've in fact designed something as good as you claimed. In that case, I seriously suggest you publish your methods in full for peer review as they could save millions spent by the likes of NASA, seL4 project, and so on. Any method that might hit full correctness with just basic coding or whatever is a potential game-changer. Very exciting stuff.
- ArkyBeagle 11y agoDunning-Kruger is a very distinct possibility :) Your handle includes the word "security"; I don't claim any powers that way beyond "don't allow memory overwrites" and "airgapping good." I doubt anybody is remotely interested in this - the problem domains are pretty boring and highly constrained. These tend to be realtime embedded ( both soft and hard realtime ). It seems wildly inappropriate for gaming, graphics or Web stuff. Perhaps I'm wrong there; not really all that clued in. There is much less to this than you might imagine. The problem is that a book is a team effort, and I have no idea who to bother with it. Not asking for a volunteer here. For an idea of the basic philosophy, it might be worth looking at Bruce Powell Douglass.
- narag 11y agoUnless you use the processes like NASA and the like use, which for most apps are infeasible from a cost point of view. LOL. I have to ask: do you "know" this from experience or someone else told you? Thousands of applications were made not so long ago with manual memory management. Many of them are still the most used desktop apps in the world. Methods to secure them are not rocket science, really. I would gladly concede it's cheaper to do CRUD apps with GC, but you're going hyperbolic with NASA ;-)
- prodigal_erik 11y ago>Thousands of applications were made not so long ago with manual memory management. And pretty much all of them are unreliable garbage that we as an industry should have been too embarrassed to ship.
- Jare 11y agoAs opposed to the slow and laggy garbage we as an industry should be too embarrassed to ship today. (of course, vulnerabilities and unreliability in those apps came from more places than just manual memory management, just as today's slowness comes from more places than the GC)
- narag 11y agoAnd pretty much all of them are unreliable garbage... So you have experienced thousands of unreliable garbage apps. I feel really sorry for you. My experience has been the opposite: lots of wonderful and reliable programs. And when I found one that wasn't good, I stopped using it and replaced it with a better one. I mean as a user. As a programmer I've seen all kind of programs, from "critical mission" to "quick hack" and from excelent to unreliable garbage. And you know what? It's not language features but ludicrous incompetence what makes an app unreliable garbage. There are programmers out there that can make unreliable garbage in any language. The "secret" to make some app reliable is not reserved to NASA and the like. Follow two simple patterns: 1. For every user action, validate input, try executing the code, catch the occasional exception and show an error message. 2. For every resource, allocate, try{ using it } finally { release it } Put each of these skeletons in a function or method, so the resource is a local variable (no colateral effects) and it's easy to debug. That's all. Well, also: don't be too "creative" unless you know what you're doing (most times you don't). I'm fifty-something, spent a lot of painful time mechanically applying that recipes to rotten codebases, and when I read the kind of criticisms you made I assume they come from people too young to have real world experience on what they're criticizing. The alternative is worse: to be the kind of people that created that rot and then blamed the language. Just in case: I don't believe that manual memory languages are "better". I love Python and (most of the time) JavaScript.
- nickpsecurity 11y agoHigh assurance niche taught us both the methods you mentioned (eg NASA) and why this comment is correct. For this one, it's because C and C++ codebases often ignore the root cause of so many vulnerabilities in their very design. Too much IT fixes symptoms instead of root cause. That highly assured systems needed immunity to many issues meant the root causes must be prevented. That eliminates use of C and C++ where possible. Such thinking is why MULTICS used PL/0, why GEMSOS used Pascal, why Wirth used Modula and Oberon for safer OS's, and why Altran-Praxis used Ada/SPARK for a CA. Results were better than C (or predecessor) every time. Deal with root cause, symptoms fade away naturally. Solutions like Eiffel and Rust take that philosophy into modern IT.