constants

A few C# naming convention questions

1) What's the policy for declaring a variable? Should you always use the keyword private, or is it OK to skip it? string MyVar1; vs. private string MyVar1; The only reason I see is that Microsoft one day can change the default access modifiers to public instead of private. Where does it say that private is optional? Any references...

C# binary constants representation

I am really stumped on this one. In C# there is a hexadecimal constants representation format as below : int a = 0xAF2323F5; is there a binary constants representation format? ...

Accessing constants using Key-Value Coding in Objective-C

I'm making a program that has a lot of constants. I decided to put them all into a separate class and I'm importing it by the classes that need it. The files look similar to this // Constants.h extern const int baseCostForBuilding; extern const int maxCostForBuilding; // etc // Constants.m const int baseCostForBuilding = 400; const int...

Too many constants?

Is there such a thing as too many constants in a project? What are some general rules of thumb about where the use of constants starts to become inappropriate and should be refactored? Perhaps moving some of these values into a model tier, or configuration files, etc. A concrete example. Using the pureMVC framework for Actionscript/Flex...

Why do we always declare constants to be powers of 2?

Most of the constants I see in others code are powers of 2, i.e. #define SIZE 256 or public static final int SIZE = 2048; Is there any particular reason why we do that instead of i.e. #define SIZE 257 ? Thanks in advance ...

Do constants always keep the same value?

I've been reading that when conforming to the NSCoding protocol and implementing the methods like -encodeWithCoder:, and encoding objects with i.e. [coder encodeObject:self.someObject forKey:kSomeConstantToIdentifyFields]; this constant is used to keep track of that object. So later, with help of that constant, the appropriate "field...

C#: Is this field assignment safe?

In this snippet: class ClassWithConstants { private const string ConstantA = "Something"; private const string ConstantB = ConstantA + "Else"; ... } Is there a risk of ending up with ConstantB == "Else"? Or do the assigments happen linearly? ...

PHP Constants Containing Arrays?

This failed: define('DEFAULT_ROLES', array('guy', 'development team')); Apparently, constants can't hold arrays. What is the best way to get around this? define('DEFAULT_ROLES', 'guy|development team'); //... $default = split(DEFAULT_ROLES, '|'); This seems like unnecessary effort. ...

Constants in Oracle SQL query

I am new to Oracle (though familiar with SQL) and have to write a fairly complex query where a value derived from the current date is used many times. Rather than calculate the value each time, it would seem obvious to declare a constant for the purpose. However, when I then try to use my DateIndex constant in the subsequent SELECT sta...

Reflecting constant properties/fields in .net

Possible Duplicate: Type.GetFields() - only returning public const fields I have a class which looks like as follows: public class MyConstants { public const int ONE = 1; public const int TWO = 2; Type thisObject; public MyConstants() { thisObject = this.GetType(); } public void EnumerateCo...

What is the best way of comparing a string variable to a set of string constants?

if statement looks too awkward, because i need a possibility to increase the number of constatnts. Sorry for leading you into delusion by that "constant" instead of what i meant. ...

How to store and retrieve constants that are not configurable in ASP.NET?

What is the best way for classes to retrieve/store constants without getting them through web.config? ...

Initialize Objective-C string constants from plist

Hi, I have defined a constants class within my iphone program using the 'extern' and 'const' keywords as in the example described in: http://stackoverflow.com/questions/538996/constants-in-objective-c At this point, I am trying to initialize some string constants from the contents of a plist file, instead of being defined right in the...

Raising an exception on updating a 'constant' attribute in python

As python does not have concept of constants, would it be possible to raise an exception if an 'constant' attribute is updated? How? class MyClass(): CLASS_CONSTANT = 'This is a constant' var = 'This is a not a constant, can be updated' #this should raise an exception MyClass.CLASS_CONSTANT = 'No, this cannot be updated, ...

How to best represent Constants (Enums) in the Database (INT vs VARCHAR)?

Hello, what is the best solution in terms of performance and "readability/good coding style" to represent a (Java) Enumeration (fixed set of constants) on the DB layer in regard to an integer (or any number datatype in general) vs a string representation. Caveat: There are some database systems that support "Enums" directly but this wo...

C#, how to handle constant tables

It seems strange that the language apparently includes no suitable functionality. I find myself with data that would best be expressed as a multi-dimensional array but it's utterly constant, there is no way anyone could want to change it without also changing the associated code. Faced with such stuff in Delphi the answer is obvious--a...

Is there a reason to use enum to define a single constant in C++ code?

The typical way to define an integer constant to use inside a function is: const int NumbeOfElements = 10; the same for using within a class: class Class { ... static const int NumberOfElements = 10; }; It can then be used as a fixed-size array bound which means it is known at compile time. Long ago compilers didn't support th...

Why do you need to append an L or F after a value assigned to a C++ constant?

I have looked at quite a few places online and can't seem to find a good explanation as to why we should append an F or L after a value assigned to a C++ constant. For example: const long double MYCONSTANT = 3.0000000L; Can anyone explain why that is necessary? Doesn't the type declaration imply the value assigned to MYCONSTANT is a l...

Objective c - static members and constants

Whats the difference between: @interface SomeClass : NSObject { NSObject *something; } and @interface SomeClass : NSObject { } NSObject *something; ? Also, what's the difference between Java's final and Objective C (C)'s const? And where should I declare static class members for the following situations: 1. When only the clas...

Is Java guaranteed to inline string constants if they can be determined at compile time.

Consider this case: public Class1 { public static final String ONE = "ABC"; public static final String TWO = "DEF"; } public Class2 { public void someMethod() { System.out.println(Class1.ONE + Class1.TWO); } } Typically you would expect the compiler to inline the ONE and TWO constants. However, is this behavior guarant...