Search Results

Search found 1030 results on 42 pages for 'refactoring'.

Page 14/42 | < Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >

  • In Intellij, how can I get a List on the left hand side when I extract a variable that's an ArrayList?

    - by tieTYT
    As an example, if I extract a variable from this: return new ArrayList<CrudTestData<Foo>>(); It will turn the code into this: ArrayList<CrudTestData<Foo>> list = new ArrayList<CrudTestData<Foo>>(); return list; How can I automatically get a list on the left hand side like this? List<CrudTestData<Foo>> list = new ArrayList<CrudTestData<Foo>>(); return list; Theoretically, Intellij should know to use a List instead of a Collection because the method returns a List.

    Read the article

  • Organizing Eager Queries in an ObjectContext

    - 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. I have an EF model and I am adding some Eager Loaded entities and i want them all to reside in the "Eager" property in the context. We originally were just changing the entity set name, but it seems a lot cleaner to just use a property, and keep the entity set name in tact. Example: Context - EntityType - AnotherType - Eager (all of these would have .Includes to pull in all assoc. tables) - EntityType - AnotherType 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

  • XHTML 1.0 Transitive, is there a tool that can refactor HTML?

    - by GenEric35
    I have a Asp.net web application running with the following config setting. <xhtmlConformance mode="Legacy"/> This limits use of AJAX and compatibility with multiple browser. If my understanding is correct, the HTML code of the aspx pages need to be fixed to comply with XHTML 1.0 Transitional. There are alot of HTML pages, ~1000, is there a tool that could speed up this process?

    Read the article

  • Converting an AWT application to SWT/JFace

    - by data
    I am currently toying with the idea of converting a small/medium sized project from AWT to SWT, although Swing is not totally out of the picture yet. I was thinking about converting the main window to an SWT_AWT bridge object, but I have no idea how the semantics for this work. After that, I plan to update dialog for dialog, but not necessarily within one release. Is this possible? Has someone done a conversion like this and can give me some hints? Is there maybe even a tutorial somewhere out there? Is there maybe even a tool that can automate parts of this? I have tried googling, but to no avail. Update: One additional thing is: Currently, this is a netbeans project. Might be of help or not, I don't know.

    Read the article

  • BDD / TDD with JSpec - Removing code duplication

    - by Chetan
    How do I refactor to remove the code duplication in this spec: describe 'TestPlugins' describe '.MovieScanner(document)' before_each MoviePage_loggedIn = fixture("movie_logged_in.html") // Get logged-in movie page MoviePage_notloggedIn = fixture("movie_not_logged_in.html") // Get non logged-in movie page scanner = new MovieScanner() // Get movie scanner end it 'should scan logged-in movie page for movie data' doc = MoviePage_loggedIn // Get document to scan // Unit Tests // ------------------------------------------------------------ // Test movie scanner's functions scanner.getMovieTitle(doc).should.eql "The Jacket" scanner.getMovieYear(doc).should.eql "2005" // Test movie scanner's main scan function scannedData = scanner.scan(doc) scannedData.title.should.eql "The Jacket" scannedData.year.should.eql "2005" end it 'should scan non logged-in movie page for movie data' doc = MoviePage_notloggedIn // Get document to scan // Unit Tests // ------------------------------------------------------------ // Test movie scanner's functions scanner.getMovieTitle(doc).should.eql "The Jacket" scanner.getMovieYear(doc).should.eql "2005" // Test movie scanner's main scan function scannedData = scanner.scan(doc) scannedData.title.should.eql "The Jacket" scannedData.year.should.eql "2005" end end end

    Read the article

  • Document-oriented database - What if the document definitions change?

    - by Sebastian Hoitz
    As I understand it, you can enter any non-structured information into a document-oriented database. Let's imagine a document like this: { name: 'John Blank', yearOfBirth: 1960 } Later, in a new version, this structure is refactored to { firstname: 'John', lastname: 'Blank', yearOfBirth: 1960 } How do you do this with Document-Oriented databases? Do you have to prepare merge-scripts, that alter all your entries in the database? Or are there better ways you can handle changes in the structure?

    Read the article

  • C++ brain teaser

    - by mxp
    I recently refactored code like this (MyClass to MyClassR). class SomeMember { long m_value; public: SomeMember() : m_value(0) {} SomeMember(int a) : m_value(a) {} SomeMember(int a, int b) : m_value(a+b) {} }; class MyClass { SomeMember m_first, m_second, m_third; public: MyClass(const bool isUp, const int x, const int y) { if (isUp) { m_first = SomeMember(x); m_second = SomeMember(y); m_third = SomeMember(x, y); } else { m_first = SomeMember(y); m_second = SomeMember(x); m_third = SomeMember(y, x); } } }; class MyClassR { SomeMember m_first, m_second, m_third; public: MyClassR(const bool isUp, const int x, const int y) : m_first(isUp ? x : y) , m_second(isUp ? y : x) , m_third(isUp ? x, y : y, x) { } }; What is the error, why does it compile (at least VC6 with warning level 3 doesn't complain) and what is the right way of doing it? I (assume) I already have all these answers but I think it's and interesting problem to share.

    Read the article

  • Avoiding "variable might not have been initialized"

    - by Mason Wheeler
    I recently ran across a routine that looks something like this: procedure TMyForm.DoSomething(list: TList<TMyObject>; const flag: boolean); var local: integer; begin if flag then //do something else local := ExpensiveFunctionCallThatCalculatesSomething; //do something else for i := 0 to list.Count do if flag then //do something else if list[i].IntValue > local then //WARNING HERE //do something else end; This gives Variable 'local' might not have been initialized even though you can tell by reading the code that you won't hit that line unless the code branch that initializes it has run. Now, I could get rid of this warning by adding a useless local := 0; at the top of the procedure, but I wonder if there might not be a better way to structure this to avoid the issue. Anyone have any ideas?

    Read the article

  • Converting C source to C++

    - by Barry Kelly
    How would you go about converting a reasonably large (300K), fairly mature C codebase to C++? The kind of C I have in mind is split into files roughly corresponding to modules (i.e. less granular than a typical OO class-based decomposition), using internal linkage in lieu private functions and data, and external linkage for public functions and data. Global variables are used extensively for communication between the modules. There is a very extensive integration test suite available, but no unit (i.e. module) level tests. I have in mind a general strategy: Compile everything in C++'s C subset and get that working. Convert modules into huge classes, so that all the cross-references are scoped by a class name, but leaving all functions and data as static members, and get that working. Convert huge classes into instances with appropriate constructors and initialized cross-references; replace static member accesses with indirect accesses as appropriate; and get that working. Now, approach the project as an ill-factored OO application, and write unit tests where dependencies are tractable, and decompose into separate classes where they are not; the goal here would be to move from one working program to another at each transformation. Obviously, this would be quite a bit of work. Are there any case studies / war stories out there on this kind of translation? Alternative strategies? Other useful advice? Note 1: the program is a compiler, and probably millions of other programs rely on its behaviour not changing, so wholesale rewriting is pretty much not an option. Note 2: the source is nearly 20 years old, and has perhaps 30% code churn (lines modified + added / previous total lines) per year. It is heavily maintained and extended, in other words. Thus, one of the goals would be to increase mantainability. [For the sake of the question, assume that translation into C++ is mandatory, and that leaving it in C is not an option. The point of adding this condition is to weed out the "leave it in C" answers.]

    Read the article

  • XHTML 1.0 Strict, is there a tool that can refactor HTML?

    - by GenEric35
    I have a Asp.net web application running with the following config setting. <xhtmlConformance mode="Legacy"/> This limits use of AJAX and compatibility with multiple browser. If my understanding is correct, the HTML code of the aspx pages need to be fixed to comply with XHTML 1.0 Strict. There are alot of HTML pages, ~1000, is there a tool that could speed up this process?

    Read the article

  • PHP: Grab an image from a stream (in an img tag) but if it's not there, i don't want the img tag wri

    - by Gary Willoughby
    I currently have code like this in a web based file called 'view_file.php' to grab an image from an internal network. <img src="put_file.php?type=<?=$TN_TYPE;?>&path=<?=$TN_PATH;?>&filename=<?=$TN_FILENAME;?>" /> The 'put_file.php' script allows access to an internal server that we don't want to expose to the internet. This script checks to see if an image is available and if it is, sends an image header and then uses readfile() to stream the image to the 'view_file.php' page. The problem is if there isn't an image available, instead of streaming a temporary 'spacer.gif' i want to not have the img tag written at all. Any Ideas how to do this? I'm thinking maybe move the img tag into the 'put_file.php' script, but how to mix strings and steams?

    Read the article

  • Help me clean up this crazy lambda with the out keyword

    - by Sarah Vessels
    My code looks ugly, and I know there's got to be a better way of doing what I'm doing: private delegate string doStuff( PasswordEncrypter encrypter, RSAPublicKey publicKey, string privateKey, out string salt ); private bool tryEncryptPassword( doStuff encryptPassword, out string errorMessage ) { ...get some variables... string encryptedPassword = encryptPassword(encrypter, publicKey, privateKey, out salt); ... } This stuff so far doesn't bother me. It's how I'm calling tryEncryptPassword that looks so ugly, and has duplication because I call it from two methods: public bool method1(out string errorMessage) { string rawPassword = "foo"; return tryEncryptPassword( (PasswordEncrypter encrypter, RSAPublicKey publicKey, string privateKey, out string salt) => encrypter.EncryptPasswordAndDoStuff( // Overload 1 rawPassword, publicKey, privateKey, out salt ), out errorMessage ); } public bool method2(SecureString unencryptedPassword, out string errorMessage) { return tryEncryptPassword( (PasswordEncrypter encrypter, RSAPublicKey publicKey, string privateKey, out string salt) => encrypter.EncryptPasswordAndDoStuff( // Overload 2 unencryptedPassword, publicKey, privateKey, out salt ), out errorMessage ); } Two parts to the ugliness: I have to explicitly list all the parameter types in the lambda expression because of the single out parameter. The two overloads of EncryptPasswordAndDoStuff take all the same parameters except for the first parameter, which can either be a string or a SecureString. So method1 and method2 are pretty much identical, they just call different overloads of EncryptPasswordAndDoStuff. Any suggestions? Edit: if I apply Jeff's suggestions, I do the following call in method1: return tryEncryptPassword( (encrypter, publicKey, privateKey) => { var result = new EncryptionResult(); string salt; result.EncryptedValue = encrypter.EncryptPasswordAndDoStuff( rawPassword, publicKey, privateKey, out salt ); result.Salt = salt; return result; }, out errorMessage ); Much the same call is made in method2, just with a different first value to EncryptPasswordAndDoStuff. This is an improvement, but it still seems like a lot of duplicated code.

    Read the article

  • How do I do distributed UML development (à la FOSS)?

    - by James A. Rosen
    I have a UML project (built in IBM's Rational System Architect/Modeler, so stored in their XML format) that has grown quite large. Additionally, it now contains several pieces that other groups would like to re-use. I come from a software development (especially FOSS) background, and am trying to understand how to use that as an analogy here. The problem I am grappling with is similar to the Fragile Base Class problem. Let me start with how it works in an object-oriented (say, Java or Ruby) FOSS ecosystem: Group 1 publishes some "core" package, say "net/smtp version 1.0" Group 2 includes Group 1's net/smtp 1.0 package in the vendor library of their software project At some point, Group 1 creates a new 2.0 branch of net/smtp that breaks backwards compatibility (say, it removes an old class or method, or moves a class from one package to another). They tell users of the 1.0 version that it will be deprecated in one year. Group 2, when they have the time, updates to net/smtp 2.0. When they drop in the new package, their compiler (or test suite, for Ruby) tells them about the incompatibility. They do have to make some manual changes, but all of the changes are in the code, in plain text, a medium with which they are quite familiar. Plus, they can often use their IDE's (or text editor's) "global-search-and-replace" function once they figure out what the fixes are. When we try to apply this model to UML in RSA, we run into some problems. RSA supports some fairly powerful refactorings, but they seem to only work if you have write access to all of the pieces. If I rename a class in one package, RSA can rename the references, but only at the same time. It's very difficult to look at the underlying source (the XML) and figure out what's broken. To fix such a problem in the RSA editor itself means tons of clicking on things -- there is no good equivalent of "global-search-and-replace," at least not after an incomplete refactor. They real sticking point seems to be that RSA assumes that you want to do all your editing using their GUI, but that makes certain operations prohibitively difficult. Does anyone have examples of open-source UML projects that have overcome this problem? What strategies do they use for communicating changes?

    Read the article

  • How to set default values to all wrong or null parameters of method?

    - by Roman
    At the moment I have this code (and I don't like it): private RenderedImage private RenderedImage getChartImage (GanttChartModel model, String title, Integer width, Integer height, String xAxisLabel, String yAxisLabel, Boolean showLegend) { if (title == null) { title = ""; } if (xAxisLabel == null) { xAxisLabel = ""; } if (yAxisLabel == null) { yAxisLabel = ""; } if (showLegend == null) { showLegend = true; } if (width == null) { width = DEFAULT_WIDTH; } if (height == null) { height = DEFAULT_HEIGHT; } ... } How can I improve it? I have some thoughts about introducing an object which will contain all these parameters as fields and then, maybe, it'll be possible to apply builder pattern. But still don't have clear vision how to implement that and I'm not sure that it's worth to be done. Any other ideas?

    Read the article

  • Is there a strategy to back-port C# code?

    - by ianmayo
    Hi all, I intend using the Argotic framework in support of a .Net Atom server. Unfortunately my target server (over which I have no control) only has .Net 1.1 - any the Argotic library is only in .Net 2 and 3.5. So, I now need to back-port the code to 1.1. Can anybody provide any strategic tips for this undertaking? I'm aware of the merits of using Unit Tests to verify the ported code (here). should I be looking for automated tools? should I just import the code into VS2003 .Net 1.1 project and work through the compiler warnings? Any tips appreciated. cheers, Ian

    Read the article

  • Flexibility starting to develop applications and DB

    - by kristaps
    Hi! First of all I want to say some info for admins. This post can help to all DBA and developers. Hope You don't close this. I'm writing about widespread problem I'm writing master work and I want that You will had little time to answer my questions in my form. These questions are about db structures. Visit here: http://spreadsheets.google.com/embeddedform?formkey=dEhmOWFGb2twWVFreWJwWXp2U3c5a1E6MQ After I summarized results, I insert it in new post and developers can choose which structure to use to reach needed requirements developing new applications. I think that my test will help a lot of people. Best regards, Kristaps

    Read the article

  • Operating on rows and then on columns of a matrix produces code duplication

    - by Chetan
    I have the following (Python) code to check if there are any rows or columns that contain the same value: # Test rows -> # Check each row for a win for i in range(self.height): # For each row ... firstValue = None # Initialize first value placeholder for j in range(self.width): # For each value in the row if (j == 0): # If it's the first value ... firstValue = b[i][j] # Remember it else: # Otherwise ... if b[i][j] != firstValue: # If this is not the same as the first value ... firstValue = None # Reset first value break # Stop checking this row, there's no win here if (firstValue != None): # If first value has been set # First value placeholder now holds the winning player's code return firstValue # Return it # Test columns -> # Check each column for a win for i in range(self.width): # For each column ... firstValue = None # Initialize first value placeholder for j in range(self.height): # For each value in the column if (j == 0): # If it's the first value ... firstValue = b[j][i] # Remember it else: # Otherwise ... if b[j][i] != firstValue: # If this is not the same as the first value ... firstValue = None # Reset first value break # Stop checking this column, there's no win here if (firstValue != None): # If first value has been set # First value placeholder now holds the winning player's code return firstValue # Return it Clearly, there is a lot of code duplication here. How do I refactor this code? Thanks!

    Read the article

  • Seeking suggestions on redesigning the interface

    - by ratkok
    As a part of maintaining large piece of legacy code, we need to change part of the design mainly to make it more testable (unit testing). One of the issues we need to resolve is the existing interface between components. The interface between two components is a class that contains static methods only. Simplified example: class ABInterface { static methodA(); static methodB(); ... static methodZ(); }; The interface is used by component A so that different methods can use ABInterface::methodA() in order to prepare some input data and then invoke appropriate functions within component B. Now we are trying to redesign this interface for various reasons: Extending our unit test coverage - we need to resolve this dependency between the components and stubs/mocks are to be introduced The interface between these components diverged from the original design (ie. a lots of newer functions, used for the inter-component i/f are created outside this interface class). The code is old, changed a lot over the time and needs to be refactored. The change should not be disruptive for the rest of the system. We try to limit leaving many test-required artifacts in the production code. Performance is very important and should be no (or very minimal) degradation after the redesign. Code is OO in C++. I am looking for some ideas what approach to take. Any suggestions on how to do this efficiently?

    Read the article

  • Retrieving all objects in code upfront for performance reasons

    - by ming yeow
    How do you folks retrieve all objects in code upfront? I figure you can increase performance if you bundle all the model calls together? This makes for a bigger deal, especially if your DB cannot keep everything in memory def hitDBSeperately { get X users ...code get Y users... code get Z users... code } Versus: def hitDBInSingleCall { get X+Y+Z users code for X code for Y... }

    Read the article

  • How can I refactor that code ? (state pattern ?)

    - by alex
    Hello guys, How can I refactor that code ? public enum enum1 { value1 = 0x01, value2 = 0x02, value3 = 0x03, value4 = 0x04, value5 = 0x05, UNKNOWN = 0xFF } class class1 { private const string STR_VALUE1 = "some text description of value1"; private const string STR_VALUE2 = "some text description of value2"; private const string STR_VALUE3 = "some text description of value3"; private const string STR_VALUE4 = "some text description of value4"; private const string STR_VALUE5 = "some text description of value5"; private const string STR_VALUE6 = "some text description of unknown type"; public static string GetStringByTypeCode(enum1 type) { switch(type) { case enum1.value1: return STR_VALUE1; case enum1.value2: return STR_VALUE2; case enum1.value3: return STR_VALUE3; case enum1.value4: return STR_VALUE4; case enum1.value5: return STR_VALUE5; default: return STR_VALUE6; } } } PS: there are many enum1...enumX and GetStringByTypeCode(enum1) ... GetStringByTypeCode(enumX) methods.

    Read the article

  • Is search and replace the only way to rename an asp control in the code behind file?

    - by Matt
    Is search and replace the only way to rename as asp control in the code behind file? I find this extremely annoying, but it is the only way I can find. Scenario: I'll find a variable that needs renaming (Usually to meet naming convention) I'll rename the variable in the aspx/ascx file. I'll have to go in the code behind files and search and replace. I get annoyed Are there any better ways - preferably that would not touch a similarly named variable in another scope in the project. I'm on VS2008 with resharper -- does VS2010 address this perhaps?

    Read the article

< Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >