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

122
votes
13answers
14k 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 ...
5
votes
4answers
1k views

Why are scientific programming languages so weird? [closed]

It seems to me that programming languages meant for use in science and engineering are consistently weird compared to general-purpose languages. Some examples off the top of my head: In Matlab, each ...
-1
votes
2answers
75 views

Hypothetical extension to C# property initializer syntax

In C#, when you call a constructor, you can add one or more property initializers in curly braces: var foo = new Bar() { Armpit = new Flapdoodle() { Limpet = 2 } }; What if that feature were ...
6
votes
4answers
1k views

What makes Common Lisp “big”? [closed]

I've been learning both Common Lisp and Racket, and one thing that I consistently hear is that Racket is a much "smaller" language than Common Lisp. I was wondering what this really meant. As far as I ...
2
votes
2answers
112 views

Regular syntax — what does it mean?

I am reading "Less is exponentially more" and there is a list of advantages of Go, first of them, quote "regular syntax (don't need a symbol table to parse)". What does it mean "regular syntax"? ...
18
votes
5answers
3k 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 ...
4
votes
1answer
123 views

How to approach syntax errors when developing a lexical analyser?

I am writing an interpreted domain-specific language for my application. Each statement is parsed and executed as soon as lexical analyser decides that the end of statement is reached. It's handling ...
13
votes
6answers
977 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. ...
27
votes
15answers
2k views

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

in JavaScript: function getTopCustomersOfTheYear(howManyCustomers, whichYear) { // Some code here. } getTopCustomersOfTheYear(50, 2010); in C#: public List<Customer> ...
5
votes
1answer
132 views

quantitatively comparing AST shapes

How could one compare the shape of abstract syntax trees of similar source code programs (C, C++, Go, or anything compiled with GCC...)? I guess that plagiarism detection on source code would use ...
27
votes
4answers
3k 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 ...
0
votes
2answers
71 views

Is the word 'statement' in 'statement block' redundant?

Is the word 'statement' in 'statement block' redundant? In other words is a block in a program composed, by definition, of statements?
2
votes
4answers
124 views

Should actions / methods be conjugated in comments?

For example, which of the following is correct ? // Return hello -- or -- // Returns hello function greeting() { return "Hello"; } I personally never conjugate them but I am wondering how ...
0
votes
1answer
37 views

Is it a reasonable task to automatically convert ANTLR grammars to my own format?

I was working on my own parser generator tool in Clojure and then I realised I want to test it with some real programming languages. I can find a lot of existing language grammars only in antlr v4 ...
0
votes
1answer
195 views

Do any languages have syntax for promises? [closed]

I'm really glad that EcmaScript 6 has promises built into the language, but the syntax will still be quite wordy: new Promise(f).then(r => { ... }).then(r2 => ... }).catch(... I'm just ...
37
votes
10answers
6k views

What is the difference between “Syntax” and “Syntactic Sugar”

Background The Wikipedia page on Syntactic Sugar states: In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express. ...
52
votes
9answers
32k 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 ...
22
votes
6answers
3k views

Explaining new or uncommon syntax in comments [duplicate]

As per the title, should I be explaining syntax that I use in my code when I have a reasonable expectation that a developer looking at my code in the future will not be familiar with it? Short caveats ...
103
votes
18answers
52k 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) ...
0
votes
2answers
184 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 ...
-6
votes
3answers
279 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 ...
2
votes
2answers
98 views

How to create a 2D array at runtime in Ada? [closed]

In Ada programming, What is a best practice way to create a 2D array of a size that is specified by the user? I'm teaching myself Ada for work (after many years of C programming), and I'm having ...
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 ...
16
votes
2answers
5k 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 ...
27
votes
1answer
2k views

Why does C++ not have a “pure” keyword for virtual functions?

I have always wondered why we code virtual void MyFunction() = 0; and not pure virtual void MyFunction(); Is there a reference for the basis of this decision?
38
votes
18answers
7k 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 ...
3
votes
3answers
377 views

In Objective C, what English words can I conceptually associate to the symbols?

I'm learning Objective C (from a C# background) and am having difficulty understanding the unusual method signatures and am looking for a shortcut to make the learning curve less steep. When reading ...
4
votes
8answers
591 views

Confusion regarding def function within Python

I've been learning Python for about 2 months now (Started with Learn Python The Hard Way, now reading Dive Into Python), and within both books, I still seem to be confused over this one bit of code. ...
7
votes
3answers
286 views

Construct your solution logic in syntax or in a faster and more efficient mental model?

