Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Stuck learning programming, need help in where to head next.

learn beginner intermediate guidance general

This topic has been archived. This means that you cannot reply to this topic.
13 replies to this topic

#13 WingedPanther73


    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 23 September 2015 - 05:10 AM

Boost is a library that helps you do various cross-platform activities more easily. It does look like Boost has a unit test framework, so that may help, however. Unit-testing is a tool for Test-Driven Development.


The trick with Test-Driven Development is that it forces you to approach coding from a completely different mindset from what we're taught in classes. The "normal" mindset is that you write all your code, then you attempt to compile it. You start a cycle of removing bugs and compiling until your code will actually compile. Once it compiles, you start running it, trying to validate that the logic of the whole thing works, while digging around for bugs (wrong output OR horrible AV errors).

When you're working on code with less than a thousand lines, the "normal" mindset isn't too bad. With massive projects, where your smallest class might be a few thousand lines of code, that rapidly changes.


Look at the classes you've roughed out. What you want to do is start looking at a small one and begin asking yourself, "What should this method do? What inputs should it accept? What outputs should it produce?" You should be able to fairly easily write a short program like the following:


#include MyClass.h

int main()
  myObject = new MyClass(/*params*/);
  if (myObject.val1 == param1) {
    cout<<"param1 passed\n";
    cout<<"param1 failed\n";
  //check all params against values
  int dummy = myObject.Method1(/*params*/);
  if (dummy = 10) {
    cout<<"Method1(/*params*/) passed\n";
    cout<<"Method1(/*params*/) failed, actually equals "<<dummy<<"\n";
  //check Method1 a few more times
  //check remaining methods
  return 0;

Note a few things about the above.
First: you're testing only one class in isolation. This means you don't have all the interactions running around.

Second: you're working with a highly controlled situation. It's much easier to debug other classes when you are SURE this one works right.

Third: you can easily add tests. If you find bug, you can add a test to ensure it's really fixed. Further, you can ensure that your bug fix doesn't break anything else. We often "fix" one thing, only to find we also "broke" another. This testing helps you ensure you don't break things.
Fourth: once you know the methods and members, you can write the test with dummy functions (such as Method1 returns 0 no matter what. This lets you start checking things one at a time. Does each constructor work? Does Method1 work? Does Method1 work with corner conditions? Does Method1 work with the second call method?
Fifth: Despite the up front effort, a LOT of coders of found that this lets them work faster. It also serves as a form of documentation. You're stating (in code) what the expectations of your logic are. Combine that with the focus of knowing when a method is complete and not having to second-guess things, and you can focus your debugging efforts far more effectively.

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/

#14 Adegrue


    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 24 September 2015 - 11:49 PM

thank you for your post.......!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download