Coder Social home page Coder Social logo

Comments (7)

 avatar commented on July 1, 2024 1

I'm not a great C coder, and I don't do much of the C in Fuzzball, but:
https://man.openbsd.org/style.9
https://www.freebsd.org/cgi/man.cgi?query=style&sektion=9
These are the ones I check when I write code that I want to pass some sort of style guide.

from fuzzball.

wyld-sw avatar wyld-sw commented on July 1, 2024 1

Closing for lack of activity.

from fuzzball.

 avatar commented on July 1, 2024

In this thread:
#329
I was mentioning the difference between indentation and alignment. Here's a nice example:
https://github.com/nyanster/fuzzball/pull/1/commits/fa3ea87e144af3e0e9c0ec89ac481e56e7eb209d
https://github.com/nyanster/fuzzball/pull/1
https://github.com/nyanster/fuzzball/blob/fa3ea87e144af3e0e9c0ec89ac481e56e7eb209d/include/dbsearch.h
Try putting it through expand(1). The comments always stay aligned. But the indentation can be moved as far left or right as a reader wants.

from fuzzball.

 avatar commented on July 1, 2024

Okay. So, I'm gonna write up a style guide so there's something to argue over. It's the style of Unix code with a couple modern exceptions to improve readability. (it's BSD. If you find a System V style guide... you're free to offer it. But I don't think any exist) It's only for C, as I have no idea what'd be useful for MUF or MPI, and I don't feel a need for a style guide for stuff like sh or Tcl. (I write sh code in an easy-to-read way for me, and if it's not easy already, well, I plan to re-work some of the current scripts)
It follows:

Indent with tabs. Align with spaces. Tabs (indentation) have semantic meaning. Indentation is something that ONLY happens at the beginning of a line, and never in the middle of a line. Thus, your code should look the same no matter what tab size a reader uses, as it'll stay aligned no matter what. This also means there will never be mixed tabs and spaces.
Don't force things to fit in an 80x24 terminal. Use as many or as few columns as you need to. Use as many or as few lines as you need to. Make your code and comments readable.
Use C99. Assume the build environment fully supports C99. Don't worry about being compatible with C89 or with systems that don't have the standard library.
C and Unix have a close relationship. Keep this in mind when writing C code.
For anything not specified here, refer to these:
https://man.openbsd.org/style.9
https://www.freebsd.org/cgi/man.cgi?query=style&sektion=9
Addendum: keep your commits and pull requests readable too! Be smart if you change style and code at the same time.

Unrelatedly (no this isn't part of the styleguide this is a new paragraph) we probably have too many ifdefs to easily use ctags, at the moment.

@wyld-sw
@tanabi
Just tagging people~ I want your opinions!

For an explanation on indentation versus alignment:
https://dmitryfrank.com/articles/indent_with_tabs_align_with_spaces
http://www.lb-stuff.com/tabs
Both are good. The first one explains it better.

from fuzzball.

 avatar commented on July 1, 2024

Indent with tabs. Align with spaces. Tabs (indentation) have semantic meaning. Indentation is something that ONLY happens at the beginning of a line, and never in the middle of a line. Thus, your code should look the same no matter what tab size a reader uses, as it'll stay aligned no matter what. This also means there will never be mixed tabs and spaces.

Looking back at this... Tabs are fine as separators when alignment is NOT desired. I've seen some examples of this in the code, where a single line of code is separated from a single comment by a tab, without relation to other code or comments.

from fuzzball.

tanabi avatar tanabi commented on July 1, 2024

I'll dig into this more when I've got a sec. I've got some counter proposals but haven't gotten around to assembling it.

from fuzzball.

digitalcircuit avatar digitalcircuit commented on July 1, 2024

As it's been… almost two years, eep, I should probably note that I'm no longer certain of the merits of auto-enforcing a coding style. Picking a coding style for consistency and aiming for it, yes, perhaps even setting up basic auto-format rules. However, it's likely not worth spending hours and hours getting an auto-formatter to handle every single edge case.

from fuzzball.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.