Thursday, 7 November 2019

Syntax

Briefing
In this short entry, through a simple analogy with everyday language, you will understand the concept of syntax in terms of writing code.



What is syntax?
As a starting point and based on the Wikipedia definition, I've come up with this answer:

"Syntax is a set of rules, principles, and processes that govern the structure of a system."

Basically, syntax is analysis of a language structure.



Rules, principles and processes: what does it all mean?

Rules:
They are unchangeable: you can't bend them, you can't break them. It is what it is, period. If you follow the rules, the programme works; if you don't, it doesn't.


Principles:
There are two ways of interpreting this concept:
1. The foundations, the base structure. The core theory behind a programming language. They are highly abstract.
2. Think of a recipe or good practices. Good coders have developed better or more efficient ways of doing things. Those ways have become techniques that can be applied to different situations. You can use them or not.

Processes:
Well... It's the actual putting into practice of those rules and principles when you're coding.



What's programming, anyway?
Programming is just like "writing"... in fact, you "write" programmes pretty much the same way you write anything else.



What's the difference, then?
Easy, programming languages are not natural languages (English, Spanish...): they don't undergo natural processes of development in the same way human languages do.

Human language never stops developing and it's unpredictable. Programming languages are born a certain way and stay that way until a new version is developed and launched.

That's why you have versions tagged 2.0, 3.5 and so on. We don't have an English 2.6... so far.



Anything else?
Yep, in natural languages there are thousands of different operations you can perform, whereas in programming... well, for now, for us, when it comes to C# in Unity, you can only declare or instantiate something.

So, in natural languages you may doubt the veracity or the accuracy of a statement. It simply depends on the context because you can't know its real meaning beforehand — it requires further analysis. That's why we call it "proposition".

But you know how complicated the concept of "truth" can be in real life, right?



In computational programming languages, the concept of truth is binary and absolute. Something is true or not, period.

That's why we talk about "declarations" and "assertions" instead of "propositions". Got it?



⇠⇡⇣⇢⇠⇡⇣⇢⇠⇡⇣⇢⇠⇡⇣⇢⇠⇡⇣⇢⇠⇡⇣⇢⇠⇡⇣⇢⇠⇡⇣⇢⇠⇡⇣⇢⇠⇡⇣⇢⇠⇡⇣⇢⇠⇡⇣⇢⇠⇡⇣⇢⇠⇡⇣⇢⇠⇡⇣⇢


Applying what we've seen so far

Given the sentence:

"I am writing a Blog."


Rules: The rules say that, in a well written English sentence, I need a subject, a verb and, in this case, an object. They also establish that a sentence starts with a capital letter and ends with a full stop.

Principles: can be interpreted in two ways:
1. As theory. We should know tenses, semantics (the meaning of words) and some basic grammar to understand that "I" is the one doing the action and "a Blog" is an object.
2. As practice. We could have just written "by writing this, I declare that I am writing a Blog". That means that, in practice, there are many ways of conveying the same (or similar) meaning.
Process: The actual situation of a person (me) at the computer hitting the keys on the keyboard... thinking and choosing the format, the medium and all the words you are reading.



The same thing applies to programming.

There are rules, there are principles and a process I'm following to write something like this:

public class NameOfTheClass ()
{

}



What does that mean?

Well, we are not going to dwell on the meaning of what that actually means in terms of coding. For now, we can bet that, if it is a piece of code, it surely is based on rules and principles.

That's about it for our short tutorial about syntax, but once you learn about methods and classes, you will thoroughly understand the analogy between coding and writing a simple sentence in, say, English... or any other language.



Where to go from here?
You can go and find out what a method and a class is in the "Method and class" entry on this Blog.



Paraphrasing what Captain D says: Develop games with your heart, use your brain for everything else.
x

No comments:

Post a Comment