undefined

What You Need to Know About Syntax vs Style

What is syntax?

Every language has rules for putting together words and phrases to create well-formed sentences. These rules are known as syntax. Some basic syntax rules in the English language that we’re taught from a young age seem like second nature to us, and might not even seem like syntax rules. Things like capitalizing the first letter of a new sentence or ending a question with a question mark (?) have been ingrained in our brains. Computer languages also have syntax rules for putting together commands and functions that are necessary.

Why is syntax so important?

We know students and even teachers get frustrated when a program doesn’t run because of a little misspelling, space in the wrong place, or a capital vs lowercase letter. The biggest reason is because in real life, aka outside of Karel and Tracy’s grid worlds, when programmers make those mistakes, their programs will not run.

We have a prime example of this happening to us at CodeHS. Here’s what one of our pages should have looked like:

undefined
Functioning CodeHS Web Page

However, due to one small error hidden in the rough, here is what the page looked like:

undefined
Broken CodeHS Web Page

What was the issue might you ask? It was not an Internet loading, Zoom slowing down your computer type of situation. It was {drumroll}… a syntax error. This page was broken (what we call an errored webpage) because there was a capital “D” on a line of code instead of a lowercase “d”.

undefined
Syntax error found

Syntax vs Style

There’s syntax, and then there’s style. John Kelly, CodeHS Tech Lead, says that “Style is something that is important for things like readability, collaboration, productivity, etc. It’s important for programmers on a team (and really even just a single programmer!) to have a consistent style, such as:

  • Use 2 spaces instead of 4 for indentation
  • Always put brackets on a new line instead of same line
  • Use camelcase naming convention instead of snake case…”

Style is important to ensure your code is readable. Having the correct indents and structure makes it so that any programmer can hop into your code and easily read, follow along and make contributions. At CodeHS, we have software engineers who all have their preferred programming language, and each language has different syntax rules and styles.

Being on an engineering team means you must have good syntax and especially style etiquette, otherwise it’ll be impossible to collaborate with your team and make a great product. Along with having readable, well structured code, comes productivity. If you can easily scan your code for potential errors, your productivity and ability to refine & improve your code will also greatly increase.

We at CodeHS understand and experience the same struggles of syntax errors throwing off our programs. Understanding and implementing good syntax is a cornerstone of becoming a great programmer.


Learn more about syntax errors and debugging student code.

Questions? Contact us at hello@codehs.com