Questions tagged [code-reuse]

The use of existing software, or software knowledge, to build new software

875 questions
9
votes
2 answers

How can I promote code reuse in a manner similar to mixins/method modifiers/traits in other languages?

I'm working on some code that interfaces to a database schema that models a persistent graph. Before I go into the details of my specific question, I thought it might help to provide some motivation. My schema is around books, people and author…
ocharles
  • 6,172
  • 2
  • 35
  • 46
9
votes
6 answers

how to Create and Use SnackBar for ReUse(Globally) in Flutter

i want create SnackBar for reusable(globally) i already created but its only for 1 page , i don't know how to create reusable. below code: import 'package:flutter/material.dart'; class SnackBarMain extends StatefulWidget { @override …
MohammedAli
  • 2,361
  • 2
  • 19
  • 36
9
votes
7 answers

Same code on browser/server

I'm writing a web app using PHP, and running into several situations where I need similar code on the server and browser. For example: I want to validate user input, and generate the same error messages on both sides. I want to format data using…
JW.
  • 50,691
  • 36
  • 115
  • 143
9
votes
3 answers

Merge catch blocks with exactly the same code?

I want to merge the catch blocks in the following code for code reuse reasons: try { DoSomeInputOutput(); } catch (InvalidOperationException ex) { HandleKnownException1(ex); } catch (InvalidDataException ex) { …
DxCK
  • 4,402
  • 7
  • 50
  • 89
9
votes
2 answers

AngularJS + Karma: reuse a mock service when unit testing directives or controllers

I'm working with AngularJS + Karma. configService manages the settings of my app (e.g. the background-color, wether it's on debug mode, general permissions...). It loads initial data with $http. I wrote the test successfully for the service but my…
Eduard Gamonal
  • 8,023
  • 5
  • 41
  • 46
9
votes
3 answers

How do you manage your custom modules?

I write tons of python scripts, and I find myself reusing lots code that I've written for other projects. My solution has been to make sure the code is separated into logical modules/packages (this one's a given). I then make them setuptools-aware…
Jeremy Cantrell
  • 26,392
  • 13
  • 55
  • 78
8
votes
2 answers

What's the best practices in code reuse between different Ruby projects?

guys! I'm a software developer with Java background and I'm starting some projects using a Ruby web framework (Padrino/Sinatra). In my java projects, I usually had some "common" projects whose classes where used in several projects. For instance, I…
Carlos Melo
  • 3,052
  • 3
  • 37
  • 45
8
votes
16 answers

What reusable code should every developer have in their toolbox?

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…
Bill Martin
  • 4,825
  • 9
  • 52
  • 86
8
votes
1 answer

EJBs in libraries - Reusing EJBs

Let's say I want to create a library which I will use in future projects but I also want to include EJBs in that library referencing other EJBs etc.. That library would also contain simple java classes. What is the best way to do that? How do I…
Bat0u89
  • 610
  • 2
  • 17
  • 25
8
votes
1 answer

WPF XAML defined MenuItem reuse starts working, then disappears

The following simple code attempts to reuse a MenuItem defined in the Window.Resources on two separate Menus.
Taterhead
  • 5,763
  • 4
  • 31
  • 40
8
votes
2 answers

Is it possible to reuse GWT UIBinder panels?

I have a layout in Google Web Toolkit using UIBinder involving a TabLayoutPanel. This layout has the superset of all tabs that will be used by my app (think of it as an admin view). I now need to create a new layout, using a subset of these tabs…
pkaeding
  • 36,513
  • 30
  • 103
  • 141
8
votes
2 answers

How to write reusable glsl code?

My shaders often share much of the same functionality. For instance calculation of diffuse/specular lighting. I would like to write this one time and then reuse the code across different shaders. Glsl has no knowledge of files, and no support for a…
bobbaluba
  • 3,584
  • 2
  • 31
  • 45
8
votes
8 answers

Overcoming bad habit of "fixing it later"

When I start writing code from scratch, I have a bad habit of quickly writing everything in one function, the whole time thinking "I'll make it more modular later". Then when later comes along, I have a working product and any attempts to fix it…
michael
7
votes
12 answers

Code reuse and refactoring

What's best practice for reuse of code versus copy/paste? The problem with reuse can be that changing the reused code will affect many other pieces of functionality. This is good & bad : good if the change is a bugfix or useful enhancement. Bad if…
horace
  • 1,263
  • 1
  • 13
  • 12
7
votes
2 answers

Avoiding writing the same algorithm in multiple different languages

I am a web developer, and I have observed that many times I need the same function on both client and server. So I write it in JS as well as in PHP or whichever server side language. I am fed up with this. If I have to change it then I need to…
Hafiz
  • 4,187
  • 12
  • 58
  • 111