Welcome to Hands-On Application Development with PyCharm, and congratulations on taking the first step in exploring the powerful and dynamic functionalities that the most popular Python IDE, PyCharm, provides. Throughout this book, we will be familiarizing ourselves with the general interface of PyCharm, various customizations of PyCharm's functionalities to best support different types of projects, and options to integrate additional features into a base Python project.
This chapter first talks about the specifics of IDEs in programming and an overview of what PyCharm is and what its general options provide. We will then discuss the usage of PyCharm among the Python community and outline several reasons for PyCharm's popularity in the community. This discussion will help us focus on why PyCharm is such a great tool for Python programmers.
We will also be making comprehensive comparisons between PyCharm and other popular Python editors/IDEs, as well as between the paid Professional Edition and the free Community Edition of PyCharm. Any Python programmer is undoubtedly familiar with a number of different Python development tools, so these comparisons will offer a way for you to decide which edition of PyCharm is the right tool for you.
The following topics will be covered in this chapter:
- The purpose of PyCharm as a Python IDE and some notable details on its developing company, JetBrains
- The usage of PyCharm within the community and a breakdown of which professions tend to utilize PyCharm the most
- A comprehensive outline regarding the advantages and disadvantages of using PyCharm, in comparison to other Python editors/IDEs
- The differences between the Professional and the Community editions of PyCharm and the additional functionalities that the paid edition offers
On the other hand, if you have already decided that PyCharm is the Python IDE for you, feel free to jump to Chapter 2, Installing and Configuring PyCharm, to go through the installation and registration process. If you have already downloaded and successfully set up PyCharm on your system, you might want to begin at the second section of the book, starting from Chapter 3, Customizing Interpreters and Virtual Environments.
Let's begin by discussing the topic of the book—PyCharm. First, we will discuss the Python language as it is the only reason why you would choose to use PyCharm in the first place. After this, it is important to start the conversation about PyCharm by pointing out the fact that there are considerable discussions surrounding the question of whether it is appropriate to use an IDE for Python programming.
Unlike many other programming languages, Python (as you already know) can be edited using just a simple text editor, due to the simplicity and readability of the code. You can then instruct a Python interpreter to execute a text file containing Python code and a Python program is thus complete.
Why would we want to use a heavy and complex IDE for Python to achieve the same result? In the following subsections, we will address this question by learning more about the idea of an IDE for Python and what specific problems PyCharm can help to solve.
Python is one of the most popular programming languages out there (if not the most) by many standards and for good reasons. The user-friendliness, readability, and simple syntax of Python make it, arguably, the most accessible programming language. This is also why most colleges all over the world are redesigning their entry computer science courses to have Python as the main programming language.
The ease of learning the language leads to one of the most important factors regarding Python, which is its support community. If you are a beginner programmer, you are more likely to start out with Python, and then you will more likely make it your main programming language.
To understand how quick and efficient development in Python is, especially in comparison to other programming languages, we can turn to the creator of Python, Guido van Rossum, and see what he has to say. In a paper for the OMG-DARPA-MCC Workshop on Compositional Software Architecture, Guido van Rossum states that development in Python is estimated to be 3-5 times faster than that in Java, and 5-10 times faster than that in C/C++. Keeping this difference in mind, we can easily understand why Python is being used so ubiquitously.
Obviously, the comparison between Python and Java or C/C++ is a weak one, since these languages are designed and used for different applications. However, it goes without saying that Python is relatively easier to write and develop programs with than the others, given its simple syntax.
All of these factors (and undoubtedly others) have resulted in a community that keeps growing stronger every day, taking in developers from all areas and of different backgrounds. Python libraries and packages are also being developed and released regularly, supporting a wide range of development tasks such as software engineering, video game development, web development, and scientific computing.
If you are a Python user, you are also likely to have noticed a sudden increase in Python usage in recent years. This is due to a new wave of data scientists and machine learning engineers who have recognized the advantages offered by Python over the long dominator of the field, R. In short, the Python community is growing like never before.
With numerous libraries and tools available, Python is seen as enticing by new programmers and developers who are looking for simpler ways to do various tasks, and thus, it generates more audience. I call this the cycle of Python, where its convenience attracts developers to use it for work, which in turn makes Python even more popular and easy to use. In fact, Codecademy (the premier online platform that offers interacting coding classes) noted recently that Python is the most popular language among their learners, and titled it The Programming Language of the Year (more details can be found here: http://news.codecademy.com/why-learn-python/).
The following chart also illustrates the growth of Python in recent years, in comparison to other popular languages (based on activities on Stack Overflow):
With the rise of Python observable, as stated previously, various development environments have been developed and enhanced to support its growing user community.
In the following sections, we will learn more about the background of one of these development environments, and the topic of our book—PyCharm—and why it has proven itself to be a top contender in competition with other environments.
A good development environment is the first step to better productivity, and Python programming is no exception. While a beginner might be better equipped with a minimal, unintegrated environment such as Python IDLE (which comes with any Python distribution), Notepad++, Emacs, or Vim, once you have become sufficiently familiar with Python, you will undoubtedly benefit from the design and support of a good IDE.
First, let's define some terms. In the context of development environments (meaning how a programmer writes their code and develops projects), an editor typically indicates a simple, minimal text editor without any additional highlighting or aligning functionalities; on the other hand, an IDE is special software that provides such features. An intuitive comparison that I'd like to make is when we draw a parallel between programming and word processing. An editor would be a simple notepad, while an IDE would be Microsoft Word, Google Docs, or similar multi-function word processors. An IDE can have various features integrated, including syntax highlighting, automatic indention, debugging tools, and so on.
As mentioned previously, the development of some programming languages does rely heavily on the use of an IDE. This is especially true for languages where there is a considerable amount of what is generally known as boilerplate code, which is necessary for the whole program itself but does not add further logic to the program instructions. Boilerplate code is typically part of the syntax of the given programming language and is always present, regardless of what the program is designed to do.
It is in these boilerplate-code-heavy programming languages that an IDE becomes convenient, or even essential. IDEs help generate boilerplate code and appropriately place it around the core instructions that the programmer wrote, saving their time and helping them focus on the development process. This is, however, not the case for Python, a language that requires minimal boilerplate code and focuses on the actual logic of the program. In other words, once you have finished the general instructions of your Python program, it is most likely ready to be executed by a Python interpreter.
How, then, can a Python developer benefit from using an IDE? Writing Python code can be done in a sufficient way using a simple text editor, but there are other aspects of Python aside from writing code such as testing/debugging, version control, the management of environments and packages, and so on that can be boiler-plate-heavy and not quite straightforward. It is during these somewhat grinding tasks that a Python IDE can shine by streamlining them and helping developers focus on the development process.
With that said, it is not always recommended for a Python developer to use an IDE in their projects. Some have argued that relying on an IDE too much can make programmers forget, or altogether prevent them from learning, the core principles and syntax of a given programming language. Say you are asked to write a class in Python with various functionalities and methods. This is a great opportunity to take advantage of an IDE since you can import the general structure of a skeleton Python class with a single command in PyCharm (or in other IDEs). The only part left is to edit the inserted code with custom instructions according to our purposes. Throughout this process, the programmer does not need to remember, or even learn in the first place, the structure of a Python class and the syntax involved.
As such, there is a certain degree of trade-off being made when choosing to use an IDE to program, even in Python. However, you cannot argue with the fact that using a good IDE can truly improve your programming productivity, and if it enhances yours, you have every reason to use one. In general, a good strategy is to start off using a simple editor to familiarize yourself with the language and its core syntax structure. Once a good understanding of the language has been gained, you can then explore advanced functionalities that an IDE provides to see if they will be able to make you more productive. Being familiar with a text editor can also help you learn how to use an IDE faster, so that is more reason to employ this strategy.
We have discussed the fact that an IDE for Python programming can be a solution to your productivity problem, given that you already have a solid familiarity and understanding of the language. Let's now turn our attention to PyCharm itself to see why it is a good IDE for us to learn to use.
Written in Java and Python, PyCharm was first introduced to the Python community in 2010, when the beta version was available for download. In 2013, the open source distribution of the software (called the Community Edition), which is free to download and use, was released. According to the developer, JetBrains, PyCharm operates on the following two core principles:
- Improving productivity: This is undoubtedly the most important feature of any good IDE. Again, PyCharm takes away most of the repetitive, uncreative aspects of Python programming, especially in large projects, helping programmers stay focused on the core development portion.
- Real-time assistance: It is no fun to complete a large project and realize afterward that there are inconsistencies and errors spreading all over the project code. PyCharm looks to address this problem by having an intelligent assisting feature that focuses on code completion, real-time checking logic for errors, PEP 8 code styles, and corresponding quick fixes, among other important functionalities.
From these two core principles, PyCharm also includes a number of higher-level features that help facilitate these principles. They are as follows:
- Intelligent coding assistance: As described previously, this real-time support system offers code-completion options, syntax and error analyses, as well as automated ways to refactor your code (which we will discuss further in Chapter 4, Editing and Formatting with Ease in PyCharm, in the Refactoring section). The smart search option also allows you to navigate through large projects seamlessly.
- Streamlined programmer tools: Again, programming is only a part of the actual development process; most of the time, programmers have to spend their time debugging, testing, and profiling their code, as well as managing the databases and packages necessary for their projects. With a straightforward GUI, PyCharm provides a way to achieve all of this in a way that is consistent, unified, and painless.
- Scientific computing support: The growth of the data science field has played an important role in the growth of Python itself, and Python is now the most common programming tool used in scientific projects (even more common than R). Notable functionalities included in PyCharm that facilitate scientific computing are the integration of IPython notebooks and an interactive console. The support for scientific computing in PyCharm is detailed in section four of the book, starting from Chapter 11, Turning On Scientific Mode. PyCharm also provides a customized view that optimally organizes workspaces in a scientific project called the SciView, which is shown in the following screenshot:
- Visual debugging: Two extreme stances that we programmers typically take in the topic of debugging in Python are: using print statements, which might prove to be too simple and limited in terms of expressing the changes taking place during the execution of a program, and using Python debuggers such as the pdb module, which can be too intimidating, and therefore inaccessible, for beginners. PyCharm offers its own solution to the debugging task—a GUI that visualizes different steps in the debugging process. In addition to being faster than pdb or any other current Python debugger, PyCharm's debugger allows us to view and customize changes in variables via watches and breakpoints.
Keeping the fundamentals of PyCharm's features and functionalities in mind, let's discuss the prevalence of the software in the Python community and see how its use is distributed across different professions.
In 2017, the Python Developers Survey (conducted by the Python Software Foundation and JetBrains) found that PyCharm is indeed the most popular development tool among all Python programmers in terms of editors and IDEs.
As observed from the Editors and IDEs section in the survey, both editions of PyCharm top the result poll for the question—what is the main editor you use for your current Python development? The results of the survey outlined that 17% of all developers used the Professional Edition and 15% used the Community Edition.
As we mentioned earlier, two of the largest subgroups in the Python community are web developers and scientific programmers. If we looked at editor/IDE use in these subgroups, we would see that the two editions of PyCharm are still the most dominant Python development environment; 30% of web developers use Professional PyCharm and 17% of scientists use Community PyCharm.
It is notable that, according to the results of the survey, other widely used editors/IDEs for Python programming are Sublime, Vim, IDLE, Atom, and Visual Studio Code. These are all viable development tools for Python programming but they might still fall short in comparison to PyCharm in a number of respects.
In the next section, we will look at a number of core differences between PyCharm and these popular editors/IDEs, and why they help PyCharm emerge as the most widely used.
We laid out several features of PyCharm in earlier sections, but it might be beneficial to repeat some of them here in comparison to other editors and IDEs in order to truly highlight the differences among them. We will start by looking at PyCharm and another powerful Python IDE (Spyder) side by side, since they generally set out to solve the same set of problems, and therefore, hold significant similarities.
In general, Spyder, like many other editors and IDEs, is a lightweight development environment. This results in less memory space, fewer system resources, and better speed in starting the software. PyCharm, on the other hand, comes as a fully supported IDE with a large set of functionalities, which will be heavier in storage and slower in execution.
In terms of support, Spyder has a simpler UI (which resembles that of MATLAB's). This can be beneficial for beginner programmers as well as people transitioning from MATLAB to Python. As for PyCharm, a comprehensive interface with different options for customization can be intimidating for unfamiliar programmers, but it can greatly improve productivity, as we have discussed and will learn first-hand in the second part of the book (Chapters 3, Customizing Interpreters and Virtual Environments, to Chapter 6, Seamless Testing, Debugging, and Profiling). However, since they are produced by the same company, users of IntelliJ IDEA specifically will also have no problem switching to PyCharm.
One previously notable way in which Spyder was superior to PyCharm was the support it offered for scientific computing, (Spyder short for Scientific Python Development Environment). The most commonly used support in Spyder is most likely the Variable explorer feature, where we have the option to inspect the value of the variables included in our program. The following screenshot demonstrates this Variable explorer feature of Spyder (please refer to this URL for more information: https://www.marsja.se/wp-content/uploads/2016/01/Spyder_variable_explorer.png):
However, this superiority Spyder had over PyCharm was only applicable until recently. PyCharm has been making some substantial improvements to its own support for scientific computing, and now it has deservedly become a serious contender to be the best scientific programming tool in Python with SciView and its other functionalities. If there is a good time to start using PyCharm for your scientific projects, then it is now!
One major difference between PyCharm and any other editor/IDE is, of course, the extensive support for complex aspects of programming from PyCharm such as version control with Git, testing and debugging, profiling, and so on. Again, the general strategy when it comes to these tasks is to first understand the foundational idea of each task and know how to do it manually before using PyCharm to automate and streamline that process. At that point, after using these support features, you will be able to appreciate the time and effort you are saving with the help of PyCharm.
Let's now take a step back and look at other editors and IDEs as well. Compared to other popular IDEs such as Visual Studio Code with the PTVS plugin (short for Python Tools for Visual Studio) or Eclipse with the PyDev plugin, PyCharm is better supported in terms of debugging and testing, web development frameworks, Jupyter Notebook and Anaconda, the real-time analysis of code, and refactoring options.
Another factor that convinces Python programmers to choose PyCharm over Visual Studio Code is its support for emulating Vim, the famous Unix text editor. Specifically, PyCharm offers a plugin that simulates the complete experience of using Vim for hardcore users. For anyone who is looking to leverage PyCharm's powerful features but still wants to keep the old Vim key bindings and interface, they can find the optimal solution with PyCharm.
Overall, the discussed features offered by PyCharm help it stand out from its competitors. While it is true that PyCharm will take up more memory space and appear uninviting to new programmers of the Python community, once you have mastered the general fundamentals of Python programming and familiarized yourself with different best practices, PyCharm will boost your productivity to another level.
I hope at this point you are somewhat convinced that PyCharm is a good IDE for Python programming. However, before heading to the website to download it, another topic that we need to discuss is the edition of PyCharm we will be using.
In this section, I will outline a number of the biggest differences between the two editions of PyCharm that are currently available and discuss the benefits of each edition with regard to different Python programmer subgroups.
Before you ask, yes, there are two editions of PyCharm—a free and a paid edition. The Community Edition is entirely free to download; in fact, as mentioned, JetBrains actually made the source code of the Community Edition available on GitHub in 2013.
The Professional Edition, on the other hand, has to be purchased; a license is then provided to you so that you can actually use it.
The Professional Edition can be purchased at $89.00 for the first year, with that price decreasing in the following years. However, there are ways that you can qualify for a discount, or a free license, for the Professional Edition:
- If you are a student, a teacher, or otherwise work in an educational setting, you are eligible for free licensing to install PyCharm (in fact, all JetBrains tools) on your system. This applies to faculty and staff of training courses, coding schools, boot camps, and developer recognition programs (for example, active Microsoft Most Valuable Professionals, ASPInsiders, Java Champions, Google Developers Experts, and so on).
- If you are working on an open source project, chances are you also qualify for a free distribution of PyCharm, Professional Edition. There are, however, several conditions regarding your open source project that need to be met.
- Former students, start-up employees, and non-profit organization members are also eligible for various forms of discount when purchasing the Professional Edition.
In the following subsection, we will be going into details regarding the additional features that the Professional Edition includes but the Community Edition does not.
In terms of the actual software differences between the two editions of PyCharm, all functionalities available in the Community Edition are included in the Professional Edition. Simply put, functionalities in the Community Edition are a subset of those in the Professional Edition.
Firstly, all the core functionalities of the GUI that puts PyCharm ahead of the competition of other editors/IDEs are fortunately available in both editions. These include the real-time code analyzer, graphical debugging features, refactoring and testing, version control, the management of packages, and virtual environments. The following screenshot shows the intelligent code analyzer (which, again, is available in both editions of PyCharm) performing a code-completion task:
Specifically, this analyzer looks at what you are typing in real time and displays a list of possible ways to complete that line of code. This can be a function/method call (similar to the previous example), variable names, or a specific syntax. This feature allows us to write code in a faster and more accurate way.
In terms of the materials covered in this book, some sections and chapters will focus on a number of features that are exclusive to the Professional Edition. Note that these chapters do not discuss only exclusive features, as there are still features available in both editions that are worth considering. For example, in section four of the book (where we focus on data science tools), the scientific mode of PyCharm and the SciView are only included in the Professional Edition, but the integration of IPython and Jupyter Notebook is applicable to both editions. In short, whichever edition you are using, it might be beneficial for you to go through all the topics that you are interested in, even if they are not supported by your Community Edition.
So which edition of PyCharm should you choose? You may have figured out by now whether you should purchase the Professional Edition (given that you do not already have it), or simply use the free Community Edition. This will mainly depend on your own Python projects and what functionalities those projects need.
Firstly, it is possible to take advantage of all the functionalities included in the Community edition of PyCharm, whatever your profession is and whatever your project's focus is on. After all, every project can benefit from the intelligent coding assisting features and various other support features in Community PyCharm.
So, whether you are a software engineer, web developer, or data scientist, Community PyCharm will undoubtedly improve your overall productivity anyway, especially if you are working on a significantly large project.
Additionally, if your web applications interact with a database in a complicated manner, Professional PyCharm can help you simplify the process with the integration of various features and the visualization of data relationships in databases.
For example, say you'd like to add some data to a project by connecting to an SQLite database; you can do that in a fairly straightforward way in Professional PyCharm, as illustrated in the following screenshot:
By the same token, if you are a data scientist working with a fairly complex stack, specifically, if your projects interact with a database, it might be beneficial to take advantage of the features of the Professional Edition. The integration of IPython and Jupyter Notebook might also be a great addition to your data science workflow, but these are web-based tools that are already well-supported by web browsers such as Google Chrome. Furthermore, if your whole pipeline is designed to revolve around the web-based interface of the software, it might be worth continuing using the bare-bones Jupyter platform without PyCharm's support.
Overall, the development work you do will dictate whether it is worth it for you to purchase the Professional Edition of PyCharm or not. A good strategy is to take advantage of the free 30-day trial of the Professional Edition to see if an upgrade from the Community Edition is worth purchasing.
In this chapter, we introduced the Python language itself, as well as the background behind Python IDEs in general, and specifically, PyCharm.
We also discussed the usability of PyCharm for Python programmers. Specifically, to be able to take full advantage of all the features and functionalities that PyCharm offers without becoming too dependent on the IDE, a programmer should first master the fundamentals of the Python language and its core syntax. We also looked at comparisons between PyCharm itself and various other Python editors/IDEs and the reason why PyCharm is considered the best development environment of them all.
Finally, we compared the two editions of PyCharm that are available for download: the paid Professional Edition and the free Community Edition. If you are working with large, complex projects with many moving parts (including database management, web development languages, and view-ability in scientific reports), then you will most likely benefit from using the Professional Edition.
In the next chapter, you will learn how to download PyCharm, set it up on your system, and configure its environment for your Python projects. This will serve as the first step in getting started with PyCharm, after which, we will start discussing the specific features PyCharm offers that this book covers.
- Programmers typically develop their code with an editor or an IDE. What is the difference between the two, and which one is PyCharm?
- Why do some think that an IDE for Python development might be inappropriate or unnecessary?
- What is the recommended strategy for using an IDE for Python development?
- What are some key features of PyCharm? Of those features, which give PyCharm an edge over other editors/IDEs?
- What are the two editions of PyCharm? What are the key differences between them?
- Who should use the Community Edition of PyCharm? Who should use the Professional Edition of PyCharm?
For more information, you can refer to the following literature:
- PyCharm, The Python IDE for Professional Developers, JetBrains s.r.o. (https://www.jetbrains.com/pycharm/)
- Text Editors vs IDEs for Python development: Selecting the Right Tool, by Jason Fruit, (https://www.pythoncentral.io/text-editors-vs-ides-for-python-development-selecting-the-right-tool/)
- Mastering PyCharm, Quazi Nafiul Islam, by Packt Publishing (https://www.packtpub.com/in/web-development/mastering-pycharm)
- Python Developers Survey 2017 Results, JetBrains s.r.o. (https://www.jetbrains.com/research/python-developers-survey-2017/)
- How does PyCharm match up against competing tools?, JetBrains s.r.o. (https://resources.jetbrains.com/storage/products/pycharm/docs/Comparisons_PyCharm.pdf)