refactoring

Diff tool that can compare sub-sections of files

孤街醉人 提交于 2020-01-21 04:07:08
问题 I'm looking for a diff tool that will allow me to compare just a sub-section of a file with a section of another file, or even of itself. Preferably eclipse based but will take all suggestions. Yes I know I can copy out the two sections into different files and compare those, but that is very tedious when you are trying to do a large amount of refactoring. Basically I'm trying to remove as much duplicated code as possible from a code base that is suffering from a great deal of ctrl-V

JS: rename variables for refactor (using an AST, not text)

随声附和 提交于 2020-01-14 22:32:28
问题 I often need to rename variables when refactoring code, which I currently do in a somewhat hacky way using regexs - I end up having to come with silly text workaround workarounds for the lack of actual structure, eg, rename 'req' to 'request' and avoid side effects with similar names like 'require'. Thinking about this stuff: it's kind of like modifying the DOM with regexs: it just doesn't work. I've learnt about ASTs and code structure modification tools like Esprima. Is there a tool to

JS: rename variables for refactor (using an AST, not text)

耗尽温柔 提交于 2020-01-14 22:29:27
问题 I often need to rename variables when refactoring code, which I currently do in a somewhat hacky way using regexs - I end up having to come with silly text workaround workarounds for the lack of actual structure, eg, rename 'req' to 'request' and avoid side effects with similar names like 'require'. Thinking about this stuff: it's kind of like modifying the DOM with regexs: it just doesn't work. I've learnt about ASTs and code structure modification tools like Esprima. Is there a tool to

Is there any tools to help me refactor a method call from using position-based to name-based parameters

混江龙づ霸主 提交于 2020-01-14 07:55:08
问题 I wish to transform code like: var p = new Person("Ian", "Smith", 40, 16) To: var p = new Person(surname: "Ian", givenName:"Smith", weight:40, age:16) As a first step in making the code more readable, I am willing to use a 3rd party refactoring tool if need be. (Please do not tell me to use parameter objects and factor methods etc, these may come later once I can at least read the code!) 回答1: Refactor v2001 vol 1.3 claims to be able to do it. ReSharper has it in it's issues database, but have

ruby fast reading from std

半城伤御伤魂 提交于 2020-01-14 06:41:30
问题 What is the fastest way to read from STDIN a number of 1000000 characters (integers), and split it into an array of one character integers (not strings) ? 123456 > [1,2,3,4,5,6] 回答1: This should be reasonably fast: a = [] STDIN.each_char do |c| a << c.to_i end although some rough benchmarking shows this hackish version is considerably faster: a = STDIN.bytes.map { |c| c-48 } 回答2: The quickest method I have found so far is as follows :- gets.unpack("c*").map { |c| c-48} Here are some results

ruby fast reading from std

…衆ロ難τιáo~ 提交于 2020-01-14 06:41:29
问题 What is the fastest way to read from STDIN a number of 1000000 characters (integers), and split it into an array of one character integers (not strings) ? 123456 > [1,2,3,4,5,6] 回答1: This should be reasonably fast: a = [] STDIN.each_char do |c| a << c.to_i end although some rough benchmarking shows this hackish version is considerably faster: a = STDIN.bytes.map { |c| c-48 } 回答2: The quickest method I have found so far is as follows :- gets.unpack("c*").map { |c| c-48} Here are some results

How to dynamically generate association names?

时光毁灭记忆、已成空白 提交于 2020-01-14 04:25:08
问题 I am using Ruby on Rails 3.2.2 and the Squeel gem. I have following statements and I am trying to refactoring the my_squeel_query method in a Mixin module (since it is used by many of my models): # Note: 'article_comment_associations' and 'model_as_like_article_comment_associations' # refer to database table names. class Article < ActiveRecord::Base def my_squeel_query commenters. .where{ article_comment_associations.article_id.eq(my{self.id}) & ... } end end class ModelAsLikeArticle <

How can I add an interface with delegate implementations to a class?

心不动则不痛 提交于 2020-01-14 03:14:33
问题 What is the fastest way in Eclipse to implement a new interface and generate delegate implementations to an existing class? For instance given an existing class Foo , suppose I want it to implement Iterator<Integer> using a delegate Iterator<Integer> . 回答1: Add the delegate field Iterator<Integer> and the implements Iterator<Integer> to foo as follows: public class Foo implements Iterator<Integer> { Iterator<Integer> iterator; } Select the source menu and then "Generate Delegate Methods".

Factoring/Refactoring a program

核能气质少年 提交于 2020-01-13 11:22:47
问题 What does the term 'poorly factored' and 'refactoring' a program mean? Can you give a simple example to understand the basic difference ? 回答1: Refactoring is a general technique that can refer to many tasks. It usually means cleaning up code, removing redundancy, improving code quality and readability. A very simple example of poorly factored code: do_task1("abc"); do_task2(123); do_task3(7.43); ... //100 lines later: do_task1("abc"); do_task2(123); do_task3(7.43); ... //80 lines later: do

Factoring/Refactoring a program

泄露秘密 提交于 2020-01-13 11:22:07
问题 What does the term 'poorly factored' and 'refactoring' a program mean? Can you give a simple example to understand the basic difference ? 回答1: Refactoring is a general technique that can refer to many tasks. It usually means cleaning up code, removing redundancy, improving code quality and readability. A very simple example of poorly factored code: do_task1("abc"); do_task2(123); do_task3(7.43); ... //100 lines later: do_task1("abc"); do_task2(123); do_task3(7.43); ... //80 lines later: do