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

0
votes
2answers
92 views

Reinforcing Syntax Elements

I am currently learning Javascript, and there is one element of the syntax that I can just not seem to nail down. That element is adding semicolons at the end of each line. I have learned Python and ...
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 ...
4
votes
5answers
325 views

How to remember the details (Core APIs) of one computer language?

I found my self often paused to check a certain usage of one core API when writing either javascript or Ruby. I am wondering how the other guys doing? Is it necessary to remember every Core API ...
0
votes
1answer
143 views

Syntax logic suggestions

This syntax will be used inside HTML attributes. Here are a few examples of what I have so far: <input name="a" conditions="!b, c" /> <input name="b" /> <input name="c" /> This ...
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 ...
0
votes
6answers
662 views

Syntax for goto labels

In C, C++ and some dialects of BASIC, goto labels are declared with the syntax label:. I'm working on a language that uses name: type as the syntax for variable declarations, so I'd prefer if possible ...
21
votes
4answers
4k views

What's the difference between implementing an Interface explicitly or implicitly?

In Visual Studio I can right-click on an interface and choose to Implement Interface, or Implement Interface Explicitly. public class Test : ITest { public string Id // Generated by Implement ...
6
votes
4answers
431 views

Backquoted symbols, good or bad?

I'm designing a programming language which has three kinds of quoted entities: strings and characters as in C, and symbols (interned strings intended for use as lookup keys and such) which I consider ...
4
votes
3answers
191 views

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 ...
24
votes
10answers
3k views

Is there any reason why most programming languages don't have '!>' (not greater than) and '!<' (not less than) operators?

I wonder if there is any reason - or if it is just an accident of history - that there are no !> and !< operators in most programming languages? a >= b (a greater OR equals b) could be ...
10
votes
11answers
674 views

Is there a personalizable programming language you can use to convert to others?

Is there a programming language in which you can set your own syntax configurations and it would convert the code to a language you choose? For instance, you would choose specific configurations like ...
52
votes
6answers
3k 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, ...
6
votes
3answers
563 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?
0
votes
2answers
232 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
595 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 ...
5
votes
2answers
3k 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 ...
13
votes
5answers
3k views

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

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
190 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
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 ...
2
votes
1answer
691 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
439 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 ...
1
vote
1answer
73 views

Is depending on references a common process or should I be memorizing syntax? [duplicate]

Possible Duplicate: Is it important for a programmer to memorize the syntax of the language? For example I could not write a SQL connection string from scratch if I tried. I always either ...
4
votes
5answers
2k 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 ...
7
votes
3answers
4k 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
243 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 ...
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 ...
5
votes
7answers
648 views

Are operators just “special” methods?

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 ...
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> ...
8
votes
4answers
412 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. ...
4
votes
1answer
400 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 ...
20
votes
5answers
6k views

A practical use of “yield” keyword in C#

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 ...
18
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
1k 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
334 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 ...
7
votes
2answers
2k 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 ? ...
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 ...
3
votes
2answers
706 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
449 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
700 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
2k 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
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 ...
1
vote
5answers
175 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 ...
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 ...
6
votes
1answer
5k 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
213 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 ...
3
votes
3answers
2k 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?
61
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) ...
8
votes
8answers
313 views

Expressions that are idiomatic in one language but not used or impossible in another

I often find myself working in unfamiliar languages. I like to read code written by others and then jump in and write something myself before going back and learning the corners of each language. To ...
10
votes
9answers
988 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 ...
8
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 ...