You are not logged in.
Oh no, not another Real Programmer!
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
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
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
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
i think i'm with k&r style
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.
Last edited by samuele.mattiuzzo (2010-03-08 15:36:37)
Offline
I prefer Allman style with 3 space tabs
void foo()
{
printf("Hai guise!\n");
if ( funny )
printf("Lulz!\n");
}
Last edited by Themaister (2010-03-08 16:02:07)
Offline
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
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
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
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).
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.
#!/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.
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
Last edited by JHeaton (2010-03-12 08:52:24)
Offline
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
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
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
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
@dmz
Ever learnt of the APL programming language? That was fun to read!
To know or not to know ...
... the questions remain forever.
Offline
@dmz
Ever learnt of the APL programming language? That was fun to read!
That was not fun, that was insane.
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
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
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
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.
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
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
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
Offline