PHP | define() vs. const

As of PHP 5.3 there are two ways to define constants: Either using the const keyword or using the define() function: const FOO = ‘BAR’; define(‘FOO’, ‘BAR’); The fundamental difference between those two ways is that const defines constants at compile time, whereas define defines them at run time. This causes most of const‘s disadvantages. … Read more

static const vs #define

Pros and cons between #defines, consts and (what you have forgot) enums, depending on usage: enums: only possible for integer values properly scoped / identifier clash issues handled nicely, particularly in C++11 enum classes where the enumerations for enum class X are disambiguated by the scope X:: strongly typed, but to a big-enough signed-or-unsigned int … Read more

Does C++11 allow vector?

No, I believe the allocator requirements say that T can be a “non-const, non-reference object type”. You wouldn’t be able to do much with a vector of constant objects. And a const vector<T> would be almost the same anyway. Many years later this quick-and-dirty answer still seems to be attracting comments and votes. Not always … Read more

How do I create a constant in Python?

You cannot declare a variable or value as constant in Python. To indicate to programmers that a variable is a constant, one usually writes it in upper case: CONST_NAME = “Name” To raise exceptions when constants are changed, see Constants in Python by Alex Martelli. Note that this is not commonly used in practice. As … Read more

Why can I change a constant object in javascript

The documentation states: …constant cannot change through re-assignment …constant cannot be re-declared When you’re adding to an array or object you’re not re-assigning or re-declaring the constant, it’s already declared and assigned, you’re just adding to the “list” that the constant points to. So this works fine: const x = {}; x.foo = ‘bar’; console.log(x); … Read more