Thread: Following the C standard library style conventions

  1. #1
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094

    Following the C standard library style conventions

    Not that this matter much, but you guys should really adhere to some C coding standards, particularly in naming functions. I know this is probably going to draw a lot of criticism and I'm not really trying to imply that there is any best way to do this.

    However, if you notice, the developers of C haven't named their functions like in Java scanFormat()... but rather scanf(). This is not an object oriented environment and it is so obvious you guys are coming from such a background, often times with the wrong ideas about C.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Unlike (........ty) Java, C has no "naming standards." It has standards that says how standard library functions are named, but that's it. How the programmer names their functions is irrelevant.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by Elysia View Post
    Unlike (........ty) Java, C has no "naming standards." It has standards that says how standard library functions are named, but that's it. How the programmer names their functions is irrelevant.
    That maybe so, but I can't see any advantage to NOT being consistent with the coding style of the libraries you are using.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654

    http://cboard.cprogramming.com/c-programming/124814-following-c-standard-library-styl

    Except upsetting people for not letting them use whatever naming convention they want to use. I don't buy those arguments.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    This is a style debate that has nothing to do with the thread, so I have moved the posts to a new thread.

    Frankly, I can see where you are coming from, but the code was readable. There is nothing to complain. If you want to enforce your opinions in your own company/project, go ahead, but this message board is not the place to mandate that others follow your style when their own style is reasonable.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Wow, thanks for deleting the post. That's really mature.
    Last edited by claudiu; 03-17-2010 at 01:49 PM. Reason: EDIT : oh you moved it, my apologies, did not notice

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by claudiu View Post
    That maybe so, but I can't see any advantage to NOT being consistent with the coding style of the libraries you are using.
    Here's an idea: you code the library, you name the variables.

    Why you would confuse CamelCase with OOP I don't know.
    Last edited by MK27; 03-17-2010 at 01:53 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    I am certainly not trying to enforce anything. I couldn't do it even if I wanted to. As I CLEARLY stated in the previous message : "I am not trying to imply that there is any best way of doing this".

    Just thought I would draw attention on an issue that's all. No need to get jumpy. I was just trying to be of help.

  9. #9
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    I prefer descriptive names over shorthand names, it makes the code easier to follow with less ambiguities in my opinion. This leads to less mistakes, and possibly fewer bugs. The naming convention used in the standard library is more a leftover from a time with small terminals and little memory.

  10. #10
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Ok, look, I certainly do not disagree with any of you, and I think it's ridiculous to turn this thread into anything more than it was intended to be: a.k.a. Just a thought.

    I find it quite funny that everyone is getting so defensive all of the sudden. My intention was not to preach or anything like that. The only offensive remark on this thread are a few gratuitous remarks concerning another language. No offense.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I believe that most people here like being able to choose freely whatever style they want instead of adhering to a particular style from somewhere, regardless of where it might be from. I know this is certainly true for me.
    I choose my own naming style for all my projects. One of the most hated things about Java is that Sun is like a dictator on setting a naming style.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by claudiu View Post
    Ok, look, I certainly do not disagree with any of you, and I think it's ridiculous to turn this thread into anything more than it was intended to be: a.k.a. Just a thought.

    I find it quite funny that everyone is getting so defensive all of the sudden. My intention was not to preach or anything like that.
    Quote Originally Posted by claudiu
    often times with the wrong ideas about C.
    No, no reason to be defensive at all.

    But really, I would think it would be a good thing to not look like the standard library, not only from a namespace perspective but also from code readability use as well. (Cue confusion about "is this unix, GNU, or standard C" reminders.)

  13. #13
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Well they certainly have that choice. Nobody is trying to take that away by no means. That in fact would go against everything I personally believe in.

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Btw, I also believe that, in some languages, there is a reason behind the naming - and it is to avoid conflicts with other peoples' naming conventions. Ie, the C++ standard library is all lower case to avoid some name clashes, I believe.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    My opinion is that it's a matter of personal preference. If you are working together with other people on a project and they have requested that you follow a certain naming convention then of course you should use that, but if not then I say use whatever you like best as long as you stay consistent and not intentionally obfuscate names.
    Personally I prefer function names like LoadFile() over say loadf(), and I don't see how the former has anything to do with an OOP mindset. And certainly not how it would make me have the wrong ideas about C
    But you are correct by assuming that my "main" language is not C though, it's C++

    Edit: (lots of people posted while I was typing this)
    Quote Originally Posted by claudiu View Post
    I find it quite funny that everyone is getting so defensive all of the sudden. My intention was not to preach or anything like that. The only offensive remark on this thread are a few gratuitous remarks concerning another language. No offense.
    None taken

    Quote Originally Posted by Elysia View Post
    Btw, I also believe that, in some languages, there is a reason behind the naming - and it is to avoid conflicts with other peoples' naming conventions. Ie, the C++ standard library is all lower case to avoid some name clashes, I believe.
    The c++ standard library is also confined in the std namespace, so name collisions should actually be less of an issue there than in C
    Last edited by _Mike; 03-17-2010 at 02:04 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Style Points
    By jason_m in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 06:15 AM
  2. Replies: 8
    Last Post: 03-08-2008, 08:50 PM
  3. Standard Template Library
    By matth in forum C++ Programming
    Replies: 1
    Last Post: 09-09-2005, 07:26 AM
  4. Abstract Base Class and References
    By Thantos in forum C++ Programming
    Replies: 9
    Last Post: 10-13-2004, 01:35 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM