Tag Info

Hot answers tagged

115

In English the semicolon is used to separate items in a list of statements, for example She saw three men: Jamie, who came from New Zealand; John, the milkman's son; and George, a gaunt kind of man. When programming you are separating a number of statements and using a full stop could be easily confused for a decimal point. Using the semicolon ...


80

The D programming language and DMC's extension to C and C++ did support these operators (all 14 combinations of them), but interestingly, D is going to deprecate these operators, mainly because what exactly is a !< b? It is a>=b || isNaN(a) || isNaN(b). !< is not the same as >=, because NaN !< NaN is true while NaN >= NaN is false. IEEE ...


79

Two of the major influences to C were the Algol family of languages (Algol 60 and Algol 68) and BCPL (from which C takes its name). BCPL was the first curly bracket programming language, and the curly brackets survived the syntactical changes and have become a common means of denoting program source code statements. In practice, on limited ...


72

Originally SQL language was called SEQUEL standing for Structured English Query Language with the emphasize on English, assuming it to be close in spelling to natural language. Now, spell these two statements as you'd spell English sentences: "From Employee table e Select column e.Name" "Select column e.Name From Employee table e" Second sounds ...


68

Semantics ~ Meaning Syntax ~ Symbolic representation So two programs written in different languages could do the same thing (semantics) but the symbols used to write the program would be different (syntax). A compiler will check your syntax for you (compile-time errors), and derive the semantics from the language rules (mapping the syntax to machine ...


62

Many languages use syntax that is modeled after C (which was modeled after B - thanks @Crollster). As can be seen in the comments, there is a long chain of such languages... B was inspired by PL/I, which was preceded by ALGOL at using the ; as a separator. Since in C the statement terminator is ;, these languages follow suit. As for why it was selected as ...


60

We write loops like: for(x = 0; x < 10; x++) The language could have been defined so that loops looked like: for(x = 0, x < 10, x++) However, think of the same loop implemented using a while loop: x = 0; while(x < 10) { x++; } Notice that the x=0 and x++ are statements, ended by semicolons. They aren't expressions like you would ...


51

The reason to choose one or the other is because of intent and as a result of this, it increases readability. Intent: the loop should run for as long as i is smaller than 10, not for as long as i is not equal to 10. Even though the latter may be the same in this particular case, it's not what you mean, so it shouldn't be written like that. Readability: a ...


51

FORTRAN used carriage return to delineate statements. COBOL used period. LISP didn't use anything, relying on parentheses for everything. ALGOL was the first language to use semicolon to separate statements. PASCAL followed ALGOL's lead, using semicolon to separate statements. PL/I used semicolon to terminate statements. There is a difference, and it ...


47

Because it doesn't make much sense to have two different operators with exactly the same meaning. “not greater” (!>) is exactly the same as “lesser or equal” (<=) “not lesser” (!<) is exactly the same as “greater or equal” (>=) This does not apply to “not equals” (!=), there is no operator with the same meaning. So, your modification would ...


38

Languages have copied that from C, and for C, Dennis Ritchie explains that initially, in B (and perhaps early C), there was only one form "&" which depending on the context did a bitwise and or a logical one. Later, each function got its operator, & for the bitwise one and && for for logical one. Then he continues Their tardy ...


35

Because SELECT is required in a select statement and FROM is not. Select 'This String' Of course your sql statement can be parsed to look for the SELECT, DELETE, UPDATE after the FROM, but is is really that big of a deal? Remember, this was all done before intellisense. It's not that complicated.


34

The switch statement (in C, C++, C#, Java, etc.) Here is an example of why I find it highly inconvenient: switch (someVariable) { case 1: int i = something(); doSomething(i); break; case 2: int i = somethingElse(); doSomethingElse(i); break; } This doesn’t compile because the variable i is ...


27

This can be handled with either enums, integers, symbols (e.g., Lisp, Ruby), nullable types (use null as the indeterminate state), option types (e.g., ML), or some similar construct - depending on your language. So while your example and rationale is sound I can't see it being on the priority list of language features to develop.


27

Haskell syntax is close to human language. It is specifically designed to resemble mathematical notation, which is a language designed by humans (thus a human language) to express precisely those concepts that Haskell is built upon. You can show a piece of Haskell code to any mathematician or logician, and he will be able to understand it, even if he has ...


26

Efficiency The yield keyword effectively creates a lazy enumeration over collection items that can be much more efficient. For example, if your foreach loop iterates over just the first 5 items of 1 million items then that's all yield returns, and you didn't build up a collection of 1 million items internally first. Likewise you will want to use yield with ...


25

Using a dict let's you translate the key into a callable. The key doesn't need to be hardcoded though, as in your example. Usually, this is a form of caller dispatch, where you use the value of a variable to connect to a function. Say a network process sends you command codes, a dispatch mapping lets you translate the command codes easily into executable ...


24

You could invent a simple syntax for the English language at first. (But don't call it syntax just yet) It's all arbitrary For instance Make up a rule what it means for something to be a word one or multiple letters define a verb to be one of: like, want define what a subject is: I, He/She now define what a sentence is: A subject, an optional "don't", ...


23

The main difference is that syntax is grammar defined in a language to allow you to expose some functionality. As soon as you could get to that functionality, any other syntax that lets you do the same thing is considered sugar. That of course runs into odd scenarios about which of the two syntaxes is the sugar, especially since it's not always clear which ...


22

Sounds really dangerous. If a compiler tries to infer your intent, infers it wrong, fixes the code, and then doesn't tell you (or tells you in some warning that you, like everyone, ignore), then you're about to run code that may seriously do some damage. A compiler like this is probably something that has very intentionally NOT been created.


21

In some sense, the act of compiling is inferring what certain syntax is meant to do, and hence a syntax error is when the compiler isn't able to figure it out. You can add more "guessing" to have the compiler infer further things and be more flexible with the syntax, but it must do this inferring by a specific set of rules. And those rules then become a part ...


21

Square braces [] are easier to type, ever since IBM 2741 terminal that was "widely used on Multics" OS, which in turn had Dennis Ritchie, one of C language creators as dev team member. Note the absence of curly braces at IBM 2741 layout! In C, square braces are "taken" as these are used for arrays and pointers. If language designers expected arrays and ...


21

Making them mandatory (or disallowing them completely) reduces the number of corner cases, eliminates a potential source of obscure bugs, and simplifies the compiler/interpreter design. The language designers who have opted to make them optional have chosen to live with the ambiguity in return for greater syntactic flexibility.


20

Technically, some syntactic sugar can be worth keeping even if it can trivially be replaced, if it improves readability of some common operation. But assignment-as-expression does not fall under that. The danger of typo-ing it in place of a comparison means it's rarely used (sometimes even prohibited by style guides) and provokes a double take whenever it is ...


19

What I look for in a programming language (as opposed to a scripting language) is consistency and strong typing. In current programming languages it is possible to omit the semicolon for instance in certain places without becoming ambiguous (the last expression in a {} block is one). If a programming language allows you to omit characters in these cases, a ...


19

It is completely normal. Hardly anyone can say that he/she knows the syntax of every PHP or Java class, function or framework. Your brain is better used for problem solving than for memorizing things. Obviously you tend to memorize things you use in a daily basis but as soon as several month pass without doing that specific thing, you forget the syntax. ...


18

How about this: "syntactic sugar is a convenience shorthand for some functionality that does not introduce any meaningful layer of abstraction." Take a->b, which, as you point out, is equivalent to (*a).b. Does this notation allow you to consider the code it's in any useful, otherwise hidden manner? No, so it's syntactic sugar. Now consider a[i] == ...


18

First of all, in your example there are "TODO" comments. These types of comments are special in a way because they are detected by IDEs (at least Eclipse and Visual Studio) as a marker for "tasks". But I'm sure you know that since you use thme, and I suppose you're not referring to them when you use the term "disabled code". As for the disabled code itself, ...


18

Smalltalk and derived languages (including Objective C) use a syntax like this for method calls. In Objective C, for instance, one can work with an NSMutableArray container with something like: id a = [[NSMutableArray alloc] initWithCapacity: 3] [a insertObject: @"Bob" atIndex: 0] [a insertObject: @"Fred" atIndex: 1] [a insertObject: @"Mary" atIndex: 2] ...


18

So why in the same languages such mapping is reversed for for loops. Technically, the mapping is not "reversed". The things separated by commas are not parameters. In (at least) C++ and Java, they can be declarations, so they are not even expressions. The things separated by semicolons are not (single) statements either. In reality what we have ...



Only top voted, non community-wiki answers of a minimum length are eligible