This article introduces the pros and cons of popular programming languages' libraries and functionalities.

In the previous articles, we have looked at different aspects of languages to help decide which one is most appropriate for your project. In this article, we will look at libraries and functionalities of different languages.

Catch up on the rest of the programming languages series here:

The Basics are Never Enough

Most languages will have some minimum level of functionality that may include objects, basic mathematical operators, inputs, and outputs. 

However, the basics that a language inherently contains are typically not enough for even the simplest program, which is why external libraries are used. To understand what we mean here, let us have a look at a basic example in C++. If you attempt to compile the following code, you will get an error because the statement “cout” and “endl” have not been defined and thus not recognized by the compiler.

For a C++ program to be able to print text to a console window, it needs to import a library that tells C++ how to do that. In the case of most operating systems this is done by importing IOSTREAM and then using the standard namespace as shown below.

This use of libraries is not limited to printing text and getting user input. Libraries are used for essentially everything, so when choosing a language, you may need to consider what libraries are available and how easy they are to use.

C and C++ Libraries

Many libraries are available for C and C++ including file operations, socket connections, serial ports, OS operations, hardware interaction, and mathematical operations. 

On the whole, the libraries are not too difficult to use, but due to the nature of C and C++ they usually require a number of parameters to configure correctly. However, as time progresses and technology advances, these languages are slowly being left behind in favor of more common languages like Java and Python. 

One advantage of libraries in C and C++ is the default libraries included with most compilers are usually platform-independent unless specific OS API calls are made. 

One massive disadvantage of libraries with C and C++ is that they can be a real pain to use if they are not part of the compiler by default. This is due to the fact that linker commands have to be included, paths need to be defined, and the compiler may not like the external library. On top of that, the program may not work unless an external library file is packaged with the program. 

Overall, library support is okay in C and C++ if those libraries come with the compiler. Otherwise, you may run into many problems if you are not an experienced programmer who understands how the C compiler works.

Java Library

Since Java is a very popular language for creating apps with an emphasis on platform independence, there are an incredible number of libraries. 

While Java comes with a decent number of libraries, there are many extra libraries available online (often for free). And unlike C/C++, external Java libraries are incredibly easy to add to projects (especially if you use an IDE like eclipse). 

Once a library has been added to the project (done by looking for the library .jar file), the library is loaded into code using an import instruction and from there the library can be used. Despite Java code being executed on a virtual machine, the user still has access to features including sockets and hardware such as serial ports, which means that microcontroller projects can, in theory, be used with a Java App. 

Python Library

Python is arguably the most user-friendly language when it comes to libraries. Python does not come with PIP by default, but once installed, most Python libraries can be installed using a command line. While that may sound difficult, you will be shocked at how simple it is to find a library and then add it to Python. 

The best way to see the simplicity is to look at PyGame as an example. Let’s say that you want to make a simple 2D game in Python. You will want the PyGame library, as it provides user keyboard input and graphical routines. To install PyGame (in Windows), you load command prompt and then enter the following command:

Then PIP automatically finds the library online, downloads the library, installs the library, and then configures it. That's it! From that point on, any Python application on your computer can use the library by simply importing PyGame by using the following instruction:

There are, however, a few disadvantages of Python libraries. The first main issue is that any computer that is going to run a Python application that was made on a different machine will also need the libraries. This means that the end user will have to install all the libraries, which should be automated by using an installer program. 

The second issue is that some Python libraries, such as PyGame, are not that platform independent and struggle to work on other computers. PyAudio, for example, is incredibly difficult to install on a Raspberry Pi, and to this day I still cannot get it to work! 

However, Python has many modern libraries, such as speech recognition and AI, that are very simple and easy to use.

VB.net and C#

VB.net and C# have massive libraries and functionality thanks to the .net framework, which is found on Windows machines. Such functionality includes graphical routines, security and encryption, hardware access, and networking. Using these libraries is also incredibly easy, and in just a few lines of code you can have access to just about every service the OS can offer. 

However, the .net framework is not cross-platform, and alternatives such as Mono do not fully support all functions that the .net framework offer. If your project will only use Windows devices, it is highly recommended that you use Visual Studio simply because of the little time needed to create a content-rich application.

Conclusion

Overall, all major languages contain many libraries and are very rich in functionality. If you need to be able to control many aspects of a library then a language such as C++ might be suitable, but if you are constrained for time, a language like Python will be better suited. Java is one of those languages that is very useful if you need platform independence but don’t want the end user to have to download libraries to make the program work. 

To summarize...

  • C++ contains many libraries and is super fast, but as time progresses it may become less targeted by library creators.
  • Java contains many libraries and can package them easily when distributed to users.
  • Python has many complex libraries available, which are easy to use, but some may be problematic to install on other platforms. However, Python also has the PIP installer (optional), which makes library installation a breeze.
Robin Mitchell
Graduated from the University Of Warwick in Electronics with a BEng 2:1 and currently runs MitchElectronics.

Categories


Maker Pro Logo
Continue to site
Quote of the day

-