Coffeehouse Post

Single Post Permalink

View Thread: General Programmer Question : how much do you reuse code/classes?
  • User profile image

    Really? I reuse classes all the time.

    Partly the way that I achieve this though is that every single problem (e.g. disassemble a file, or parse HTML or magic a graphical widget into existence) I write as a library.

    A consequence of this is that all of my Applications are really tiny, but import a bajilion libraries, and call the logic from each library. The Application is then almost entirely graphical stuff* (like this widget goes over here in this docking panel next to this thing that does notifications) and glues user events like mouse clicks into calls into the respective libraries.

    (* by which I mean, interacts with graphical controls defined in libraries )

    In my code, if logic that isn't strongly coupled to the Application (i.e. code that has any reuse value whatsoever) is going into the Application and not into a library, it automatically feels like I'm doing it wrong.

    The cool thing is, once you start programming like that, you quickly learn that there's no need to have a Service locator, because the service locator is the app itself. All of the power and all of the functionality of your code gets hived off into different libraries which because of the law of C# dependencies need to be carefully designed to avoid cyclic dependencies and hence end up being naturally decoupled, and the really cool thing is that next time you build a new application, it can quickly import the same libraries you've just built. Want that GUI component that you built on the other project? Import. Done. Want to disassemble this other type of file compiled for a different architecture? Import. Done.

    And when your other app wants more power out of your GUI component, you update it in the library and when you go back to your other project, your libraries have automatically improved underneath the app because it will automatically inherit the code from where-ever you're using it.

    I am seriously immensely glad that I decided to move to that model about 5 years ago. It has been a complete god-send to be able to never have nasty coupling and always have APIs that were always meant to be libraries to call instead of just having a huge mash of code to deal with.


    For context, I write all kinds of software, but recently I've written web servers, database engines, compilers, web-pages, operating system boot loaders, UEFI device drivers, protocol parsers and fuzzers, as well as GUI components for when I get bored to render the results in a pretty way Smiley