Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

For classes and functions, it is clear cut: each should do only one thing.

For libraries though, this is less clear. If you have a library with collections, it might have multiple collections. It might have useful functions like sorting, which aren't strictly collection based but users would expect. Each of these results in a 'wider' library.

On the other side is having a library for the specific collection type and/or with little built-in functionality. If you want a queue, it gives you a queue. If you want to sort that list, then the library lets you do that yourself.

What is the best practice here (if any)? I can see arguments for each side.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Wide enough to make the main elements of the library usable.

Your example with sorting is a good one. If your target language/environment has default sorting functions for collections and you, are implementing collections that cannot be sorted with the normal sort functions, then I would think it would be desirable to include sorting functions.

If you can implement the collections to sort with the default functions of your target environment then adding helper functions probably is not necessary and the library can be lighter.

Occasionally it is useful to add a convenience method even when the default functions do work if your library is a specific enough that there would be specific custom sorts that would always be needed like a job title seniority sort on an employee collection.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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