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.

Filter by
Sorted by
Tagged with
47 votes
5 answers
19k views

When does it make sense to compile my own language to C code first?

When designing an own programming language, when does it make sense to write a converter that takes the source code and converts it to C or C++ code so that I can use an existing compiler like gcc to ...
danijar's user avatar
  • 846
266 votes
21 answers
224k 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) {...
85 votes
6 answers
19k views

Why does the type go after the variable name in modern programming languages?

Why is it that in nearly all modern programming languages (Go, Rust, Kotlin, Swift, Scala, Nim, even Python last version) types always come after the variable name in the variable declaration, and not ...
Andre Polykanine's user avatar
147 votes
15 answers
31k 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 ...
100 votes
3 answers
50k 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 ...
SomeKittens's user avatar
  • 4,240
136 votes
14 answers
22k 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 ...
A Coder's user avatar
  • 1,343
41 votes
18 answers
11k 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 ...
41 votes
2 answers
26k views

Why does C use the asterisk for pointers? [closed]

I'm just now learning about C. I find it odd that the creators chose the asterisk (*) as the symbol for pointers rather than a symbol that actually looks like a pointer (->). Considering how ...
Noob Saibot's user avatar
33 votes
14 answers
13k views

Why don't programming languages automatically manage the synchronous/asynchronous problem?

I have not found many resources about this: I was wondering if it's possible/a good idea to be able to write asynchronous code in a synchronous way. For example, here is some JavaScript code which ...
Cinn's user avatar
  • 473
29 votes
16 answers
3k 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> ...
26 votes
11 answers
8k 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 ...
amara's user avatar
  • 1,310
95 votes
13 answers
126k 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 ...
gsgx's user avatar
  • 1,807
73 votes
2 answers
8k views

Why do bitwise operators have lower priority than comparisons?

Could someone explain the rationale, why in a bunch of most popular languages (see note below) comparison operators (==, !=, <, >, <=, >=) have higher priority than bitwise operators (&, |, ^...
SF.'s user avatar
  • 5,156
27 votes
9 answers
13k views

What is the benefit of having the assignment operator return a value?

I'm developing a language which I intend to replace both Javascript and PHP. (I can't see any problem with this. It's not like either of these languages have a large install base.) One of the things ...
billpg's user avatar
  • 611
26 votes
36 answers
7k 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 ...
22 votes
12 answers
10k 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 ...
Loïc Faure-Lacroix's user avatar
18 votes
1 answer
2k views

Dollar Sign Blues: Javascript and PHP

I grew up programming C++ and Java where everything was safe and beautiful. Compilers made sure to keep me in check if I ever strayed. Of course, everyone did a little Perl in college, but I didn't ...
Alan Turing's user avatar
  • 1,533
18 votes
6 answers
24k 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 ...
iammilind's user avatar
  • 2,232
2 votes
1 answer
776 views

How are "Json.org"-like specs graphs called and how can I generate them?

In http://www.json.org Douglas Crockford shows the specs of the JSON format in two interesting ways: In the right side column he lists a text spec that looks like a YACC or LEX listing. In the main ...
Sebastián Grignoli's user avatar
73 votes
6 answers
11k views

Why is the Select before the From in an SQL query? [closed]

This is something that bothered me a lot at school. Five years ago, when I learned SQL, I always wondered why we first specify the fields we want and then where we want them from. According to my ...
Cyril Gandon's user avatar
  • 1,326
71 votes
3 answers
33k views

Is there a performance benefit to using the method reference syntax instead of lambda syntax in Java 8?

Do method references skip the overhead of the lambda wrapper? Might they in the future? According to the Java Tutorial on Method References: Sometimes... a lambda expression does nothing but call an ...
GlenPeterson's user avatar
  • 14.9k
14 votes
12 answers
6k 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 ...
Nathan Osman's user avatar
13 votes
3 answers
3k 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'...
Casebash's user avatar
  • 7,662
12 votes
5 answers
7k 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 have ...
Patrick McElhaney's user avatar
12 votes
22 answers
4k 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 ...
Maniero's user avatar
  • 10.8k
12 votes
6 answers
91k views

Checking "instanceof" rather than value using a switch statement

Is there some syntax (other than a series of if statements) that allows for the use of a switch statement in Java to check if an object is an instanceof a class? I.e., something like this: switch (...
Cameron Fredman's user avatar
9 votes
8 answers
2k 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"...
dsimcha's user avatar
  • 17.2k
8 votes
2 answers
8k views

Helper Methods Placement [duplicate]

Here's a question that's always bugged me. I'm going to use java as an example because I've almost never run into a problem in java where I didn't need to use helper methods in its class structure. ...
user1427661's user avatar
7 votes
5 answers
4k views

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

And what do you think about operator precedence? Would be harder programming in a language where the operations are executed in sequential order? Ex.: 2 + 3 * 4 == 20 2 + (3 * 4) == 14 OK, the Lisp ...
Maniero's user avatar
  • 10.8k
3 votes
6 answers
553 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/...
c_maker's user avatar
  • 8,280
0 votes
2 answers
3k views

Nested functions; allow or not? [closed]

Having programmed a whole lot in python, using nested functions is a good way to not clutter the namespace with small helper functions that are only used once. Now I'm programming in go, and upon ...
Filip Haglund's user avatar
-4 votes
3 answers
3k views

Why different languages have different syntax? [duplicate]

Different programming language always/most of the time use different syntax. For example take PHP, Java and Python. In Php & Java semicolons are compulsory at the end of the line, yet Python ...
Pratik Joshi's user avatar