1

Suppose I use a open source framework in my project and I would not contribute (submit changes) to that framework, and the current version is stable, should we keep the framework unchanged when possible?

for example, if I found a function in a class of framework does not fulfill my requirements:

public class Fruit{
    public float calculatePrice(){
        return weight*1.2;
    }
}

I would wrap it to add my requirements:

public class MyFruit{
    Fruit fruit;
    public float calculatePrice(){
        return fruit.calculatePrice()*myConstant;
    }
}

instead of modify Fruit directly, and for another example, if I need to use a protected property in the class (e.g.:locale):

public class Fruit{
    protected String locale;
}

I would extend it to access the locale

public class MyFruit{
    public void checkLocale(){
        if(locale.equals("abc")){
        }
    }
}

instead of changing locale into public.

I think the motivations behind it are:

  1. The resources of the frameworks (e.g.:tutorials, behaviour ,bugs,issues) are based on the original version of the framework, when we change the framework directly, the resources may not be applicable to my modified framework anymore, or we may not be able to use the resource directly (e.g.:copy and paste online examples)

  2. It is easier to upgrade the framework when the framework keeps the original look

  3. If we modify codes in framework, it may introduce bugs in the framework, and debugging frameworks is more difficult than debugging my custom codes.

  4. Keeping the frameworks in original version allows us to add other extensions for the frameworks easily because most extensions are worked based on the original version

  5. It is more difficult to ask for help if we use a custom modified framework because you may need to post and explain the modified parts of the framework

  6. When problem occurs, if we just use the original version, it is faster and easier for volunteers to setup the environment, then reproduce and find out the problem, because they can just download the framework directly and then add my additional codes.

is it true that we should not modify codes in frameworks directly when possible? And is this attitude correct?

2

The rule-of-thumb about not modifying frameworks unless you intend to submit the modification back is mostly a pragmatic one: every time you do this you commit to re-applying the modification every time you update the framework to a new version. If you forget to re-apply the modification after an update, or if the framework changes the code in question so that your modification no longer works, the application will encounter errors or unexpected conditions. It's entirely a question of whether the benefit is worth the risks and the extra work.

If the modified code is going to be distributed there can be philosophical questions about not submitting the modification for inclusion in the upstream code. That would be better addressed on Open Source beta.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.