Search Results

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

Page 3/42 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • SQL University: Database testing and refactoring tools and examples

    - by Mladen Prajdic
    This is a post for a great idea called SQL University started by Jorge Segarra also famously known as SqlChicken on Twitter. It’s a collection of blog posts on different database related topics contributed by several smart people all over the world. So this week is mine and we’ll be talking about database testing and refactoring. In 3 posts we’ll cover: SQLU part 1 - What and why of database testing SQLU part 2 - What and why of database refactoring SQLU part 3 - Database testing and refactoring tools and examples This is the third and last part of the series and in it we’ll take a look at tools we can test and refactor with plus some an example of the both. Tools of the trade First a few thoughts about how to go about testing a database. I'm firmily against any testing tools that go into the database itself or need an extra database. Unit tests for the database and applications using the database should all be in one place using the same technology. By using database specific frameworks we fragment our tests into many places and increase test system complexity. Let’s take a look at some testing tools. 1. NUnit, xUnit, MbUnit All three are .Net testing frameworks meant to unit test .Net application. But we can test databases with them just fine. I use NUnit because I’ve always used it for work and personal projects. One day this might change. So the thing to remember is to be flexible if something better comes along. All three are quite similar and you should be able to switch between them without much problem. 2. TSQLUnit As much as this framework is helpful for the non-C# savvy folks I don’t like it for the reason I stated above. It lives in the database and thus fragments the testing infrastructure. Also it appears that it’s not being actively developed anymore. 3. DbFit I haven’t had the pleasure of trying this tool just yet but it’s on my to-do list. From what I’ve read and heard Gojko Adzic (@gojkoadzic on Twitter) has done a remarkable job with it. 4. Redgate SQL Refactor and Apex SQL Refactor Neither of these refactoring tools are free, however if you have hardcore refactoring planned they are worth while looking into. I’ve only used the Red Gate’s Refactor and was quite impressed with it. 5. Reverting the database state I’ve talked before about ways to revert a database to pre-test state after unit testing. This still holds and I haven’t changed my mind. Also make sure to read the comments as they are quite informative. I especially like the idea of setting up and tearing down the schema for each test group with NHibernate. Testing and refactoring example We’ll take a look at the simple schema and data test for a view and refactoring the SELECT * in that view. We’ll use a single table PhoneNumbers with ID and Phone columns. Then we’ll refactor the Phone column into 3 columns Prefix, Number and Suffix. Lastly we’ll remove the original Phone column. Then we’ll check how the view behaves with tests in NUnit. The comments in code explain the problem so be sure to read them. I’m assuming you know NUnit and C#. T-SQL Code C# test code USE tempdbGOCREATE TABLE PhoneNumbers( ID INT IDENTITY(1,1), Phone VARCHAR(20))GOINSERT INTO PhoneNumbers(Phone)SELECT '111 222333 444' UNION ALLSELECT '555 666777 888'GO-- notice we don't have WITH SCHEMABINDINGCREATE VIEW vPhoneNumbersAS SELECT * FROM PhoneNumbersGO-- Let's take a look at what the view returns -- If we add a new columns and rows both tests will failSELECT *FROM vPhoneNumbers GO -- DoesViewReturnCorrectColumns test will SUCCEED -- DoesViewReturnCorrectData test will SUCCEED -- refactor to split Phone column into 3 partsALTER TABLE PhoneNumbers ADD Prefix VARCHAR(3)ALTER TABLE PhoneNumbers ADD Number VARCHAR(6)ALTER TABLE PhoneNumbers ADD Suffix VARCHAR(3)GO-- update the new columnsUPDATE PhoneNumbers SET Prefix = LEFT(Phone, 3), Number = SUBSTRING(Phone, 5, 6), Suffix = RIGHT(Phone, 3)GO-- remove the old columnALTER TABLE PhoneNumbers DROP COLUMN PhoneGO-- This returns unexpected results!-- it returns 2 columns ID and Phone even though -- we don't have a Phone column anymore.-- Notice that the data is from the Prefix column-- This is a danger of SELECT *SELECT *FROM vPhoneNumbers -- DoesViewReturnCorrectColumns test will SUCCEED -- DoesViewReturnCorrectData test will FAIL -- for a fix we have to call sp_refreshview -- to refresh the view definitionEXEC sp_refreshview 'vPhoneNumbers'-- after the refresh the view returns 4 columns-- this breaks the input/output behavior of the database-- which refactoring MUST NOT doSELECT *FROM vPhoneNumbers -- DoesViewReturnCorrectColumns test will FAIL -- DoesViewReturnCorrectData test will FAIL -- to fix the input/output behavior change problem -- we have to concat the 3 columns into one named PhoneALTER VIEW vPhoneNumbersASSELECT ID, Prefix + ' ' + Number + ' ' + Suffix AS PhoneFROM PhoneNumbersGO-- now it works as expectedSELECT *FROM vPhoneNumbers -- DoesViewReturnCorrectColumns test will SUCCEED -- DoesViewReturnCorrectData test will SUCCEED -- clean upDROP VIEW vPhoneNumbersDROP TABLE PhoneNumbers [Test]public void DoesViewReturnCoorectColumns(){ // conn is a valid SqlConnection to the server's tempdb // note the SET FMTONLY ON with which we return only schema and no data using (SqlCommand cmd = new SqlCommand("SET FMTONLY ON; SELECT * FROM vPhoneNumbers", conn)) { DataTable dt = new DataTable(); dt.Load(cmd.ExecuteReader(CommandBehavior.CloseConnection)); // test returned schema: number of columns, column names and data types Assert.AreEqual(dt.Columns.Count, 2); Assert.AreEqual(dt.Columns[0].Caption, "ID"); Assert.AreEqual(dt.Columns[0].DataType, typeof(int)); Assert.AreEqual(dt.Columns[1].Caption, "Phone"); Assert.AreEqual(dt.Columns[1].DataType, typeof(string)); }} [Test]public void DoesViewReturnCorrectData(){ // conn is a valid SqlConnection to the server's tempdb using (SqlCommand cmd = new SqlCommand("SELECT * FROM vPhoneNumbers", conn)) { DataTable dt = new DataTable(); dt.Load(cmd.ExecuteReader(CommandBehavior.CloseConnection)); // test returned data: number of rows and their values Assert.AreEqual(dt.Rows.Count, 2); Assert.AreEqual(dt.Rows[0]["ID"], 1); Assert.AreEqual(dt.Rows[0]["Phone"], "111 222333 444"); Assert.AreEqual(dt.Rows[1]["ID"], 2); Assert.AreEqual(dt.Rows[1]["Phone"], "555 666777 888"); }}   With this simple example we’ve seen how a very simple schema can cause a lot of problems in the whole application/database system if it doesn’t have tests. Imagine what would happen if some outside process would depend on that view. It would get wrong data and propagate it silently throughout the system. And that is not good. So have tests at least for the crucial parts of your systems. And with that we conclude the Database Testing and Refactoring week at SQL University. Hope you learned something new and enjoy the learning weeks to come. Have fun!

    Read the article

  • Groovy Refactoring in NetBeans

    - by Martin Janicek
    Hi guys, during the NetBeans 7.3 feature development, I spend quite a lot of time trying to get some basic Groovy refactoring to the game. I've implemented find usages and rename refactoring for some basic constructs (class types, fields, properties, variables and methods). It's certainly not perfect and it will definitely need a lot fixes and improvements to get it hundred percent reliable, but I need to start somehow :) I would like to ask all of you to test it as much as possible and file a new tickets to the cases where it doesn't work as expected (e.g. some occurrences which should be in usages isn't there etc.) ..it's really important for me because I don't have real Groovy project and thus I can test only some simple cases. I can promise, that with your help we can make it really useful for the next release. Also please be aware that the current version is focusing only on the .groovy files. That means it won't find any usages from the .java files (and the same applies for finding usages from java files - it won't find any groovy usages). I know it's not ideal, but as I said.. we have to start somehow and it wasn't possible to make it all-in-one, so only other option was to wait for the NetBeans 7.4. I'll focus on better Java-Groovy integration in the next release (not only in refactoring, but also in navigation, code completion etc.) BTW: I've created a new component with surprising name "Refactoring" in our bugzilla[1], so please put the reported issues into this category. [1] http://netbeans.org/bugzilla/buglist.cgi?product=groovy;component=Refactoring

    Read the article

  • Refactoring tool

    - by Polaris
    I am using several months ReSharper 4.5 It's very powerfull tool but use a lot of system resources and VS working very slow with it. With which tool I can replace Resharper with the same functionality. Which refactoring tool do you use?

    Read the article

  • Tool for sql refactoring?

    - by C. Ross
    Is there a refactoring tool available for SQL (TSQL in particular). Is there any tool that can do automatic simplification of SQL? I have a set of views where only the top two are used, and I'd like to refactor this into only two views, hence 10+ queries into two queries.

    Read the article

  • Is there a tool that can refactor this C code correctly?

    - by Alex
    Lets say I have the following code (the array* function are what we use for resizable arrays and they operate on pointers-to-arrays that are null initialized): typedef struct MyStruct { int i; } MyStruct; MyStruct* GetNewMyStruct(int i) { MyStruct* s = malloc(sizeof(MyStruct)); s->i = i; return s; } int SomeFunction(int number, MyStruct *elem) { MyStruct **structs = NULL; int i; for (i = 0; i < number; i++) arrayPush(&structs, GetNewMyStruct(i)); arrayPush(&structs, elem); return arraySize(&structs); } I decide that SomeFunction is too large and I want refactor it. Currently where I work we use VisualAssist X, which has some refactoring capabilities, but when I use it on this it does not work correctly. If I attempt to use it to refactor out the loop, this is what I get: void MyMethod( int number, MyStruct ** structs ) { int i; for (i = 0; i < number; i++) arrayPush(&structs, GetNewMyStruct(i)); } int SomeFunction(int number, MyStruct *elem) { MyStruct **structs = NULL; MyMethod(number, structs); arrrayPush(&structs, elem); return arraySize(&structs); } This is not correct. MyMethod should take a MyStruct ***, not a MyStruct **. This is because the code I'm refactoring takes the address of structs. The result is that the refactored version will always return 1 (since only one object has been pushed into my array) rather than number+1. Are there other tools out there that do this type of refactoring correctly?

    Read the article

  • What do you think about RefactoringManifesto.org?

    - by Gan
    Quite some time ago, on December 19 2010, a site called RefactoringManifesto.org was launched. The site is to voice concerns about refactoring. It lists ten main points as shown below (head over the website to see more details): Make your products live longer! Design should be simple so that it is easy to refactor. Refactoring is not rewriting. What doesn't kill it makes it stronger. Refactoring is a creative challenge. Refactoring survives fashion. To refactor is to discover. Refactoring is about independence. You can refactor anything, even total crap. Refactor – even in bad times! What do you think about this? Would you sign the manifesto? If not, why?

    Read the article

  • How to make Databinding type safe and support refactoring

    - by Ian Ringrose
    When I wish to bind a control to a property of my object, I have to provide the name of the property as a string. This is not very good because: If the property is removed or renamed, I don’t get a compiler warning. If a rename the property with a refactoring tool, it is likely the data binding will not be updated. I don’t get an error until runtime if the type of the property is wrong, e.g. binding an integer to a date chooser. Is there a design-paten that gets round this, but still has the ease of use of data-binding? (This is a problem in WinForm, Asp.net and WPF and most likely lots of other systems) I have now found "workarounds for nameof() operator in C#: typesafe databinding" that also has a good starting point for a solution.

    Read the article

  • Refactoring tools for namespaces and physical project structure

    - by simendsjo
    When I hack around, some code tend to get much bigger than originally planned. As this happens I usually introduce/collapse/merge namespaces, move files between them, move folders etc etc. Sometimes, if I don't have a clear picture of the end result, this is a real pain and really easy to just "skip". This leads the project deteriorate where classes belong elsewhere, strange namespaces, no folders/wrong folders etc. And then I usually cannot take it anymore and do a larger cleanup - which is usually not difficult, just very tedious and it feels nice to do everything at once, so I do a code freeze while finishing up. So my question is... Are there any tools to help refactoring the namespace/physical aspects of a project?

    Read the article

  • Good code visualization / refactoring tools for C++?

    - by Paul D.
    I've found myself coming across a lot of reasonably large, complicated codebases at work recently which I've been asked to either review or refactor or both. This can be extremely time consuming when the code is highly concurrent, makes heavy use of templates (particularly static polymorphism) and has logic that depends on callbacks/signals/condition variables/etc. Are there any good visualization tools for C++ period, and of those are there any that actually play well with "advanced" C++ features? Anything would probably be better than my approach now, which is basically pen+paper or stepping through the debugger. The debugger method can be good for following a particular code path, but isn't great for seeing the big picture you really need when doing serious refactoring. EDIT: I should mention that Visual Studio plugins aren't going to be a lot of help to me, since our stuff is mostly Linux-only.

    Read the article

  • What is the politically correct way of refactoring other's code?

    - by dukeofgaming
    I'm currently working in a geographically distributed team in a big company. Everybody is just focused on today's tasks and getting things done, however this means sometimes things have to be done the quick way, and that causes problems... you know, same old, same old. I'm bumping into code with several smells such as: big functions pointless utility functions/methods (essentially just to save writing a word), overcomplicated algorithms, extremely big files that should be broken down into different files/classes (1,500+ lines), etc. What would be the best way of improving code without making other developers feel bad/wrong about any proposed improvements?

    Read the article

  • How should I start refactoring my mostly-procedural C++ application?

    - by oob
    We have a program written in C++ that is mostly procedural, but we do use some C++ containers from the standard library (vector, map, list, etc). We are constantly making changes to this code, so I wouldn't call it a stagnant piece of legacy code that we can just wrap up. There are a lot of issues with this code making it harder and harder for us to make changes, but I see the three biggest issues being: Many of the functions do more (way more) than one thing We violate the DRY principle left and right We have global variables and global state up the wazoo. I was thinking we should attack areas 1 and 2 first. Along the way, we can "de-globalize" our smaller functions from the bottom up by passing in information that is currently global as parameters to the lower level functions from the higher level functions and then concentrate on figuring out how to removing the need for global variables as much as possible. I just finished reading Code Complete 2 and The Pragmatic Programmer, and I learned a lot, but I am feeling overwhelmed. I would like to implement unit testing, change from a procedural to OO approach, automate testing, use a better logging system, fully validate all input, implement better error handling and many other things, but I know if we start all this at once, we would screw ourselves. I am thinking the three I listed are the most important to start with. Any suggestions are welcome. We are a team of two programmers mostly with experience with in-house scripting. It is going to be hard to justify taking the time to refactor, especially if we can't bill the time to a client. Believe it or not, this project has been successful enough to keep us busy full time and also keep several consultants busy using it for client work.

    Read the article

  • Quick help refactoring Ruby Class

    - by mplacona
    I've written this class that returns feed updates, but am thinking it can be further improved. It's not glitchy or anything, but as a new ruby developer, I reckon it's always good to improve :-) class FeedManager attr_accessor :feed_object, :update, :new_entries require 'feedtosis' def initialize(feed_url) @feed_object = Feedtosis::Client.new(feed_url) fetch end def fetch @feed_object.fetch end def update @updates = fetch end def updated? @updates.new_entries.count > 0 ? true : false end def new_entries @updates.new_entries end end As you can see, it's quite simple, but the things I'm seeing that aren't quite right are: Whenever I call fetch via terminal, it prints a list with the updates, when it's really supposed return an object. So as an example, in the terminal if I do something like: client = Feedtosis::Client.new('http://stackoverflow.com/feeds') result = client.fetch I then get: <Curl::Easy http://stackoverflow.com/feeds> Which is exactly what I'd expect. However, when doing the same thing with "inniting" class with: FeedManager.new("http://stackoverflow.com/feeds") I'm getting the object returning as an array with all the items on the feed. Sure I'm doing something wrong, so any help refactoring this class will he greatly appreciated. Also, I'd like to see comments about my implementation, as well as any sort of comment to make it better would be welcome. Thanks in advance

    Read the article

  • A C# Refactoring Question...

    - by james lewis
    I came accross the following code today and I didn't like it. It's fairly obvious what it's doing but I'll add a little explanation here anyway: Basically it reads all the settings for an app from the DB and the iterates through all of them looking for the DB Version and the APP Version then sets some variables to the values in the DB (to be used later). I looked at it and thought it was a bit ugly - I don't like switch statements and I hate things that carry on iterating through a list once they're finished. So I decided to refactor it. My question to all of you is how would you refactor it? Or do you think it even needs refactoring at all? Here's the code: using (var sqlConnection = new SqlConnection(Lfepa.Itrs.Framework.Configuration.ConnectionString)) { sqlConnection.Open(); var dataTable = new DataTable("Settings"); var selectCommand = new SqlCommand(Lfepa.Itrs.Data.Database.Commands.dbo.SettingsSelAll, sqlConnection); var reader = selectCommand.ExecuteReader(); while (reader.Read()) { switch (reader[SettingKeyColumnName].ToString().ToUpper()) { case DatabaseVersionKey: DatabaseVersion = new Version(reader[SettingValueColumneName].ToString()); break; case ApplicationVersionKey: ApplicationVersion = new Version(reader[SettingValueColumneName].ToString()); break; default: break; } } if (DatabaseVersion == null) throw new ApplicationException("Colud not load Database Version Setting from the database."); if (ApplicationVersion == null) throw new ApplicationException("Colud not load Application Version Setting from the database."); }

    Read the article

  • Refactoring an ASP.NET 2.0 app to be more "modern"

    - by Wayne M
    This is a hypothetical scenario. Let's say you've just been hired at a company with a small development team. The company uses an internal CRM/ERP type system written in .NET 2.0 to manage all of it's day to day things (let's simplify and say customer accounts and records). The app was written a couple of years ago when .NET 2.0 was just out and uses the following architectural designs: Webforms Data layer is a thin wrapper around SqlCommand that calls stored procedures Rudimentary DTO-style business objects that are populated via the sprocs A "business logic" layer that acts as a gateway between the webform and database (i.e. code behind calls that layer) Let's say that as there are more changes and requirements added to the application, you start to feel that the old architecture is showing its age, and changes are increasingly more difficult to make. How would you go about introducing refactoring steps to A) Modernize the app (i.e. proper separation of concerns) and B) Make sure that the app can readily adapt to change in the organization? IMO the changes would involve: Introduce an ORM like Linq to Sql and get rid of the sprocs for CRUD Assuming that you can't just throw out Webforms, introduce the M-V-P pattern to the forms Make sure the gateway classes conform to SRP and the other SOLID principles. Change the logic that is re-used to be web service methods instead of having to reuse code What are your thoughts? Again this is a totally hypothetical scenario that many of us have faced in the past, or may end up facing.

    Read the article

  • jquery small refactoring , json call

    - by Alexander Corotchi
    Hi everybody, I need you suggestion to make some refactoring in jquery code because now it looks terrible for me. I have 4 json calls but the difference it is just the URL call. EX: var userId = MyuserID; var perPage = '45'; var showOnPage = '45'; var tag = 'tag1'; var tag1 = 'tag2'; var tag2 = 'tagn'; $.getJSON('http://api.flickr.com/services/rest/?format=json&method='+ 'flickr.photos.search&api_key=' + apiKey + '&user_id=' + userId + '&tags=' + tag + '&per_page=' + perPage + '&jsoncallback=?', function(data){ var classShown = 'class="lightbox"'; var classHidden = 'class="lightbox hidden"'; $.each(data.photos.photo, function(i, rPhoto){ var basePhotoURL = 'http://farm' + rPhoto.farm + '.static.flickr.com/' + rPhoto.server + '/' + rPhoto.id + '_' + rPhoto.secret; var thumbPhotoURL = basePhotoURL + '_s.jpg'; var mediumPhotoURL = basePhotoURL + '.jpg'; var photoStringStart = '<li><a '; var photoStringEnd = 'title="' + rPhoto.title + '" href="'+ mediumPhotoURL +'"><img src="' + thumbPhotoURL + '" alt="' + rPhoto.title + '"/></a><span>'+rPhoto.title+'</span></li>;' var photoString = (i < showOnPage) ? photoStringStart + classShown + photoStringEnd : photoStringStart + classHidden + photoStringEnd; $(photoString).appendTo("#flickr ul"); }); $("#flickr a").fancybox(); }); $.getJSON('http://api.flickr.com/services/rest/?format=json&method='+ 'flickr.photos.search&api_key=' + apiKey + '&user_id=' + userId + '&tags=' + tag1 + '&per_page=' + perPage + '&jsoncallback=?', function(data){ var classShown = 'class="lightbox"'; var classHidden = 'class="lightbox hidden"'; $.each(data.photos.photo, function(i, rPhoto){ var basePhotoURL = 'http://farm' + rPhoto.farm + '.static.flickr.com/' + rPhoto.server + '/' + rPhoto.id + '_' + rPhoto.secret; var thumbPhotoURL = basePhotoURL + '_s.jpg'; var mediumPhotoURL = basePhotoURL + '.jpg'; var photoStringStart = '<li><a '; var photoStringEnd = 'title="' + rPhoto.title + '" href="'+ mediumPhotoURL +'"><img src="' + thumbPhotoURL + '" alt="' + rPhoto.title + '"/></a><span>'+rPhoto.title+'</span></li>;' var photoString = (i < showOnPage) ? photoStringStart + classShown + photoStringEnd : photoStringStart + classHidden + photoStringEnd; $(photoString).appendTo(".SetPinos1 ul"); }); $(".Sets a").fancybox(); }); $.getJSON('http://api.flickr.com/services/rest/?format=json&method='+ 'flickr.photos.search&api_key=' + apiKey + '&user_id=' + userId + '&tags=' + tagn + '&per_page=' + perPage + '&jsoncallback=?', function(data){ var classShown = 'class="lightbox"'; var classHidden = 'class="lightbox hidden"'; $.each(data.photos.photo, function(i, rPhoto){ var basePhotoURL = 'http://farm' + rPhoto.farm + '.static.flickr.com/' + rPhoto.server + '/' + rPhoto.id + '_' + rPhoto.secret; var thumbPhotoURL = basePhotoURL + '_s.jpg'; var mediumPhotoURL = basePhotoURL + '.jpg'; var photoStringStart = '<li><a '; var photoStringEnd = 'title="' + rPhoto.title + '" href="'+ mediumPhotoURL +'"><img src="' + thumbPhotoURL + '" alt="' + rPhoto.title + '"/></a><span>'+rPhoto.title+'</span></li>;' var photoString = (i < showOnPage) ? photoStringStart + classShown + photoStringEnd : photoStringStart + classHidden + photoStringEnd; $(photoString).appendTo(".SetPinos ul"); }); $(".Sets a").fancybox(); }); var tag is only one difference in this url : Can somebody help me not to repeat all this stuff ?? Sorry by so long garbage :(

    Read the article

  • Help with refactoring PHP code

    - by Richard Knop
    I had some troubles implementing Lawler's algorithm but thanks to SO and a bounty of 200 reputation I finally managed to write a working implementation: http://stackoverflow.com/questions/2466928/lawlers-algorithm-implementation-assistance I feel like I'm using too many variables and loops there though so I am trying to refactor the code. It should be simpler and shorter yet remain readable. Does it make sense to make a class for this? Any advice or even help with refactoring this piece of code is welcomed: <?php /* * @name Lawler's algorithm PHP implementation * @desc This algorithm calculates an optimal schedule of jobs to be * processed on a single machine (in reversed order) while taking * into consideration any precedence constraints. * @author Richard Knop * */ $jobs = array(1 => array('processingTime' => 2, 'dueDate' => 3), 2 => array('processingTime' => 3, 'dueDate' => 15), 3 => array('processingTime' => 4, 'dueDate' => 9), 4 => array('processingTime' => 3, 'dueDate' => 16), 5 => array('processingTime' => 5, 'dueDate' => 12), 6 => array('processingTime' => 7, 'dueDate' => 20), 7 => array('processingTime' => 5, 'dueDate' => 27), 8 => array('processingTime' => 6, 'dueDate' => 40), 9 => array('processingTime' => 3, 'dueDate' => 10)); // precedence constrainst, i.e job 2 must be completed before job 5 etc $successors = array(2=>5, 7=>9); $n = count($jobs); $optimalSchedule = array(); for ($i = $n; $i >= 1; $i--) { // jobs not required to precede any other job $arr = array(); foreach ($jobs as $k => $v) { if (false === array_key_exists($k, $successors)) { $arr[] = $k; } } // calculate total processing time $totalProcessingTime = 0; foreach ($jobs as $k => $v) { if (true === array_key_exists($k, $arr)) { $totalProcessingTime += $v['processingTime']; } } // find the job that will go to the end of the optimal schedule array $min = null; $x = 0; $lastKey = null; foreach($arr as $k) { $x = $totalProcessingTime - $jobs[$k]['dueDate']; if (null === $min || $x < $min) { $min = $x; $lastKey = $k; } } // add the job to the optimal schedule array $optimalSchedule[$lastKey] = $jobs[$lastKey]; // remove job from the jobs array unset($jobs[$lastKey]); // remove precedence constraint from the successors array if needed if (true === in_array($lastKey, $successors)) { foreach ($successors as $k => $v) { if ($lastKey === $v) { unset($successors[$k]); } } } } // reverse the optimal schedule array and preserve keys $optimalSchedule = array_reverse($optimalSchedule, true); // add tardiness to the array $i = 0; foreach ($optimalSchedule as $k => $v) { $optimalSchedule[$k]['tardiness'] = 0; $j = 0; foreach ($optimalSchedule as $k2 => $v2) { if ($j <= $i) { $optimalSchedule[$k]['tardiness'] += $v2['processingTime']; } $j++; } $i++; } echo '<pre>'; print_r($optimalSchedule); echo '</pre>';

    Read the article

  • Is there a 3 way merger tool that “understands” common refactoring?

    - by Ian Ringrose
    When a simple refactoring like “rename field” has been done on one branch it can be very hard to merge the changes into the other branches. (Extract method is much harder as the merge tools don’t seem to match the unchanged blocks well) Now in my dreams, I am thinking of a tool that can record (or work out) what well defined refactoring operations have been done on one branch and then “replay” them on the other branch, rather than trying to merge every line the refactoring has affected. see also "Is there an intelligent 3rd merge tool that understands VB.NET" for the other half of my pain! Also has anyone try something like MolhadoRef (blog article about MolhadoRef and Refactoring-aware SCM), This is, in theory, refactoring-aware source control.

    Read the article

  • Refactoring method with many conditional return statements

    - by MC.
    Hi, I have a method for validation that has many conditional statements. Basically it goes If Check1 = false return false If Check2 = false return false etc FxCop complains that the cyclomatic complexity is too high. I know that it is not best practice to have return statements in the middle of functions, but at the same time the only alternative I see is an ugly list of If-else statements. What is the best way to approach this? Thanks in advance.

    Read the article

  • Xcode raises exception when refactoring

    - by Sam Gwydir
    When I run a refactor on my code in xcode, all the files are correctly refactored except one, and when I click to check the changes made in that file, the following 'Internal Error Occurs': Uncaught Exception: Invalid parameter not satisfying: fileName Stack Backtrace: The stack backtrace has been logged to the console. Here is what it spat out in the console: 4/7/10 06:47:30 Xcode[35355] [MT] Uncaught Exception: Invalid parameter not satisfying: fileName Backtrace: 0 0x92842bbd __raiseError (in CoreFoundation) 1 0x914b9509 objc_exception_throw (in libobjc.A.dylib) 2 0x92842908 +[NSException raise:format:arguments:] (in CoreFoundation) 3 0x98801dc3 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] (in Foundation) 4 0x98db0f8e -[NSDocument(NSDeprecated) initWithContentsOfFile:ofType:] (in AppKit) 5 0x0075c07e -[PBXTextFileDocument initWithContentsOfFile:ofType:] (in DevToolsInterface) 6 0x007dc5be -[PBXFileDocument initWithFileReference:usingType:] (in DevToolsInterface) 7 0x00b1c0f8 -[XCRefactoringFileChangeSet(XCRefactoringModule_HelperMethods) referencedTextFileDocument] (in DevToolsInterface) 8 0x00b1d1f4 -[XCRefactoringEditableExistingTextFileChangeSet populateComparator:] (in DevToolsInterface) 9 0x00ab19b7 -[XCRefactoringModuleFileItem populateComparator:previewFinished:] (in DevToolsInterface) 10 0x00aa4606 -[XCRefactoringModule(MasterListDelegate) outlineViewSelectionDidChange:] (in DevToolsInterface) 11 0x987381cb _nsnote_callback (in Foundation) 12 0x927ca3f9 __CFXNotificationPost (in CoreFoundation) 13 0x927c9e2a _CFXNotificationPostNotification (in CoreFoundation) 14 0x9872d098 -[NSNotificationCenter postNotificationName:object:userInfo:] (in Foundation) 15 0x9873a475 -[NSNotificationCenter postNotificationName:object:] (in Foundation) 16 0x98af1de2 -[NSTableView _enableSelectionPostingAndPost] (in AppKit) 17 0x98bd11d0 -[NSTableView mouseDown:] (in AppKit) 18 0x98bcfeea -[NSOutlineView mouseDown:] (in AppKit) 19 0x007596c3 -[PBXExtendedOutlineView mouseDown:] (in DevToolsInterface) 20 0x98b6e548 -[NSWindow sendEvent:] (in AppKit) 21 0x00757a06 -[XCWindow sendEvent:] (in DevToolsInterface) 22 0x98a871af -[NSApplication sendEvent:] (in AppKit) 23 0x006f6dec -[PBXExtendedApplication sendEvent:] (in DevToolsInterface) 24 0x98a1ac4f -[NSApplication run] (in AppKit) 25 0x98a12c85 NSApplicationMain (in AppKit) 26 0x0000eee1 27 0x000021a5 If you would like to take a look at the project I'm working on, here is a link to download my xcodeproject: Tea Timer.zip To recreate my problem, open Timer.h, attempt to refactor timeField to minuteField, use the preview function of refactor and then select Timer.m, to look at the changes supposedly made within. It will then raise this error without editing the file.

    Read the article

  • Rails XML Builder - Code refactoring

    - by Vijay Dev
    I have written the following code in my Rails app to generate XML. I am using Aptana IDE to do Rails development and the IDE shows a warning that the code structure is identical in both the blocks. What changes can be done to the code to remove the duplicity in structure? Is there any other way to write the same? xml.roles do @rolesList.each do |r| xml.role(:id => r["role_id"], :name => r["role_name"]) end end xml.levels do @levelsList.each do |lvl| xml.level(:id => lvl["level_id"], :name => lvl["level_name"]) end end

    Read the article

  • linq null refactoring code

    - by user276640
    i have code public List<Files> List(int? menuId) { if (menuId == null) { return _dataContext.Files.ToList(); } else { return _dataContext.Files.Where(f => f.Menu.MenuId == menuId).ToList(); } } is it possible to make it only one line like return _dataContext.Files.Where(f = f.Menu.MenuId == menuId).ToList();?

    Read the article

  • A report of refactoring recommendations

    - by Chris
    Hi, I'm working on an old site that needs to be optimised, I've installed Refactor! and its coming up with lots of recommendations, including lots of instances where objects aren't disposed off. Is there a way to create a report of these recommendations or another tool that I could use? Thanks, Chris.

    Read the article

  • Refactoring many nested ifs or chained if statements

    - by Icarus
    Hi, I have an object with large number of similar fields (like more than 10 of them) and I have to assign them values from an array of variable length. The solution would be either a huge nested bunch of ifs based on checking length of array each time and assigning each field OR a chain of ifs checking on whether the length is out of bounds and assigning each time after that check. Both seem to be repetitive. Is there a better solution ?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >