You are not logged in.

#26 2009-11-25 12:19:17

dr_te_z
Member
From: Zoetermeer, the Netherlands
Registered: 2006-12-06
Posts: 154

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

Ranguvar wrote:

Oh no, not another Real Programmer! yikes

and old programmes code object-disoriented and use this: http://buffy.sighup.org.uk/hfiles/aafn.html


Somewhere between "too small" and "too large" lies the size that is just right.
- Scott Hayes

Offline

#27 2009-11-27 22:48:52

Neheb
Member
From: Norway
Registered: 2009-05-23
Posts: 39

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

Prefer Allman style indentation. Feel like I have to look around too much for the braces when they are on the same lines as the control statements. When I was helping people with our Java the first year of college I learned to never trust the indentaion to be correct.

I use // for all comments, and have them on their own line.
use /// for function explainers.

both are because I mostly use VS and C#/XNA rigth now.

I don't have any line lenght rule, but have been thinking of trying 80 chars for my own stuff.

Offline

#28 2010-03-08 11:08:21

iljo
Member
From: Croatia
Registered: 2008-11-26
Posts: 29

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

I have a question for guys here that use 80-char limit. What is your tab width, is anyone using 8-char tab width?

Offline

#29 2010-03-08 13:52:20

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

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

iljo wrote:

I have a question for guys here that use 80-char limit. What is your tab width, is anyone using 8-char tab width?

Borderline necro, but I'll answer it anyway.  Yes, I use 8 character tabs, but I never embed tab characters in my source code, instead indenting 4 spaces instead.  Any decent editor will do that for you.

Offline

#30 2010-03-08 15:32:38

samuele.mattiuzzo
Member
From: Treviso, IT
Registered: 2009-10-12
Posts: 307
Website

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

i think i'm with k&r style smile

void foo(int arg){
    /*Comments*/
        if(something_else){
        } else {
             /*other comment*/
        }
}

