background preloader

Google

Facebook Twitter

Code Style Guidelines for Contributors. The rules below are not guidelines or recommendations, but strict rules. Contributions to Android generally will not be accepted if they do not adhere to these rules. Not all existing code follows these rules, but all new code is expected to. Java Language Rules We follow standard Java coding conventions. We add a few rules: Don't Ignore Exceptions Sometimes it is tempting to write code that completely ignores an exception like this: void setServerPort(String value) { try { serverPort = Integer.parseInt(value); } catch (NumberFormatException e) { }} You must never do this. Anytime somebody has an empty catch clause they should have a creepy feeling. Acceptable alternatives (in order of preference) are: Don't Catch Generic Exception Sometimes it is tempting to be lazy when catching exceptions and do something like this: You should not do this.

Alternatives to catching generic Exception: Catch each exception separately as separate catch blocks after a single try. Don't Use Finalizers import foo or and. Code Conventions for the Java Programming Language: Contents. Google C++ Style Guide. Definition: Streams are a replacement for printf() and scanf(). Pros: With streams, you do not need to know the type of the object you are printing. You do not have problems with format strings not matching the argument list. (Though with gcc, you do not have that problem with printf either.) Streams have automatic constructors and destructors that open and close the relevant files. Cons: Streams make it difficult to do functionality like pread(). Decision: Do not use streams, except where required by a logging interface. There are various pros and cons to using streams, but in this case, as in many other cases, consistency trumps the debate.

Extended Discussion There has been debate on this issue, so this explains the reasoning in greater depth. Proponents of streams have argued that streams are the obvious choice of the two, but the issue is not actually so clear. Cout << this; // Prints the address cout << *this; // Prints the contents. Get that job at Google. I've been meaning to write up some tips on interviewing at Google for a good long time now. I keep putting it off, though, because it's going to make you mad. Probably. For some statistical definition of "you", it's very likely to upset you. Why? Because... well, here, I wrote a little ditty about it: Hey man, I don't know that stuffStevey's talking abooooooutIf my boss thinks it's importantI'm gonna get fiiiiiiiiiiredOooh yeah baaaby baaaay-beeeeee.... I didn't realize this was such a typical reaction back when I first started writing about interviewing, way back at other companies.

See, it goes like this: Me: blah blah blah, I like asking question X in interviews, blah blah blah... You: Question X? Me: So in conclusion, blah blah... huh? You: Aaaaaaauuuggh!!! Me: That's it. It doesn't matter what X is, either. And then nobody actually does anything, because we're all afraid of getting stabbed violently by People Who Don't Know X. Caveats and Disclaimers This blog is not endorsed by Google. Styleguide - Style guides for Google-originated open-source projects.