Quote:
Originally Posted by richinsc
What programing tools do you use. What software packages if any do you use. Do you vi, pico, emacs, or is there some other tool which you use. I am looking to get into Linux programming but want to know what tools you programmers of LQ use.
|
I use scons, make, gdb, vim, jedit, kate (or any other available text editor). I don't use emacs or any IDE.
Quote:
Originally Posted by richinsc
As far as Linux programming goes, any other languages worth knowing or learning bides c++?
|
python. Or perl. Or any other interpreted language. Helps for writing quick utility programs. I recommend python.
Quote:
Originally Posted by richinsc
I know a number of web programming languages such as php, html.
|
html isn't programming language.
Quote:
Originally Posted by richinsc
Any suggested reading on keeping code clean and organized, or any standards to follow.
|
Here you go:
I use following set of rules (C++ rules, partially taken from Qt4 source):
1) class name or any typename always starts with uppercase letter.
2) function name always starts with lowercase letter
Code:
void someFunction();
3) long function or class names are written as: "veryLongFunctionName" and "VeryLongClassName".
Code:
class VeryLongClassName{
};
void veryLongFunctionName{
}
4) underscores should be avoided. no "very_long_function_name" stuff.
5) member names and class variables do
not use special prefixes (things like m_classVariable are not allowed)
6) type of variable is not indicated in it's name (lpszStr is not allowed)
7) All constants are stored as unnamed enums, when possible.
Code:
enum {bufferSize=100};
That is unless constant is required to be variable.
8) constant names start with lowercase letter.
9) All enums or constants should be put into namespace or a class, unless they aren't declared into *.h (i.e. internal, used only in one *.cpp file). This keeps global namespace free of junk.
10) Global variables or functions should not be used in large projects. Large means larger than 10kbytes source code. Any global function or variable should be put into namespace or class. This helps to avoid name clashes, and keeps global namespace clean.
Code:
namespace Utilities{
extern int globalVariable;
void doSomethingGlobal();
}
class PseudoNamespace{
static void doSomethingGlobal();
};
11) NULL is not used, because it doesn't have special meaning in c++. 0 (zero) is used instead of null.
12) Pointers as parameters should be used only if argument is a pointer to first element of array, or function should be able to take 0 as argument. In all other cases references should be used. This makes code self-documented.
Code:
//incorrect function
void incorrectFunction(int* p){
*p = 1;
}
void correctPointerFunction(int* p = 0){
if (!p)
return;
*p = 1;
}
void correctReferenceFunction(SomeLargeStructure& dest){
dest.a = 1;
}
14) Or pointers or references in function arguments should be declared as "const" unless function writes to that pointer.
15) Short function/variables should be avoided. All function names, class names, and variable names should be as descriptive as possible. From short names, only "i" is allowed, because it stands for "iterator"
16) Most functional classes should be placed into separate *.h and *.cpp file, which should have same name as class. This helps to keep code organized. I.e. class MyClass should be stored in separate files "MyClass.h" and "MyClass.cpp" even if each is 20 lines big. The exception of the rule is allowed only if class is declared for internal use (subclassing, etc, helper classes for STL, etc) and isn't supposed to be used (or even visible) in other places. In this case class might be declared inside *.cpp near the place of usage.
17) All member functions should have "const" modifier unless they change class fields or internal data. This keeps code self-explanatory. Example:
Code:
class C{
protected:
int i;
public:
inline int getI()const{
return i;
}
}
18) Opening curly bracket is placed at the end of line.
19) Closing curly bracket is placed on separate line
Code:
void myFunction(){
if(true){
}
else{
}
}
20) There is no space between ")" and "{"
21) There is always empty line at the end of each file (requirement of unix compilers).
22) All classes and functions should be as short as possible, when it is possible. dozen lines or two, not more.
23) Function or member function should never be completely written in header, unless it is inline or template. Helps to avoid many errors.
24) Only template classes can be completely written in header files. For normal classes all function should be "mentioned" in header, but body should be kept in the corresponding *.cpp file.
25) When class uses multiple inheritance, dynamic_cast or static_cast should be used to cast class pointer into derived/base type.
26) In "if-else" block curly brackets are not used if there is only one line after if or else.
Code:
//this is incorrect:
if (true){
doSomething();
}
else{
doSomehingElse();
}
//this is correct:
if (true)
doSomething();
else
doSomethingElse();
The exception is when there is nested "if" within if-else.
Code:
//this is correct:
if (a){
if (b)
doSomething();
}
else
doSomethingElse();
This should be every rule I use, however there is a chance that I forgot to mention something.