Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] default code templates

Hello everyone.

It's my turn to pick nits. :-)

I propose we change the default code templates to use the pre-increment 
operator explicitly rather than hoping that the compiler will recognize 
that the post-increment operator can be replaced by the pre-increment 
operator (at least for POD types).

It's always been a pet peeve of mine that too many people (even 
well-respected authors) use post-increment (or decrement) needlessly. 
Compilers are probably smart enough to fix this for POD types but can't 
legally do so for class types. In those cases more work is done than is 
needed. Let's lead by example.

-Keith
------

Index: src/org/eclipse/cdt/internal/corext/template/default-templates.xml
===================================================================
retrieving revision 1.3
diff -u -r1.3 default-templates.xml
--- src/org/eclipse/cdt/internal/corext/template/default-templates.xml  22 
Dec 2003 21:12:45 -0000 1.3
+++ src/org/eclipse/cdt/internal/corext/template/default-templates.xml  6 
Feb 2004 16:21:30 -0000
@@ -10,13 +10,13 @@
 <!-- C++ -->
 
 <template description="for loop" name="for" context="C Function">
-for (${var} = 0; ${var} &lt; ${max}; ${var}++) {
+for (${var} = 0; ${var} &lt; ${max}; ++${var}) {
        ${cursor}
 }
 </template>
 
 <template description="for loop with temporary variable" name="for" 
context="C Function">
-for (int ${var} = 0; ${var} &lt; ${max}; ${var}++) {
+for (int ${var} = 0; ${var} &lt; ${max}; ++${var}) {
        ${cursor}
 }
 </template>



Back to the top