Search Results

Search found 4704 results on 189 pages for 'refactoring databases'.

Page 30/189 | < Previous Page | 26 27 28 29 30 31 32 33 34 35 36 37  | Next Page >

  • How to find all initializations of instance variables in a Java package?

    - by Hank Gay
    I'm in the midst of converting a legacy app to Spring. As part of the transition, we're converting our service classes from an "instantiate new ones whenever you need one" style to a Springleton style, so I need a way to make sure they don't have any state. I'm comfortable on the *nix command-line, and I have access to IntelliJ (this strikes me as a good fit for Structural Search and Replace, if I could figure out how to use it), and I could track down an Eclipse install, if that would help. I just want to make absolutely sure I've found all the possible problems. UPDATE: Sorry for the confusion. I don't have a problem finding places where the old constructor was being called. What I'm looking for is a "bullet-proof" why to search all 100+ service classes for any sort of internal state. The most obvious one I could think of (and the only one I've really found so far) is cases where we use memoization in the classes, so they have instance variables that get initialized internally instead of via Spring. This means that when the same Springleton gets used for different requests, data can leak between them. Thanks.

    Read the article

  • c++ templates and inheritance

    - by Armen Ablak
    Hey, I'm experiencing some problems with breaking my code to reusable parts using templates and inheritance. I'd like to achieve that my tree class and avltree class use the same node class and that avltree class inherits some methods from the tree class and adds some specific ones. So I came up with the code below. Compiler throws an error in tree.h as marked below and I don't really know how to overcome this. Any help appreciated! :) node.h: #ifndef NODE_H #define NODE_H #include "tree.h" template <class T> class node { T data; ... node() ... friend class tree<T>; }; #endif tree.h #ifndef DREVO_H #define DREVO_H #include "node.h" template <class T> class tree { public: //signatures tree(); ... void insert(const T&); private: node<T> *root; //missing type specifier - int assumed. Note: C++ does not support default-int }; //implementations #endif avl.h #ifndef AVL_H #define AVL_H #include "tree.h" #include "node.h" template <class T> class avl: public tree<T> { public: //specific int findMin() const; ... protected: void rotateLeft(node<T> *)const; private: node<T> *root; }; #endif avl.cpp (I tried separating headers from implementation, it worked before I started to combine avl code with tree code) #include "drevo" #include "avl.h" #include "vozlisce.h" template class avl<int>; //I know that only avl with int can be used like this, but currently this is doesn't matter :) //implementations ...

    Read the article

  • Refactor C++ code to use a scripting language?

    - by Justin Ardini
    Background: I have been working on a platformer game written in C++ for a few months. The game is currently written entirely in C++, though I am intrigued by the possibility of using Lua for enemy AI and possibly some other logic. However, the project was designed without Lua in mind, and I have already written working C++ code for much of the AI. I am hoping Lua can improve the extensibility of the game, but don't know if it would make sense to convert existing C++ code into Lua. The question: When, if ever, is it appropriate to take fully functional C++ code and refactor it into a scripting language like Lua? The question is intentionally a bit vague, so feel free give answers that are not relevant to the given background.

    Read the article

  • How easy would it be to refactor a small JSP/Servlet/JDBC project to SpringMVC/Hibernate

    - by John
    With reference to this post, I am considering starting a new web-based Java project. Since I don't know Spring/Hibernate I was concerned if it's a bad plan to start learning them while creating a new project, especially since it will slow down the early development. One idea I had was to write a prototype using tech I do know, namely JSP/Servlets/JDBC, since I can get this running much quicker with my current knowledge. I could then throw the whole thing away and start over with Spring, etc, but I'd like to consider how easy it would be to refactor a smallish project from JSP/Servlets/JDB to SpringMVC/Hibernate? My DB could of course be re-used but what about other code... would I expect to save most of it plugged into an MVC framework, or is the paradigm shift big enough this would cause more trouble than it avoids? Please use the other question for more general advice on choosing technologies

    Read the article

  • Mix and match class in C++/MFC

    - by Coder
    I'm trying to re-factor a code base, and there is some common functionality among unrelated classes that I'd love to unite. I would like to add that functionality in common base class, but I'm not sure if it's clean and good approach. Say I have CMyWnd class and CMyDialogEx class, both different, so they cannot inherit from one base class. I want to add a button to both classes and add the message handlers to both classes as well. So I'd like to do something like this: CMyWnd : public CWnd, public COnOkBtnFunctionality, public COnCancelBtnFunctionality CMyDialogEx: public CWnd, public COnOkBtnFunctionality Where COnOkBtnFunctionality would define CButton m_buttonOk, and all the afx_msg functions it should have. And so on. Is this approach doable/good? Or are there better patterns I should resort to?

    Read the article

  • Help me refactor my World Cup Challenge Script

    - by kylemac
    I am setting up a World Cup Challenge between some friends, and decided to practice my Ruby and write a small script to automate the process. The Problem: 32 World Cup qualifiers split into 4 tiers by their Fifa ranking 8 entries Each entry is assigned 1 random team per tier Winner takes all :-) I wrote something that suffices yet is admittedly brute force. But, in my attempt to improve my Ruby, I acknowlege that this code isn't the most elegant solution around - So I turn to you, the experts, to show me the way. It may be more clear to check out this gist - https://gist.github.com/91e1f1c392bed8074531 My Current (poor) solution: require 'yaml' @teams = YAML::load(File.open('teams.yaml')) @players = %w[Player1 Player2 Player3 Player4 Player5 Player6 Player7 Player8] results = Hash.new players = @players.sort_by{rand} players.each_with_index do |p, i| results[p] = Array[@teams['teir_one'][i]] end second = @players.sort_by{rand} second.each_with_index do |p, i| results[p] << @teams['teir_two'][i] end third = @players.sort_by{rand} third.each_with_index do |p, i| results[p] << @teams['teir_three'][i] end fourth = @players.sort_by{rand} fourth.each_with_index do |p, i| results[p] << @teams['teir_four'][i] end p results I am sure there is a better way to iterate through the tiers, and duplicating the @players object ( dup() or clone() maybe?) So from one Cup Fan to another, help me out.

    Read the article

  • Can you help me refactor this piece of clojure code to produce a seq?

    - by ique
    I want to produce a seq that I can later do a (map) over. It should look like this: ((0 0) (0 1) (0 2) (0 3) ... (7 7)) The piece of code I have to do it right now seems very, very ugly to produce such a simple result. I need some help getting this straight. (loop [y 0 x 0 args (list)] (if (and (= y 7) (= x 7)) (reverse (conj args (list y x))) (if (= x 7) (recur (+ y 1) 0 (conj args (list y x))) (recur y (+ x 1) (conj args (list y x))))))

    Read the article

  • Refactor the following two C++ methods to move out duplicate code

    - by ossandcad
    I have the following two methods that (as you can see) are similar in most of its statements except for one (see below for details) unsigned int CSWX::getLineParameters(const SURFACE & surface, vector<double> & params) { VARIANT varParams; surface->getPlaneParams(varParams); // this is the line of code that is different SafeDoubleArray sdParams(varParams); for( int i = 0 ; i < sdParams.getSize() ; ++i ) { params.push_back(sdParams[i]); } if( params.size() > 0 ) return 0; return 1; } unsigned int CSWX::getPlaneParameters(const CURVE & curve, vector<double> & params) { VARIANT varParams; curve->get_LineParams(varParams); // this is the line of code that is different SafeDoubleArray sdParams(varParams); for( int i = 0 ; i < sdParams.getSize() ; ++i ) { params.push_back(sdParams[i]); } if( params.size() > 0 ) return 0; return 1; } Is there any technique that I can use to move the common lines of code of the two methods out to a separate method, that could be called from the two variations - OR - possibly combine the two methods to a single method? The following are the restrictions: The classes SURFACE and CURVE are from 3rd party libraries and hence unmodifiable. (If it helps they are both derived from IDispatch) There are even more similar classes (e.g. FACE) that could fit into this "template" (not C++ template, just the flow of lines of code) I know the following could (possibly?) be implemented as solutions but am really hoping there is a better solution: I could add a 3rd parameter to the 2 methods - e.g. an enum - that identifies the 1st parameter (e.g. enum::input_type_surface, enum::input_type_curve) I could pass in an IDispatch and try dynamic_cast< and test which cast is NON_NULL and do an if-else to call the right method (e.g. getPlaneParams() vs. get_LineParams()) The following is not a restriction but would be a requirement because of my teammates resistance: Not implement a new class that inherits from SURFACE/CURVE etc. (They would much prefer to solve it using the enum solution I stated above)

    Read the article

  • Mocking a namespace in a partial class.

    - by Nix
    I am messing around with Entity Framework 3.5 SP1 and I am trying to find a cleaner way to do the below. Basically I have an EF model and I am adding some Eager Loaded entities and i want to put them in the partial class context Eager namespace. Currently I am using composition but I feel like there is an easier way to do what I want. namespace Entities{ public partial class TestObjectContext { EagerExtensions Eager { get;set;} public TestObjectContext(){ Eager = new EagerExtensions (this); } } public partial class EagerExtensions { TestObjectContext context; public EagerExtensions(TestObjectContext _context){ context = _context; } public IQueryable<TestEntity> TestEntity { get { return context.TestEntity .Include("TestEntityType") .Include("Test.Attached.AttachedType") .AsQueryable(); } } } } public class Tester{ public void ShowHowIWantIt(){ TestObjectContext context= new TestObjectContext(); var query = from a in context.Eager.TestEntity select a; } }

    Read the article

  • Rails 3 ActiveRecord group_by sort by count

    - by Craig
    The following view code generates a series of links with totals (as expected): <% @jobs.group_by(&:employer_name).sort.each do |employer, jobs| %> <%= link_to employer, jobs_path() %> <%= "(#{jobs.length})" %> <% end %> However, when I refactor the view's code and move the logic to a helper, the code doesn't work as expect. view: <%= employer_filter(@jobs_clone) %> helper: def employer_filter(jobs) jobs.group_by(&:employer_name).sort.each do |employer,jobs| link_to employer, jobs_path() end end The following output is generated: <Job:0x10342e628>#<Job:0x10342e588>#<Job:0x10342e2e0>Employer A#<Job:0x10342e1c8>Employer B#<Job:0x10342e0d8>Employer C#<Job:0x10342ded0>Employer D# What am I not understanding? At first blush, the code seems to be equivalent.

    Read the article

  • How to refactor logging in C#?

    - by Jader Dias
    In my services all exposed methods have: try { // the method core is written here } catch(Exception ex) { Log.Append(ex); } It's boring and ugly to repeat it over and over again. There is any way to avoid that? There is better way to keep the service working even if exceptions occurs and keep sending the exception details to the Log class?

    Read the article

  • How to pass a function to a function?

    - by ShaChris23
    Suppose I have a class with 2 static functions: class CommandHandler { public: static void command_one(Item); static void command_two(Item); }; I have a problem DRY problem where I have 2 functions that have the exact same code for every single line, except for the function that it calls: void CommandOne_User() { // some code A CommandHandler::command_one(item); // some code B } void CommandTwo_User() { // some code A CommandHandler::command_two(item); // some code B } I would like to remove duplication, and, ideally, do something like this: void CommandOne_User() { Function func = CommandHandler::command_one(); Refactored_CommandUser(func); } void CommandTwo_User() { Function func = CommandHandler::command_one(); Refactored_CommandUser(func); } void Refactored_CommandUser(Function func) { // some code A func(item); } I have access to Qt, but not Boost. Could someone help suggest a way on how I can refactor something like this?

    Read the article

  • Find completely commented files which are commented by /* */.

    - by Dave
    Similar to this question. I would like to find all commented files. But in my case /* */ is a possibility. Apparently when you write changes to a database project, dropped objects are only commented out instead of deleting the file. I would like to remove all of these commented out files from the project. Is is possible to find all files which start with /* and end with */?

    Read the article

  • Entities used to serialize data have changed. How can the serialized data be upgraded for the new entities?

    - by i8abug
    Hi, I have a bunch of simple entity instances that I have serialized to a file. In the future, I know that the structure of these entities (ie, maybe I will rename Name to Header or something). The thing is, I don't want to lose the data that I have saved in all these old files. What is the proper way to either load the data from the old entities into new entities upgrade the old files so that they can be used with new entities Note: I think I am stuck with binary serialization, not xml serialization. Thanks in advance! Edit: So I have an answer for the case I have described. I can use a dataContractSerializer and do something like [DataMember("bar")] private string foo; and change the name in the code and keep the same name that was used for serialization. But what about the following additional cases: The original entity has new members which can be serialized Some serialized members that were in the original entity are removed Some members have actually changed in function (suppose that the original class had a FirstName and LastName member and it has been refactored to have only a FullName member which combines the two) To handle these, I need some sort of interpreter/translator deserialization class but I have no idea what I should use

    Read the article

  • Please help me with this Ruby code

    - by Bragaadeesh
    Hi, I am new to Ruby and I know that I am not using the simple and powerful methods available within it. I made my code work but it has to be simple not this huge (especially I feel I am very bad at loop variables) i = 0 j = 0 loop_count = ((to_date-from_date)/(60*60*24)).to_i#diff b/w two dates in days loop_count.times do 48.times do event = Icalendar::Event.new status = get_availability_on_date_and_hour(@templates, @availabilities, from_date+j.days, i).downcase if(status != 'unavailable') #Initialize start and end dates in DateTime's civil format bias_date_time = DateTime.civil(from_date.year, from_date.month, from_date.day) event.dtstart = bias_date_time + j.day + (i/2).to_i.hour + (i%2*30).to_i.minutes event.dtend = event.dtstart + 30.minutes event.summary = status.upcase cal.add_event(event) end i += 1 end i = 0 j += 1 end

    Read the article

  • Class library modification / migration

    - by Clint
    I have 3 class libraries. A BBL, a DAL, and a DATA (about 15 datasets). Currently 4 [major] applications utilize the functionality in these DLL's. I'm rewriting one of those applications and I need to (1) Use some of the existing functionality in the libraries (2) Change some of it (3) Add new functionality (4) Add new datasets. I'm back and forth about the best way to do this, while keeping my risks at a minimum. Some thoughts.. 1) Use the existing projects and don't make any modifications, only additions 2) Make new libraries, bring over the code I can use, and make additions as needed 3) Implement partial classes in the existing projects Eventually all 4 applications will use the newest functionality, but it will be a slow migration; so the old code can't be depricated yet. Any thoughts?

    Read the article

  • Method to concatenate 2 Strings in Java

    - by GooF
    I have a method in Java that concatenates 2 Strings. It currently works correctly, but I think it can be written better. public static String concat(String str1, String str2) { String rVal = null; if (str1 != null || str2 != null) { rVal = ""; if (str1 != null) { rVal += str1; } if (str2 != null) { rVal += str2; } } return rVal; } Here are some of the requirements: If both str1 and str2 are null, the method returns null If either str1 or str2 is null, it will just return the not null String If str1 and str2 are not null, it will concatenate them It never adds "null" to the result Can anyone do this with less code?

    Read the article

  • What are some alternatives to resharper?

    - by Zaps
    Hi, I'm considering purchasing a resharper license but would like to know if there are any possible alternatives to resharper and how would you rate these compared to reharper? It doesn't necessarily have to be a free alternative but I would just like to know how good equivalent products are. Thanks in advance, Zaps.

    Read the article

  • Anyway to surround code block with curly braces {} in VS2008?

    - by Jim McKeeth
    I always find myself needing to enclose a block of code in curly braces { }, but unfortunately that isn't included in the C# surround code snippets, which seems to be an oversight. I couldn't find anything on building your own surround snippets either (just other kinds of snippets). I am actually running Resharper too, but it doesn't seem to have this functionality either (or I haven't figured how to activate it). We have a coding standard of including even a single line of code after an if or else in curly braces, so if I could just make Resharper do that refactor automatically that would be even better!

    Read the article

< Previous Page | 26 27 28 29 30 31 32 33 34 35 36 37  | Next Page >