Re: Should we follow standards? Do you follow?
Posted: Sat Feb 14, 2009 12:00 pm
I follow the standards that don't get in my way... I use to declare variables all in the upper block of a function.. but C++ broke me from that.... (although I am trying to correct that bad habit of mine in C)
I think /**/ comments are clunky for one-liners so // is fine. It's included in C99 anyway...
Recently I have begun trying to stick to standards enough so that my code compiles with gcc and pcc. This included some weird __packed handling macros though(which some might consider a hack).
[rant]
Trying to follow strict C++ orthodoxy is just insane. For instance, what about command line arguments? like
That according to some people would be bad C++ coding. Because myfile can be accessed before it is constructed. The only "correct" solution is
or
I think /**/ comments are clunky for one-liners so // is fine. It's included in C99 anyway...
Recently I have begun trying to stick to standards enough so that my code compiles with gcc and pcc. This included some weird __packed handling macros though(which some might consider a hack).
[rant]
Trying to follow strict C++ orthodoxy is just insane. For instance, what about command line arguments? like
Code: Select all
MyFileClass myfile;
int main(argc,argv){
myfile.load(argv[1]);
}
Code: Select all
int main(argc,argv){ //I'm lazy rofl
MyFileClass myfile(argv[1]);
}
Code: Select all
MyFileClass *myfile;
int main...
myfile=new MyFileClass(argv[1]);
}
[/code
The error of that code though is that now to use myfile, you must pass it to every function. A few extra pushes per function in a loop though can have a rather big performance penalty. Can even mean about 10000 extra instructions that are NOT necessary. Not to mention the overhead of mov [ebp+xxx],xxxx. displacements cost clock cycles. I ran into this problem when making my x86 emulation project in C++. When changing from an "improper" global CPU class to a "proper" local CPU class(passed on stack) I saw a loop of 5 instruction executed about 0xFFFF times, slow down by about 5 seconds.
The problem with the pointer version of that code is now you must use the clunky "->" convention. Which also means more indirection and more memory accesses, which would have the same problem as the local version.
It is for this reason, I no longer use C++... C++ is built for people wanting fastly developed code, not necessarily the fastest code, C is built to work anywhere and as fast as you would like to optimize it for.
[/rant]