What is your programming style with C-like-syntax langauges?

EDIT: I decided this might be better off as a general style thread for C-like-syntax languages (C, C++, Java, ObjC, D)
Everyone, what's the general style you use with languages that have a bracketed syntax like C does?
What are the advantages to your style, as you see it?  For example, K&R style saves vertical file length, but Allman (aka ANSI) makes block starts more clear.
A nice rundown of some common ones here: http://en.wikipedia.org/wiki/Indent_style
And, what is your preferred 'style' when it comes to comments in C?
Do you use the C++-style '//' comments for single lines, or do you still use the C-style '/**/', and why?  Is there anyone that prefers C-style even if they don't care about supporting old non-C99 compilers?
Second, and this is what I'm most curious about, do you often put short comments on the same lines as source code?  How often, and with how much of a space between the comment and the code itself?
When writing comments on the same line as code, do you capitalize the beginning of the comment?  Do you add a period to the end?
Lastly, while we're on the subject, what's your 'rule' for line length?  I like a 100-char limit, but 80-char is the 'standard', and some people use more than 100 due to a rise in large and widescreen monitors.
No holy wars, please!  Just a few questions I've been pondering, it's all personal preference in the end
Last edited by Ranguvar (2009-11-21 01:05:26)

Still my biggest C program (pathetic, I know), this is a solution to K&R's Ch.1 Q.13, which you can read at the beginning of the file.
It's a good example of my current style.
http://repo.or.cz/w/tcpl.git/blob_plain … :/ch1/13.c
I use tabs for indentation, and spaces for aligning code, to allow anyone to set their own tab width.
I like 8-character indent in my editor, though.  The clearly defined blocks really help.
Since the blocks are so clearly defined, I see no need for Allman-style:
if (something)
foo();
bar();
else
bar();
foo();
I use a more K&R style:
if (something) {
foo();
bar();
} else {
foo();
bar();
I use C-style comments for important single-liners and multi-liners, as such:
* IMPORTANT
For single-line comments that are descriptions of a following block of code, I use C++-style comments on their own line, capitalized and with some punctuation except for extremely short comments.
I have no patience for compilers that can't keep up with ISO/ANSI C99 (*cough*MSVC*cough*), which is around 10 years old now, and was publicly in the works long before that
// This next block of code kicks ass.
while (awesomeness) {
kick_ass("awesomeness");
foo();
And for comments that share lines with source code, they are quick lowercase sloppy notes in C-style.  The C-style makes them stand out more and just looks better there, IMO.
No real rule on how far away from the code they are spaced, but usually a 5-char or so minimum, and I often align them with other comments.
super_fuction(1, 2455, "foobar"); /* note to make this understandable, if possible */
Last edited by Ranguvar (2009-11-21 06:50:16)

Similar Messages

  • What's your biggest frustration with security right now?

    I was wondering what’s your biggest frustration with security right now? I write a security blog and was thinking about it. If you don't mind please share! 
    Thank you for your time!

    I am working with some random logs at work on a Windows computer. I am just learning bash script and cant figure this out. The lines I am lookin for contain error and launcher, and I would like the line on the log that contains both of those words to then be copied to a text document that I can reference later. If you all could help me out and maybe walk through what you are doing step by step. I am working hard to try and figure this out all to no avail.-Cant figure out how to grep for a word and then another-I then cant figure out how to copy the line to a new document so I can reference laterThank you so much in advance. I am working with some random logs at work on a Windows computer. I am just learning bash script and cant figure this out. The lines I am lookin for contain error and launcher, and I would like the line on the log...

  • What apple email program works with OSX 10.6.7?  I have Apple mail 4.4, but it doesn't work with OSX 10.6.7?

    What apple email program works with OSX 10.6.7?  I have Apple mail 4.4, but it doesn't work with OSX 10.6.7?

    The reason you're seeing this is that you have somehow gotten an outdated copy of Mail on your system.  One possible reason is that you moved Mail out of the Applications folder (or into a sub-folder inside the Applications folder), in the process preventing it from being updated.  You'll want to put Mail back directly in the Applications folder if this is the case.  The other possibility is that you have somehow installed, restored or copied an old copy of Mail on your machine.
    In either case, as long as Mail is in the right place, applying the combo updater will update Mail to the current version.  Software Update cannot do that because Software Update sees that you are using the current version of the OS and believes there is no need to update, while the combo updater "forces" installation of all updated files.

  • What is your bracket style?

    What is your bracket style?
    type 1:
      if (true)
          bla bla bla...
    type 2:
      if (true) {
          bla bla bla...

    for (int C = i; use < this; style; C++)
      if (C < i)
        printf("and i indent with spaces whenever possibel");
      else
        printf("makes copying code samples to here a lot easyer");
    while (usning.java()) {
      try {
        setBracketStyle(this);
      } catch (BracketStyleException bse) {
        bse.printStackTrace();
      } finally {
        System.out.println("before brackets at the end of line i put space...");
        System.out.println(
          "that way these brackets will not 'get lost' while looking through code");
    if (i.debugCode() && bracketStyle != me.getBracketStyle())
        System.out.println("then i continnue using style in the source");
    // comment by [email protected] on 2003.03.21@09:32
    // there are some other bracketing styles as well that i might use...
    // but i try to stay with the one i'm using in java.
    // and while debuging i allways add timestamp and explanation to my
    // code/comments or bugs i find and don't have to correct just yet

  • How to view what are all programs maped with the event....

    I am new to this events concept - could you please say
    in SM64 we can give Event....
    <b>How to view what are all programs maped with the event..</b>
    Thanks in advance.

    Hi Sam,
    See these links:
    How-to trigger a process chain using ABAP?
    Re: scheduling process chain 3 specific times a day
    NOTE: If you want to trigger the process chain from R/3, there are many examples in this forum. However, since the search function is not working now, I suggest you look at OSS Note 135637. This will show you how to do it also.
    Hope this helps.
    concerning to sm64 ..
    Triggering events manually ...
    Events let you start background jobs when particular changes in the R/3 System take place. When an event occurs, the background processing system starts all jobs that were scheduled to wait for that event.
    example : JOB_OPEN to create a background job..
    When scheduling a background job, you can specify it to start "after event".
    If you do so, you'll have to create an event in SM62.
    If a job is scheduled after event event and you trigger the event with SM64, the job will start.
    Events can be raised by external systems in SAP by sending a command to a SAP application server. You can also raise event in any program using function mosule BP_EVENT_RAISE.
    Reward if helpful.
    Regards,
    Harini.S

  • What is your programming environment?

    For those of you who are always using the latest sdk, what is your setup if u don't use flashbuilder  Just lookings for other options

    hi
    i use flash builder myself but the other popular options are FDT, Flash Develop and IntelliJ

  • How to get back up your programs up for leopard like ilife 08 and i work 08

    i am planning to upgrade/ clean install to leopard this week and i was wondering how to keep ilife 08 and iwork 08 as they came with my laptop and the only place i have them are on the mac os x 10.4 discs what can i do apart from buying them from the apple store.

    *Hi oliver, Welcome* to Apple's Users Help Users Forums.
    A bit of reading in the Leopard Forum will help you explore your options.
    http://discussions.apple.com/forum.jspa?forumID=1230
    1st have a bootable tested clone no matter which choice you make. In order of ease they are:
    Upgrade is the easiest. If probs, clone back.
    Then try Archive and Install.
    More probs, now you will have to Erase and Install.
    No poster ever had to erase and install. Upgrade worked for the vast majority.
    Do you have a particular reason for wanting to do E&I? If you have system probs, maybe get those fixed 1st. The forums are an excellent help for that.

  • Program exited with status 8

    i have concurrent program which exited with
    Program exited with status 8
    Please let me know what does that mean?

    If you mean your program exited with an error number (also called an "errno", or
    "system call return status", or something like that), it means:
    #8 ENOEXEC "Exec format error"
    which generally means you are trying to run an executable on the wrong type of
    host. Could you provide more details on what the program is and any screen
    messages you saw?

  • How to determine what OS your java prog is running on?

    Is there a Java command to determine what OS your program is running on?
    Yes it IS important -- because there are things that are OS-specific, such as valid characters for filenames.
    I could just disallow ALL "shady characters", but then my program would be skipping a lot of GOOD files in Linux, which only disallows the '/' character.
    http://www.linuxboxadmin.com/articles/tools-and-utilities/linux/mac/windows-file-name-friction.html
    Any ideas how I should proceed?
    Matthew

    I assume, if it's looking at "ALL" files in a directory, that it is running in a loop, right? Well, put the try/catch in the loop, rather than around it, and let it throw an exception. Catch it and keep a list of files that didn't work. But then again, if you're talking about "reading" a file, this shouldn't be a problem, because if it is an invalid character, how did the file get there? and should it really be your worry?
    As far as writing one with a character like that, let the user enter tha name he wants, attempt to create it, and if it fails ask for another, and for those filenames that you generate within the program, stick to the "safe" characters.

  • What's your favorite coffee vehicle?

    The Matt wrote:vehiclePretty sure you mean vessel

    As I sit here half-asleep, listening to my coffee pot toiling away,  I gaze lovingly at my coffee chalice, waiting for it to supply me with my day's motivation. 
    What's your favorite coffee mug look like? Post up!
    This topic first appeared in the Spiceworks Community

  • Your What are Your Recommended TextPad Embellishments

    As a long-time TextPad user I've been quite impressed with the editor's amazing and powerful features and is why I have been feeling lately that the ESTK is coming up a little on the short end as I begin this journey into writing attempting to write ExtendScript /JavaScript for InDesign.
    With Theunis's compiled CHM help file as an added tool available from TextPad, I may try scripting away from the ESTK, but will miss ESTK's visual enhancement of the code.
    There are so many add-ons available to the TextPad user to use, and as many of you have traveled this road already; what are your recommended clip libraries, macros and syntax definitions that would be worthwhile to the aspiring InDesign script writer?
    Thanks in advance for any suggestions.
    Kelly
    PS. Thanks to Theunis (aka Jongware) for making the CHM available to this community!

    You're welcome, Kelly!
    Personally, I use TextPad "as is", as it already does a great job on syntax highlighting Javascript. Actually I cannot remember if it did this natively, or if I had to download it somewhere -- have been using it for years like this. The only thing I added was a hotkey to the CHM help file (instructions to do so are in TextPad's Help on running external files).
    But I'm as curious as you: does anyone else have suggestions to further enhance TextPad?
    On the same: on my Mac I use TextWrangler to code. Are there any useful additions for that as well?

  • Hello, I would like to know what is your policy for higher educational institutes or with whom should I be in touch with? Thanks

    I would like to know what is your policy for higher educational institutes or with whom should I be in touch with?
    Thanks a lot for your help,

    Apple HED has no published email addresses, and since Apple does not sell their products directly in Israel, you will probably need to work through local distributors or dealers in any case. I would suggest contacting Apple's authorized distributor, iConGroup:
    http://www.icongroup.co.il
    Regards.

  • Java update (3 days ago) won't let me play yahoo games anymore.  I've tried moving java security to Medium and adding web address as "permissive use".  Still nothing.  I'd really like a fix.   Really, apple?  What's your beef with yahoo games?

    Installed Java update three days ago.  Now, can't play yahoo games as it's now blocked by security settings.  Already have tried moving Java security to Medium and adding yahoo.games.com (including web address of game) as a "Permissive exception".   Also tried removing java and installing older version.  Still nothing.  Really Apple?!?  What's your beef with yahoo games? 

    csnorth,
    all of the older update versions of Java SE 7 can be found here. If 7u45 also didn’t work with your Yahoo! games, you can choose from any of the even older versions there as well.

  • What word processing program should I use with my Mac, what word processing program should I use with my Mac, what word processing program should I use with my Mac

    what word processing program should I use with my Mac?

    steve359 wrote:
    For free you can download NeoOffice
    Not quite. Downloading the current version of NeoOffice is definitely not free (downloading the previous version is). The developers of NeoOffice (the most Mac-like of the StarOffice descendants) make a distinction between the application itself (which is free) and downloading it, for which they require what they are pleased to call a "donation" (since it's mandatory, I would call it a fee).
    shldr2thewheel wrote:
    I totally forget about TextEdit all the time..
    Indeed. For basic WP tasks, TextEdit can be quite satisfactory.
    embauerxz
    I only need it for reports
    Would that include the report on the state of the US economy -- you know, the one President Obama asked you to deliver to the White House no later than 7AM on January 4? The one in two columns, with numbered paragraphs, table of contents, footnotes, mathematical formulae, 40 figures, 60 charts, quotations in Arabic, Japanese, and classical Greek, and 15 pages of references in APA style?
    Grant Bennet-Alder is right -- "the real answer depends on what work you expect to do with it, and with whom you expect to do this work". There are dozens of word processors for Mac, from the venerable Word to the no less venerable Tex-Edit+. It would pointless to start listing them all, when many of them might be either too little or too much for your needs.

  • I downloaded a job application with Adobe.  What is your suggestion on editing it?  What is the best way on my iMac?

    I downloaded a job application with Adobe.  What is your suggestion on editing this?  What is the best way or best program?  Thanks!

    Simply, export the data from this esy share system to standard formats like jpeg, making sure to preserve all metadata on the way. How to do that? YOu'll need to post on a Kodak forum I'm afraid.
    Then copy the files to the Mac and import them.
    Regards
    TD

Maybe you are looking for

  • Insert into dropdown list filled from database

    Hi, I have a dropdownlist which is filled from a database. I want to insert an empty/dummy option at index 0. I couldn't find when the rowset execute in the code( the autogenerated constructor have datasorce and command setup but no execute()), and d

  • No SID found for value 'ZDP ' of characteristic 0PO_UNIT

    hi all, iam loading daily delta for invoice verification infocube.. today iam getting following error 1. Data records for package 1 selected in PSA - 1 error(s) 2. Record 496 :No SID found for value 'ZDP ' of  characteristic    0PO_UNIT 3. Error 4 in

  • How come almost all complete themes dont work with ver. 30.0 can a get a ver. that will work with them?

    looking through the "complete themes" and almost all of them say " not available for firefox 30.0 " i guess that what ver. i have i thought i had the newer version and would think theese theme's would work with it is there somewhere else to look for

  • Trial photoshop cs5 extended extended

    i try to download a trial version of photshop cs5 extended but only photoshop cs6 appear. as a result i fail to download photoshop cs5 extended. pls help

  • Web Services Security Sample

    I colud not understand that: "9.The mail also contains links to the Root Certificate using whose key your Certificate was signed. Follow the link and click Accept. This install the root certificate in your browser.(Use Internet Explorer)." in the Web