In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
The content of this article mainly focuses on what are the specific skills for the use of IDE. The content of the article is clear and clear. It is very suitable for beginners to learn and is worth reading. Interested friends can follow the editor to read together. I hope you can get something through this article!
A background
1 purpose
If you want to do something good, you must first sharpen its tools. For R & D students, in the daily development work, we deal with the most is the programming IDE. Whether we can use IDE efficiently and flexibly will play an important role in our work efficiency.
The two main things that R & D students do in development are architecture design and coding, the former mainly depends on a large number of project experience accumulation and personal thinking depth, but also as the core competitiveness of R & D, it is difficult to achieve rapid success in a short period of time; the latter mainly depends on daily coding exercises and a certain degree of IDE information gap, which can quickly complete and consolidate the ability through a series of skills introduced below.
The main purpose of the editor is in two aspects:
On the one hand, the fast operation and efficient skills of IDE, combined with their own years of practice and understanding, carry out a systematic summary and comb.
On the other hand, I hope that through the systematic carding of this article, it can help more students to improve the efficiency of research and development. whether you are a newcomer or an expert with many years of development experience, I believe you can find a new world in this article. so that you can have more time and energy to do more meaningful things.
2 positioning
Many technical websites and personal blogs on the Internet summarize the various skills and convenient operations of IDE in detail, which are of great reference and learning value for the level of detail of a single point. But the corresponding problem is that many of these excellent articles come from different writings, have their own writing styles, and are scattered in the scattered spots of various websites, so it is difficult to systematize.
My position for this article is to gather and aggregate various skills in the form of a large classification, in order to help you build and improve the overall knowledge system and greatly improve the efficiency of development. For each classification point on arrival, an alternative to chewing indoctrination is to use progressive guidance as far as possible.
3 universality
JetBrains series of IDE products are numerous, in addition to the following figure, there are other unlisted, such as the secondary development of Google Android Studio and so on. Although classified as multiple product instances, the kernels of these IDE are all the same, with additional language features added to the kernel. This article will take the most widely used IDE--IDEA as an example. Most of the abilities and techniques mentioned in this article are also applicable to other IDE.
Two Postfix Completion
1 introduction
Postfix Completion (hereinafter referred to as Postfix) is a kind of adoption. + template Key to add and apply coding enhancements to preset code templates for currently outputted expressions.
The core problem to be solved is to abstract and precipitate some common code structure paradigms in the coding process, and to pass them in the same type of scenarios. + template Key for wake-up and reuse.
For example, now you need to complete the following code for null protection of the name parameter:
If (name! = null) {}
In a plain text editor, if 2 times, name 4 times, () {}! = 6 times, plus space Tab and cursor toggle, you need to press the key 23 times.
In the IDEA editor, when you don't use Postfix, you need to press a total of 20 keys, which can be reduced to 16 regardless of code formatting.
In the IDEA editor, you only need to use Postfix 8 times, as shown in the following figure:
In this example, you can compare the effect before and after using Postfix, which reduces the manual keystroke operation in the coding by half, and the generated code is formatted. In the actual coding process, although the size and complexity of each project vary greatly, they are integrated when refined to the programming paradigm of this basic unit.
Postfix,IDEA juxtaposed with nn in the above example gives us a lot of presets. Here are some very frequently used Postfix to sort out.
2 carding
Var
Quickly define a local variable with type inference with IDE
Notnull
Rapid air protection of NPE:
Nn
The same as notnull, is its abbreviation, it is recommended to use this, it is more convenient:
Try catch
Quickly add try catch exception traps to the current statement, and IDE automatically infers the type of Exception in catch:
Cast
Fast type overturning without repeated use of () parcels and cursor switching, and automatic inference of cast types when used with instanceof:
If
Quickly implement the code paradigm for if judgment:
Throw
Quickly implement throwing exceptions:
For
Quickly iterate through a collection or array:
Fori
Quickly implement indexed iterations of collections or arrays; also support integer numbers:
Sout/soutv
Fast (no / with parameters) printing function:
Return
Quickly implement the value return logic in the method:
Format
Quickly implement string formatting:
3 advanced usage
Worried that the default Postfix of the system is not enough to meet our coding needs, IDEA also provides the custom function of Postfix.
Here, I'll give an example of the process of customizing Postfix by customizing a code paradigm that nullifies the collection:
1) enter the IDE configuration page, and then enter Editor = > General = > Postfix Completion = > the plus sign in the lower left corner of the panel = > Java:
2) in the pop-up page, configure as shown below, and then save the exit settings page.
At this point, our custom isempty Postfix is complete. Let's take a look at the actual effect:
In the actual development process, we can all use this custom way to abstract and reuse the code for the function that the next code format can be determined according to the expression already entered.
Next, let's introduce an ability in IDE that is very similar to Postfix, but more flexible-Live Template.
Three Live Template
1 introduction
Before the introduction, you can take a look at a short coding process:
In the above coding, I successively used the following three template capabilities of Live Template:
Psfs: define string constants
Main: add entry function
Sout: implement log output
Here we compare it with the Postfix mentioned above, both of which provide the functionality of code-level templates. The difference is that Postfix requires an expression that has been entered and. + template Key to trigger, but Live Template does not need these, it only needs template Key to trigger.
The preset template provided by Live Template is an order of magnitude higher than that of Postfix, so instead of demonstrating one by one, we can set up the panel and view it by following the path of Editor = > Live Templates, as shown below:
2 advanced usage
Like Postfix, Live Template supports custom templates, but its custom templates are relatively more flexible and open, and even allow us to populate scripts directly. In view of the high flexibility of Live Template, a separate introduction to this area will take up a lot of space, so here I will open up ideas from several actual case scenarios, but the specific custom expansion process will not be described in detail.
Key value mapping
The data of List structure queried in DB is transformed into data of Map structure according to key value mapping, so as to facilitate the subsequent data filling logic:
DB batch query
When querying data, we will ask for batch DB data query based on ID primary key, as follows:
List users = userMapper.queryUserByIds (userIds)
One drawback of this writing is that when the userIds is large to a certain order of magnitude, the query becomes very time-consuming.
One solution to this problem is to split the large userIds into multiple batches and then let the batches query asynchronously in parallel. Here, we use Live Template to extract a code template for this scenario, as follows:
According to this template, our query statement will look like this:
List users = batchQuery (userIds, 100, userMapper::queryUserByIds, null)
As you can see, compared with before, one more batch of size parameters is passed, and the custom configuration of the specified asynchronous task scheduler is also supported, and the returned results are exactly the same as the previous query, and no additional adaptation work is required.
Script implantation
This feature is the main reason why I am very optimistic about Live Template, and its flexibility and expansibility mainly come from here. It allows us to evoke and execute a script through a template Key, which means that our custom Live Template template is programmable, greatly improving the extensibility of the template.
The single description function will be a little empty. Here I will introduce it with an actual case. Let's implement a code sharing function across computers:
1) first, write a minimalist server application using python's flask framework and launch it, providing the simplest push and pull capabilities, as follows:
From flask import Flask, requestDEFAULT = 'nothing'code = DEFAULTapp = Flask (_ _ name__) @ app.route (' / push') def push (): global code code = request.args.get ('code', DEFAULT) return' Success'@app.route ('/ pull') def pull (): return codeapp.run ()
2) then, we will implement a template of code pull through the groovy script, where the groovy script capability of Live Template is applied, and the corresponding script is as follows:
Def url = new URL ('http://127.0.0.1:5000/pull');def conn = url.openConnection () as HttpURLConnection;def result = conn.inputStream.text;return result
3) finally, implement the template of the code push. The script is as follows (the following code input parameters are passed through clipboard assignment):
Def code = _ 1 as HttpURLConnection;def result def url = new URL ('http://127.0.0.1:5000/push?code=' + new URLEncoder () .encode (code)); def conn = url.openConnection () def = conn.inputStream.text;return result
At this point, the cross-device code sharing function has been completed. For the convenience of demonstration, two classes People1 and People2 are used to simulate two independent computers. People1 copies a piece of its own code to the clipboard, and then calls the push API through the push template to upload the code to the Python service application. People2 then invokes the server's pull API through the pull script, accesses the code uploaded by People1 and inputs it into the current code editor, as shown below:
The code sharing here is just an introduction. In addition, we can write a lot of interesting scripts, such as checking the weather in IDE, chatting through IDE, and so on.
After introducing Live Template, let's move on to the file-level template, File Template.
Four File Template
1 introduction
File Template, as its name implies, corresponds to a file-level template. For this template, we mainly use the script in two scenarios, namely, the file header and the file customization, which are expanded in turn with the case.
2 Custom file header
Change the format of the file header according to the path of the figure below, and IDE will automatically generate the corresponding file comment header according to the configuration format here when we create a new class or interface.
3 Abstract general Controller
Take a look at the following code. This is an API class for adding, deleting, modifying and querying User domain:
Package com.alibaba.ide.code.controller;import com.alibaba.ide.code.entity.Result;import com.alibaba.ide.code.entity.User;import com.alibaba.ide.code.service.Condition;import com.alibaba.ide.code.service.UserService;import org.springframework.web.bind.annotation.*;import javax.annotation.Resource;import java.io.Serializable;import java.util.List / * * @ author puke * @ version 2021-2-9 * / @ RestController@RequestMapping ("api/user") public class UserController {@ Resource private UserService userService; @ PostMapping public Result create (@ RequestBody User record) {User user = userService.insert (record); return Result.success (user);} @ PutMapping public Result update (@ RequestBody User record) {User user = userService.update (record); return Result.success (user) } @ DeleteMapping ("{id}") public Result deleteById (@ PathVariable Serializable id) {boolean success = userService.deleteById (id); return success? Result.success (): Result.fail (); @ GetMapping ("{id}") public Result queryById (@ PathVariable Serializable id) {User user = userService.queryById (id); return Result.success (user);} @ GetMapping public Result queryByCondition (Condition condition) {List list = userService.queryByCondition (condition); return Result.success (list);}}
If you take a closer look at this code, you will find that if you add another Controller interface class corresponding to domain based on this interface, the basic structure and logic in the code can be reused. At this time, is where File Template comes in handy, we define a general Controller template, abstract the common part into the template, and then pass the different part into the parameter Subject variable through the template (Note, here you need to use the knowledge of the Velocity template [1]).
# set ($SubjectOfLowerFirst = ${Subject.substring (0Magne1). ToLowerCase ()} + $Subject.substring (1) package ${PACKAGE_NAME}; import com.alibaba.ide.code.entity.Result;import com.alibaba.ide.code.entity.$ {Subject}; import com.alibaba.ide.code.service.Condition;import com.alibaba.ide.code.service.$ {Subject} Service;import org.springframework.web.bind.annotation.*;import javax.annotation.Resource;import java.io.Serializable;import java.util.List # parse ("File Header.java") @ RestController@RequestMapping ("api/$ {SubjectOfLowerFirst}") public class ${Subject} Controller {@ Resource private ${Subject} Service ${SubjectOfLowerFirst} Service; @ PostMapping public Result create (@ RequestBody ${Subject} record) {{Subject} ${SubjectOfLowerFirst} = ${SubjectOfLowerFirst} Service.insert (record); return Result.success (${SubjectOfLowerFirst}) } @ PutMapping public Result update (@ RequestBody ${Subject} record) {${Subject} ${SubjectOfLowerFirst} = ${SubjectOfLowerFirst} Service.update (record); return Result.success (${SubjectOfLowerFirst});} @ DeleteMapping ("{id}") public Result deleteById (@ PathVariable Serializable id) {boolean success = ${SubjectOfLowerFirst} Service.deleteById (id); return success? Result.success (): Result.fail ();} @ GetMapping ("{id}") public Result queryById (@ PathVariable Serializable id) {${Subject} ${SubjectOfLowerFirst} = ${SubjectOfLowerFirst} Service.queryById (id); return Result.success (${SubjectOfLowerFirst});} @ GetMapping public Result queryByCondition (Condition condition) {List list = ${SubjectOfLowerFirst} Service.queryByCondition (condition); return Result.success (list);}}
After the template definition is complete, let's take a look at the actual usage effect:
Using Goods as the new domain object, you can see that the generated Controller code already has all the capabilities of UserController, and the generated code is all Goods-related api, thus realizing the horizontal migration capability of File Template.
Five low frequency efficient shortcut keys
1 introduction
There are hundreds of shortcut keys in IDEA, it is difficult for us to remember each one clearly, and there are many corresponding summaries on the Internet. Here I mainly comb some, we use relatively low-frequency, but very efficient keyboard shortcuts.
2 carding
Select repeating element: Control + G
In general, we can use Shift + F6 to make batch changes to class, method, and variable names, but this shortcut is particularly appropriate for other elements and is not limited to the programming language.
Batch box selection: Option + left mouse button drag and drop
There is no one of the best solutions for batch changes to "aligned" code:
Full line mobile: Option + Shift + ↑ / ↓
Quickly adjust the order of code execution to avoid the tedious cut-and-paste process:
Full line / block copy: Command + D
For whole line / block copy, it is much more efficient than manual copy and paste:
Expand / fold: Command +. Or Command + Shift + + /-
The former, which quickly shows / hides the current method body, and the latter, which provides a quick overview of all methods of the current class:
Modify method signature: Command + F6
This method is extremely efficient when the method is called by multiple files or multiple places:
View the history clipboard: Command + Shift + V
There are often requests to copy multiple texts in development, but only one clipboard can be saved by default in PC. This feature is specifically used to solve this pain point:
Code extraction
Code extraction is mainly used in code refactoring to achieve the purpose of extracting a variable and method as quickly as possible.
1) extract local variables: Command + Option + V
2) extract member variables: Command + Option + F
3) draw static constant: Command + Option + C
4) input parameters of extraction method: Command + Option + P
5) drawing method: Command + Option + M
Six code debugging
Code debugging is widely used in development, and the conventional single-step, multi-step, in-and-out operations are not specifically described here.
It is worth saying that using conditional breakpoints to implement runtime code implantation, take a look at the following figure:
As you can see, when the Debug mode is running, we can dynamically change the value of the age variable, which is assigned a value of 20, but the output is 10.
This is a feature I stumbled upon in development, which can be regarded as a Trick. However, this feature is particularly useful in the actual development process, especially in scenarios where it is expensive to run again after code changes. For example, in the process of Android development, you can dynamically modify the style of each element in the page, the request of the interface, the content of data, and so on without repackaging; for example, in the server scenario, if our application supports the Debug pattern, you can use this feature to dynamically change the context logic without redeploying the application.
Thank you for your reading. I believe you have a certain understanding of "what are the specific skills for the use of IDE?" go ahead and practice it. If you want to know more about it, you can follow the website! The editor will continue to bring you better articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.