According to you, how do you indent your code and comments? how do you write comments?
e.g
/*Variable declaration*/
int i;
or
int i; /*Variable declaration*/
it's always useful to know the way other pple work. thx:)
Printable View
According to you, how do you indent your code and comments? how do you write comments?
e.g
/*Variable declaration*/
int i;
or
int i; /*Variable declaration*/
it's always useful to know the way other pple work. thx:)
another :p thread....
it varies....
cause sometimes you write it like this and sometimes the other way round...
Why do u say : "another :p thread..."?
i just wanted to know what u thought was better ;) i'm still a beginner and i want to know from pros like u.
It depends. Here's an example
[EDIT: I wrote the example too fast and forgot the semicolons]Code:...
/* Attributes of Cats */
char name[8]; /* Name of the Cat */
int age; /* Age of cat*/
int weight; /* Weight of Cat */
...
What he meant by "another :p thread" was that this is another noobie thread. Don't feel to bad, though. I have a lot of them too.
The most important thing is to write decent comments.
Things like "variable declaration" and "name of cat" are not the type of thing you want to be commenting. This is simply because anyone with half a clue about C will know that a char array called "name" is an array for holding a name!
Document why your code does things, and if complexity requires it, document the how. Don't document the blindingly obvious.
It's different, how to comment your code
you have to find your own way.....
comments are there, to make the code more readable.....
and "another :p thread"....
=> another funny thread
I don't laugh.... I find just the question funny....
>>It's different, how to comment your code
you have to find your own way....<<
Not when you're working in a team. A common understanding/style is a better approach, imo.
My style also varies some, but in general:
A block comment before a block of code explaining what's about to happen, probably multiline comment
A post-line comment to explain what this line does or what the variable is for
int tramp; /* counts the number of hobos to date */
Post-line comments also at the end of if/for/while/switch structures
I will also mix /* */ and // in a program -- I'm not that much of a puristCode:} // end of if (a != 7)
} // end of for lp2
} // end of if !done
oops, forgot the close code. at least I remembered the opening tag!
[QUOTE]
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
[/QUOTE]
Don't comment things that can be easily understood from the code. Remember, documentation has to be kept synchronized with the code itself. If code is clear, but the comments are out of date, then the programmer doing maintenance has to figure out if the comment is in fact out of date, or if the code is actually doing something more than meets the eye, and wastes time on that. Of course, if your code does do something more than meets the eye, it should be commented.
I indent my code like this
I think that most people find it a lot easier to read than those "other" ways.Code:int main()
{
char a,b,c,d;
return 0;
}
Comment as needed. When you're learning, you might want to comment stuff that you'd never consider commenting later. Just comment whatever you think might confuse you.
At uni, my lecturer makes us comment on every bit of code. i think he's doing this coz there's many students who've never done programming before. i just love programming!!! (though i get some probs with C);)
I generally don't comment (for personal use) unless I feel that I might forget what the hell it is.
I usually write all the comments needed at the beginning
of a function so that it is more detailed and readable. However,
I'll add some comments next to some lines if I feel it is imp.
I also keep two versons (one without comments) so that the code is more readable :) You know, that actually helps sometimes.
I always use // instead of /* */ comments just because I find it looks better. Although it is a pain to have to take out twenty //'s when you would have just had to take out the /* */'s. :P
hey, i thought // was used in C++ and not in C. i don't think i can use // in C. well, that's what i learnt!
Once more, thx to all of you. i don't know how you find time to help us but u're angels;)
>> i don't think i can use // in C.
Older compilers don't support the // syntax, so it may be best to stick to /**/.
How old are we talking here? Turbo C++ version 1.0 from 1985? supports it.Quote:
Older compilers don't support the // syntax, so it may be best to stick to /**/.
in fact we're talking about C. the old version. well, we've started with it at uni and next semester we're doing C++. :)
You can download Turbo C version 2.0 from the mid 80's on Borland/Inprise's website and it supports // AFAIK.Quote:
in fact we're talking about C. the old version. well, we've started
with it at uni and next semester we're doing C++.
thx but don't think i'll use C anymore coz exams will end in 2 weeks time and next semester we're doing C++. ;) think it's much better than C.:)
C++ is not better than C. Like comparing apples and apples.
C++ is a superset of C, an extension to an already great language.
>C++ is a superset of C
which means that
C++ is better than C - no doubt.
lol. that's what i meant too.;)
One is not better than the other. Just a matter of opinion. Both very useful, both very powerful, both have their place.Quote:
>C++ is a superset of C
which means that
C++ is better than C - no doubt
I don't say C isn't powerful, but if you have a taste of C++ you won't return back to C..
Funning thing is, a lot of C++ compilers are written in C. So how would C++ be better. Its not better, just a different style.
The real question for "is C++ better than C", is whether you think OOP is better than non-OOP?
,why do you have strings in c++ instead of arrays of charcters?Quote:
The real question
why was another thingy created just so you dont have to have a '.h' at the end of your includes?
You have both. You can use whatever one does the job. String classes are generally "better" because they aren't as easily confused. (IE: Less prone to memory leaks, though you still can, and less likely to trash your program by running off the end of your allocated space.)Quote:
Originally posted by mart_man00
,why do you have strings in c++ instead of arrays of charcters?
Quzah.
>>why was another thingy created just so you dont have to have a '.h' at the end of your includes?
Because if your building a 1000 line file, why would you want that much more to type. lol, count the number of times you typed ".h" since the first time you started programming and think about how much time you would save not having to type them. 1 is miniscule (spelling???) but 100,000 is a lot.
>>why was another thingy created just so you dont have to have a '.h' at the end of your includes?
Because if your building a 1000 line file, why would you want that much more to type. lol, count the number of times you typed ".h" since the first time you started programming and think about how much time you would save not having to type them. 1 is miniscule (spelling???) but 100,000 is a lot. That goes the same thing for "typedef" which isn't needed anymore in C++.
:) another question: i've written a prg to detect prime number. well, using VC, the largest number i can detect is a 11digit one. using C, well, it's only a 10 digit number. i want to detect at least a 17 digit number(17 is my fav number;) )
how i gonna declare my variable in C for this? and in the printf what i gonna use? :)
You can't have a number with 17 digits since the longest number you can get is pow( 2, 31 ) - 1 ( = 2147483647 = 10 digits )