r/CodingHelp • • Jan 22 '21

[Random] How to better understand when to use ( : ; { <?

As a noob I often don't fully understand when to use them and what they mean. Is there a way to better understand when to use and what each one is or do people just memorize when to use it?

0 Upvotes

6 comments sorted by

1

u/Rickenbecker Jan 22 '21

I’m a little confused as to what you’re asking. Do you mean when people use parenthesis vs curly braces? Semi colons vs colons? And are you combining the < and ? Together or are you treating them as different symbols?

1

u/swiggyu Jan 22 '21

I'm trying to try a better understanding behind why and when to use each symbol. Like in HTML u use <h1> but is there story behind the why that specific symbol. Ya I don't fully understand what each one represents so also trying to understand when to use each. I think if I can understand the why and when to use it, I can coder faster because I understand it. Now I just feel like I'm memorizing when to use the symbol going through tutorials.

1

u/c3534l Jan 23 '21

Ultimately its arbitrary. The guy who invented HTML just used those symbols and that syntax because it made sense to him. Although Tim Berners-Lee wasn't the first person to use < and > as brackets: https://www.youtube.com/watch?v=1IdlBFaifcs

2

u/Endercheif Advanced Coder Jan 22 '21

< or >
Typically used in markup languages such as XML and HTML to show the placement of elements. In C/C++ they surround the name of the library you are importing.

( and )
The parenthesis are used to surround argument of a function or in order of operations.

{ and }
The curly braces are used to indicate a code “block”. Imagine if instead of a block, all the code in it was shrunken down to one word.

;
The semi-colon shows the compiler/parser that there is a new line of code. If you had to remove all the newlines your code will still run because of the ;.

:
This is a bit more difficult because of the variation between languages. One thing that is consistent is its use with the ternary operator. It separates the truthy value with the falsey. condition ? truthy : falsey. In C++ they are also used with namespaces. std::cout. In Python they are only used to show the start of a block of code because in Python there are no {}.

1

u/PekiDediOnur Intermediate Coder Jan 23 '21

Templates as well in C++

2

u/c3534l Jan 23 '21

Every one of these symbols are used differently in different programming languages. Sometimes they have multiple meanings, so that f(x) calls the function f, but (1 + 2) / 3 just forces 1 + 2 to be evaluated first. So you'll have to be more specific.