943,699 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 89438
  • C++ RSS
You are currently viewing page 5 of this multi-page discussion thread; Jump to the first page
Sep 1st, 2006
2

Re: C and C++ Timesaving Tips

I totally agree to what Jerry Jongerius says:

Quote ...
Use a debugger only as last resort. Having to resort to a debugger means your programming methodologies have failed.


Last edited by Grunt; Sep 1st, 2006 at 12:05 am.
Reputation Points: 197
Solved Threads: 12
Junior Poster
Grunt is offline Offline
147 posts
since Jul 2006
Sep 1st, 2006
0

Re: C and C++ Timesaving Tips

Click to Expand / Collapse  Quote originally posted by Grunt ...
I totally agree to what Jerry Jongerius says:
I guess everyone has heard about the Promo event :cheesy: (just kidding)

For anyone intrested in actually saving time while coding and to know of the best programming practices i actually recommend "The C++ programming languguage" by the inventor of C++.

Personally i feel that the code should be organized in the following way:

1. Header file (one per class) and each header having minimalistic clutter. I personally feel that developing good programming practices is a matter of experience, the more you are exposed everyday to correct modular programming practices the more your skills will be honed. Just having the knowledge of modular programming practices does not suffice. (Header.h)

2. Implementation of Header file (Header.cpp)

3. Driver file which utilises the above two files (Driver.cpp)

Hope it helped, bye.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Sep 2nd, 2006
1

Re: C and C++ Timesaving Tips

Click to Expand / Collapse  Quote originally posted by ~s.o.s~ ...
I guess everyone has heard about the Promo event :cheesy: (just kidding)
What does this mean? Is this an inside joke?:cry:
Reputation Points: 166
Solved Threads: 0
Junior Poster in Training
Shane_Warne is offline Offline
59 posts
since Jul 2006
Sep 2nd, 2006
1

Re: C and C++ Timesaving Tips

What does this mean? Is this an inside joke?:cry:
Even I am not sure what he meant but I didn't ask because that would have spoiled his fun
Reputation Points: 197
Solved Threads: 12
Junior Poster
Grunt is offline Offline
147 posts
since Jul 2006
Sep 3rd, 2006
1

Re: C and C++ Timesaving Tips

Click to Expand / Collapse  Quote originally posted by Grunt ...
Even I am not sure what he meant but I didn't ask because that would have spoiled his fun
See Wolfpack's signature...
Moderator
Reputation Points: 3278
Solved Threads: 890
Posting Sage
WaltP is online now Online
7,718 posts
since May 2006
Sep 3rd, 2006
0

Re: C and C++ Timesaving Tips

Click to Expand / Collapse  Quote originally posted by WaltP ...
See Wolfpack's signature...
Ah, now I get it.
He recently changed the signature but this tip came before that :mrgreen:
Last edited by Grunt; Sep 3rd, 2006 at 7:43 am.
Reputation Points: 197
Solved Threads: 12
Junior Poster
Grunt is offline Offline
147 posts
since Jul 2006
Dec 23rd, 2006
0

Re: C and C++ Timesaving Tips

Use a descriptive name for the type. If you are having difficulty in finding a name for the type, you should do some more research about the type. You still don't know enough about what you want to implement.
Last edited by SpS; Dec 23rd, 2006 at 12:40 am.
SpS
Reputation Points: 70
Solved Threads: 32
Posting Pro
SpS is offline Offline
598 posts
since Aug 2005
Mar 20th, 2007
0

Re: C and C++ Timesaving Tips

Not sure if this belongs here, but non-the-less it has saved me LOT of time when I've to work with someone else's code.
Use Astyle to format the C, C++, C#, and Java code.
Download
Documentation
Project Home

DISCLAIMER:
Be warned, if you're scared of blind tool runs that modify code, don't use this. If you use it on production/customer-release code be sure to test. .
Reputation Points: 254
Solved Threads: 74
Practically a Posting Shark
thekashyap is offline Offline
804 posts
since Feb 2007
Sep 8th, 2007
0

Re: C and C++ Timesaving Tips

Click image for larger version

Name:	vector.jpg
Views:	59
Size:	108.8 KB
ID:	4041
Click to Expand / Collapse  Quote originally posted by Narue ...
Post your tips for making life easier in C and C++. I'll start:


Standard vector object initialization

The biggest problem with the standard vector class is that one can't use an array initializer. This forces us to do something like this:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. vector<int> v;
  9.  
  10. v.push_back(1);
  11. v.push_back(2);
  12. v.push_back(3);
  13. v.push_back(4);
  14. v.push_back(5);
  15.  
  16. // Use the vector
  17. }
Anyone who's had the rule of redundancy pounded into their head knows that the previous code could be wrapped in a loop:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. vector<int> v;
  9.  
  10. for (int i = 1; i < 6; i++)
  11. v.push_back(i);
  12.  
  13. // Use the vector
  14. }
However, it's not terribly elegant, especially for a vector of complex types. So, Narue's first timesaving tip for C++ is to use a temporary array so that you can make use of an initializer. Because the vector class defines a constructor that takes a range of iterators, you can use the array to initialize your vector:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int a[] = {1,2,3,4,5};
  9. vector<int> v(a, a + 5);
  10.  
  11. // Use the vector
  12. }
So here's what happened.
I was on DaniWeb getting help, and while waiting on someone to reply I looked through the sticky threads. I sent my C++ professor the link to Performance Tips and this thread on Thursday (i think). He sent me a message back saying he liked the one about vector something or other.
So on Friday morning he tells the class he added two slides (he uses powerpoint with most of his lectures), and one of them was because of a tip on the website I go to (daniweb ). I attached one of the slides he added.

Congrats Narue!
Last edited by Duki; Sep 8th, 2007 at 1:29 pm.
Reputation Points: 817
Solved Threads: 32
Nearly a Posting Virtuoso
Duki is offline Offline
1,474 posts
since Jun 2006
Sep 8th, 2007
1

Re: C and C++ Timesaving Tips

using boost.assign http://www.boost.org/libs/assign/doc/index.html is the easiest way to fill containers; and it also works with containers other than vector<>.
C++ Syntax (Toggle Plain Text)
  1. #include <vector>
  2. #include <list>
  3. #include <map>
  4. #include <string>
  5. #include <boost/assign.hpp>
  6. using namespace std;
  7. using namespace boost::assign;
  8.  
  9. int main()
  10. {
  11. vector<string> strings = list_of("abcd")("efg").repeat(5,"hi")("jkl") ;
  12. // "abcd" "efg" "hi" "hi" "hi" "hi" "hi" "jkl"
  13. strings += "mnop", "qrs", "tuvwx", "yz" ;
  14. // "abcd" "efg" "hi" "hi" "hi" "hi" "hi" "jkl" "mnop" "qrs" "tuvwx" "yz"
  15.  
  16. list<int> numbers = list_of(100).repeat(7,22)(75)(80)(85)(90)(83) ;
  17. numbers += 555, 666, 1, 2, 3, repeat(4,99), 56, 75, 80 ;
  18.  
  19. map<string,int> pbook = map_list_of("abcd",100)("efg",75)("hi",83) ;
  20. insert(pbook)("mnop",555)("qrs",4)("tuvwx",999)("yz",56) ;
  21. }
where is narue? even if daniweb does not miss her, the c++ forum does.
Last edited by vijayan121; Sep 8th, 2007 at 2:26 pm.
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C++ Forum Timeline: not sure why program crashes
Next Thread in C++ Forum Timeline: helpppppp me with this program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC