Should students be using syntax highlighting?
A few months ago, someone asked a question on StackExchange, wondering if there is a research paper indicating whether syntax highlighting helps or slows down the learning process of future programmers. The question was closed and deleted, so here are my thoughts on the subject.
Is syntax highlighting helpful for any programmer?
Syntax highlighting is a convinient and effective tool which let you find errors in code soon. Actually, it's one of a few tools which find errors instantly, something even background compiling, for instance, is unable to do.
I can give you two examples to use as empirical evidence.
First example:
This piece of bash code contains a bug.
ln -s /var/a/b \
/etc/c/d
cp /var/demo/example \
/var/hello/world
This one doesn't.
ln -s /var/a/b \
/etc/c/d
cp /var/demo/example \
/var/hello/world
With default syntax highlighting provided by vim, the bug becomes obvious: why is the backslash displayed in white instead of red? This can't be right.
Second example:
This piece of JavaScript will fail:
var records = processing.generateRecords();
continue = canContinue(processing.getStatus());
if (continue) {
processRecords(records);
}
With syntax highlighting, the mistake becomes apparent: something is wrong with “continue” used as the name of the variable, and the word looks a lot like a reserved keyword.
Is syntax highlighting helpful for new learners?
This is a tough question, and I don't have any research in mind to support the answer. But here are a few points which can give you some ideas:
Some students will be able to become more proficient faster with the help of syntax highlighting, since they will avoid basic errors. Being stuck for hours with a bash script which doesn't copy a file for no apparent reason is a waste of time: instead, the student could be learning something useful...
...but some students may learn a precious lesson with a problem such as the bash illustration. The lesson here is that text editors should always be configured to display whitespace and newlines. I configured this option consistently in every IDE and text editor I was using to write code. Thanks to this practice, I successfully solved in a matter of seconds a few problems my colleagues where stuggling with for hours. Indeed, with special characters being displayed, it's much easier to see where the error is:
ln·-s·/var/a/b·\⤶ ······/etc/c/d⤶ cp·/var/demo/example·\·⤶ ···/var/hello/world⤶
Over-reliance on tools when learning how to program is not a good idea. A JavaScript programmer is expected to know that
continue
is a reserved keyword, and even if he doesn't know the exact list of 34 reserved keywords and future reserved keywords, he should chose the names of variables carefully, and try to avoid words which might be reserved, such asvirtual
(a reserved keyword in C#, but not in JavaScript)......but over-reliance on tools is not the worst weakness of a programmer: not knowing how to use popular tools (including an IDE) properly would be a more serious issue. Cases where a developer won't have a normal text editor are extremely rare, so I won't expect a programmer to be able to write a working JavaScript program using an MS-DOS terminal or a pen and a piece of napkin (although I've already written code on a napkin.)
Syntax highlighting is not substantially different from other tools which help finding errors: compilers, linters, static checkers. Should we force students to use none of them?
Back to research paper, I don't think it would be possible to make an experiment that shows that students using syntax highlighting learn better/less well. In order for the results to be meaningfull, the experiment should be performed:
On two large groups of students, one using syntax highlighting, the other not using it. Small groups won't achieve statistical significance, due to the large number of other factors which may increase a gap between the groups.
Over a long period of time, such as a year; exams would be the dependent variable. A short period won't permit to evaluate well the progress of each student.
In a way which guarantees that the syntax highlighting is the only independent variable. This means that both the control group and the experimental group should have the same teachers, the same timetable, etc.
Aside the fact that the dependent variable is not very effective, there is a larger problem: how do you force students from experimental group not to use syntax highlighting? If they talk with students from the control group (and they will, since they have the same timetable and the same teachers), they will necessarily use syntax highlighting sooner or later, and some will start using one at home.