开发者

Most effective way of dealing with open problems in programming

开发者 https://www.devze.com 2022-12-21 17:56 出处:网络
I program in C++. Sometimes there are 1000 ways to do something, and depending on the inspiration/energy, etc of the moment, I can tak开发者_运维知识库e \"the right one\" or not, and spend 10 minutes

I program in C++. Sometimes there are 1000 ways to do something, and depending on the inspiration/energy, etc of the moment, I can tak开发者_运维知识库e "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


  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.


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.


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...


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.


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.


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.


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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号