Questions tagged [syntax]

Syntax refers to the set of rules that define how to write a correctly structured program in a language. It explicitly does not deal with the program's meaning or interpretation.

The syntax of a programming language is the set of rules that define the combinations of symbols that are considered to be correctly structured programs in that language. The syntax of a language defines its surface form. Text-based programming languages are based on sequences of characters, while visual programming languages are based on the spatial layout and connections between symbols (which may be textual or graphical).

The syntax of a language describes the form of a valid program, but does not provide any information about the meaning of the program or the results of executing that program. The meaning given to a combination of symbols is handled by semantics (either formal or hard-coded in a reference implementation). Not all syntactically correct programs are semantically correct.

From Wikipedia

195 questions
39
votes
9 answers

'<' versus '!=' as condition in a 'for' loop?

Say you have the following forloop*: for (int i = 0; i < 10; ++i) { // ... } which it could commonly also be written as: for (int i = 0; i != 10; ++i) { // ... } The end results are the same, so are there any real arguments for using one…
gablin
  • 17,407
22
votes
12 answers

Would you see any use of a Trilean (True, False, ??)

Sometimes I have a function that should return true or false. But sometimes three possible values would make more sense. In some language theses cases would be handled with integers or with exceptions. For exemple you want to handle the age of a…
11
votes
6 answers

What do you think of this new if-then syntax

I was just thinking of something that would be really cool to have in my if-elif-else controls. if condition: stuff() elif condition: otherstuff() then: stuff_that_applies_to_both() else: stuff_that_doesnt_aply_to_either() So…
Falmarri
  • 297
4
votes
6 answers

Logical Operators

A typical curly brace programming lang has two types of AND and OR: logical and bitwise. && and || for logical ops and & and | for bitwise ops. Logical ops are more commonly used than bitwise ops, why logical ops are longer to type? Do you think…
Ming-Tang
  • 856
4
votes
3 answers

Syntactic sugar regarding function parameters

Are there any modern programming languages where you don't have to specify types for each parameter in a function's definition? Ex: procedure P(a, b, c, d: integer) vs void P(int a, int b, int c, int d) Is there a good reason why the latter form…
3
votes
2 answers

foreach over multiple lists at once

Are there any languages that support foreach over multiple lists at once? Something like this: foreach (string a in names, string b in places, string c in colors) { // do stuff with a, b, c } Sure, this can be done with a regular for…
Joe
  • 388
  • 1
  • 4
  • 13
1
vote
5 answers

When should you move the post-statement of a 'for' loop inside the actual loop?

With a for loop you can move the post-statement empty and move it to the bottom of the code in the loop: for (int i = 0; i < 10; /* empty */ ) { //... ++i; } But in this case it doesn't gain you anything; more importantly it makes the code…
gablin
  • 17,407
1
vote
5 answers

Why are programming instructions 'verb-initial'?

In all programming languages, every command is sorted as command-arguments. For instance, in pygame, the command to draw a rectangle to the screen is: pygame.draw.rect(surface,color,rect) This seems rather odd to me thinking about it. Wouldn't a…
user8600
  • 159
  • 1
0
votes
7 answers

Markup languages syntax

If computers are able to parse data organised in curly braces, why are we using syntax in certain languages? Only because of legacy etc or are there further reasons behind this? I think I speak for many people if I say that that looks…
deprecated
  • 3,297
0
votes
1 answer

What is the difference between saying something like root->data and root.data?

As the title states, what is the difference between -> and . I thought they were the same thing?
johnson
  • 109
0
votes
2 answers

Is the word 'statement' in 'statement block' redundant?

Is the word 'statement' in 'statement block' redundant? In other words is a block in a program composed, by definition, of statements?
52d6c6af
  • 730
0
votes
2 answers

What Does "The Program Must Process Each Character Before Reading the Next One" Mean?

From the book Think Like a Programmer (emphasis mine) The Luhn formula is a widely used system for validating identification numbers. Using the original number, double the value of every other digit. Then add the values of the individual digits…
Levi Hackwith
  • 843
  • 1
  • 7
  • 13