Should students be using syntax highlighting?

Arseni Mourzenko
Founder and lead developer
August 18, 2015
Tags: short 48 quality 29

A few months ago, some­one asked a ques­tion on Stack­Ex­change, won­der­ing if there is a re­search pa­per in­di­cat­ing whether syn­tax high­light­ing helps or slows down the learn­ing process of fu­ture pro­gram­mers. The ques­tion was closed and delet­ed, so here are my thoughts on the sub­ject.

Is syn­tax high­light­ing help­ful for any pro­gram­mer?

Syn­tax high­light­ing is a con­vinient and ef­fec­tive tool which let you find er­rors in code soon. Ac­tu­al­ly, it's one of a few tools which find er­rors in­stant­ly, some­thing even back­ground com­pil­ing, for in­stance, is un­able to do.

I can give you two ex­am­ples to use as em­pir­i­cal ev­i­dence.

First ex­am­ple:

This piece of bash code con­tains a bug.

ln -s /var/a/b \
cp /var/demo/example \ 

This one doesn't.

ln -s /var/a/b \
cp /var/demo/example \

With de­fault syn­tax high­light­ing pro­vid­ed by vim, the bug be­comes ob­vi­ous: why is the back­slash dis­played in white in­stead of red? This can't be right.

Sec­ond ex­am­ple:

This piece of JavaScript will fail:

var records = processing.generateRecords();
    continue = canContinue(processing.getStatus());
if (continue) {

With syn­tax high­light­ing, the mis­take be­comes ap­par­ent: some­thing is wrong with “con­tin­ue” used as the name of the vari­able, and the word looks a lot like a re­served key­word.

Is syn­tax high­light­ing help­ful for new learn­ers?

This is a tough ques­tion, and I don't have any re­search in mind to sup­port the an­swer. But here are a few points which can give you some ideas:

  1. Some stu­dents will be able to be­come more pro­fi­cient faster with the help of syn­tax high­light­ing, since they will avoid ba­sic er­rors. Be­ing stuck for hours with a bash script which doesn't copy a file for no ap­par­ent rea­son is a waste of time: in­stead, the stu­dent could be learn­ing some­thing use­ful...

  2. ...but some stu­dents may learn a pre­cious les­son with a prob­lem such as the bash il­lus­tra­tion. The les­son here is that text ed­i­tors should al­ways be con­fig­ured to dis­play white­space and new­lines. I con­fig­ured this op­tion con­sis­tent­ly in every IDE and text ed­i­tor I was us­ing to write code. Thanks to this prac­tice, I suc­cess­ful­ly solved in a mat­ter of sec­onds a few prob­lems my col­leagues where stug­gling with for hours. In­deed, with spe­cial char­ac­ters be­ing dis­played, it's much eas­i­er to see where the er­ror is:

  3. Over-re­liance on tools when learn­ing how to pro­gram is not a good idea. A JavaScript pro­gram­mer is ex­pect­ed to know that continue is a re­served key­word, and even if he doesn't know the ex­act list of 34 re­served key­words and fu­ture re­served key­words, he should chose the names of vari­ables care­ful­ly, and try to avoid words which might be re­served, such as virtual (a re­served key­word in C#, but not in JavaScript)...

  4. ...but over-re­liance on tools is not the worst weak­ness of a pro­gram­mer: not know­ing how to use pop­u­lar tools (in­clud­ing an IDE) prop­er­ly would be a more se­ri­ous is­sue. Cas­es where a de­vel­op­er won't have a nor­mal text ed­i­tor are ex­treme­ly rare, so I won't ex­pect a pro­gram­mer to be able to write a work­ing JavaScript pro­gram us­ing an MS-DOS ter­mi­nal or a pen and a piece of nap­kin (al­though I've al­ready writ­ten code on a nap­kin.)

Syn­tax high­light­ing is not sub­stan­tial­ly dif­fer­ent from oth­er tools which help find­ing er­rors: com­pil­ers, lin­ters, sta­t­ic check­ers. Should we force stu­dents to use none of them?

Back to re­search pa­per, I don't think it would be pos­si­ble to make an ex­per­i­ment that shows that stu­dents us­ing syn­tax high­light­ing learn bet­ter/less well. In or­der for the re­sults to be mean­ing­full, the ex­per­i­ment should be per­formed:

Aside the fact that the de­pen­dent vari­able is not very ef­fec­tive, there is a larg­er prob­lem: how do you force stu­dents from ex­per­i­men­tal group not to use syn­tax high­light­ing? If they talk with stu­dents from the con­trol group (and they will, since they have the same timetable and the same teach­ers), they will nec­es­sar­i­ly use syn­tax high­light­ing soon­er or lat­er, and some will start us­ing one at home.