CSC/ECE 517 Fall 2014/ch1a 11 ap: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 56: Line 56:
While deleting a class or a file, the programmer checks if that class or file is being used anywhere else in the program. Using Safe Delete, the programmer can be warned of any such multiple usages through a warning message. The search is also extended to comments and strings.
While deleting a class or a file, the programmer checks if that class or file is being used anywhere else in the program. Using Safe Delete, the programmer can be warned of any such multiple usages through a warning message. The search is also extended to comments and strings.


=== Extract ===
=== Extract/Inline ===
 
To quickly move code around in a full swing of refactoring, it comes in handy to inline some variable, or to extract an expression to a variable. You can even extract a full code block into a new method, and add a parameter to it using Introduce Parameter refactoring.
 
 
At any moment you need a refactoring, just press Ctrl+T to see what refactorings are suitable for the current context. Note the new Move refactoring: it allows you to move any class or member, or even a top level element, say a namespace through your project. Not only will AppCode move an element, but it will update the references, automatically manage imports and escalate visibility if needed.


=== Inline ===
=== Inline ===

Revision as of 05:25, 18 September 2014

Introduction: Automated Refactoring Techniques for AppCode.<ref>http://en.wikipedia.org/wiki/Ruby_on_Rails</ref>

AppCode is an Integrated Development Environment (IDE) for Objective-C,C, C++, and JavaScript development built on JetBrains’ IntelliJ IDEA platform, which is built on Java. Users can extend its abilities by either installing plug-ins created for IntelliJ Platform, or they can write their own plug-ins.

Code refactoring is the process of restructuring existing computer code – changing the factoring – without changing its external behavior. Many a times, we face the need to change the name of a variable in our code- mostly because we find another one better suited for its functionality. Doing this manually can be time consuming & often leads to many mistakes. That is why, many new IDEs (Integrated Development Environments) come with inbuilt functions for refactoring. As you read further, you will know that refactoring is not limited to changing variable name. There are many things IDEs allow programmers to do to edit their code. These changes are not logical, in the sense that they do not make any change to functionality or behavior of the program; but are needed to improve code in terms of understanding & user friendliness.

Background

"By continuously improving the design of code, we make it easier and easier to work with. This is in sharp contrast to what typically happens: little refactoring and a great deal of attention paid to expediently adding new features. If you get into the hygienic habit of refactoring continuously, you'll find that it is easier to extend and maintain code." —Joshua Kerievsky, Refactoring to Patterns

Refactoring improves nonfunctional attributes of the software. Advantages include improved code readability and reduced complexity to improve source code maintainability, and create a more expressive internal architecture or object model to improve extensibility. To help programmers easily improve code design as it evolves over time, AppCode provides a solid set of reliable code refactorings. These include vital ones like Rename, Extract Method, Introduce Variable and Inline, as well as more powerful ones, e.g. Extract Block Parameter/Protocol/Category/Superclass, Change Signature, Convert Method to Function and back, Pull Members Up/Push Members Down, and others. First public preview version of AppCode became available in April 2011. The latest stable release is version 3.0 and is available at JetBrains’ official web site.

Features of AppCode

Finest coding assistance Context-aware editor gives you precise code completion choices due to deep understanding of your code structure, saves you from unnecessary typing by generating code, allows you to program by intention and minimize the routine tasks. AppCode automatically imports a class if it is not imported by the programmer in the code. Parameter Info(ctrl+P) assists the programmer in determining what exact parameters need to be passed to a method or function. Code reordering allows you to order your code. For example, to move block of code up or down, the following commands can be used:Cmd+Shift+Up/Down and for lines of code: Alt+Shift+Up/Down. Such assistance allows user to concentrate more on the logic of program than its structure.

Reliable refactorings Safe, accurate and reliable refactorings allow you to modify and improve your code at any time. Whether you need to revive old code base, or brush up the project structure, you can always lean on AppCode. Various refactoring techniques mentioned below make it easy to refactor code.

Fast project navigation Navigate from a method to its declaration or any of its usages, through classes hierarchy or from one file to another. Jump to any file, class, or symbol in your project in no time, or see all real usages of a symbol, not just text matches.

Code quality tracking On-the-fly code quality analysis forObjective-C, C, C++, JavaScript, CSS, HTML, XML and Xpath. AppCode saves you from potential errors, and gives you hints when your code can be improved. Moreover, it comes with integrated Clang Static Analyzer.

Powerful debugger Programmers can fine-tune apps or unit tests using a convenient debugger with flexible breakpoints, watches, frames view and evaluate expressions. With the help of conditional breakpoints in AppCode, one can have more control over the debugging process, and an option to log an evaluated message when a breakpoint is hit.

Seamless integrations AppCode seamlessly integrates with the most popular version control systems, like Git, Mercurial, Perforce, etc.; Kiwi testing framework, Dash and Ingredients documentation tools, a number of issue trackers and provides 100% interoperability with Xcode. AppCode is also integrated with Reveal , a fantastic tool from Itty Bitty Apps that helps debug iOS applications. You can experience the benefits of this tool right from AppCode, including the ability to inspect view elements and hierarchies of your iOS apps in real time, use the 2D and 3D visualization possibilities, and apply the view's editing on the fly, which is a convenient way to tweak the interface without recompiling.


Refactoring Techniques in AppCode:

Automated Techniques used by appCode are listed below:

Rename

By using this, one can rename a file, class, method, property, ivar, local variable, and so on. In the file or project view, the shortcut triggers renaming a file or a class. If you just are renaming a file (such as a plist or an image), AppCode will rename the file, and also change where it is referenced. If you are renaming a class, both the header, and the implementation of the class is renamed, and the references of the files in the project file. If you select Rename when the cursor is on a class name used by the class, the selected class is renamed. If you triggers the rename from inside the source file, the name of the class, variable, and so on, is entering a “edit mode,” almost like “Edit all in Scope,” in Xcode. The difference is that while in Xcode you renamed only the names inside the current class, the renaming in AppCode is global.

Change Signature

Often, a programmer needs to alter a method signature. This can be to include an additional argument, or maybe the argument is not needed anymore, or even the order of the arguments is not right. If the method is called from several places, this can be a time-consuming and error prone task. By using AppCode, this is done in a simple and safe way. This is a really powerful feature in AppCode. You can also change the return type, and even convert a method to a function or a block, or vice versa.

Convert

Converting a method to a function or a block can also be done by using one of the Convert to menu items. In addition to these, you also have Convert to Property and Convert to Instance Variable.

Move

The Move refactoring allows you to move a property, variables and methods from one class to another. If the target class does not exist, you get a warning that tells you that.

Copy

When in the project browser, selecting a header, or an implementation file, or when inside one of these files, F5 will prompt you to enter the name of the new copy of the files, and where to copy them. While in the “To directory” input field ⌃␣ will provide path completion. When accepting, the class name inside the source files is changed as well.

Safe Delete

While deleting a class or a file, the programmer checks if that class or file is being used anywhere else in the program. Using Safe Delete, the programmer can be warned of any such multiple usages through a warning message. The search is also extended to comments and strings.

Extract/Inline

To quickly move code around in a full swing of refactoring, it comes in handy to inline some variable, or to extract an expression to a variable. You can even extract a full code block into a new method, and add a parameter to it using Introduce Parameter refactoring.


At any moment you need a refactoring, just press Ctrl+T to see what refactorings are suitable for the current context. Note the new Move refactoring: it allows you to move any class or member, or even a top level element, say a namespace through your project. Not only will AppCode move an element, but it will update the references, automatically manage imports and escalate visibility if needed.

Inline