(where i can i'm not using braces, since i'm used to languages like ML, haskell, and their indentation interpretation. if i'm using C, i think that braces are always for good)

but i think it depends on what i'm doing. if i exactly know what i'm doing, i'll stick with this one, but if i'm just "experimenting" i'll go with

void foo()
{
        bla bla bla
        bla bla bla
}

so i can have more visibility on scopes.

smile

Last edited by samuele.mattiuzzo (2010-03-08 15:36:37)

Offline

#31 2010-03-08 16:01:50

Themaister
Member
From: Trondheim, Norway
Registered: 2008-07-21
Posts: 652
Website

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

I prefer Allman style with 3 space tabs tongue

void foo()
{
   printf("Hai guise!\n");
   if ( funny )
      printf("Lulz!\n");
}

Last edited by Themaister (2010-03-08 16:02:07)

Offline

#32 2010-03-08 19:42:33

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

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

K&R style places the opening brace of a function definition on its own line.  This is, as I understand, a holdover from pre-ANSI C, where the arguments of a function were declared between the foo(a,b,c) and the {.

Offline

#33 2010-03-10 21:13:25

Peasantoid
Member
Registered: 2009-04-26
Posts: 928
Website

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

I generally use /*...*/ for line and block comments. // is for 'temporary' comments such as TODOs for stuff I expect to implement in a future revision.

** edit("typo");

Last edited by Peasantoid (2010-03-10 21:17:40)

Offline

#34 2010-03-10 22:42:09

Anikom15
Banned
From: United States
Registered: 2009-04-30
Posts: 836
Website

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

K & R style, no double braces on elses. I find it quite readable, especially with highlighting in vim.


Personally, I'd rather be back in Hobbiton.

Offline

#35 2010-03-11 22:48:01

JHeaton
Member
From: United Kingdom
Registered: 2009-05-16
Posts: 158

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

iljo wrote:

I have a question for guys here that use 80-char limit. What is your tab width, is anyone using 8-char tab width?

I only use a four-character tab-width regardless of the limit I use (which is only occasionally 80-characters - i.e. when I'm being lazy and just coding in nano rather than gVim), because it's enough for readable indentation, but doesn't use too much space (which, I know, some people will find confusing when they see what I do with spacing of certain things below - a habit I have picked up from a friend's code because it makes reading through hers easier).

Anikom15 wrote:

K & R style, no double braces on elses. I find it quite readable, especially with highlighting in vim.

I agree. Although I also do a few things with mine that I haven't seen many others do (so far - I don't look at that many other peoples' code >.>). For example, all the extra spacing here:

if ( $ServerPing -> ping ( $Server, 2 ) ){

I'm more used to seeing it like this:

if ($ServerPing->ping($Server, 2)) {

Anyways, on to an example that I have written. smile

#!/usr/bin/perl

use strict;
use warnings;

# Load modules.
use Net::Ping;
use Win32::GUI();

my @Servers = ( "WS-LOGON", "WS-SIMS", "WS-GHOST", "WS-STUDENT", "WS-STAFF", "WS-APPLICATION", "WS-PRINT", "WS-PROXY", "WS-EXCHANGE" );
my $ServerPing = Net::Ping -> new ();
my $Window = Win32::GUI::Window -> new  (   -name   => "Servers",
                                            -width  =>  200,
                                            -height =>  300
);
my $Server;

foreach $Server ( @Servers ) {
    if ( $ServerPing -> ping ( $Server, 2 ) ) {
        $Window -> AddLabel ( -text => $Server, " is OK." );
    }
    else {
        $Window -> AddLabel ( -text => $Server, " is not OK." );
    }
}

$Window -> Show ();
Win32::GUI::Dialog ();

sub Main_Terminate {
    -1;
}

Tends to be how I do stuff. Well, once I started coding properly. Before I just threw anything anywhere, often with catastrophic results. Also, I haven't tested the above script (because I don't have a Windows machine) so anyone who actually does so for some reason might be disappointed, and anyone telling me it is wrong is most likely correct. tongue

When I did all my assignments in C, I mixed /* ... */ and // all the time. However, I generally used the /* ... */ style for explaining what the following section of code (and I mean the entire section) did in some detail. // was for explaining what little bits within that section did, although towards the end of the assignments I was getting sick of programming something so pointless that my comments effectively became useless, one-word things that would give me a reminder but would not help anyone else at all. Fortunately, bad habits are (for the most part) gone now smile

Last edited by JHeaton (2010-03-12 08:52:24)

Offline

#36 2010-03-12 01:57:06

Anikom15
Banned
From: United States
Registered: 2009-04-30
Posts: 836
Website

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

Yeah I don't like all those extra spaces in my code. I get that from Python's standards.

Also I don't get GNU style. It's the weirdest.

Last edited by Anikom15 (2010-03-12 01:57:36)


Personally, I'd rather be back in Hobbiton.

Offline

#37 2010-03-13 01:16:19

Moose9999
Member
Registered: 2010-03-09
Posts: 32

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

I cant stand it when my code looks like the follosing

if (some_stuff) {
         //comments
         more_stuff;
         even_more_stuff;
         if (other_stuff) {
             //more comments
         }
}

It gets really cluttered when comments are right next to code without newlines

if (some_stuff) {
         //comments

         more_stuff;
         even_more_stuff;

         if (other_stuff) {
             //more comments

             even_more_other_stuff;
        }
}

as far as the 80 character issue, if I can't see the end of the line I will just zoom out, but there is a limit since the text does start getting pretty small

Last edited by Moose9999 (2010-03-13 01:18:36)


"The beautiful thing about learning is nobody can take it away from you."
B.B. King

Offline

#38 2010-03-13 07:55:43

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,281

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

iljo wrote:

I have a question for guys here that use 80-char limit. What is your tab width, is anyone using 8-char tab width?

TAB is 8 characters, always. But real indentation is done on 4 or 2 space levels.

And about the 80 characters line limit, this is what usually fits on a standard (A4) paper listing. I hate it when thoroughly maintained indentation layouts become scrambled just because of too long lines. And I do not like landscape formatted listings either (or those big sized A3 line printouts of the older days).

BTW: I prefer to proofread code on printed paper at least once in the development cycle.

Last edited by bernarcher (2010-03-13 07:57:15)


To know or not to know ...
... the questions remain forever.

Offline

#39 2010-03-13 09:02:04

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 881
Website

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

What are you talking about... comments? Whitespace? Indention? I usally do it like this:

$c='python';$_=`printf hack`;$_=~s;ck;;;;$c=~s%^(?!\x68)(.)(?2)(?1)(.)(?1)(?2)(?<!.{4}h)$%$2%;print j.substr($_,1),p,$c.",\n"

Offline

#40 2010-03-13 11:50:46

bernarcher
Forum Fellow
From: Germany
Registered: 2009-02-17
Posts: 2,281

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

@dmz
lol
Ever learnt of the APL programming language? That was fun to read! tongue


To know or not to know ...
... the questions remain forever.

Offline

#41 2010-03-15 05:01:50

dmz
Member
From: Sweden
Registered: 2008-08-27
Posts: 881
Website

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

bernarcher wrote:

@dmz
lol
Ever learnt of the APL programming language? That was fun to read! tongue

That was not fun, that was insane. lol
To be serious though, I do it like this:

if(!defined($foo)) {
  push(@baz, $bar);
  while($bar>1) {
    --$bar;
  }
  if($TIMTOWTDI eq 'true') {
    print 'purrrl', "\n";
  }
  else {
    die 'miserably';
  }
}

I dont know how bad my style is, but it works for me. I've experimented
with the

if($foo) {
  $foo++;
} else {
  $baz++;
}

approach, but I dont know... I think I'll stick to what I'm doing right now.

Edit: And 80 col ... everything else is just stupid. Expandtab with 2 spaces.

Last edited by dmz (2010-03-15 05:03:53)

Offline

#42 2010-03-15 06:15:30

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

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

I generally do...

/* oh hells yeah
 * how much do you live multiline comments?
 * answer? ALOT!
**/

const char *some_function_name(char *somevar);

/* this is an awesome function
 * because I wrote it!
**/
const char *
some_function_name(char *somevar) {
    int a = 0;
    if (somevar) {
        a++; // do this here so we get more TACOS!
        printf("holy crap"); 
    else {
        printf("you passed me a null. shoopdawhoop");
    }
    return "push button. receive bacon.";
}

"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#43 2010-03-15 07:41:08

PJ
Member
From: Sweden
Registered: 2005-10-11
Posts: 602

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

I prefer K&R/1TBS.

Usually I tend to keep it below 80 characters but it really depends on the code that I am actually writting. If the readability is increased by going above 80 characters I pretty much tend to make it go above just to make it more readable. I use 4 spaces for the indentation and I prefer spaces over tabs.

Offline

#44 2010-03-15 08:40:19

JHeaton
Member
From: United Kingdom
Registered: 2009-05-16
Posts: 158

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

bernarcher wrote:

And about the 80 characters line limit, this is what usually fits on a standard (A4) paper listing.

Really? I didn't know that. I've never printed out any code, so I haven't had the opportunity to find that out, but with some of the projects I've got coming up, I might have to think about that.

Thank you for that little bit of information. smile

PJ wrote:

I use 4 spaces for the indentation and I prefer spaces over tabs.

Is there a particular reason for this? Any advantages of spaces over tabs?

Last edited by JHeaton (2010-03-15 08:43:55)

Offline

#45 2010-03-15 17:10:41

PJ
Member
From: Sweden
Registered: 2005-10-11
Posts: 602

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

JHeaton wrote:
PJ wrote:

I use 4 spaces for the indentation and I prefer spaces over tabs.

Is there a particular reason for this? Any advantages of spaces over tabs?

I guess one of my reasons are because the code looks the same even if the tab character isn't the same size, another reason is that my personal coding style has been affected by the coding conventions at my work, where we are using spaces over tabs.

Offline

#46 2010-03-15 18:15:47

JHeaton
Member
From: United Kingdom
Registered: 2009-05-16
Posts: 158

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

PJ wrote:
JHeaton wrote:
PJ wrote:

I use 4 spaces for the indentation and I prefer spaces over tabs.

Is there a particular reason for this? Any advantages of spaces over tabs?

I guess one of my reasons are because the code looks the same even if the tab character isn't the same size, another reason is that my personal coding style has been affected by the coding conventions at my work, where we are using spaces over tabs.

I see. Well that is certainly interesting. I think it is something that I might consider more in the future, having seen in here already that people set their tabs differently in their editors. Thanks for explaining that smile

Offline

Board footer

Powered by FluxBB