Use of ‘const’ for function parameters

The reason is that const for the parameter only applies locally within the function, since it is working on a copy of the data. This means the function signature is really the same anyways. It’s probably bad style to do this a lot though. I personally tend to not use const except for reference and … Read more

What does the PHP error message “Notice: Use of undefined constant” mean?

You should quote your array keys: As is, it was looking for constants called department, name, email, message, etc. When it doesn’t find such a constant, PHP (bizarrely) interprets it as a string (‘department’, etc). Obviously, this can easily break if you do defined such a constant later (though it’s bad style to have lower-case … Read more

What is a class constant?

JLS-8.3.1.1. static Fields says (in part) A static field, sometimes called a class variable, is incarnated when the class is initialized (§12.4). JLS-4.12.4. final Variables says (in part) A constant variable is a final variable of primitive type or type String that is initialized with a constant expression (§15.28) tl;dr Putting that together, a class constant is a static final field.

Why does JSHint throw a warning if I am using const?

When relying upon ECMAScript 6 features such as const, you should set this option so JSHint doesn’t raise unnecessary warnings. /*jshint esnext: true */ (Edit 2015.12.29: updated syntax to reflect @Olga’s comments) This option, as the name suggests, tells JSHint that your code uses ECMAScript 6 specific syntax. http://jshint.com/docs/options/#esversion Edit 2017.06.11: added another option based on this answer. While inline … Read more

Class constants in python

In python, I want a class to have some “constants” (practically, variables) which will be common in all subclasses. Is there a way to do it with friendly syntax? Right now I use: and I’m wondering if there is a better way to do it or a way to do it without then having to … Read more

Constant pointer vs Pointer to constant

declares ptr a pointer to const int type. You can modify ptr itself but the object pointed to by ptr shall not be modified. While declares ptr a const pointer to int type. You are not allowed to modify ptr but the object pointed to by ptr can be modified. Generally I would prefer the declaration like this which make it easy to read and understand (read from right to left):