Why doesn’t C# let you declare multiple variables using var?

When we designed the feature I asked the community what var x = 1, y = 1.2; should mean. The question and answers are here: http://blogs.msdn.com/b/ericlippert/archive/2006/06/26/what-are-the-semantics-of-multiple-implicitly-typed-declarations-part-one.aspx http://blogs.msdn.com/b/ericlippert/archive/2006/06/27/what-are-the-semantics-of-multiple-implicitly-typed-declarations-part-two.aspx Briefly, about half the respondants said that the obviously correct thing to do was to make x and y both double, and about half the respondants said that … Read more

C++11 – declaring non-static data members as ‘auto’

The rule for prohibiting non-static members is in 7.1.6.4 clause 4: The auto type-specifier can also be used in declaring a variable in the condition of a selection statement (6.4) or an iteration statement (6.5), in the type-specifier-seq in the new-type-id or type-id of a new-expression (5.3.4), in a for-range-declaration, and in declaring a static … Read more

setq and defvar in Lisp

There are several ways to introduce variables. DEFVAR and DEFPARAMETER introduce global dynamic variables. DEFVAR optionally sets it to some value, unless it is already defined. DEFPARAMETER sets it always to the provided value. SETQ does not introduce a variable. (defparameter *number-of-processes* 10) (defvar *world* (make-world)) ; the world is made only once. Notice that … Read more

Why does `int ;` compile fine in C, but not in C++?

The C standard says A declaration other than a static_assert declaration shall declare at least a declarator (other than the parameters of a function or the members of a structure or union), a tag, or the members of an enumeration. C++ says In a simple-declaration, the optional init-declarator-list can be omitted only when declaring a … Read more

Is it possible to declare a public variable in vba and assign a default value?

.NET has spoiled us ๐Ÿ™‚ Your declaration is not valid for VBA. Only constants can be given a value upon application load. You declare them like so: Public Const APOSTROPHE_KEYCODE = 222 Here’s a sample declaration from one of my vba projects: If you’re looking for something where you declare a public variable and then … Read more

Variable declaration after goto Label

The syntax simply doesn’t allow it. ยง6.8.1 Labeled Statements: labeled-statement: identifier : statement case constant-expression : statement default : statement Note that there is no clause that allows for a “labeled declaration”. It’s just not part of the language. You can trivially work around this, of course, with an empty statement. JUMP:; int a = … Read more

What does “var FOO = FOO || {}” (assign a variable or an empty object to that variable) mean in Javascript?

Your guess as to the intent of || {} is pretty close. This particular pattern when seen at the top of files is used to create a namespace, i.e. a named object under which functions and variables can be created without unduly polluting the global object. The reason why it’s used is so that if … Read more

Python Variable Declaration

Okay, first things first. There is no such thing as “variable declaration” or “variable initialization” in Python. There is simply what we call “assignment”, but should probably just call “naming”. Assignment means “this name on the left-hand side now refers to the result of evaluating the right-hand side, regardless of what it referred to before … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)