refactoring

Improve this snippet from a prototype class

This is a snippet from a prototype class i am putting together. The scoping workaround feels a little hacky to me, can it be improved or done differently? var myClass = Class.create({ initialize: function() { $('formid').getElements().each(function(el){ $(el).observe("blur", function(){ this.valid...

How to diff two regions of the same file in Eclipse

I'm a TDDer and often have a need to refactor out common or similar code. If it is exactly the same there is no big problem, Eclipse can almost always do that by itself. But to get there I'm finding myself often looking at similar, but not identical, code fragments in the same, or even different, files. It would be very handy if there w...

Combining database tables

Hi all, I have two tables which look kind of similar and i was thinking about combining them and thought i would get some input from everyone. Here's what they currently look like: Issues Id | IssueCategory | IssueType | Status | etc.. ------------------------------------------------- 123 | Copier | Broken | Open | 1...

Simple way to reorder methods of a Java class in IntelliJ?

Is there a simpler way of reordering methods within a class source file in IntelliJ than cutting and pasting the code manually? Nowadays I often need this while refactoring legacy code, e.g. to move related methods close to each other in the source code. In Eclipse AFAIK there is a view similar to the Structure view of IntelliJ, where I...

What are some alternatives to resharper?

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. ...

C variable argument refactoring

I have a function irc_sendline that can be called like printf can irc_sendline(s, "A strange game.\nThe only %s is not to play.", "winning move"); It works perfectly, but I'm not happy with its implementation: int irc_sendline(irc *iobj, char *msg, ...) { char tmp_msg[BUFSIZE], fmsg[BUFSIZE]; va_list args; int len; va_st...

Refactor/rewrite code or continue?

I just completed a complex piece of code. It works to spec, it meets performance requirements etc etc but I feel a bit anxious about it and am considering rewriting and/or refactoring it. Should I do this (spending time that could otherwise be spent on features that users will actually notice)? The reasons I feel anxious about the code ...

How can this verbose, unpythonic routine be improved?

Is there a more pythonic way of doing this? I am trying to find the eight neighbours of an integer coordinate lying within an extent. I am interested in reducing its verbosity without sacrificing execution speed. def fringe8((px, py), (x1, y1, x2, y2)): f = [(px - 1, py - 1), (px - 1, py), (px - 1, py + 1), ...

Modified map2 (without truncation of lists) in F# - how to do it idiomatically?

I'd like to rewrite such function into F#: zipWith' :: (a -> b -> c) -> (a -> c) -> (b -> c) -> [a] -> [b] -> [c] zipWith' _ _ h [] bs = h `map` bs zipWith' _ g _ as [] = g `map` as zipWith' f g h (a:as) (b:bs) = f a b:zipWith f g h as bs My first attempt was: let inline private map2' (xs : seq<'T>) (ys : seq<'U>) (f ...

Does resharper add any kind of code refactoring to VS that Eclipse doesn't have?

And if so are there Eclipse plugins that add those types of code refactoring to eclipse? note:for C#/Java respectively. ...

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

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 Docu...

Using ideas from Uncle Bob's Clean Code in real-world code

I just finished reading the "Functions" chapter from Uncle Bob's Clean Code. The main advice was to make sure that functions are short -- really short. And they should only do one thing per level of abstraction. Here's a function from an app I'm making to learn Cocoa (idea from Andy Matuschak). - (IBAction)go:(id)sender { NSString *outp...

Is there any point to an interface if only one class implements it?

Looking at the (mature) codebase at my new job, there is an interface, and only one class implements it (as far as I can tell). Can/should I get rid of the interface? ...

Factoring out a while loop in SQL script

Suppose I have a table amountInfo with columns (id, amount1, amount2, amount3) where amountX are money values and id is an int value ranging from 1 to some int under 10. Currently I have some code that approximately does this: declare @id int, @idmax int, @amounttotal money select @idmax = (select max(Id) from amountInfo) while (@id <=...

Good code visualization / refactoring tools for C++?

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/sig...

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

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 che...

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

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 value...

What's the steps for SQL optimization and changes without reflect live system ?

we have a big portal that build using SharePoint 2007 , asp.net 3.5 , SQL Server 2005 .. many developers work in it since 01/2008 and we are now doing huge analysis for current SQL Databases [not share-point DB ] to optimize and enhance it. The main db have about 330 table and 1720 stored procedure (SP) created from 01/2008 till now Ma...

SQL select row-wise increase in amount of running total column

Suppose I have a table with columns (DayId, RunningTotal): DayId RunningTotal --------------------- 1 25 3 50 6 100 9 200 10 250 How can I select the DayId and the amount the RunningTotal has increased from the previous day? i.e. how can I select: DayId DayTotal --------------------- 1 2...

A report of refactoring recommendations

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. ...