Tag Info

Hot answers tagged

116

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 ...


96

While case folding is fairly trivial in English, it's much less so in some other languages. If a German programmer uses ß in a variable name, what are you going to consider the upper-case equivalent? Just FYI, "ß" is only ever used in lower case. OTOH, "ss" is equivalent -- would you consider a compiler obliged to match them? When you get into Unicode, you ...


87

Why would anyone WANT case insensitivity? In what scenario is it useful to be able to refer to a single variable as VARIABLE in one place, Variable in another, and variable in a third? Case insensitivity is exasperating. I’d much rather get a compiler error when I accidentally type VAriable instead of Variable rather than let case-typos like that slip into ...


83

When used at the start of a block, as first checks made, they act like preconditions, so it's good. When used in the middle of the block, with some code around, they act like hidden traps, so it's bad.


81

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 ...


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 ...


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 ...


71

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 ...


65

Your observations are correct. C++ is a complicated beast, and the new keyword was used to distinguish between something that needed delete later and something that would be automatically reclaimed. In Java and C#, they dropped the delete keyword because the garbage collector would take care of it for you. The problem then is why did they keep the new ...


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 ...


61

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 ...


53

In short, you are right. Keyword new is superfluous in languages like Java and C#. Here are some insights from Bruce Eckel who was a member of C++ Standard Comitee in 1990s and later published books on Java: http://www.artima.com/weblogs/viewpost.jsp?thread=260578 there needed to be some way to distinguish heap objects from stack objects. To solve this ...


53

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 ...


52

Yes it does. If you're in doubt, take APL, or J, or Brainfuck, or even plain and simple Lisp or Forth, and try to understand any not entirely trivial program on it. Then compare to e.g. Python. Then compare the same Python (or Ruby, or even C#) to things like Cobol or VB6. I'm not trying to say that hairy syntax is bad and natural-language-like syntax is ...


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 ...


42

Haskell is a completely different way of programming, if you're not used to it. Here's a good free online reference.


40

Java-bean syntax due to lack of C# properties /** * Name of user */ private String name; /** * Gets name of user * @return Name of user */ public String getName() { return this.name; } /** * Sets name of user. * @param name */ public void setName(final String name) { this.name = name; } GAH!!! Issues I have with this Too much code - ...


39

Semicolon insertion in JavaScript. I haven't really been bitten by it often, but it's just such a phenomenally bad idea it makes my head spin. Here's the rules (from ECMA-262 Section 7.9) When the program contains a token that is not allowed by the formal grammar, then a semicolon is inserted if (a) there is a line break at that point, or (b) the ...


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 ...


37

You could read Donald Knuth's 1974 paper Structured Programming with go to Statements, in which he discusses various uses of the go to that are structurally desirable. They include the equivalent of break and continue statements (many of the uses of go to in there have been developed into more limited constructs). Is your boss the type to call Knuth a bad ...


37

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 ...


36

Yes, and yes. Yes there's such a language, and yes, many people find it more readable once they get used to it. In Objective-C, the method would be: - (NSArray*)getTop:(int)count customersOfTheYear:(Year)year; That's actually a pretty contrived example that doesn't read very well, so here's a better one from actual code: + (UIColor ...


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 ...


34

Whitespace Sensitivity. Python annoys me in this respect. I mean, I indent properly anyway, but it bugs me that I should have to. Making presentation part of the syntax irks me.


30

As with many things, unit testing is best supported at the library level, not the language level. In particular, C# has numerous Unit Testing libraries available, as well as things that are native to the .NET Framework like Microsoft.VisualStudio.TestTools.UnitTesting. Each Unit Testing library has a somewhat different testing philosophy and syntax. All ...


29

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 ...


28

Array Declarations in VB.NET I always manage to forget that when initializing fixed arrays in VB.NET, you're specifying the upper bound of the array and not the number of elements like in C/C++, PHP, or Java. Besides VB6 (we won't go there...), I can't think of another language that does it this way: Dim myArray(20) as Integer '# Creates an array with 21 ...



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