Comments (7)
To get things rolling, how about the Linux kernel style but with a more reasonable indent (3 spaces instead of 8)?
In other words, something like this:
static int blah(int a)
for (i = 0; i < num_elements; i++) {
foo[i] = foo[i] + 42;
if (foo[i] < 35) {
printf ("Foo!");
foo[i]--;
} else {
printf ("Bar!");
foo[i]++;
}
}
return a;
}
This is widely used, already documented, and can be auto-formatted using GNU indent
on any reasonable OS with the following settings:
-nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4
-cli0 -d0 -di1 -nfc1 -i3 -nut -ip0 -l80 -lp -npcs -nprs -npsl -sai
-saf -saw -ncs -nsc -sob -nfca -cp33 -ss -il1
We could even integrate a formatting check into our CI build to help us maintain consistent style.
from c.
I don't think you'll ever get 100% agreement on any coding style, but that looks like a sane set of choices to me, and the autoformatting idea is great 👍
I think you have the wrong settings listed for indent though. As far as I can tell you need to remove -i8
and instead use -i3 -nut
to get an indentation level of 3 without tabs.
from c.
Thanks @patricksjackson. I've updated my post above and will test this out once I'm on my development machine.
from c.
I agree that the ability to use a simple program like indent
is key to enforcing a formatting standard. At least, it would immediately answer the question "is my code formatted correctly?" Something that I have often asked myself on other language tracks.
from c.
This should also include a preference for C99 features (#53)
from c.
This should also include a preference for fixed-width types (#52)
from c.
Once we update the contributing guide, we need to also document the odd #includes for the example solutions, (writing the code as if the files are named something else) see conversation in #50.
from c.
Related Issues (20)
- Add learn track for C HOT 5
- Implement the exercise "high-scores" HOT 9
- Change to "community-contributions-accepted" HOT 2
- Expected and actual assertion arguments reversed in some tests HOT 2
- Docs: test framework overview links to empty article HOT 1
- More documentation to `Grade School` HOT 1
- Add `make memcheck` tip for the HELP.md file. HOT 1
- Building a training set of tags for c HOT 23
- Rework the gigasecond exercise? HOT 3
- Problems in pascals-triangle test HOT 12
- The order of the results actually matters for the Word Count exercise HOT 4
- Pascal's Triangle has a bad Test Case defining Zero Rows. HOT 2
- Exercises for #48in24 HOT 17
- pig latin in C track HOT 2
- Grade school : ARM64 - Some tests fail when run online HOT 5
- The square root problem needs to be improved HOT 4
- Return type for `convert(char result[], int drops)` in "Raindrop" should be of type `void` HOT 2
- Approach is missing in "Hamming" HOT 5
- Jumped right from Hello World to Armstrong Numbers? HOT 5
- Use of macros in "Series" isn't clear, consideration for removal? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from c.