Example Code
In these tips and tricks I try to provide most examples with code written in Java and Python demonstrating the topic in a trivial way. There are a select few examples that have sample code written in C/C++, but those cases are for very niche topics – so one may argue the choice of language can play a part in the overall outcome.
I truly believe one of the best ways to learn something new is to take something that works, break it, then figure out a way to make it work again. Because of this philosophy, each example will be complete in that compiling and running the sample code should produce non-erroneous output – assuming you have a proper development environment set up for the language. This does make the example code a bit lengthy, and does add extra fluff like import statements, but I believe it should be easy for you to have a play with the code. Change it, break it, fix it. If nothing else, question it.
To make things even easier, all of the example code is supplied in a few Gitlab projects with README files that detail how to set up the project and run the sample code. These Gitlab links have also been included in the "Space Shortcuts" on the left.
"go easy-cpp" "go easy-java" "go easy-python"
I also try to avoid as much as possible the requirement of third-party libraries. However, for certain tips and tricks it may be required that you have a working development environment to import such a library. With regards to Java, the Gradle build.gradle script defines all extraneous libraries. Running any Gradle build command should pull down the necessary dependencies assuming Gradle was configured with a custom mirror. With regards to Python, I supplied a simple setup.py script that will install the dependencies for you via pip3.
Language Requirements
For the most accurate documentation, each project's README.md file documents the exact development environment required to run the sample code. But generally speaking:
-
The C/C++ project depends on CMake version 3.5 or above on your
$PATH
. -
The Java project requires a JDK version 11 pointed to by your
$JAVA_HOME
variable. In addition, the Java project uses Gradle as the build and dependency management system. You will need a version of Gradle version 2 or version 4 (but preferably something recent) on your$PATH
. -
The Python project requires python3 and pip3 on your
$PATH
. This project also supplies a setup.py script to make Python dependency management even easier. When you pull down the repository, make sure to run the script to enable any third-party dependencies the same code requires.
Language Choices
In all of the ESE example code projects I have decided to use relatively recent versions of their respective languages. It is very possible to port the examples to older versions, however I would rather focus on the concept each tip/trick is trying to convey rather than the implementation of a particular example. In my opinion, any new code should be written against a recent but stable language version. However there are valid use-cases that absolutely require previous versions, and so I leave it up to the reader to back-port any examples they may find useful in the older standards. I do not perceive that as a challenging exercise, but if you do run into particularly difficult issues I am more than willing to help resolve any back-porting you may endeavor.
C/C++
In many topics the Java and Python example code will suffice. There are however a few niche topics where one may argue the choice in language is important, and getting as "close to bare metal as possible is required." I do not believe that argument holds up in many cases that it is used, so I do have a few topics that dispel that myth with actual C/C++ examples.
Suffice it to say, the C/C++ project will not get very large as it will only have code from very niche topics.
Java
The Java example code provided in ESE was written with a Java 11 development kit. It is possible to tweak the code to support earlier versions of Java, however I decided to stick with this version of Java since it provides developers with more features and utilities to make many examples shorter and more concise. And with Java's fast release cycle, the minimum version of Java required to run the examples will periodically be upgraded.
Also, Java is typically used in Object-Oriented (OO) projects. Since I will make example code short and concise the Java code may not use many OO design principles as that would add extra noise to what I'm trying to get across. In many cases I will choose to convey a particular topic with simple methods and functions than an OO design.
Python 3
The Python example code in ESE was written with a Python 3 interpreter. The main reason why I chose to provide examples in Python 3 was because Python 2 is no longer in active development. Python 2.6 was the last version to genuinely have new features, and Python 2.7 was created as an interim version that back-ported several Python 3 features to Python 2. The idea was that Python 2.7 will help ease the pain when converting a project from Python 2 to 3. I should not even have to say this, but unfortunately there are still many Python 2-only projects running around. Hopefully ESE puts pressure on them to upgrade their compatibility with Python 3.
Lastly, there are multiple implementations of Python that are generally compatible with one another. CPython and Jython are among two industry standard implementations. CPython is the official implementation with the interpreter written in C, while Jython is another popular Python implementation but the interpreter is written in Java. In many cases, it might not matter which implementation you are using, but it is very important to know the strengths and limitations of the interpreter you decide to use because your application or script may genuinely behave differently between the two. The examples and descriptions provided in ESE were tested with CPython.