C and C++ Timesaving Tips

Closed Thread

Join Date: Jul 2006
Posts: 147
Reputation: Grunt has a spectacular aura about Grunt has a spectacular aura about 
Solved Threads: 12
Grunt's Avatar
Grunt Grunt is offline Offline
Junior Poster

Re: C and C++ Timesaving Tips

 
2
  #41
Sep 1st, 2006
I totally agree to what Jerry Jongerius says:

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.
The key to eliminating bugs from your code is learning from your mistakes.
Quick reply to this message  
Join Date: Jun 2006
Posts: 7,581
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 461
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: C and C++ Timesaving Tips

 
0
  #42
Sep 1st, 2006
Originally Posted by Grunt View Post
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.
I don't accept change; I don't deserve to live.
Quick reply to this message  
Join Date: Jul 2006
Posts: 59
Reputation: Shane_Warne is an unknown quantity at this point 
Solved Threads: 0
Shane_Warne Shane_Warne is offline Offline
Junior Poster in Training

Re: C and C++ Timesaving Tips

 
1
  #43
Sep 2nd, 2006
Originally Posted by ~s.o.s~ View Post
I guess everyone has heard about the Promo event :cheesy: (just kidding)
What does this mean? Is this an inside joke?:cry:
Quick reply to this message  
Join Date: Jul 2006
Posts: 147
Reputation: Grunt has a spectacular aura about Grunt has a spectacular aura about 
Solved Threads: 12
Grunt's Avatar
Grunt Grunt is offline Offline
Junior Poster

Re: C and C++ Timesaving Tips

 
1
  #44
Sep 2nd, 2006
Originally Posted by Shane_Warne View Post
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
The key to eliminating bugs from your code is learning from your mistakes.
Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: C and C++ Timesaving Tips

 
1
  #45
Sep 3rd, 2006
Originally Posted by Grunt View Post
Even I am not sure what he meant but I didn't ask because that would have spoiled his fun
See Wolfpack's signature...
Quick reply to this message  
Join Date: Jul 2006
Posts: 147
Reputation: Grunt has a spectacular aura about Grunt has a spectacular aura about 
Solved Threads: 12
Grunt's Avatar
Grunt Grunt is offline Offline
Junior Poster

Re: C and C++ Timesaving Tips

 
0
  #46
Sep 3rd, 2006
Originally Posted by WaltP View Post
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.
The key to eliminating bugs from your code is learning from your mistakes.
Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: C and C++ Timesaving Tips

 
0
  #47
Dec 23rd, 2006
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.
Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: C and C++ Timesaving Tips

 
0
  #48
Mar 20th, 2007
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. .
Quick reply to this message  
Join Date: Jun 2006
Posts: 1,169
Reputation: Duki has a spectacular aura about Duki has a spectacular aura about Duki has a spectacular aura about 
Solved Threads: 9
Duki's Avatar
Duki Duki is offline Offline
Veteran Poster

Re: C and C++ Timesaving Tips

 
0
  #49
Sep 8th, 2007
vector.jpg
Originally Posted by Narue View Post
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:
  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:
  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:
  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.
It is practically impossible to teach good programming style to students that have had prior exposure to Basic; as potential programmers they are mentally mutilated beyond hope of regeneration.

-Edsger Dijkstra
Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: C and C++ Timesaving Tips

 
1
  #50
Sep 8th, 2007
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<>.
  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.
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC