Home > Thoughts > Code Snippet and Include Repository

Code Snippet and Include Repository

December 16th, 2009 kaheidt Leave a comment Go to comments

If you’re any sort of programmer what so ever, regardless of what language you code in, then you have most likely at one time or another run into efficiency antagonist known as “reinventing the wheel”.  I’m talking about that string reformatting function that you’ve just written for the third time which is a little different (and hopefully a little better) than the first two versions because you forgot the first two even existed.  If you DO remember that you already invented the wheel, then you spend a good amount of time trying to figure out where you put that damned wheel.  And if you work in a team environment, any situation where one programmer creates a subroutine and then another programmer many months later remembers the email from the first programmer and then reuses that code, well that’s what we call “a friggin miracle”.

In an effort to fight this never-ending war, I suggested to my manager at work that we implement a centralized documentation system that everyone can update with their own pieces of code.  Then if you need to create a function to perform some task, you can search through the system to see if anyone has done something similar.  For my work place, this system ended up being an open source asp.net WIKI.  It’s not bad, and it’s certaintly better than nothing, but it still leaves the problem of having to search by a keyword and then sift through the results until it looks like there’s something useful, if anything.  This is especially true if you’re trying to search by one of the key words in your programming language.  You’d probably end up with every single entry as a result.

After thinking about possible ideas to make searching for code a little easier, I came up with one that I think could be really useful.  Basically my idea is to come up with a search method that is specifically designed for searching for code.  My initial thought is to allow a person the ability to search using specific input and/or output and overall characteristics and examples, and then have the search results be listed in priority using the percentage likeliness of a match.

For example, let’s suppose I wrote a function that is designed to take a dollar amount and then round it to the nearest multiple of 50.  My entry of this function into my documentation system would have the following characteristics:

Name: Round Amount To Nearest Multiple Of 50
Keywords: Rounding, Amount, Multiples of 50, Number
Input Type: String
Input Length: 20
Input Example: "342.99"
Output Type: String
Output Length: 20
Output Example: "350.00"
Variable Types Used: String, Integer
Search Process: [See Below]
Function: [The actual function code]

Then if I wanted to search for a function that did what the above does, I could search with the following criteria:

Keywords: Amounts, Rounding
Input Type: Integer
Input Length:
Input Example: 320
Output Type: Integer
Output Length:
Output Example: 300
Variable Types used: Integer

When the search with the above criteria is executed, the search program would not only check for similarities of what I actually put for each item versus what’s entered for each function, but it would also perform whatever data manipulation is entered in the “Search Process” part of the function entry on the example input data of the criteria in order to see how closely the results match the example output.  In order to do that, there’d have to be some translation depending on what language the document system is built in versus what language the code is that the repository is for, but believe me, it would be really REALLY nice to be able to provide my data and what I’d like my data to look like, and have the necessary code snippet come up to be copied and pasted.

Maybe there’s already something like this, or even more advanced than this, I have no idea.  But if it doesn’t already exist, well damn it, it very well should.  Google… read this and then do that thing you do to make dreams come true.  Thanks.

Categories: Thoughts Tags:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.
Contact Form Powered By : XYZScripts.com