Visual Studio Code and PyCharm compared

Visual Studio Code seems to be the cool new programming editor and IDE in town. I wanted to give it a try and compare it to PyCharm which I usually use.

Installation

For Fedora Linux, there are two sensible options: RPM packages and Flatpak. VS Code is not in the Fedora repository, so one needs to obtain the RPMs from Microsoft. This works pretty well.

For Flatpak there is com.vscodium.codium which one could use. This is a build of the open source version and doesn't include telemetry (tracking). There is just one huge caveat to it: Flatpak isolates applications from the file system and therefore severely restricts them. This is great in principle, but you will run into trouble when you try to access system files like other Python interpreters.

The Python support ships with a Python 3.10, which is displayed in the status bar:

When I try to select the /usr/bin/python3.11 on my system, I get this error:

This comes from the Flatpak security restrictions.

So just install it via Microsoft's RPM packages and you will be fine. With Flatpak it just doesn't seem to work properly. The same holds for PyCharm, the unofficial Flatpak also doesn't really work for me.

Python plugin

VS Code isn't really a fully fledged IDE (Integrated Development Environment), rather it is an editor with a very rich plugin marketplace. So when you open a Python project in it, you don't get very far. The syntax highlighting is also very minimal.

When you try to actually run the code, it will eventually ask you to install a plugin for Python:

And then you get the official Python extension from Microsoft (ms-python):

With that you then have a more sensible looking syntax highlighting:

Python environment

I use Poetry to manage my dependencies. There are multiple ways to get the environment into VS Code. One is to just see where Poetry created it:

 poetry run python -c 'import sys; print(sys.path)'
['', '/home/mu/main/vocaby/python', '/usr/lib64/python311.zip', '/usr/lib64/python3.11', '/usr/lib64/python3.11/lib-dynload', '/home/mu/.cache/pypoetry/virtualenvs/martins-obsidian-vault-helpers-UHTmxF9t-py3.11/lib64/python3.11/site-packages', '/home/mu/.cache/pypoetry/virtualenvs/martins-obsidian-vault-helpers-UHTmxF9t-py3.11/lib/python3.11/site-packages']

And then you add that environment from a list of possible environments:

The other way is to just start it via Poetry:

poetry run code .

code is the command line name for VS Code. Poetry will setup the environment variables properly and VS Code will pick that up.

In order to run the code, one has to create a launch.json, though VS Code is very helpful in creating it for you.

One cool thing is the interactive debugger, which works very nice. Here I lacked a command line argument. And then it just pops up:

So I use the autocompletion to add the missing argument there:

Then I could enter it, nicely done!

Git integration

There is a default integration into Git, and that works without a fuzz.

Autocompletion

One of the things that I value most in an IDE is the autocompletion. And VS Code also has sensible autocompletion:

This is pretty much what I expected.

But PyCharm has a bit more context there. There are function signatures and return types, also from where it is inherited.

Again, slightly better.

Refactoring capabilities

The other important thing are refactoring capabilities. And here I noticed that VS Code does have some, but not the same capability that PyCharm has.

For instance you have the possibility to extract a method, that is nice.

Then there is the usual refactoring to change the name of something. This usually works well. But I ran into a problem there. I had a module command.py which contained a function command(). Somewhere else I had imported it as from .command import command. Now I disliked the name of the function and changed it to print_context(). VS Code changed the import line to from .print_context import print_context, which broke the code. PyCharm however realized that these are two different things and made that line from .command import print_context. Here one can see how VS Code just isn't on the level that PyCharm is.

VS Code also lacks the capability to change the function signature. PyCharm has this, and it is pretty nice. Just click on a function:

And then you can change the signature:

It will update all the call sites accordingly.

Finding usages

Finding usages is an elementary thing, and VS Code can find them. It is not too pretty, though, and it doesn't really group them into definitions and other things.

PyCharm on the other hand gives you a nicer panel with the findings and then also a preview panel with the call sites.

Quick fixes

Another value of an IDE is that it directly shows errors while you type the code. I usually write the usages first and then import the stuff that I need. Here I didn't have the import subprocess that one needs. VS Code helpfully suggests to import that:

But this already falls short with Collection. This is available in typing, but the more modern version is from collections.abc. VS Code doesn't seem to know the new one:

PyCharm does this better:

Another more demanding thing is urllib.parse.unquote() for which one has to import urllib.parse. VS Code doesn't suggest anything there:

PyCharm at least suggests to import urllib:

But then it fails to find parse in there, because it only created an import urllib.

Trying to resolve that doesn't show helpful things there:

I guess it is just urllib that is a bit hard for IDEs.

Conclusion

VS Code is a nice IDE that one can get for free. For a lot of development it is pretty nice. And I also like that you can get tons of plugins for various languages in there, also for stuff like GraphViz or PlantUML.

As the better is the evil of the good, though, I still prefer PyCharm over VS Code. There are just some missing features in VS Code (like function signature change) and subtle issues (like renaming the command). I'm happy to have tried it, and I might use it for a few things here and there. But I will stick with PyCharm for now.