views:

753

answers:

16

I'm trying to build up a library of reusable code to use from project to project. As I write code snippets and components, I'm trying to decide which libraries I will get the most use out of long term VS will I really use this again?

What code or components do you reuse that should every developer have?

I'm primarily interested in .net web and winforms.

+1  A: 

I easily think of:

  • Linked list templates
  • Red-Black tree templates
  • Database initialization mini-api (for your favorite database or persistency layer)
fmsf
+2  A: 

Personally I think a good framework should provide these tools, not you. If not the language's default library (Java is a good example).

Malfist
Sooner or later for fun i guess we all implement them so it's easily re-usable :)
fmsf
+1  A: 

I think that this will greatly differ depending on the language and what the framework you may be using has to offer. Much of the needed reusable code would be in a modern framework.

Brawndo
+10  A: 

Regular Expressions for verifying

  • Valid Date
  • Valid Number
  • Between two Dates
  • Zip
  • Postal
  • Age
  • Number Range

Depending on the language as some have these features already

cgreeno
Some of these are specific only to a subset of applications. And you have localisation problems too if you stick to regular expressions. Is 07/24/2009 a valid date? Not where I come from. And 90210's not a postal code, either. If you're going to have it in a toolbox, you want something a bit more sophisticated that handles these things.
Edmund
I would also include, code to only allow certain type of characters in text input fields.
Fábio Antunes
+2  A: 

It depends on what kind of applications you write. So I don't think there is a real toolbox for any problem. (Or it should be the framework).

We have several applications and a cross application library. That contains a lot of code:

  • Printing functions.
  • Shape processing (we do a lot with shapes and polygons)
  • dB calculations
  • general application behaviour (housestyle).

Each time we have something in an application that is possibly useful for other applications, it is moved to the library.

Gamecat
A: 

In .Net:

  • Extension methods that are not in .Net Framework (ForEach, AddRange, RemoveWhere, etc)
  • Switch.Type statement (for visitors)
  • Basic argument validation (Argument.EnsureNotNull)

That's almost all, various free libraries cover up the rest.

Andrey Shchekin
+1  A: 

The answer depends on your goal -- often making something "reusable" takes more effort at the onset but of course, pays out later when reused -- provided of course, that it's truly reusable. Sometimes this ability is overrated ... IMO ...

The true answer to this will be answered as you write code -- when you find yourself saying, gee, I just wrote something like this last week.

My "toolbox" consists of string, math, network, database, file, logging, and a host of other "library" routines (assemblies, etc) that I can quickly include as a references. Of course, the key to making this a living library is to keep the code of these library items truly separate from the app/code being developed.

hope it helps ...

Borzio
+2  A: 
  • Database Pooling code
  • Logging
  • String and collection manipulation
  • IoC maintenance (annotations or XML)
  • File and directory handling

Some of these may be supplied with a VM or standard libraries but you will always need something extra.

Fortyrunner
A: 

PKI authentication

Drell
+6  A: 

A *nix operating system (Unix, Solaris, Linux, MacOS, Cygwin) and it's "classic" set of command line utilities.

The ways to merge, mix, bake, shred, and abuse these fundamental concepts are immeasurable.

Will Hartung
I'm reading The Unix Programming Environment right now. it is almost as old as me, but still surprisingly valid.
Joel Hooks
A: 

My two:

  • Dependency injection code, so you can make it more testable; and not rely on a single implementation of a singleton.

  • Modular/Plugins functionality. It is also a great idea to make this mockable, so your client code can be tested without invoking a full-blown plugin system.

There are several implementations of both, though sometimes you can't avoid writing your own. :(

jamesh
A: 

Parsing classes

Date manipulation classes

messaging classes

validation classes

ooo
A: 

great question

  1. business object level caching
  2. my own custom authentication toolkit
  3. jquery selectors
  4. css for forms, tabs and ui elements
  5. encryption and hashing for passwords etc

altho I'm starting to replace my stuff with enterprise library - http://msdn.microsoft.com/en-us/library/cc467894.aspx - it at least gets improved up on over time and has way more eyes on it than my implementations

BPAndrew
+1  A: 

I've been working on creating a set of re-usable code for c#, for a little while now. By adding 1 component at a time and more importantly, using the framework for a real application, I've finally made the framework faily simple, well documented, and with various "modules" that tend to be used again and again.

Check it out at CommonLibrary.NET on CodePlex

It's a bit simpler and more lightweight than SpringFramework and MS App Blocks.

It includes things like : 1. Argument/Options parsing 2. ActiveRecord/Domain Model classes 3. Collections 4. Validation and a lot more..

A: 

As a weary and disgruntled code maintainer, I would look at this questions differently: what code should the project require be used, to avoid seven* developers creating seven different solutions, which require seven modifications when something changes (after discovering that there are seven different solutions).

I guess most people look at reuse as an efficiency tool in initial development, and forget that it is also the key to efficient maintenance.

*I think there are only seven, but I am still in testing.

cvsdave
A: 

A Money class that can handle currency, distribution, arithmetic operations, and formatting.

Jeff Sternal