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

3
votes
0answers
71 views

Why does the order of the link elements in <head> matter? [migrated]

From Code Academy's Make a Website: CSS Styling: <head> <link href="font.css" rel="stylesheet"> <link href="main.css" rel="stylesheet"> </head> ...
0
votes
2answers
418 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 ...
-1
votes
0answers
17 views

DrRacket: If-else Problem [migrated]

I have a problem with Racket. (I'm using the tutorial at http://docs.racket-lang.org/guide/conditionals.html) I tried to write a function that does this: If x is smaller than 4, then it should be ...
2
votes
1answer
135 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
74 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 ...
5
votes
4answers
501 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 ...
35
votes
12answers
4k 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
475 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
1answer
122 views

if else brackets on same line, best comment style? [closed]

I used to do this: // If the cat is black if ( $catColor == 'black' ) { ... } // Otherwise eat a taco else { ... } But I've more recently started to move toward this style of conditional ...
0
votes
4answers
100 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
217 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 ...
5
votes
1answer
462 views

Why does C use the asterisk for pointers?

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 ...
3
votes
2answers
582 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 ...
2
votes
0answers
105 views

Programmatically manipulate expressions accounting for operator precedance [closed]

There are times when an expression becomes confusing because of implicit operator precedence. Take this Python expression: a, b, c, d = range(4) e = a + b // c << d >> a ** b or a + c * ...
6
votes
7answers
728 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. ...
29
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, ...
0
votes
1answer
164 views

Syntax of passing lambda

Right now, I'm working on refactoring a program that calls its parts by polling to a more event-driven structure. I've created sched and task classes with the sced to become a base class of the ...
0
votes
0answers
27 views

What syntax should I use to execute functions in jQuery Terminal?

I want to add feature, to jQuery Terminal, that will allow to execute commands from the server. Right now it only have formatting syntax that look like this: [[<list of one letter styles> ; ...
0
votes
1answer
69 views

RFC syntax definition [closed]

I would like to bring our specifications to a better level of fine-grained definition of syntaxes, semantics and the like. I read my fair share of RFCs and just love the way they define things like ...
1
vote
1answer
162 views

Why some Javascript code needs to be written in different tags and not embedded within the same

When I was using the modernizr file, I came across this problem where in I need to source a file and call the script. <script src="js/modernizr-min.js"></script> <script> if ...
0
votes
4answers
2k 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 ...
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, ...
2
votes
3answers
578 views

Typical instantiation of new object - is there a way to avoid repetitious syntax?

When learning C# (and OO concepts more generally at the same time) something I found very distracting is exemplified by the following line: ExampleClass exampleObject = new ExampleClass(); It's the ...
0
votes
0answers
53 views

Using JavaScript to find the correct offset in bundled files

I am currently making multiple parsers using PEGjs and have implemented my own partial preprocessor which using a RegExp finds and replaces '#include' directives with the desired files, resulting in a ...
1
vote
1answer
164 views

About AST construction in LL1 non recursive parser

I have implemented a LL1 parser in a non recursive approach with a explicit stack. The following algorithm is from the Dragon Book: set zp to point to the first symbol of w; set X to the top stack ...
3
votes
4answers
748 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 ...
21
votes
9answers
2k 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 ...
2
votes
3answers
555 views

Syntactic Sugar for old languages

I first learned about the existence of syntactic sugar languages, like CoffeeScript and SASS while working in Rails. This got me thinking... why do we not have well-known (if any at all) syntactic ...
11
votes
7answers
550 views

What is idiomatic use of arbitrary blocks in C?

A block is a list of statements to be executed. Examples of where blocks come up in C are after a while statement and in if statements while( boolean expression) statement OR block if (boolean ...
2
votes
6answers
848 views

Stacking keywords on top of each other - poor style? [closed]

I have always wondered about this, especially in C/Java style languages. For example, consider the first 3 lines of this C# code: lock (serviceLock) using (var client = new ServiceClient()) try { ...
3
votes
2answers
372 views

Variable declaration versus assignment syntax

Working on a statically typed language with type inference and streamlined syntax, and need to make final decision about syntax for variable declaration versus assignment. Specifically I'm trying to ...
0
votes
2answers
131 views

Languages like Tcl that have configurable syntax? [duplicate]

I'm looking for a language that will let me do what I could do with Clipper years ago, and which I can do with Tcl, namely add functionality in a way other than just adding functions. For example in ...
7
votes
3answers
227 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 ...
8
votes
6answers
947 views

Optional semicolons

Most often, in a general-purpose imperative language - semicolons as statement-delimiters are either required, or completely disallowed (e.g. C and Python). However, some languages, like JavaScript, ...
2
votes
3answers
245 views

What language has integrated “list insertion” as part of code *syntax*?

Many programming languages permit natural manipulation of strings, and some languages permit the manipulations of lists too. More often then not (always?), these operations are done as procedure ...
1
vote
1answer
464 views

How to write a syntax checker [closed]

How is a syntax checker for a programming language written? I am guessing a grammar has to be written first. How to then proceed? Motivation I'm using a programming language (Apex for Salesforce) ...
0
votes
3answers
377 views

Any languages use the '=>' and '=<' operators? [closed]

I'm just curious if there are any programming languages that use the '=>' and '=<' operators for something. I wonder why these are not commonly used when their variant '<=' and '>=' are so ...
12
votes
1answer
7k views

Why there is no markdown for underline? [closed]

I am wondering why there is no markdown syntax for underline? I know that basic html tags can be embedded to achieve this but I am trying to understand why underline got omitted when bold and italics ...
0
votes
1answer
150 views

Truth condition testing with BOOL

BOOL myBool; myBool = YES; ... if (myBool) { doFoo(); } I have read that because there are instances where the above does not actually call the doFoo() function, it is best to instead always test ...
4
votes
5answers
692 views

Does relying on intellisense and documentation a lot while coding makes you a bad programmer? [duplicate]

Is a programmer required to learn and memorize all syntax, or is it ok to keep handy some documentation? Would it affect the way that managers look at coders? What are the downside of depending on ...
7
votes
4answers
777 views

What makes Common Lisp “big”?

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 ...
15
votes
1answer
688 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 ...
2
votes
1answer
152 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 ...
0
votes
2answers
104 views

What Does “The Program Must Process Each Character Before Reading the Next One” Mean?

From the book Think Like a Programmer (emphasis mine) The Luhn formula is a widely used system for validating identification numbers. Using the original number, double the value of every other ...
2
votes
2answers
780 views

foreach over multiple lists at once

Are there any languages that support foreach over multiple lists at once? Something like this: foreach (string a in names, string b in places, string c in colors) { // do stuff with a, b, c ...
2
votes
1answer
209 views

Objective C - nested messages … confusion about

Wonder if anyone could shed some light on this messaging construct: The documentation says that messages appear btwn brackets [] and that the msg target/object is on the left, whilst the msg itself ...
2
votes
2answers
220 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. ...
45
votes
7answers
4k views

Why are semicolons and commas interchanged in for loops?

In many languages (a wide list, from C to JavaScript): commas , separate arguments (e.g. func(a, b, c)), while semicolons ; separate sequential instructions (e.g. instruction1; instruction2; ...
37
votes
2answers
2k 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 (&, |, ...
34
votes
11answers
3k 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. ...