Questions tagged [code-reuse]

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

1
vote
2answers
39 views

Sharing code between classes with runtime versus compile-time parameters

Consider a class which simulates an associative cache: template <size_t S, size_t L, size_t W> class AssociativeCache { size_t which_set(size_t index) { return index % (L * W); } // ... }; ...
0
votes
2answers
51 views

How do I reuse code for similar yet distinct types in Rust?

I have a basic type with some functionality, including trait implementations: use std::fmt; use std::str::FromStr; pub struct MyIdentifier { value: String, } impl fmt::Display for MyIdentifier {...
0
votes
1answer
23 views

Render table cells (td) with different HTML tags in React

I am developing a React application that fetches data from an API and renders it into a Table. I have 3 components: Row, Body and Table. Table fetches the data, passes it to Body, Body passes it to ...
0
votes
1answer
49 views

multiple iteration is done for creating the generic filters

I am trying to develop a generic filter component which can have many fields to filter on like color, size, price range etc and each field might have different types of elements like color may have ...
0
votes
0answers
49 views

django: taking DRY & code reuse to the next level?

In the django culture, I have encountered the concept of app reuse but not snippet reuse. Here is an example of what I mean by snippet reuse: I have a function getDateTimeObjFromString( sDateTime ), ...
2
votes
4answers
53 views

How to change background color of a reusable component in ReactJS?

I have a CTA component in React project. I am using it a few times on my page. I would like to change the background color and color of the text for one of the CTA uses. How can I do that? I ...
0
votes
1answer
61 views

How to construct a ParseIntError in my own code?

I want to reuse the standard library's ParseIntError in my function. However, I'm implementing parsing of the input string myself, so I don't need to return an error value returned by the standard ...
0
votes
1answer
132 views

React Native - How to re-use files?

I have design header, footer video player view, etc as a separate files. How do I include those in every pages? I tried this method. but doesn't work.
0
votes
2answers
28 views

How to reuse a scenario in citrus framework?

I set this testing scenario with citrus framework. Now I'm trying to reuse it in other scenarios. I'm creating a behavior for each step. My behaviors are mainly http requests public class ...
0
votes
0answers
13 views

how to reuse camera layout screens

Good afternoon friends, I'm facing a problem and a question about re-using screens on android. I'm working on an application, which has a screen where the user takes photos of his document, the front ...
0
votes
0answers
29 views

Reuse large quantity of Xaml interface elements

I have made a very similar post about this earlier where I asked how to reuse a part of some Xaml code. Although that worked for the small element I had, it does not quite work on the current scale. ...
1
vote
1answer
23 views

XAML reuse specific UI elements

With Xamarin, I have a small UI element which acts as a content divider: <BoxView StyleClass="contentDivider" HeightRequest="2" WidthRequest="1000" Margin="3, 0"/> Since I use this a ...
0
votes
0answers
57 views

Can I reuse Java Kafka Consumer?

I want to have consumer pool and reuse each consumer. Is it correct? KafkaConsumer consumer = createConsumer(); TopicPartition topicPartition = new TopicPartition("topic", 2); consumer.assign(List....
0
votes
0answers
59 views

How to reuse react-native code in a next.js (with react-native-web support) project?

Reusing code between react-native and react-native-web is fairly well documented. Reusing code between next.js and react-native-web works perfectly thanks to "create-next-app --example with-react-...
-2
votes
1answer
47 views

What is the correct way to reuse code in any team-based (work) project?

So while I was working, a colleague of mine (code-)reviewed my code (shown below). The code is edited a little bit so it doesn't show what it's about. //Types is a static class with static strings (...
0
votes
1answer
44 views

Exactly same function but data struture returned would be different

I have a function foo(). I want it to either return a std::queue or a thread safe queue object. What's the best way of doing this? I considered templates but not sure they fit the situation. I could ...
0
votes
1answer
65 views

Can I use the 'react-redux' 'connect' HOC to provide custom selectors to 'generic' React components through mapStateToProps?

I'm trying to create re-usable React components for a large React project my team is working on. For instance, I have a panel which consists of two sub-components, each of which consists of further ...
0
votes
2answers
185 views

Multiple Angular Apps using a common folder of modules

What I am trying to achieve is reusable modules. However we have many applications that are different but all require some of the same basic building blocks. For example a module for graphs would be ...
0
votes
1answer
46 views

PHP - Wrap a variable block in the same try-catch

in my PHP project, I use Guzzle to make a lot of different API requests. In order to handle all exception, each API call is wrapped into a try-catch block. An example: try { $res =...
0
votes
0answers
13 views

vs constants relating to projects not available in sharedproject

I have a set of source code which is reused. I recently learned about shared-project in VS which can be used for this purpose. I moved these reusables to a new shared-project and referenced it in ...
0
votes
0answers
34 views

Implement submit directive of form based on parent component

Hello i am trying to understand how can you create reusable forms in Typescript .What i understood so far is that you can create a Form Component , write its HTML file where you use the model fields....
1
vote
2answers
74 views

Two level settings menu with reusable tableview for iOS

I am very new to iOS App development and need some help. I am trying to implement a settings kind of screen where some of the items will display more options in the next screen. Trying nested two ...
-1
votes
2answers
152 views

How can I remove duplicated code between classes without implements?

I wrote many implementations of a function to compute the Fibonacci number at a given position. Fibonacci Class: this class helps me to test each implementation without rewrite same test code. I don'...
0
votes
1answer
44 views

programming python number in python program 3.6 version

Below is my code: Number = input("write your number: ") if tall.isdigit(): print("The number is integer") else: print("The number is a floating point") How does the python program ...
0
votes
0answers
27 views

Code Re-Use leading to StackOverFlow Exception

I am using MVC5 with Entity Framework and my application has 2 layers(projects): the Data Layer (DL) and the combined Business/Presentation Layer (BPL). The CRUD operations are defined in the DL and ...
1
vote
1answer
38 views

Zend Framework - How can I subdivide an application in two?

I'm working in a project with many modules, these modules may refer to classes from another module. Exemple: ControllerModule1 { $newClass = new ClassModule2(); } My question is... Is there a way ...
0
votes
1answer
25 views

Reuse element/class with JAXB unmarshalling

I have this XML structure: <?xml version="1.0" encoding="UTF-8"?> <specie name="Puma concolor" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="species....
1
vote
0answers
45 views

Reusing a cmake-built QT project in Visual Studio 2015: “connectSlotsByName: No matching signal”

As mentioned above my task is to change the code of an existing visual studio project that uses QT 5.7. The student who has worked on it before me built his project with cmake with which I am ...
0
votes
0answers
53 views

Best way to create 'optional' models in a Django reusable app

I'm trying to create a reusable app where I define some abstract models, and some concrete versions of those models that the user can use if they don't want to inherit the models themselves. If the ...
1
vote
2answers
81 views

Runtime type resolution on a non-default constructible class without polymorphysm

I have a bit of a puzzle. I have a template class graph with a template parameter - a class vertex, that can be either symmetric or asymmetric, compressed or raw, and I only know which at runtime. ...
0
votes
0answers
54 views

Reusable component UITableView datasource for multiple screen with same structure in Swift

I have 3 screens that contain almost the same display for UITableView and cells. All the three screen have same table structure but model type is different for all screens. I can do that but I have ...
0
votes
0answers
46 views

How to load latest Class from two different projects

Consider below example. I have two projects. I have used common class c in both project. I want to load the latest class c from anyone of the project. E.g. Project 1: class a { } if ( ! ...
1
vote
3answers
42 views

How to start One Activity from Multiple Activities without violating the DRY Principle?

I am working on an Android App in which some Activities maybe started from Multiple Activities, I know how to move between Activities using Intents. I am just struggling with how to do code it without ...
0
votes
2answers
103 views

Reuse database-connection (PDO) in PHP-file sent by AJAX

I want to check on every key-up, if a username is available or already stored in the database. I use a JS-function with he html-tag onkeyup. In the JS-Function I use AJAX asynchronously to open a ...
0
votes
1answer
1k views

Nuxt.js/Vue.js resuable modal

My question is about core logic for the thing below 1) I have a Section Component and a Modal Component 2) In the Section Component i have an array of objects with title and description 3) In the ...
3
votes
2answers
253 views

How to define reusable blocks in gradle build

I'm writing a gradle build for a kotlin project where I want to reuse the same kotlinOptions in multiple tasks. At the moment my build script looks like this, as the kotlinOptions are the same for ...
0
votes
5answers
434 views

best practice of Symfony controllers

I'm looking for best practice in symfony controller logic. My current code have one controller: <?php namespace App\Controller; use App\Entity\Categories; use Symfony\Bundle\FrameworkBundle\...
0
votes
1answer
354 views

How do I use Twig to create reusable form inputs?

I'm using PHP and Twig for an application in which I want to be able to have consistent form inputs across the site that are all rendered from one place in the code. That is, I want all the form ...
-2
votes
2answers
46 views

Attempting to instantiate in loop, get unexpected type (expected variable)

I'm trying to instantiate three objects in a loop so that I don't reuse the constructor text. This is because, for Uni, we get marked down if we reuse the same line of code (it's marked automatically)....
2
votes
1answer
28 views

expandTitle(…) is not a function

I try to reuse this part but the console keeps logging this error. I have made sure that I do not have any typo mistakes in the function name. $(document).ready(function () { ... function ...
0
votes
1answer
288 views

Laravel Eloquent split large query in to chunk and reuse it

I am having really a very big query formation like below. i want to split this and need to re-use for many other ajax call's $buildquery=Hotel::has('room'); $buildquery->whereHas('room', ...
1
vote
1answer
146 views

How to automatically call script with environment variable set

I want to be able to call this script using ./script.sh -e "${env}" -a "${app}". -e (environment), while -a (application). Basically, by setting the environment as either stage or prod it grabs the IP ...
1
vote
2answers
69 views

Java code reuse in two or more methods with same code

I have the following code in Java to query a database: public interface MapReduceDAO { String host = "mysql"; int port = 3306; String user = "root"; String password = "root"; ...
0
votes
2answers
72 views

How can I split test methods for reuse in multiple case with Minitest?

I blocked for refactor my code in my Minitest files. I have this example: test_calls.rb describe Aircall::Calls do before do @call_by_id = DefaultAircall::AIRCALL.calls.get_by_id(34043501) @...
0
votes
1answer
46 views

Repetative “If statements” save and reuse results

I am in Visual Studio view of the MVC (razor code). I have the same bool "if statemant" being used several times in different area's of the code. I have been told that I could save the results of ...
0
votes
1answer
24 views

How can I reuse a specific function from a gallery to a blog to switch between gallery view of all posts and a specific post in slideshow view

I'm excited to ask for help from the coding heroes here at Stack Overflow. I'm trying to replicate a Javascript function. I had already used it before to display, on a single web page, the element ...
2
votes
2answers
147 views

Reuse r code with knitr in rnw / sweave files

I'm searching for a way to reuse r-code in latex using knitr. I have multiple excel documents, that I want to import, analyze and plot in the same way throughout my thesis. Right now I am making a new ...
2
votes
5answers
90 views

Is it possible to create a generic method that is suitable for different classes in Java?

I have different classes that have a structure like this: public class MyClass { private String name; private List<International> internationalList; } What I want is to have a generic ...
-3
votes
1answer
45 views

Reuse Codes In Laravel

I've some if() { } else { } condition, which is used in several times. I want to reuse them rather typing them over and over again. here is my controller source code: MyController.php
0
votes
2answers
42 views

How to show redundant docs on multiple pages in read the docs

In our read the docs project we have a use case where we need to show some specific docs on multiple pages in the same version of docs. As of now, we do this either by one of the following ways Copy-...