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

58
votes
6answers
4k views

Why the Select is before the From in a SQL Query? [closed]

This is something that bothered me a lot at school. 5 years ago, when I learned SQL, I always wondered why we specify first the fields we want and then where we want them from. According to my idea, ...
7
votes
3answers
901 views

Is there a reason to prefer lambda syntax even if there is only one parameter?

List.ForEach(Console.WriteLine); List.ForEach(s => Console.WriteLine(s)); To me, the difference is purely cosmetic, but are there any subtle reasons why one might be preferred over the other?
1
vote
2answers
349 views

Does syntax matters for a (Lispy) Domain Specific Language (MELT, inside GCC)?

I am the main author and designer of MELT, a domain specific language to extend GCC (the Gnu Compiler Collection). The implementation is available free software (GPLv3 licensed). If you want a ...
12
votes
5answers
830 views

Does the syntax of programming languages depend upon their implementation?

Although, my question may be entirely irrelevant, but I have sensed a pattern between most programming languages and their official implementations. Interpreted (byte-interpreted?) languages like ...
9
votes
2answers
6k views

Why do PHP variables need to be preceded with a dollar sign?

I understand that all PHP variables need to be preceded by a dollar sign (e.g. $someValue = 1), but why is this the case? Why was this design choice made? The reason I ask is my girlfriend asked why ...
16
votes
6answers
9k views

Why pointer symbol and multiplication sign are same in C/C++? [duplicate]

I am writing a limited C/C++ code parser. Now, multiplication and pointer signs give me really a tough time, as both are same. For example, int main () { int foo(X * p); // forward declaration ...
0
votes
2answers
213 views

Naming Rules: Standards, Reserved, and what do they depend on? [closed]

I want to know the rules of naming (AlwaysCapitalize, _underscore, firstSmallLetter, etc...) for each of Namespaces, Classes, Interfaces, Exceptions, Data Members, Methods, Variables, etc.... also I ...
11
votes
5answers
2k 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 ...
3
votes
1answer
2k views

What's the point of initializing a variable with the same value twice? [closed]

I was reading Ben Cherry's "JavaScript Module Pattern: In-Depth", and he had some example code that I didn't quite understand. Under the Cross-File Private State heading, there is some example code ...
3
votes
6answers
488 views

Is there a language that allows this syntax: add(elements)at(index); [duplicate]

Possible Duplicate: Is there a language out there in which parameters are placed inside method name? Does a language exist with such a syntax? If not, what are some of the limitations/...
7
votes
5answers
4k views

Why was the C syntax for arrays, pointers, and functions designed this way?

After having seen (and asked!) so many questions similar to What does int (*f)(int (*a)[5]) mean in C? and even seeing that they'd made a program to help people understand the C syntax, I can'...
9
votes
3answers
7k views

Whats the difference between syntax and grammar?

I understand the difference between syntax and semantics - syntax - how the symbols are combined to form a valid expression or statement. semantics - the meaning of those symbols that form an ...
0
votes
5answers
274 views

ternary or something similar for choosing function?

I posted this question on stackoverflow and it got a poor reception. In reality, the problems I'm facing are minor and any workaround can be considered impractical. However, I believe it might be of ...
67
votes
12answers
72k 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 ...
5
votes
7answers
708 views

Are operators just “special” methods? [closed]

Here's what is meant by operators and methods. Attempting to keep the questions as simple and open ended as possible, since the question is more about the conceptual nature of operators and methods ...
28
votes
15answers
2k views

I'm writing about language syntax. 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> ...
8
votes
4answers
446 views

Should the syntax for disabling code differ from that of normal comments?

For several reasons during development I sometimes comment out code. As I am chaotic and sometimes in a hurry, some of these make it to source control. I also use comments to clarify blocks of code. ...
5
votes
1answer
833 views

How do I view Scala code without all the syntactic sugar?

I have been studying Scala, but what I keep running into is the optimization of syntax. I'm sure that will be great when I am an expert, but until then.. Not so much. Is there a command or a program ...
56
votes
9answers
37k views

A practical use of “yield” keyword in C# [closed]

After almost 4 years of experience, I haven't seen a code where yield keyword is used. Can somebody show me a practical usage (along explanation) of this keyword, and if so, aren't there other ways ...
9
votes
14answers
3k 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
409 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 this?...
10
votes
2answers
5k 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
3k 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 ...
2
votes
2answers
838 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
1k 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
947 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 ...
10
votes
6answers
7k 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
5answers
184 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 ...
24
votes
9answers
5k 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
11k 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
224 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 ...
122
votes
19answers
61k 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
2k 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
2k 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 ...
105
votes
15answers
21k 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 ...
7
votes
3answers
2k 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 ...
13
votes
6answers
1k 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. ...
20
votes
12answers
4k views

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

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
2k 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 ...
40
votes
18answers
8k views

Does syntax really matter in a programming language? [closed]

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
2k 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 ...
11
votes
6answers
900 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() else:...
40
votes
14answers
10k 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
590 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? [closed]

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 sugar"...
4
votes
5answers
2k 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 ...
8
votes
3answers
1k 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 can'...
27
votes
36answers
5k views

What syntax element do you hate most in a programming language you use frequently? [closed]

No matter how much you love a programming language, there are always a few details in it that aren’t quite as nice as they could be. In this question, I would like to specifically focus on syntax ...
28
votes
22answers
31k 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 ...