Improve your C++ coding style

Pages: 12
Hi, I've been searching for std::tr1 documentation and finished on open-std.org then I found a smal pdf book which inspired me so much.

few(all exactly) examples in that book are so cool on how to improve your coding...
there are also some diagrams showing the results.

take a look and see what you have to say:
http://www.open-std.org/JTC1/SC22/WG21/docs/ESC_Boston_01_304_paper.pdf
Last edited on
Only just begun reading, but should be wary of "old" optimization guides. Many common micro-optimization tricks have been made redundant by improved compilers. Many of my "speed hacks" were completely useless (or even worsening) once I upgraded to VS2010.

My suggestion would be making small examples yourself and testing them on your compiler.
By the way, I'm very interested in what you're programming if these tricks get you a 50% speedup.
thanks for reply Gaminic,
Many of my "speed hacks" were completely useless
whell that's because you allready had the knowelede of making your code as short as possible.

By the way, I'm very interested in what you're programming if these tricks get you a 50% speedup.


I din't say that this book speeds my programs up to 50%
but I see alot of beginers are writing a code which could be wrten in 2x or 3x less code!

so I thought maybe someone can find that book interesting :)

"old" optimization guides

old optimization guides??
for every new programer who just started learning C++ this are very new things.

You're most welcome.
cheers!
smaller code != faster code
@quirkyusername
your reply doesn't clarify anything.

can you be more precise about what do you want to say exactly?

EDIT:
smaller code != faster code

what is that mean fast code ?
Last edited on
@ codekiddy, it seems you're talking about code which is written fast.

But most coders think "fast code" is a program that runs fast.

Edit: grammar.
Last edited on
Ok I've edited a title of this thread to
Improve your C++ coding style


I hope now will be less misunderstandings :D

Edit @Catfish
Yeah well, even fast programs are runing slow on slow comps lol
Last edited on
Writing time is pretty much a useless measure. The time spent thinking far outweighs the actual typing time anyway. I'm not certain how you drew the "less typing" conclusion. How exactly would a jump-table or reversing loops reduce the required amount of typing?

Anyway, "fast code", like Catfish said, is code that executes fast. A common example is sorting: a BubbleSort algorithm can be written in <5 lines of code, but it is [for non-trivial cases] much, much slower than QuickSort, even though QuickSort is going to require quite a few more lines to implement.

This might also clarify my previous post a bit more: these optimization tricks are "old", because compilers have gotten much, much smarter. If a jump-table is generally faster than if-then-else or switch constructs, you can be quite certain that most modern compilers will generate the same assembly code for either version. Reversing loop order is one of the few things I'm certain of that have lost their purpose between VS2008 and VS2010.
quirkyusername wrote:
smaller code != faster code

Usually it does. The more instructions a program contains
1. The longer it will likely take to execute them, although 10 instructions that each take 2 cycles to complete is faster than 5 instructions that each take 5 cycles to complete.
2. The more instruction cache misses there will probably be
Complexity is probably a better estimator, though.
If you're coding assembly, maybe. Anything above that does a terrific job at hiding the actual number of instructions.
That document reads like a documentation of the optimizations compilers typically perform.
I was talking about the actual code in the executable, i.e., bytecode or machine code.
closed account (1yR4jE8b)
a 5 line bubble sort will generally be much much slower than a 50+ line QuickSort.
@chrisname: Why would you bring up machine code in this discussion? That is by far the least useful measure to go by, considering nobody ever gets to see or touch it.
If by line you mean sequence point, then it depends on optimizations.
If by line you mean line, then I shall write my entire program on one line. Or should I put a new line every time I am allowed whitespace? :p
hi guys i want to make a code program using visual paradigm but i cant start the new project will you tell me were to start using C++
@Gaminic,
I'm obviously not getting my point across.
Nura wrote:
hi guys i want to make a code program using visual paradigm but i cant start the new project will you tell me were to start using C++


Hi.

The only kind of program I know is a program written in code, so saying 'code program' doesn't make sense ;)

Visual Paradigm? What do you mean by that?

Probably you want File -> New Project if you are using Visual Studio/Visual C++

If by 'were' you mean 'where', then you're already in the right place for starting C++. Go here for a tutorial:
http://www.cplusplus.com/doc/

By the way, don't respond to topics unless you have relevant information or questions. ;)
Nura,
if you mean Graphical interface by saying visual paradigm then you'll have to spend some time before reaching Forms and buttons.
Pages: 12