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 > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "what are the writing tools for Python", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what writing tools are suitable for Python.
Secret weapon # 1: code can be written faster with Kite, reducing Google writing time
Most code editors have auto-completion, which looks like this:
... Use language (and sometimes library) documentation to suggest things like function names and parameters.
Sure, but if your editor can browse GitHub data for years and do it automatically, it can be not only the function name, but also the entire line of code.
This is just the first of three reasons to use Kite.
Reason 1: line of code is complete
The kite will check your code base and variables, common parameter names used online, documentation, and then make the following super context recommendations:
The above example shows how Kite predicts the variables you will use in a common name such as b or a common name such as x or y.
... We have spent about 50 years as engineers working on Github to semantically index all code, build statistical type inference, and rich statistical models that can use this semantic information very deeply. -Adam Smith, founder / CEO of Kite
This is a live demo video, or, if you like, you can play it in sandboxie.
Reason 2: co-pilot documentation
If you've never heard of "RTFM", you probably haven't made my mistake.
In any case, you should always read the documentation before calling a senior developer or even checking the Stack Overflow answer.
Kite Copilot makes documents stupid and easy. It runs with your editor and displays documents for any objects / functions / etc., that you highlight with the cursor in real time.
Dear senior developer, my first job: sorry. Now, I really have no excuse not to look for answers in the document first.
Reason 3: run privately locally
It's based on everything that runs locally, so you can get incredibly quick advice, it can work offline, and your code will never be sent to the cloud.
This is very important for people with poor Internet connections and people working in a closed source base.
Result
I have been using kites for many years, and I have been making progress. With more than $17 million in investment, the company is ubiquitous, and for some stupid reason, the tool is completely free.
All you have to do is download the Kite plug-in for your editor, or download the copilot, which can install the plug-in for you. To realize it (dream); to get it (things!
Secret weapon 2: use Mypy to stabilize your code
Python is a dynamic type, and an oversimplified explanation is that you can set any variable to any data type (strings, integers, etc.) at any time.
# These two variable types are declared the exact same way # Python figures out the data type on it's own, dynamically # string var_name = "string here" # integer var_name = 1234
In contrast, statically typed languages, where variables must have a specific data type and must always follow that data type.
# Many languages require the data type to be declared too # string str var_name = "string here" # integer int var_name = 1234
Advantages / disadvantages of dynamic types
The advantage of dynamic typing is that you can be lazy when writing and reduce code clutter.
There are many shortcomings, but they are also great:
Later in the development cycle, you usually encounter errors
Because Python keeps finding types, the execution of the code is even worse
Function is unstable because its input and output can change the data type without warning
Handing over the code will be more unstable because others may not know what data type your variable is or is likely to be
Static types in Python
Enter Mypy. A free Python module that allows you to use static types within Python.
After you click to install mypy, the following is just an example of usage:
# Declaring a function using normal dynamic typing, without mypy def iter_primes (): # code here # Declaring the same function with mypy static typing from typing import Iterator def iter_primes ()-> Iterator [int]: # code here
In the mypy example, we specify that the function returns an integer iterator. By performing consistent output, this simple change makes the feature more responsive to future needs.
Other developers can simply look at the declaration to see which data type the output will be, and unlike just using documents, if you don't comply with that declaration, your code will go wrong.
This is a very simple example, taken from the examples here, and if it still doesn't make sense, check them.
Result
It's hard to list all the ways static typing can ease your pain in the future, but mypy documentation has good answers to frequently asked questions, but there are more pros and cons.
If you are working in a production code base where stability is critical, definitely give mypy a try.
Secret weapon # 3: use Sonarlint to find errors faster and write simpler functions
Today, every editor has some type of error checking or built-in "lint". It usually looks at the code without running it and tries to guess what might be wrong. This is called static code analysis.
Dynamic code analysis actually attempts to run / compile some of the code to see if it is working properly, but it is performed automatically in the background. In fact, it doesn't need to guess, but knows whether it works and exactly what the error is.
SonarLint is at its best and is a leader in dynamic code analysis. These features are what I like about it:
Comments or uncalled code
I feel gui about leaving printed statements, commented-out code, and unused functions throughout the code base. This will warn me, make it hard to forget, and tell me where it is and easy to find.
Safety risk
Throw a large, constantly updated security risk database into your code base in real time to warn you of any known vulnerabilities you may face.
Security risks are too small to remember, so everyone should use some way to track them. SonarLint is a good place to start.
Code that will never be executed
Slightly different from uncalled code, this warns me if the evaluation I create cannot be reached. These problems are hard to find and can lead to hours of debugging, so this is one of my favorite warnings.
This is an example:
A = None if a = = None or not an or a: this_will_always_get_called () else: # sonarlint will warn you about this line never being executed this_will_never_get_called ()
Cognitive complexity
I can write a complete post, which is a very interesting topic. In fact, there is a complete white paper on it.
The simple explanation is that they have created a mathematical formula that scores the difficulty of reading / comprehension of the code.
It is not only very useful, but also easy to follow. Whenever SonarLint asks me to "reduce cognitive complexity," it comes with a simple description of the rules I violate, such as "too many nested if statements."
Result
I find this more useful than basic blocking and shedding practices, and I believe it leads me to write human-friendly code. By the way, this is Pythonic!
SonarLint is free, so there's no reason not to get it right away and attach it to your editor.
At this point, I believe that you have a deeper understanding of "which writing tools are suitable for Python". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.