Skip to content

Instantly share code, notes, and snippets.

@jpwspicer
Last active October 19, 2016 16:44
Show Gist options
  • Save jpwspicer/e0c577f4181bad9f215cb1cb9a2b05fd to your computer and use it in GitHub Desktop.
Save jpwspicer/e0c577f4181bad9f215cb1cb9a2b05fd to your computer and use it in GitHub Desktop.

The Essentials of Clearer Code

An increasing number of computer lanuages are making use of unicode symbols, offering the tantalizing possibility of elegant, easy-to-read code that's a pleasure, rather than a pain, for untrained humans to read and debug.

Contents

Problem

Consider the following equations:

Original Equations

In older languages such as Fortran, C, and C++, variable names were restricted to alphnumeric characters. The above equations would have been implemented like this:

Boring Code

Not very easy to see what's going on, seemingly unrelated to the original equations, and painstaking to debug.

However unicode-enabled languages such as Java, Python 3, C#, or Julia enable implementations such as this:

Pretty Code

This is significantly easier to read and so much closer to the original equations that even someone with no software background can easily read and debug the script.

Solution

To be user-friendly and legible, two things need to happen:

1. Enable Unicode fonts

If ♃ᵦ ω̃ ξ⃗ n̈₀ ∛Δ̇‴ shows up as ⍰⍰⍰⍰, your browser cannot handle the necessary Unicode characters.

It's no good typing beautiful scripts if you can't read them. All interfaces on which you view and edit code must use a unicode-enabled font.

First, pick a unicode-enabled, fixed-width font (I've listed a few here). Then change the default font in your browsers, shells, and text editors (instructions here).

2. Enable auto-completions

Typing unicode characters must become as straightforward as tpying alphanumeric characters otherwise no-one will bother. Auto-completions automatically correct typing nddot to .

Implementations vary depending on program and operating system, but I've collected a few ideas here.

That's it! By changing system fonts and using auto-completions, your scripts can be more user-friendly and efficient than ever before.

Appendices

1. Fixed-width font comparisons

Test letters:

Test Letters

  1. FreeMono

    • Windows
    FreeMono Windows
    • OSX
    FreeMono Mac
  2. Courier

    • Windows
    Courier Windows
    • OSX
    Courier Mac
  3. Courier New

    • Windows
    Courier New Windows
    • OSX
  4. Consolas

    • Windows
    Consolas Windows
    • OSX

2. Change default fixed-width fonts

  1. Browsers
    1. Most browsers will need to be restarted before the changes below will take effect.
    2. Chrome
    3. '⋮' → 'Settings' → 'Show advanced settings' → 'Customize fonts' → Change the default 'fixed-width font' setting.
    4. Firefox
    5. '≡' → 'Options' → 'Content' → 'Advanced' → Change the default 'Monospace' setting.
    6. Safari
    7. Save this file. Open it in a text editor and change 'Consolas' to the name of your desired fixed-width font, and save the changes. In Safari, go to 'Safari' → 'Preferences' → 'Advanced' → 'Style Sheet' → 'Other' → Select the .css file you just downloaded and altered.
    8. Internet Explorer
    9. '⚙' → 'Internet Options' → 'General' → 'Fonts' → Change the default 'Plain text font' setting.
  2. Shells
    1. OSX Terminal
    2. 'Terminal' → 'Preferences' → 'Profiles' → 'Font' → 'Change' → Change default 'family' setting.
    3. Windows Command Prompt
    4. Right-click on taskbar → 'Properties' → 'Font' → Change the default font setting. If the font you've installed is not visible, follow the instructions on this page.
    5. Linux Shell
    6. Same process as for Safari.

3. Auto-completion implementations

  1. Operating Systems
    1. OSX
    2. Windows
    3. Download AutoHotkey. Open command prompt and run shell:startup to open your startup folder. Save this autocomplete file to your startup folder. Double-click it to start it running right now.
  2. Text Editors
    1. Sublime Text
    2. Download and install this package. Instructions on page.
    3. Notepad++
    4. Vim
    5. Emacs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment