Programmersʼ editors #
For this class, consider using a programmersʼ text editor, a text editor with added features tuned to make programming easier. Syntax highlighting, linting, autocompletion, git integration, and even real-time collaboration are just a few of the features that these text editors have to offer. While there is a learning curve – as with everything – these options can make your coding process quicker and more pleasant. We describe how to install, configure, and use two text editors popular with CS51 students: VSCode and Sublime Text. (Many thanks to Karina Halevy for instructions for VSCode and Rebecca Cremona for instructions and advice on configuring Sublime Text.)
Visual Studio Code #
We highly recommend using Visual Studio Code for CS51. It has live collaborative editing capabilities and good support for OCaml as well. See below for instructions on how to install and use it.
Download and unzip Visual Studio Code from https://code.visualstudio.com/.
Unzip the downloaded file (if your computer hasn’t done so automatically) and drag the unzipped app into your Applications folder.
On the leftmost sidebar, click the fifth icon from the top (it should look like a grid of four squares with the top right square floating away). This should open up a menu called “Extensions” on the second-from-left sidebar. On this sidebar, search for and install “Live Share”. Follow the instructions on the Live Share extension’s Details page to install it correctly. In short, you should see the words “Live Share” in the bottom left corner of your VS Code application window (right below the gear icon) when the installation has been completed.
For OCaml support, search for and install “OCaml and Reason IDE” as well.
To open up a lab, problem set, or project hosted on GitHub (as you’ll need to do throughout this course), click on “Source Control” on the leftmost sidebar - it’s the third button from the top of that sidebar, and it’s shaped like a couple of branches.
To open up a repository, either select “Open Folder” and open up the local copy of the lab/problem set/project repo you’ve already cloned from GitHub or “Clone Repository” and paste in the URL of your copy of the repository (not the CS51 template copy, but your Github classroom copy, which should have your GitHub username somewhere in its name).
You should now be able to open up any relevant files from the second-to-left sidebar.
To run files and code, click View -> Terminal from the top menu (top of your computer, not part of application window) to pull up an integrated terminal. It should initialize the working directory to the top level of your repository.
For more information on Visual Studio Code’s support for live collaborating, see A guide to pair programming.
Sublime Text 3 #
You can install Sublime Text (which has a free evaluation version) from its website at https://www.sublimetext.com.
After downloading Sublime, begin by installing the package manager. This will allow you to install any other package you need. You can follow the instructions here.
After the package manager installs, restart Sublime. Now, you can install any package you want! To do so, go to ‘‘Tools’’ in the main menu and select ‘‘Command Palette’’, and then select ‘‘Package Manager: Install Package’’. From there, you can search or enter the package you want to install, and Sublime will automatically do it for you.
Some packages CS51 TFs recommend:
SideBarEnhancements — This package provides enhancements to sidebar operations, by allowing you to do more by right-clicking files on the sidebar (for example, delete, cut, copy, etc.)
GitGutter — This package will add subtle icons to the left side of your files so every time you hit ‘‘save’’, you can see what change you’ve made since your last ‘‘git commit’’. This makes it really easy to spot certain mistakes, and also helps remind you to commit, since you can see your changes building up.
Merlin — This adds OCaml-related fanciness. In particular: when you save your file, it looks for OCaml syntax errors and type problems. If you have a mistake, it puts a black dot next to the line with the problem, and makes detailed information on the error available via an error list.
First, install ‘‘merlin’’ by running in your terminal
% opam install merlin
Now, use Package Manager: Install Package to install ‘‘Merlin’’
Lastly, to make sure that it works regardless of how you launch Sublime, run in your terminal
% which ocamlmerlin
and copy the path that you get. Then, in the preferences menu -> Package Settings -> Merlin -> Settings - User, paste in the following, replacing ‘‘my_path’’ with the path that you copied:
{ "ocamlmerlin_path": "my_path" }
SublimeREPL — This will allow you to execute OCaml code directly from Sublime without having to copy/paste into an OCaml toplevel.
Better OCaml — An improved version of the default OCaml package, giving better highlighting for certain OCaml code. Follow the instructions on the README to set it up.
Of course, this is a small set of all the packages that are available on Sublime. You do not need to install all or any of the packages above, and should feel free to explore and experiment with whatever you think would be helpful for your coding benefit.
The next important thing to do is to tweak your settings. On the main menu, go to Preferences and select Settings. Now, add the following to the ‘‘User’’ file (not the one that says ‘‘Default’’):
{
"ensure_newline_at_eof_on_save": true,
"rulers":
[
80
],
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true
}
With these settings, Sublime Text will draw a line at the 80 character column in your editor to help you with line lengths. The settings also provide good defaults for managing whitespace in your code. Feel free to play around with the settings and see what you like.
Others #
You might not like any of the options we presented, you might have a
favorite editor already, or maybe Sublime and VSCode aren’t your
style. Some other text editors that have special support for OCaml
programming (through merlin
) include:
- Vim
- Emacs