DEV Community

Si for CodeTips

Posted on • Originally published at codetips.co.uk on

4 1

What is syntax?

Syntax to programming is what grammar is to languages.

What is syntax?

This article is written in English. In order to be grammatically correct, there is a set of structural rules I have to follow.

  • I, shouldn't, put, a, comma, after, every, word, and, declare, my, sentence, grammatically, correct.
  • .I shouldn't start my paragraph with a full stop.
  • Its a grammatical error to omit the apostrophe in "it's" when the meaning is "it is".

The three above bullets are all poorly written, grammatically.

Syntax is exactly this, for programming languages. Each programming language has a defined syntax, which advises its users (developers) how to write code in the language.

The difference is if you make a grammatical error, the reader may not fully understand your message, but they could probably make an educated guess and move on.

If you make a syntactical error, your computer will not understand what you're trying to do and will crash. Computers purposefully don't try to guess what the user means and will crash to avoid unforeseen side effects.

Examples

If you've followed these articles, you should already know what a variable is. Each language specifies the Syntax of how to write a variable.

Javascript

var x = "Hello World"
Enter fullscreen mode Exit fullscreen mode

Go

x := "Hello World"
Enter fullscreen mode Exit fullscreen mode

Python

x = "Hello World"
Enter fullscreen mode Exit fullscreen mode

All three code snippets do exactly the same thing - they define a variable (x) and set the value to the string Hello World.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay