View Full Version : coding tips plz....
alaios
07-23-2005, 11:24 AM
Hi ... i am writing these days.. a complex c program... That has lot of files as well as header file.... After some days of coding... i have noticed thats difficult to remember everything... So i need some advice how to keep my code clean easy readable and how i must keep the documentation for remembering what i have implemented and what is to be implemented..
At start i have thought uml ... but uml is good for object-oriented programming like c++ and not for c. I have also thought to open a text editor and start writing text for each file i have... but i dont know if this is sufficient is clever enough or not... So i need your experience to make things better.... Suggestions?
Thx a lot :)
For the same kind problem of yours, a lot of programmers on the web suggest me to read articles or IT papers with titled "System Design and Development" and "Structured Programming Methods". :thumbsup:
DoubtlessOne
07-30-2005, 04:43 AM
I've heard Pascal was good for object-orientation as well
but usually it has it's limits like many
C seems to have a limited Syntax, C++ I've heard was a very common and useful coding language (which I was hoping to find some interesting and experienced people around here to help me on my project :D )
C# however I've heard is the best of the best in the C series, however it should be the most difficult
My tips upon coding would be "Find the best snippets to match your project"
Header files are usually a hassle to create (My opinion really, but my opinions suck I know)
however a massive amounts of DLLs to cover up the messes any header files would make is usually how the CIA covers up Alien discoveries
I'm not sure if this what you're asking concerning clean/easy/readable, but:
I'd suggest a consistent coding style:
http://en.wikipedia.org/wiki/Programming_style
maybe take a look at:
http://www.gnu.org/prep/standards/
and, you could have a generalized flow charts of how things are supposed to work(I believe there are apps that can help you with that).... or, comment your code.
you could have a generalized flow charts of how things are supposed to work(I believe there are apps that can help you with that).... or, comment your code.
For this task, I love to use the Microsoft Visio.
That's great, I think.
Mhtml
08-03-2005, 06:57 PM
So long as your style is consistant you should not have any trouble at all. My programs and libraries usually contain 50 or more files and tens of thousands of lines of code. Sometimes for very complex functions, like those involving recursion I like to use internal documentation for algorithms and if something involves some mathematical forumlae I made up for some problem I write that out as internal documentation as well.
I can come back to a project I did months ago and continue on without too much trouble. It all comes down to consistancy as was mentioned. Don't try to be too cryptic with variables and file names.
I program in C++, so I have the luxury of using objects. I keep different objects separate from others in the file system. It's much easier, I also name them different. My current project has lots of objects, however there are 3 main ones.
GUISUBSYSTEM, GDISUBSYSTEM and RSCSUBSYSTEM. All files belonging to those parent classes, regardless of if they themselves are classes are named according to the parent. GUI_XXX.h/cpp, GDI_XXX.h/cpp, RSC_XXX.h/cpp..
Don't be afraid to make variables really obvious either.
bool windowHasFocus; //Pretty self explanitary isn't it?
Some people even prefer-
bool bWindowHasFocus; //b stands for bool
int iNumberOfWidgets; //i stands for integer
char* cPtr; //char pointer
Program in a way that feels comfortable. I use my own indentation level, my syntax colors all contrast with a dark-grey background (easier on my eyes during long periods).
You don't know the meaning of complex until you've stepped into c++ with polymorphism and function pointers. Things are everywhere, you have so many abstract data types you've nearly forgotten what int looks like lol.. I don't have any problems managing all that.
Also, I should mention code stubs are always useful.
Most IDE's should provide a todo list, dev-c++ does at least.
Aradon
08-03-2005, 08:06 PM
Mhtml has a very good point, while I'm not a C++ programmer, I do program in the child of C++, Java. (argue all you like it's true)
Java has dumbed down a lot of the references problem but we still have the same polymorphism, abstract, ect. that C++ has. And Mhtml is right when he says do whatever is comfortable and be consistant.
When I first started coding I coded with variables such as bah, blah, gah, higa, ect. because at the time that was easy for me to do. I was consistant and was able to tell you anything and everything about those variables. As I got into more complex code however, I learned the value of having a name mean something. Now I make sure to include useful variable names in my programs. After all, who says you can't have a variable named
"windowPopupOnMouseClick" :P
Make sure your .cpp files and .h files (that's c++ right? :P ) names make sense. Don't just name them test1.cpp or test2.h or what not. It's just eaiser to go back to a program if it's meaningful.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.