14

I was looking for a way to let datatables.js take into account hidden rows (with the .hide() function) when redrawing tables (for paging purpose). Datatables doesn't support this feature, and I couldn't find any suitable workaround on sites like Stack Overflow.

As I couldn't find any simple resolution, I decided to dive into the datatables.js source code to try and solve my issue. The solution I came up with looks good to me, and I think it could help others in the same case.

Is it OK to submit an answer suggesting editing the source code of an open-source external library (like datatables.js) to solve an issue?

8
  • 10
    what do you mean by "is it ok"? Is it a "valid" answer by the site's rules? Yes. It's generally a good idea to suggest to edit vendor code in place? Usually not.
    – yivi
    Commented Oct 29 at 13:46
  • It was more of a "Is is frowned upon to do so ?" question, so both your answers are helpful, thanks ! Based on your second answer, I guess the code edit and its effects should be thoroughly examined before suggesting it. Also should the answerer remind the asker that their solution might have side effects, and that the edit should be tracked and mentionned somewhere.
    – Hordrist
    Commented Oct 29 at 14:47
  • 4
    The good thing about open-source external libraries is that you can try putting that feature into the library. Takes more work, and a lot more thinking about the problem, and then it still might be rejected for whatever reason, but that approach is far more future-proof than hacking a local copy of the library. Commented Oct 29 at 23:19
  • 1
    If I change "answer suggesting editing" to "edit of", I get the question "Is it ok to submit an edit of the source code of an open-source external library (like datatables.js) to solve an issue?" to which the answer is (typically) an emphatic "yes", with the understanding that you would now be submitting to the library, rather than to Stack Overflow, and thereby helping others in the same situation (without them having to look for your solution)...
    – JaMiT
    Commented Oct 30 at 1:03
  • 1
    For an answer you probably want to demonstrate that it works. So you have to make the change yourself, not only suggest it. In that case, at the very least, publish your change (a fork for example). Commented Oct 30 at 7:34
  • 1
    <It's more than ok, in my opinion.> Both helping others, yourself, and the library creators to improve the situation, to later provide tested tools. Also by now, Github require an account and a registered phone, just to leave a message about a bug in whatever random library. Very bad move, but what to expect from Microsoft.
    – NVRM
    Commented Oct 30 at 7:58
  • 1
    @NVRM you are talking about the act of doing it, not about whether it would make a valid Stack Overflow answer or not which is the subject of this meta post.
    – Gimby
    Commented Oct 30 at 7:59
  • 1
    open source lives from contribution. Also datatables has ways to write plugins for that, the more reusable your change is for others, the better.
    – john Smith
    Commented Oct 31 at 11:19

3 Answers 3

18

It's "OK" in the sense that it's not against Stack Overflow rules, and such an answer shouldn't be flagged unless there's something else wrong with it.

But it would probably get downvoted since it's poor practice and will likely cause you headaches in the future, especially if you ever need to update the library. Maybe if it was clear that it's a workaround due to the lack of any better options, but I would make absolutely certain that there actually aren't any better options at the very least (for instance if you could add the functionality you need through a class extension in a separate file).

2
  • 10
    As Andras Deak mentioned in comments under the question, a good long-term way to modify open-source libraries is to get your change accepted upstream so you don't have to manually merge or rebase your patch every new upstream release. This of course requires them to be useful to multiple people and developed in a way that upstream might want to accept. Using your own fork of the project before a pull-request is accepted upstream is a viable option, but if it doesn't get accepted you need a plan to either do something else or to maintain your own fork / patch. Commented Oct 30 at 1:15
  • 7
    I think such an answer would be very well received if the answer included a warning, and, even better, a remark saying the author has opened a PR on said library to merge the new functionality into the library.
    – TylerH
    Commented Oct 30 at 15:08
5

It's fine as long as you warn of the drawbacks

As Andras Deak mentioned in comments under the question, a good long-term way to modify open-source libraries is to get your change accepted upstream so you don't have to manually merge or rebase your patch every new upstream release.

This of course requires them to be useful to multiple people and developed in a way that upstream might want to accept.

Using your own fork of the project before a pull-request is accepted upstream is a viable option, but if it doesn't get accepted you need a plan to either do something else or to maintain your own fork / patch.

I agree with TylerH's comment that such an answer would likely "be very well received if the answer included a warning, and, even better, a remark saying the author has opened a PR on said library to merge the new functionality into the library."

With a warning in the answer, future readers are less likely to get sucked into a maintenance problem without realizing the consequences of the road they're heading down. And if the changes can be plausibly upstreamed by someone, that makes it a lot better. It doesn't necessarily have to be by the author of the answer; someone else could fleshes out their ideas and do the actual work of sending a pull request or patch with credit to the OP. (A comment under the question would be appropriate for anyone who starts on that task, to let others know it's being done.)

0

Generally it'd be seen as unhelpful because in a lot of cases, it won't be possible to do so..

But now if you manage to "fix" the library, you can add a valid answer in the form of "this is now possible to do in version A.B.C, you can do this via...."

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .