Questions tagged [code-reuse]

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

875 questions
398
votes
6 answers

What is the purpose of Android's tag in XML layouts?

I've read Romain Guy's post on the tag, but I still don't understand how it's useful. Is it a sort-of replacement of the tag, or is it used like so: . . …
cesar
  • 8,944
  • 12
  • 46
  • 59
127
votes
14 answers

Errors: "INSERT EXEC statement cannot be nested." and "Cannot use the ROLLBACK statement within an INSERT-EXEC statement." How to solve this?

I have three stored procedures Sp1, Sp2 and Sp3. The first one (Sp1) will execute the second one (Sp2) and save returned data into @tempTB1 and the second one will execute the third one (Sp3) and save data into @tempTB2. If I execute the Sp2 it will…
HAJJAJ
  • 3,667
  • 14
  • 42
  • 70
78
votes
6 answers

Add rounded corners to all UIImageViews

I would like to add some rounded corners to all of the UIImageViews in my project. I have already got the code working, but am having to apply it to every image; should I subclass UIImageView to add this? If so, can someone give me some pointers as…
Jack
  • 3,878
  • 15
  • 42
  • 72
63
votes
8 answers

How would you implement a "trait" design-pattern in C#?

I know the feature doesn't exist in C#, but PHP recently added a feature called Traits which I thought was a bit silly at first until I started thinking about it. Say I have a base class called Client. Client has a single property called Name. Now…
mpen
  • 272,448
  • 266
  • 850
  • 1,236
46
votes
12 answers

How do you make code reusable?

Any code can be reused in a way or an other, at least if you modify the code. Random code is not very reusable as such. When I read some books, they usually say that you should explicitly make the code reusable by taking into account other…
Silvercode
  • 977
  • 1
  • 7
  • 13
28
votes
2 answers

Django: How do I override app-supplied urls in my project urlconf?

Let's say I have a Django project with three apps: foo, bar, and glue. I'm trying to follow reusable app conventions, so foo and bar are not dependent on (and don't know anything about) each other or on glue. Glue contains code to integrate the…
Chris Acheson
  • 983
  • 1
  • 7
  • 11
25
votes
3 answers

How to re-use code between AngularJS client and Node.js server

What are the best-practices in order to re-use/share code between an AngularJS client and a Node.js server? I implemented an AngularJS application. Now I need to implement a RESTful-server providing the client with data. Some client-side angular…
jeromerg
  • 2,997
  • 2
  • 26
  • 36
22
votes
2 answers

How to re-use a reusable app in Django

I am trying to create my first site in Django and as I'm looking for example apps out there to draw inspiration from, I constantly stumble upon a term called "reusable apps". I understand the concept of an app that is reusable easy enough, but the…
Roland Tepp
  • 8,301
  • 11
  • 55
  • 73
22
votes
2 answers

Split one big XAML in number of Sub-XAML files

In my WPF4 Desktop-based application there is a big block with sidebar menu that repeats in each window and takes about 70 lines of XAML. In order to improve code reuse, I would like to split XAML file in two files: XAML-file that contains code for…
Mike
  • 14,010
  • 29
  • 101
  • 161
22
votes
2 answers

React Native: How to split a file up into multiple files and import them?

I am writing my first app in react native and my js file is getting pretty big. What is the proper way to split the file up. If i have something like var MyClass = React.createClass({ ... }) Can I save it at myclass.js and include in by some…
22
votes
3 answers

How can I write reusable Javascript?

I've started to wrap my functions inside of Objects, e.g.: var Search = { carSearch: function(color) { }, peopleSearch: function(name) { }, ... } This helps a lot with readability, but I continue to have issues with reusabilty. To be…
aw crud
  • 8,791
  • 19
  • 71
  • 115
21
votes
1 answer

Android Layout: Is reusable component UI possible?

I'll preface this with, I've just started learning Android so be gentle. I come from an ASP.NET / Silverlight background so I was looking for something along the lines of controls. I want to reuse a layout (a ListView item template) in other…
Tristan Warner-Smith
  • 9,631
  • 6
  • 46
  • 75
21
votes
7 answers

Does it exist: Repeated Code Finder?

In the near future, I will be inheriting a somewhat large project. I've been making some small updates to it recently, and noticed that parts of it could use some refactoring, since there are methods that perform the same operation with a small…
Dan McClain
  • 11,780
  • 9
  • 47
  • 67
20
votes
7 answers

How to avoid repeated code?

I'm still quite new to programming and I noticed that I'm repeating code: protected void FillTradeSetups() { DBUtil DB = new DBUtil(); DataTable dtTradeSetups; dtTradeSetups = DB.GetTradeSetups(); ddlSetups.DataValueField =…
Mark Allison
  • 6,838
  • 33
  • 102
  • 151
20
votes
2 answers

Library for both iOS and OS X apps?

For a while now I have been killing spare time by creating a 2D game programming toolkit/library. It is written in Objective C, and consists of an OpenGL rendering system and a whole bunch of AI, physics code, a bunch of specialized containers and…
os x nerd
  • 897
  • 1
  • 10
  • 18
1
2 3
58 59