Quantcast
Channel: Category Name
Viewing all articles
Browse latest Browse all 10804

Why write Python in Visual Studio?

$
0
0

Recently, Visual Studio 2015 was released with support for Python. Python Tools for Visual Studio (PTVS) are available to help throughout Visual Studio in all the places you’d expect, from editing and IntelliSense, to debugging, profiling, and publishing to Azure. You can find all the details and some video walkthroughs, documentation, and other resources on visualstudio.com, and the post announcing Python Tools 2.1 and Python Tools 2.2 beta. In this post I want to talk about some of the reasons to consider using Visual Studio next time you are working in Python.

IntelliSense is actually pretty helpful

I know, we talk about IntelliSense all the time. Visual Studio has always had great IntelliSense for all of its languages, so if you’ve been coding in C# or VB for the last fifteen years you aren’t even impressed anymore. Python developers have not been so lucky, having to be content with only minimal code suggestions and basic syntax highlighting.

Unlike many other languages, Python code does not need you to specify types everywhere. This saves a lot of time while coding, but it requires a deep understanding of your program and every bit of help from your editor is important. Most editors do not provide helpful tips and force you to keep your entire program's operation in your own head.

In Visual Studio, we provide this deep understanding for you. Using full-program analysis, we track variables from the first time they are initialized to every place they are used. You can mouse-over any variable to see what types it could be at that point, or “dot-through” to see its members.

Hover over to see types or dot-through to see members We’ve spent a lot of time optimizing our analysis for common Python patterns. Here are some things to try out:

  • Put different types into a tuple and then unpack them later
  • Call a function with different arguments and look at the return values
  • Add a value to a list that’s been passed into a function
  • Make a subclass and start typing some method overrides

Debugging is a big deal

Similar to IntelliSense, interactive debugging in Python is a fairly recent development. Python developers traditionally spent a lot of their time at a terminal or command prompt, switching back and forth from their editor, and so early command-line debugging tools developed around this workflow. For exampleEarly Debugging

Although this kind of debugging is tolerable for very small projects, it can be very disorientating to step through code in this way, and becomes very inefficient for projects of any significant complexity. In contrast, Visual Studio overlays the debugging interface directly on your code in the editor, so you can see your breakpoints, current statement, and call stack in the same context.

Debugging with Visual Studio

Customizable Watch windows and floating expressions automatically update, so you can keep track of values without having to repeatedly ask for them, and it’s easy to jump up the call stack and review the variables that lead to the current state.

The best part is that this debugging is implemented using standard Python interfaces. So you don’t need a special version of Python to get it, and your code can run on Windows or any other platform. We can also use some non-standard interfaces with recent CPython versions to provide mixed native/Python debugging, letting you move between C/C++ and Python code as easily as pressing Step In. And when you want the keyboard-oriented experience, we have a Debug Interactive window with that functionality.

“Large” projects are really large

Everyone has a different concept of how large a “large” project is. Is one hundred files “large”? What about a thousand classes? Ten thousand lines of code? Regardless of the measurement, as your project becomes larger it gets harder to find your way around it, safely make changes, and keep the rest of your team updated.

Although the rich IntelliSense in Visual Studio will show you what you need from anywhere in your project, it can also help find all references to your classes and functions in a way that’s much more meaningful than just going a global text search. Go To Definition and Find All References are valuable tools for navigating your code, while Navigate To will help you find files, classes or function with smart filtering.

Tools to navigate large projects

Application Lifecycle Management with Python Projects

A rich set of features for application management are available with Visual Studio Online, including TFS and git version control, interactive code reviews, online planning dashboards, team rooms, hosted test, build, deployment services, and integration with even more third-party services. All of these features can be used with Python projects directly within Visual Studio, through the Team Explorer Everywhere plugin for Eclipse, and through any web browser. In short, when managing a project in Python or any other language, Visual Studio helps keep everyone in your team moving ahead together, whether you’ve got one hundred or one million lines of code.

How do I get it?

A lot of Python code is open-source, and if you’re working on it, you can get Visual Studio 2015 Community Edition for free. You may also have access to Visual Studio 2015 Professional or Enterprise through your employer or school. In any of these cases, you don’t need to download and install the Python Tools for Visual Studio separately: they’re available directly through Visual Studio’s setup.

Visual Studio Community 2015 Setup

On our release page you’ll find sample packs and extensions, as well as the main installers. If you would prefer to use Visual Studio 2015 Express for Web or Express for Desktop, or you are still using Visual Studio 2013, you will need to get the installer from the release page.

Finally, PTVS is a free, open-source project and we accept community contributions. Come visit our page on github to get involved, provide feedback, ask questions, or try out our latest features before they are officially released.

 

SteveDower, Software Engineer, Python Tools

Steve is an engineer who tells people about Python and then gives them excuses to use it and great tools to use it with. He works on Python Tools for Visual Studio, contributes to many of Microsoft’s Python libraries, and is a core contributor and Windows expert for CPython.


Viewing all articles
Browse latest Browse all 10804

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>