I am a newbie, studying programming and I came across this question today: How can I make sure that I'm actually learning how to program rather than simply learning the details of a language? A ...
32
votes
4answers
38k views

Why store a function inside a python dictionary?

I'm a python beginner, and I just learned a technique involving dictionaries and functions. The syntax is easy and it seems like a trivial thing, but my python senses are tingling. Something tells me ...
2
votes
1answer
167 views

How do I distinguish between things belonging to the standard library, specific gems, and those that are user-generated in Ruby?

I'm a beginning programmer, that for various reasons is using an existing Ruby codebase to learn to program. My goal is to be able to understand and eventually extend this codebase. However, I find it ...
3
votes
2answers
355 views

Why was the AT&T assembly syntax designed this way?

The AT&T assembly syntax, often called the GAS syntax, keeps surprising me. For example, its parameter order: mov $100,%eax /* Destination after source */ This just seems so counter-intuitive! ...
2
votes
2answers
199 views

Make functions that imply other functions

I'm developing a game that often has repetitious code that I can't simplify. Example of what I do normally: Square object; GL11.glPushMatrix(); // Pushes a matrix stack down by one. This allows us ...
4
votes
4answers
18k 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 ...
4
votes
2answers
401 views

Needs (in principle) C++ parenthesis around if statement condition?

In current C++ when body of if statements contain only one command then: Parenthesis around if condition are mandatory but block are optional. So, both examples are OK: if ( condition ) { return 0; ...
0
votes
1answer
67 views

Why do objects created with no assignment not generate a syntax error in Python?

While working on a Python project, I realized that during my editing I had left a string floating around in the middle of my code and it didn't generate an error. For example, these few lines execute ...
6
votes
6answers
1k views

Would a “downcast if block” be a reasonable language feature?

Consider the following "if cast": class A { public void f1() { ... } } class B : A { public void f2() { ... } } A a = foo(); // might return A or B if ( a is B ) { // Inside block, ...
0
votes
2answers
523 views

Does any other language use the uniform initialization syntax found in c++? [closed]

Are there any other languages that use the new C++11 uniform initialization syntax thoroughly throughout the entire language, or is this entirely a C++ idiom at this point? I tried googling and ...
2
votes
1answer
167 views

What exactly is this Python statement doing?

I'm trying to port a very basic dual contouring algorithm written in Python (here) to C++. I'm not a Python programmer so some of the language syntax is a bit foreign to me. Specifically, this block ...
0
votes
2answers
244 views

BNF parsing rule for left associativity

Can someone please assist me with the following question. Write a BNF rule to parse into C -> E C -> E && E C -> E && E && E so that C generates as many E ...
36
votes
12answers
5k views

Why do most programming languages have special keyword or syntax for declaring functions? [closed]

Most programming languages (both dynamically and statically typed languages) have special keyword and/or syntax that looks much different than declaring variables for declaring functions. I see ...
4
votes
3answers
541 views

Intentionally incorrect use of language features, specifically “ref” in C#, as a hint to colleagues

I recently came across a piece of code something like this (roughly C#): public bool ValidateStuff(ref ArrayList listOfErrors, Stuff thingsToValidate) { if (!thingsToValidate.isValid() ) { ...
0
votes
4answers
107 views

Developing configuration syntax - best practise/rules/methods?

I am currently developing a small application, which checks if provided data meets certain requirements. The requirements are actually a long list, and might be changing, so I defined a syntax which ...
0
votes
2answers
480 views

Writing a superset of a programming language as a transcompiler

My idea is to write a superset of C# (but question is not language-specific), so that it source-to-source compiles (transcompiles) to C# itself (fall-through switch clauses, default method parameters ...
4
votes
4answers
9k views

Why do C# developers newline opening brackets? [closed]

I've spent most of the last several years working mainly with C# and SQL. Every programmer I've worked with over that time was in the habit of placing the opening brace of a function or control flow ...
3
votes
2answers
677 views

Haskell syntax for type definitions: why the equality sign?

I am a bit confused by the choice of Haskell syntax for type definitions, like in data Foo = Bar Namely: does the equality sign here really mean an equality in some subtle sense, or is it just a ...
7
votes
7answers
2k views

Why isn't there a next operation on enums?

In most popular programming languages like Java and C# there is a way to define enums, which are essentially datatypes with a fixed set of values, e.g. DayOfWeek. The problem is, given a value, e.g. ...
32
votes
6answers
3k views

Why isn't testing a language a supported feature at the syntax level?

You can find an endless list of blogs, articles and websites promoting the benefits of unit testing your source code. It's almost guaranteed that the developers who programmed the compilers for Java, ...
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 ...
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 ...