Okay. This was a pain in the butt. But it was worth it.
The reason I'm so comfortable with Python is that you don't have to explicitly compile it to understand how code behaves. You can write functions and immediately play around with them to understand how they behave. It makes developing and learning iterative procedures of trial and error, and it makes the language very approachable.
I've never been able to do this with C++ before, and consequently I'm far less comfortable with C++. C++ is a compiled language, so you have to write the entire program, compile it, and then run it as an executable to see what it does. It adds time and effort and possible errors/frustration between writing the code and understanding how it behaves. But C++ has some very nice libraries for a variety of tasks and it's often much faster than Python. More importantly, it's possible to extend Python functions with C++ functions, so facility with C++ can supplement the life mostly Pythonic. Now, for many tasks you can bring Python very close to C-like speed with the clever use of Numpy, but this can be challenging and sometimes just not possible. Fortunately, the physicists at CERN didn't just give us the World Wide Web, they more recently developed an interpreted C++, Cling. And it's available in Jupyter as the Xeus-Cling kernel.
I tried the Windows installer, but Xeus-cling doesn't actually support Windows yet. It half-worked, but it didn't handle output properly. Because I have Windows 10, what I ended up doing is installing it on my Windows Subsystem for Linux. In principle, that should've been super easy, but Conda kept hanging when it tried to download the larger dependencies.
In my WSL terminal:
conda create -n cling
source activate cling
conda install xeus-cling notebook jupyterlab -c QuantStack -c conda-forge
The last command I had to run many many times, due to the aforementioned hanging. Finally, disproving Einstein's supposed definition of insanity--"doing the same thing over and over again and expecting a different result"--in the common case that there's some unobserved variable determining success versus failure, it installed. After exiting and restarting the terminal, I can do this:
#include <iostream>
using namespace std
Look! I did something wrong and found out immediately. Bully for interpreters!
#include <iostream>
using namespace std;
Let's be traditional:
cout<<"Hello world";
int x=3;
cout<<x;
Just some notes on running this on the WSL. The WSL is not designed to run GUIs (Graphical User Interfaces) but Jupyter Lab is run in a web browser. One option is to follow this guide and run Firefox/Chrome in the WSL with an X-server. This is far less complicated than it sounds. First, you add a line at the end of the .bashrc file, to set it up processing graphics. Then you turn on the X-server--I opened up MobaxTerm and just clicked the "Start X-server" function. Restart the terminal, install a browser, and run Jupyter Lab.
The problem with this is that WSL is still not designed for GUIs. So while it will run, it ends up looking like you're running it on your grandfather's Windows 3.1 machine back in the early 1990s. And this is pretty distracting. And it gives me flashbacks of 8-year-old-Me's early attempts to write computer games on my grandfather's PC by creating new files, naming them evocatively, and then wondering why nothing happened when I opened them.
My work-around is to simply copy the link Jupyter Lab provides when it starts, into my normal browser running on Windows. So Jupyter Lab runs on the Linux Subsystem but I use Firefox running on Windows as my interface.
As I mentioned, I've never been able to do this with C++ before. But now I can and it feels the opening of doors.