Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coding Style #1

Open
mottosso opened this issue Dec 29, 2014 · 8 comments
Open

Coding Style #1

mottosso opened this issue Dec 29, 2014 · 8 comments

Comments

@mottosso
Copy link
Member

Right off the bat there are things to discuss, lovely. :)

  • File name convention
  • CamelCase, snake_case or mixedCase
  • Where to put the braces

Filename convention

Currently the filename is snake_case, like Python. What is the pros/cons of this, as opposed to mixedCase.c or simply nocase.c? What is more common and accepted?

Case

Within the code, let's have a think about what case is mostly used today, by looking at other established codebases. Looking at Qt and C++, it looks like mixedCase is preferred, for example.

Braces

int main()
{
    printf("hello, world\n");
}

Or

int main() {
    printf("hello, world\n");
}

Personally, I prefer less lines, but let's have a chat about what is more common.

Summary

Is it a good idea to try and establish a convention for ourselves to follow throughout the series of projects?

@mottosso
Copy link
Member Author

Thanks for @agudmund for sharing the performance concern with using mixed cases in file- and directory names.

http://www.open-e.com/site_media/download/documents/Manual_OE-DSS-V7_BAS_EN_1_00_r1.pdf
Page 112 has an example.

From the chat:

to each his own and all that, but keep in mind there is only one naming convention which has a literal performance difference
most file systems, like Lustre, BlueArc, Open-e and so on, have extended indexing functionalities which speed up the file system considerably
works on the premise to skip all files with uppercase letters in them or lower case
so if you have a 100T server, and your production data is all named lowercase, from a file server configuration point you can speed up access by telling the server to only look for those.
such is not possible with camelcase

@ghost
Copy link

ghost commented Dec 29, 2014

In regards of braces,

I always loved to have them in the same level of indentation (for the sake of clarity). Having said that, Dennis Ritchie (creator or C and co-author of The C Programming Language) seems to use the one that uses less lines:

int main() {
    printf("hello, world\n");
}

@ljkart
Copy link

ljkart commented Dec 29, 2014

int main() {
    printf("hello, world\n");
}

This one is more common in many IDE, who support auto-complete.
Eg: Qt Creator

@mottosso
Copy link
Member Author

How about choosing a "mentor", some library/software with an already established coding style, and then sticking to that until we find any reason to deviate.

Qt

For example.

Google

There is also this.

They both relate to C++, but I figure since we're heading there eventually, it might be good to get into the habit early.

Thoughts?

@mottosso
Copy link
Member Author

Here's some perspective on the Google Style Guide.

@ghost
Copy link

ghost commented Dec 29, 2014

The idea of choosing a "mentor" and sticking to that until we have a good reason not to do that sounds good to me.

Personally I think that the most important thing to remember is to keep consistency across all of our projects. I think that the lack of consistency is the first step towards unmaintainable code.

HERE is an interesting and fun read in regards of maintainability.

@mottosso
Copy link
Member Author

Personally I think that the most important thing to remember is to keep consistency across all of our projects.

This sounds good, and I agree, but seeing as none of us know C very well I'm sure our code and conventions will change in time and that it will change for the better. I wouldn't want to be stuck with conventions we come up with today down the road when I actually know what I'm doing.

I guess what I'm saying is, our projects will likely differ in style, and that there isn't too much we can do about it, other than embrace it as a sign of maturity. As long as we keep our guides clear and concise, we should do well.

@ghost
Copy link

ghost commented Dec 29, 2014

Absolutely. I expect our code and conventions to change in time as well and that's just fine. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants