Reply to post: Re: Googley

Google says Android runs better when covered in Rust

T. F. M. Reader

Re: Googley

I don't quite see where the style document prohibits RAII, but I only gave it a quick look. Mentioning RAII is very much on topic though.

In my rather long career of writing C and C++ code I never found safe usage of memory difficult. All you need is a bit of discipline. In C++ RAII is an important technique to promote such discipline. C/C++ don't prevent you from being careless, but this does not mean you should be. It's not difficult to be careful at all, though it does require a bit of effort to think of ownership and the full lifecycle of your objects. That, incidentally, is crucial for lots of other reasons beside memory safety.

All the talk of the advantages of "memory-safe languages" is basically "elf'n'safety" cushioning, a.k.a. not trusting engineers to be adults. There may be reasons for that (and yes, I've seen rather spectacular examples), but it does not address the root cause. I have no hard data, but I strongly suspect that many people who blame C++ for the fact that they never bothered to learn to use it effectively won't be effective, and will write dangerous code, in other languages as well. On occasion they will write so much code to work around language restrictions to do something fairly simple that the result will be dangerous just because of that. Some other people can use C++ effectively themselves, but blame it for their lack of trust in others whom they refuse to treat as adults who can be educated.

Some parts of Google's style guide certainly smell like not trusting programmers. While I didn't find a prohibition on RAII, the prohibition on forward declarations is a case in point. I would rather encourage Google programmers to use forward declarations as much as possible, to loosen compile time dependencies. I imagine Google may have a few large projects where this will be particularly important. The main justification of the prohibition is based on a contrived example involving ambiguous code. Well, C++ allows you to write ambiguous code almost as a matter of philosophy, but it doesn't mean you should. I looked for a "don't write ambiguous code" style guideline, but didn't find it. The last argument in that section looks downright weird as well. If Google engineers write code like that they should think of ways to address the real issue rather than blame the tools.

Disclaimer: the above must not be construed as implied criticism of Rust.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon