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.

learn more… | top users | synonyms

60
votes
18answers
17k views

Are `break` and `continue` bad programming practices?

My boss keeps mentioning nonchalantly that bad programmers use break and continue in loops. I use them all the time because they make sense; let me show you the inspiration: function verify(object) ...
24
votes
15answers
2k views

Is there a language out there in which parameters are placed inside method name?

in JavaScript: function getTopCustomersOfTheYear(howManyCustomers, whichYear) { // Some code here. } getTopCustomersOfTheYear(50, 2010); in C#: public List<Customer> ...
37
votes
14answers
6k views

Why is there still case sensitivity in some programming languages?

I don't see any use for case sensitivity in a programming language, apart from obfuscating code. Why implement this in a programming language? Update: It looks like someone you know made a ...
16
votes
12answers
1k views

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 ...
4
votes
6answers
2k views

Is there a language that transcompiles to C with a better syntax? [closed]

CoffeeScript is a language with a very clean Ruby-like syntax that transcompiles to JavaScript. Does the same thing exists with C? Then writing more readable and as fast as original C programs would ...
51
votes
12answers
23k views

What's the difference between syntax and semantics?

I've always thought that referring to the syntax of a language was the same as referring to the semantics of a language. But I've been informed that apparently that's not the case. What's the ...
102
votes
12answers
10k views

Why are statements in many programming languages terminated by semicolons?

Is there a reason that a semi-colon was chosen as a line terminator instead of a different symbol? I want to know the history behind this decision, and hope the answers will lead to insights that may ...
16
votes
9answers
1k views

Teaching kids to program - how to teach syntax? [closed]

I've been spending this week teaching kids (11-18) to program. Teaching them the core concepts and the logic has been going fine, but I've noticed one snagging point for them all: syntax. I feel like ...
14
votes
13answers
982 views

Are there any compilers that attempt to fix syntax errors on their own?

I heard a while back that there used to be a compiler that attempted to fix syntax errors by analyzing context and inferring what was intended. Does such a compiler really exist? Obviously it has ...
13
votes
8answers
2k views

Why do most programming languages not nest block comments?

A few do, but not any of the popular ones as far as I know. Is there something bad about nesting comments? I plan to have block comments nest in the (small) language I'm working on, but I would like ...
64
votes
3answers
21k views

Why do programming languages, especially C, use curly braces and not square ones?

The definition of "C-Style language" can practically be simplified down to "uses curly braces ({})." Why do we use that particular character (and why not something more reasonable, like [], which ...
78
votes
15answers
7k views

Why did memory-managed languages like Java, Javascript, and C# retain the `new` keyword?

The new keyword in languages like Java, Javascript, and C# creates a new instance of a class. This syntax seems to have been inherited from C++, where new is used specifically to allocate a new ...
31
votes
17answers
4k views

Does syntax really matter in a programming language?

One of my professors says "the syntax is the UI of a programming language", languages like Ruby have great readability and it's growing, but we see a lot of programmers productive with C\C++, so as ...
15
votes
10answers
3k views

'<' 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 ...
28
votes
2answers
8k views

Why is VB so popular? [closed]

To me, Visual Basic seems clumsy, ugly, error-prone, and difficult to read. I'll let others explain why. While VB.net has clearly been a huge leap forward for the language in terms of features, I ...
11
votes
22answers
1k views

Which useful alternative control structures do you know? [closed]

Similar question was closed on SO. Sometimes when we're programming, we find that some particular control structure would be very useful to us, but is not directly available in our programming ...
3
votes
5answers
925 views

Which programming languages doesn't use operator precedence besides Lisp like languages? [closed]

And what do you think about operator precedences? Would be harder programming in language where the operations are executed in sequential order? Ex.: 2 + 3 * 4 == 20 2 + (3 * 4) == 24 Ok, Lisp ...
9
votes
8answers
1k views

Rigorous Definition of Syntactic Sugar?

It seems like in language holy wars, people constantly denigrate any feature they don't find particularly useful as being "just syntactic sugar". The line between "real features" and "syntactic ...
11
votes
5answers
1k views

What's the idiomatic name for a throwaway variable? [closed]

Velocity Template Language's set directive requires a variable on the left hand side. This doesn't work. #set ( $entries.add("d") ) Even though I have no use for the return value of add("d"), I ...
10
votes
6answers
804 views

What do you think of this new if-then syntax [closed]

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() ...
6
votes
3answers
561 views

How useful are infix operators in a programming language?

How useful are infix operators in a programming language? Are they worth the extra complexity they provide? Can you provide any examples where infix operators are better suited to the problem that ...
1
vote
8answers
993 views

Do you use i-->0 for backward loops?

Some people write for (int i=N; i-->0; ) doSomething(i); instead of for (int i=N-1; i>=0; --i) doSomething(i); for backward loops. The --> "operator"1 looks very confusing at the first ...