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

5
votes
7answers
549 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. ...
-2
votes
0answers
20 views

Syntax error in visual studio [migrated]

I started Udacity's Intro to Comp Sci course today, and generated this code at the end of the first lesson: page = '<a href="http://udacity.com">Hello world</a>' start_link = ...
-5
votes
0answers
34 views

Mixing arrays of different types in python [closed]

I'm trying to accomplish a certain task in Python that can be best described in short through the following example scenario. Suppose I want to calculate an array representing the polynomial ...
27
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, ...
25
votes
5answers
8k 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 ...
0
votes
0answers
4 views

What happens when there is multiple expressions in the condition part of a for loop seperated by commas? [migrated]

I have an infinite loop here, but why? int end = 5; for(int i = 0; i < end, printf("at condition i=%d\n",i); ++i) { printf("inside i=%d\n",i); }
1
vote
4answers
695 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 ...
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 ...
0
votes
0answers
4 views

js syntax errors in text adventure [migrated]

hi i'm new to java script and I wrote a text adventure for a school project and I keep getting these error when I try to run it js: "adventure.js", line 4: missing ( before condition js: if var ...
9
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 ...
0
votes
0answers
32 views

What are {curly brackets} for in Gnu-Apl? [migrated]

What are {curly brackets} for in GNU-APL? As far as I know, GNU-APL uses the APL Iso standard.
0
votes
1answer
130 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
23 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> ; ...
22
votes
4answers
9k 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
3answers
455 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
1answer
57 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
153 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 ...
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, ...
82
votes
15answers
8k 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 ...
0
votes
0answers
50 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
4answers
630 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
vote
1answer
102 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 ...
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 ...
14
votes
13answers
1k views

Are there any compilers that attempt to fix syntax errors on their own?

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 ...
19
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 ...
55
votes
12answers
26k 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 ...
10
votes
10answers
2k views

How should I pronounce the :: and -> in PHP? [closed]

When I read these lines aloud to someone: $controller->process(); UserManager::getInstance(); How should the -> and :: be pronounced? Reading the characters themselves in cumbersome and I ...
2
votes
3answers
412 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 ...
2
votes
6answers
819 views

Stacking keywords on top of each other - poor style?

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 { ...
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 ...
1
vote
4answers
219 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 ...
11
votes
7answers
505 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 ...
62
votes
18answers
20k 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) ...
32
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. ...
37
votes
14answers
6k 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 ...
3
votes
2answers
240 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
116 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 ...
8
votes
4answers
419 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. ...
7
votes
3answers
215 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
902 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, ...
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 ...
26
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> ...
2
votes
3answers
240 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 ...
66
votes
3answers
22k 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 ...
0
votes
1answer
149 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 ...
1
vote
1answer
341 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
365 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 ...
4
votes
3answers
513 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 ...
7
votes
1answer
3k 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 ...
3
votes
5answers
630 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 ...