views:

131

answers:

7

I program in C++. Sometimes there are 1000 ways to do something, and depending on the inspiration/energy, etc of the moment, I can take "the right one" or not, and spend 10 minutes or three days to solve a problem or find a solution or do a task for the boss.

When you are programming, how do you deal with this "open" situations? Use your intuition? Prefer to plan a lot before?

Thanks a lot

+6  A: 
  1. from all possible solutions choose one that is easily testable.
  2. implement a test
  3. implement the code.

Repeat until I have the functionality I need to actually solve the problem.

Now check if the code is clean enough. Most of the time it won't. In that case, refactor until it is clean.

Clean enough means: Either considerably cleaner then the average piece of code in the project, or as clean as I am able to write it. Whatever is reached earlier.

Ok I have to admit, this is atleast how I try to write my code.

Choosing the solution by testability as a side effect prefers the well designed solutions.

Jens Schauder
+1 Excellent summary.
Preet Sangha
+1  A: 

I would:

  1. Write a unit test that checks off the expected solution to the problem
  2. Implement the first algorithm that comes to mind
  3. Refactor and repeat

This works especially well for a problem you are attacking for the first time. If you are worried your boss will say "stop" after point 2, just do a few iterations before you talk to him/her...

xcut
A: 

I usually try to find a well known pattern to apply to a particular problem. If I can't find one, or one close enough to derive my solution, then I do what I believe is best and fully document what I'm doing.

Then, six months later, I refactor it to apply a better pattern someone else has used in a similar situation.

Then, twelve months later, I refactor out the whole goddamn thing and replace it with five lines of code.

Will
+2  A: 

Try to maximize the amount of work not done.

For an open problem I just produce a minimum code which reflects my currently known information.

This does not mean that I produce low quality code. If I don't care about the quality of the code, I will make my life unnecessary hard for future changes, which will happen, when it is an open problem. If new information is dropping in I try to incorporate them into already existing code. Also the design/architecture will be then aligned to the currently known information.

Theo Lenndorff
A: 

Testability is great thing to have.

Another thing I pay lots of attention is readability. I'm usually going to support that code, so it better be shortest, cleanest way, including minimum of non-task-related entities.

In spirit of DDD, this would mean an almost natural-language description of your task translated into programming language.

Victor Sergienko
+1  A: 

Make it run; make it right; make it simple.

Or to elaborate:

  1. Build the simplest thing that might possibly relate to a solution.
  2. Refine it so it meets requirements. Design and accumulate unit tests; when all the tests run, your project is done.
  3. No, wait! It's not done until the code is so simple that it obviously has no faults. If the code is so complex that it has no obvious faults, you're not being true to your craft.
Norman Ramsey
A: 

Hmmm, i prefer not to answer as plain-text but .Net Code-Segment ;)
I think its easy for C++ Dev to understand the following:

SolutionRefining()
{
    result= Requirements.Brianstorming(Current_Experience_Knowledge);
    if(!result.Equals("Its Time To Design and Code"))//Assuming analysis is already done!
    {
        do
        {
            this.TakeRest_Break_HaveFun();//Multi-Processes OS ;)
            result = QuickResearchSession(searchEngine Google, softwareCommunity StackOverflow, inHouseGuru Anonymous);
        }
        while(!result.Equals("Its Time To Design and Code"));
    }
    else
    {
        while(Testing().MajorBugs >= 1 && !Coding().Finished)
            Develop().Review_UnitTesting().Commit();//artificial .NET! Don't try it in VS 2010.

        SubmitProject().GetMoney().GetLaid();
        WakeUp().GoToWork().BeReadyForNewFeaturesAttack();
    }


    MeanWhile (!Solution.Equals("Standard & Best Practice")) //MeanWhile can be found in .NET Framework 11.7301 Beta RC.45

    {
                    //this method shall always invoked during the developer journey in the Software Life Cycle.
        Study("Design Patterns").Understand().UnderstandMore().Apply();
        UpdateTheToolKit();
        SearchFor("Standard & Best Practice").Consume();
    }

    finally("Write your own A-Z framework").GetRetired();
}
jadook
Please tell us why your first line is out-dented?
John Saunders
VS2008 to StackOverflow Editor QA Bug!
jadook
@jadook: could you be more specific? I've been hoping to reproduce this bug for months now, but have not been able to.
John Saunders
@John: VS2008TeamSystem.Clipboard(C# Class).FireFox().SO_Editor().Misaligned()! maybe because i didn't use ctrl+K+D before clipboarding it. is that enough specification dude?
jadook
@jadook: What are your indentation settings in VS IDE?
John Saunders
@John: The Default set.
jadook
this is what I think of you, in binary: 1010111010101101010111001001111011001010111101010101100101010101100101010101010101010101010011010101111101001011010101010101010101010100101010100101000101101000101010101 :)
Werner