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

20
votes
12answers
2k views

Is there a language offering LISP-like macros with a more complex syntax?

LISP's macros are extremely powerful constructs, and the inability to introspect and modify the program itself beyond the method signature level has always struck me as a limitation. Yet I favour ...
9
votes
14answers
2k views

How do you keep all those languages straight in your head

I know Java, C#, C++. I have used Perl, and am picking up Python and Actionscript 3. This is certainly a path others have trodden, so I am asking how do you keep all these languages straight in your ...
0
votes
7answers
358 views

Markup languages syntax

If computers are able to parse data organised in curly braces, why are we using <foo></foo> syntax in certain languages? Only because of legacy etc or are there further reasons behind ...
8
votes
2answers
3k views

Javascript Ternary Operator vs. ||

I was taking a look at some node.js code earlier, and I noticed that the guy who wrote it seemed to favour the following syntax: var fn = function (param) { var paramWithDefault = null == param ? ...
12
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 ...
3
votes
2answers
751 views

Why do more languages not support ===

I mean it as it is used in JavaScript. Just curious why this is not supported in more languages? Like Java for example does not have it? Seems to be a very useful operator to have.
4
votes
3answers
648 views

Best representation for relative dates & durations

I use ISO 8601 to represent dates & durations and all is OK. But now I need to represent relative dates and durations like: The date for first day, at midnight, of the next week All the last ...
5
votes
4answers
767 views

Shouldn't the lazy evaluation/execution be syntactically differentiated from eager evaluation/execution in C#?

We know about the deferred execution or lazy evaluation features introduced in C#. But at times, people become confused with them. Because there is no significant difference. You can only know if you ...
5
votes
6answers
3k views

Proper syntax formatting for SQL? [duplicate]

Is there are a widely accepted standard for formatting SQL queries? I've never been given any guidance as to the "typical" or "standard" way of doing it. I've seen three styles in the wild, and ...
1
vote
8answers
1k 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 ...
1
vote
5answers
180 views

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 ...
20
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 ...
6
votes
1answer
6k views

A combined if/switch statement syntax with exception handling for a C#-inspired language

It is sometimes necessary to try/catch exceptions inside the "if" condition, but not the body that follows. In C#, this is really rather cumbersome, requiring locals and code that isn't entirely ...
1
vote
4answers
220 views

Syntax extension in weakly typed lanuages?

I like languages that give me the ability to extend the syntax of the language. At the same time, all the languages that I know will let me extend the syntax have relatively heavy type systems. Are ...
4
votes
3answers
3k views

How do you think about using `//` for JSON comment? [closed]

I'm considering extending JSON by adding comment. For just my own project, internally. If JSON got a comment, I think its syntax should be //~\n style, JavaScript syntax. How do you think?
71
votes
19answers
26k 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) ...
10
votes
9answers
1k views

Should programming languages be strict or loose?

In Python and JavaScript, semi-colons are optional. In PHP, quotes around array-keys are optional ($_GET[key] vs $_GET['key']), although if you omit them it will first look for a constant by that ...
9
votes
1answer
1k views

I feel something uncomfortable with Haskell record syntax

Most of Haskell syntax has beauty of purity. But the record syntax looks ugly. It's uncomfortable. It feels some kind of mixture with C. It requires comma and braces. Haskell has tab,line based ...
85
votes
15answers
10k 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 ...
9
votes
10answers
2k views

How should I pronounce the :: and -> in PHP? [closed]

When I read these lines aloud to someone: $controller->process(); UserManager::getInstance(); How should the -> and :: be pronounced? Reading the characters themselves in cumbersome and I ...
6
votes
3answers
1k views

What are the most common programming mistakes PHP programmers make in Java?

I am more practiced in PHP than in Java, and when I use Java I find myself looking at it from a PHP perspective. This can cause trouble, so I'd like to know, what are the most common programming ...
10
votes
8answers
671 views

Is it possible to design a language that doesn't have syntax errors? [closed]

In other words, a language where every possible string is valid syntax? EDIT: This is a theoretical question. I have no interest in using such a language; I'm just asking whether it's possible.
18
votes
12answers
2k 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 ...
12
votes
12answers
1k views

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

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 ...
31
votes
17answers
5k 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 ...
12
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 ...
10
votes
6answers
827 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() ...
37
votes
14answers
7k 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 ...
4
votes
6answers
536 views

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 ...
8
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 ...
3
votes
5answers
1k 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 ...
6
votes
3answers
620 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 ...