problem about code-reuse-Collection of common programming errors


  • Robert Harvey
    components soa code-reuse
    A couple of years ago the media was rife with all sorts of articles on how the idea of code reuse was a simple way to improve productivity and code quality.From the blogs and sites I check on a regular basis it seems as though the idea of “code reuse” has gone out of fashion. Perhaps the ‘code reuse’ advocates have all joined the SOA crowd instead? :-)Interestingly enough, when you search for ‘code reuse’ in Google the second result is titled:”Internal Code Reuse Considered Dangerous”!To me the

  • DxCK
    c# .net exception-handling try-catch code-reuse
    This question already has an answer here:Catch multiple Exceptions at once?14 answersI want to merge the catch blocks in the following code for code reuse reasons:try {DoSomeInputOutput(); } catch (InvalidOperationException ex) {HandleKnownException1(ex); } catch (InvalidDataException ex) {HandleKnownException1(ex); } catch (ArgumentNullException ex) {HandleKnownException1(ex); } catch (ArgumentOutOfRangeException ex) {HandleKnownException2(ex); } catch (ArithmeticException ex) {HandleKnownExcep

  • Chuck Callebs
    php mysql class scope code-reuse
    For a new project that I’m doing in PHP I’ve created an SQLMethods class to connect to the database and perform queries. Tonight was the first night that I actually got to test it (I wrote it a week or so ago and forgot about it) and an unexpected error occured: When it was calling my ExecuteQuery() function, it wouldn’t use the database I selected in the constructor.The constructor:public function SQLMethods() {$SQLConnection = mysql_connect($SQLDBAddress, $SQLUserName, $SQLPassword);if (!$SQLC

  • Has AlTaiar
    c# dll web windows-mobile code-reuse
    I have a class library that targets Windows Mobile CF, and I want to use the same dll on some Desktop/Web application. When adding a reference to the project I get the following error. adding a reference to a device project may produce unexpected resultsI am not sure what would be the result of such “unexpected results”

  • Dave Jarvis
    java object-oriented code-reuse encapsulation null
    BackgroundTony Hoare’s billion dollar mistake was the invention of null. Subsequently, a lot of code has become riddled with null pointer exceptions (segfaults) when software developers try to use (dereference) uninitialized variables.In 1989, Wirfs-Brock and Wikerson wrote:Direct references to variables severely limit the ability of programmers to re?ne existing classes. The programming conventions described here structure the use of variables to promote reusable designs. We encourage users of

  • jluzwick
    refactoring code-reuse
    Before I ask this question I will preface it with our environment. My team consists of 3 programmers working on multiple different projects. Due to this, our use of testing is mostly limited to very general black box testing. Take the following assumptions also:Unit Tests will eventually be written but I’m under strict orders to refactor first Ignore common Test-Driven Development techniques when given this environment, my time is limited. I understand that if this were done correctly, our tea

  • Jamal
    php readability code-reuse
    I needed to build a one-way web service for a mobile app I developed. Its only goal is to receive incoming JSON data and insert it into the correct tables. It works, but it looks very “kludgy” and cobbled together (happens a lot with solo development). I’d like another pair of eyes to see where it could be improved as far as design, robustness, readability, etc. This code is not yet in production, so I can implement suggested changes as needed.<?php$body = file_get_contents(“php://input”); $j

  • Murat
    java io code-reuse
    I wrote a FastReader utility class that is supposed to read input fast. Mostly aimed at parsing input files in competitive programming.How could I made this better? I am mainly looking for good code suggestions rather than the specific details of the logic. Though, any comments/recommendations are appreciated.package com.muratdozen.playground.util.io;import com.muratdozen.playground.util.threading.NonThreadSafe;import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream

  • T.R.
    jsp code-reuse
    I’m new to JSP, and I’m trying to reduce a massive amount of cut-and-pasted code. On each page in the project, there are around 25 lines of mixed JSP,Struts tags,JSTL tags, and HTML, which have been cut and pasted at various points in the page. These ~25 lines of re-used code are not even remotely similar from page to page (and there ~250 pages), but exactly the same within each page. Ultimately this (business logic) code should be moved out of the View, but doing so would be a larger project th

  • casperOne

  • Myles Gray
    c# reflection code-reuse
    I got myself in a situation where using the System.Attribute class seemed (at first glance) to be a good idea. I have an object to be printed in my application, and I need a label before each property (or just a string before it). I could put each property hardcoded like:Console.WriteLine(“Color:”+obj.color); Console.WriteLine(“Size:”+obj.size);And so on for each property. But instead of it, I was trying to create a code where this ‘label’ doesn’t needed to be hardcoded, so I could print every p

  • Vittorio Vittori
    javascript jquery cakephp code-reuse
    I’m developing a web community in CakePHP and started to have doubts about using jQuery to provide useful widgets around the views when needed.For example, I’ve wrote a jQuery plugin which searches the data inside specific input text, asks to my database and get the results handled with events.Basically the plugin is perfect for simple applications but it’s basically useless for a community where I use it almost in all the views and every time handling it with different events and methods, makin

  • Nathan Farrington
    licensing libraries code-reuse software-updates dependencies
    Modular programming and reusable software routines have been around since the early 1960’s, if not earlier. They exist in every programming language. Conceptually, a software library is a list of programs, each with its own interface (entry points, exit points, function signatures) and state (if applicable). Libraries can be high quality because modules are focused on solving narrow problems, have well-defined interfaces, and the cost can be amortized across all future software programs that wil

  • assylias
    design architecture interfaces code-reuse
    I have an interface to communicate with a DB (actually it is not a database, but this is to give a concrete example):interface DbInterface{Result sendQuery(Query q); }And I am trying to improve reusability by separating specific components into individual projects:App1, an application that requires access to a database App2, an application that requires access to a database DB1, a concrete implementation of DbInterface (let’s say SQL) DB2, a concrete implementation of DbInterface (let’s say usin

  • gnat
    c# code-reuse modules content-management
    I am trying to run multiple sites using single code base and code base consist of the following module (i.e. classes)User module Q & A module Faq moduleand each class works on MVC pattern i.e. it consist ofEntity class Helper class (i.e. static class) View (i.e. pages and controls)and let’s say I have 2 sites site1.com and site2.com. And I am trying to achieve following functionalitysite1.com can have User, Q & A and Faq module up and running site2.com can have User and Q & A mod

  • gmail user
    c# delegates code-reuse
    I borrowed the code from this question. I’m trying to implement the delegate in that code. Below is my outcome so far.What else can be done to improve this code? Any suggestions? I would appreciate suggestions regarding delegate, code reuse, etc.class Program { static void Main(string[] args){var flights = new List<Flight>{new Flight {Number = “FL001”, DepartureTime = DateTime.Now},new Flight {Number = “FL002”, DepartureTime = DateTime.Now.AddHours(1)},new Flight {Number = “FL003”,

  • Chris Marisic
    c# lambda code-reuse
    I have a Result object that lets me pass around a List of event messages and I can check whether an action was successful or not.I’ve realized I’ve written this code in alot of placesResult result;try {//Do Something …//New result is automatically a success for not having any errors in itresult = new Result(); } catch (Exception exception) {//Extension method that returns a Result from the exceptionresult = exception.ToResult(); }if(result.Success) ….What I’m considering is replacing this u

  • Larry Morries
    code-reuse
    I would like to use some of the classes that are available in Coded UI Tests, such as BrowserWindow, Playback, etc. But I would like to be able to run the resulting code without using VS, MSTest, TCM, etc, since the code needs to run in tightly scrutinized production environments. The first thing I ran into is the error:”FileNotFoundException was unHandled” Could not load file or assembly ‘Microsoft.VisualStudio.TestTools.UITest.Playback, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7

  • ExplodingRat
    c code-quality code-reuse
    I’m rather new to C, and I’m wondering if code duplication is a necessary evil when it comes to writing common data structures and C in general?I could try to write a generic implementation for a hash map for example, but I’m always finding the end result to be messy. I could also write a specialized implementation just for this specific use case, keep the code clear and easy to read and debug. The latter would of course lead to some code duplication. Are generic implementations a norm, or do yo

  • Silvercode
    code-reuse
    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 situations of code usage too. But certain code should not be an omnipotent all doing class either.I would like to have reusable code that I don’t have to change later. How do you make code reusable? What are the requirements for code being reusable? What are t

  • Ricardo Medeiros Penna
    javascript knockout.js code-reuse custom-binding
    I am trying to encapsulate the creation of an observable inside a custom binding, much like isValid of knockoutjs-validation, but without extending the binding because this property in the future will be the result of another binding that records a complicated sequence of events on the input and it feels like i shouldn’t do more than using a custom binding for this.The following code shows my custom binding responsible for the creation of the observable.ko.bindingHandlers.myBinding = {init: func

  • Rimbuaj
    javascript ajax angularjs angularjs-directive code-reuse
    I know this is maybe too general question but i would like to know how to make a reusable select (or any input) that when i am wating for its options (by an ajax request) it shows a ‘Charging …’ message as the selected option.So for example in any of my views i can use a directive called ‘ajax-charged’ and every select with that directive would have that behaviour. The Html i imagine while charging:<select ng-options=”opt in options” ajax-charged> <option>Charging … </option&g

  • Muhammad Reda
    drupal drupal-7 drupal-modules code-reuse include-path
    I am using the node_clone module with great effect but there is a need in my project to use node_clone functions from my custom module. So I put in the following code:module_load_include(‘inc’, ‘node_clone’, ‘clone.pages’);function mymodule_init(){clone_node_save(118); }That code returns Fatal error: Call to undefined function clone_node_save().My modules are categorized by source into directories labelled mine and contrib. Node_save is in contrib while myModule is in mine.So, I amended the cod

  • Mohamad
    jquery code-reuse
    I use this function to make a help box stay visible when a user scrolls down:var top = $(‘.help-box’).offset().top – parseFloat($(‘.help-box’).css(‘marginTop’).replace(/auto/, 0)); $(window).scroll(function (event) {var y = $(this).scrollTop();if (y >= top) {$(‘.help-box’).addClass(‘fixed’);} else {$(‘.help-box’).removeClass(‘fixed’);} });I want to reuse it across several pages, so I included it in my layout (on every page load). The problem now is that I get an error on pages that do not hav

  • kolrie
    ruby-on-rails rspec code-reuse
    In my Rails 3 application, I have a RSpec spec that checks behavior of a given field (role in the User model) to guarantee that the value is within a list of valid values.Now I am going to have the exact same spec for another field, in another model with another set of valid values. I would like to extract the common code instead of merely copying and pasting it, changing the variables.I am wondering if this would be the case to use a shared example or other RSpec reuse technique. Here’s the rel

Web site is in building