2

I'd like to have one coding style across multiple languages. Can anyone provide a link to code that is styled nicely, that I can use for each language?

It is easiest to just look at an example rather than read for the multitude of cases that arise.

3
  • 1
    You could read code complete cc2e.com Commented Nov 7, 2011 at 20:23
  • Style guides read like dictionaries...is there just a simple example to well formatted say C++ code which I can infer the rest from? Commented Nov 7, 2011 at 21:47
  • You could do some very very generic things and stick to that. For example, indent one tab for every increase in scope depth, format all if statements the same way, use braces consistently on loops and/or functions, decide how you will write multi-line concatenations and long arrays or function signatures Commented Aug 16, 2021 at 11:03

5 Answers 5

7

There's not a chance in hell. There's no such thing as code that's styled nicely for C and C++, let alone across the other languages too. You haven't exactly picked C# and Java here in terms of language similarities.

Edit: Do not, ever, use the Google Style Guide. It is horrendous and terrible. It was only ever devised to make C++ compatible with C, which basically means not using virtually all of the useful language features and writing some terrible code. And even then, you'd never make it compatible with JavaScript and PHP.

Sign up to request clarification or add additional context in comments.

3 Comments

Surely there is a way to do it? Sytle is a matter of preference with in certain guidelines
@Chris: Absolutely not. All four of your languages have completely different styles and paradigms. You could never, ever write code that was both good C and C++. Let alone JavaScript and PHP, too.
Could you concretetize on the exact issues of the Google Style guide for C++? How can style be incompatible with language features? I use it to keep consistent, and it served me pretty good so far.
1

Wikipedia has an article that lists several C coding styles. Anything that works for C should work similarly for all the languages you ask for with little additional thinking.

Comments

1

Javascript - Probably not compares with the others.

Worth reading the coding styles from ESA wrt Java, C++.

Also getting documentation out of Doxygen is another good starting point.

Comments

0

It's really a matter of taste. There are no definite standards to follow in this case.

See the many questions on this subject:

And more. All you need to do is search :)

1 Comment

The referenced PHP coding standards are down! :(
0

I would suggest something like this, it seems the way most people are heading, at least on the non-microsoft side of things:

http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml

Although that is for C++, it also applies to the c-like languages you mention. You can look at example code Google provides for other languages, it all tends to stick this this general style. For instance the code within these pages: http://code.google.com/apis/maps/documentation/javascript/basics.html and http://code.google.com/apis/calendar/data/1.0/developers_guide_php.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.