3 ms·
You can use malloc/free and RAII if you prefer it to automatic memory management. It's nice to have a choice. Having a high performance GC requires inserting w
by WalterBright 5y ago
You can use malloc/free and RAII if you prefer it to automatic memory management. It's nice to have a choice.
Having a high performance GC requires inserting write gates into the executable code. This is only worthwhile if GC is the only allocation strategy the language uses. As the GC is optional in D, and is not actually used that much it is not worth the general slowdown of the write gates.
> you'd hardly find a mature or reliable codebase written by a team of professionals using hacks like these.
I wouldn't be so sure, as mature and reliable codebases use the hackish unhygienic preprocessor macros every day :-)
- spijdar 5y ago> I wouldn't be so sure, as mature and reliable codebases use the hackish unhygienic preprocessor macros every day :-) Isn't it funny how the most mature software (and often by extension, "reliable" e.g. have been in use the longest with the most bugs beaten out by years of hacks and patches) seem so far away from "best practices"? I've always wondered about the root of this. Are programmers trudging along using "brute force" more effective, or is it just pure survivor bias on projects/products that people didn't give up on?
- nicwilson 5y agoProbably because best practice and changes at a faster rate than coding standards for old codebases. I suspect this observation exhibits some survivorship bias as well, then again you get things like OpenSSL...
- tzs 5y agoIt's probably useful to distinguish between two kinds of "best practices". One kind is things dealing directly with the underlying thing you are trying to accomplish with a program. Say it is a program doing some sort of physics or engineering calculation that at some point needs to add a bunch of floating point numbers. Best practice might include using something like Kahan summation [1] to reduce the error. I'd expect to see that kind of best practice in both mature programs and new programs because it is something that directly relates to what the program actually is trying to do. The other kind of "best practices" are those concerning the environment and practice of programming itself. Many of those seem designed to deal with the case where there is a lot of turnover in who is working on the software. People join a project, work on it for a year or two, and then move off to something else. You adopt these best practices so that new people will be productive faster so you can get useful work out of them before they leave. So these best practices tend to change as fad and fashion come and go. The mature software that has been in use for a very long time I think is more likely to have a much higher percentage of its work done by people who have been working on it long term, and have a lower turnover, and when someone new does come on they stay longer. They don't need to have their best practices match the fad and fashion best practices used by the shorter term projects. [1] https://en.wikipedia.org/wiki/Kahan_summation_algorithm https://en.wikipedia.org/wiki/Kahan_summation_algorithm
- cyber_kinetist 5y agoIs it possible to use the standard library without the GC though? It would be nice to have at least some string/container/IO libraries that are designed to be used ergonomically without the GC.
- WalterBright 5y agoYes. Not much of the library uses the GC.
- mhh__ 5y agoLarge amounts of the standard library are deliberately lazy so don't actually allocate at all. Exceptions however do end up using the GC, but there is a flag to work around that. Libraries that don't use it at all are available. At work we have a large library, being a hedge fund, that must be consumed from Excel. This means it cannot use the GC because [reasons], it's not a particularly big issue. Garbage collection is not a bug, by the way. It's one of biggest productivity wins D has over C++. Performance is often as near as makes no difference identical, only you now eliminate all memory safety issues without thinking about lifetimes. D also has very nice composable allocators in the standard library