Thread: Creating a custom library

  1. #1
    Registered User officedog's Avatar
    Join Date
    Oct 2008
    Posts
    77

    Creating a custom library

    I am getting to the stage that I would like to shorten the time it takes to work on projects and thought of creating my own custom library of functions for general use in projects. Is this a wise investment of time / is this what other people do? If so, are there any tips about what functions i should consider adding?

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by officedog View Post
    I am getting to the stage that I would like to shorten the time it takes to work on projects and thought of creating my own custom library of functions for general use in projects. Is this a wise investment of time / is this what other people do? If so, are there any tips about what functions i should consider adding?
    Making libraries or otherwise generalizing your code base is never a bad thing. As to what kinds of functions you should add, that's going to depend on the kind of code you normally write.

    I think most programmers want to have their own "ultimate library." But sitting down and trying to figure out what functions you are going to need most often is futile -- and I can tell you that after decades of experience. Instead, try to identify common algorithms or design patterns in your own code and lift them out into utility libraries.

    Resist the little voice in your head which screams "This stuff is all unrelated, I want a single, cohesive library which just does everything The Right Way." That voice will just ruin you, making you start over and over again, throw away perfectly good code, rework or refactor stuff for which there is no evidence that further generality is needed, etc.

    The only way to start developing a general base of code is to start dumping things in the bucket. Over time you can scan over what you've accumulated and start to refactor, but in the beginning, make it a point to just get the code in there. Refactoring might involve actual code changes, or just breaking things into separate sublibraries, but that step should come later.

    Once you start breaking things up, though, realize that in C most design is data-structure driven. So generally the most logical places to split libraries are along the lines where common data structures are used. As you do this try to reduce coupling between your libraries -- ideally, none of them should be absolutely dependent on any of the others -- if that were the case, they should not have been separated in the first place.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User officedog's Avatar
    Join Date
    Oct 2008
    Posts
    77
    Thanks for your sharing your experience on this brewbuck. These are extremely helpful suggestions. I'll get started throwing stuff into the bucket...

  4. #4
    Registered User
    Join Date
    Jun 2008
    Posts
    266
    I would also check to make sure there aren't already libraries for what you are doing. You don't want to spend 2 hours coding a string library only to find a better one online!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Property Set Library (PSL) - Announcement
    By vultur_gryphus in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 05-29-2008, 06:04 AM
  2. Library Wrapper
    By cusavior in forum C Programming
    Replies: 3
    Last Post: 03-25-2008, 10:27 AM
  3. Difficulty choosing graphics library
    By jdiperla in forum Game Programming
    Replies: 11
    Last Post: 02-27-2008, 06:35 PM
  4. better c string functions
    By samps005 in forum C Programming
    Replies: 8
    Last Post: 11-04-2003, 01:28 PM
  5. Question with Winamp Library
    By moonwalker in forum Tech Board
    Replies: 3
    Last Post: 08-07-2003, 08:08 PM