constants

Char Array vs String: which is better for storing a set of letters

I need to store in a constant class 4 letter of a code. I can do: static final String CODE_LETTERS = "TRWAG"; or static final char[] CODE_LETTERS = {'T', 'R', 'W', 'A', 'G'}; After, I can obtain one of that characters in two ways: final char codeLetter = CODE_LETTERS.charAt(index); or final char codeLetter = CODE_LETTERS[index]...

How do I access math constants (eg. M_PI) in Visual C++ 2008?

I want to use the math constants, such as M_PI and M_E, in Visual C++ 2008. I assumed they were defined in the cmath header. ...

Is there a function that returns the character/string at a point in a .txt? (C++)

I know its possible to get a part of a .txt, then convert it to an integer, then store it in a variable, but is it possible to to that in a single declaration. (The variable needs to be global). Ie: [data.txt] 1020 [convert_data.cpp] #include<fstream> fstream convert("data.txt"); //way to declare something equal to A PARTICULAR POINT i...

How can I make this declaration work?

EDIT: I also got an answer to make sector a vector of vectors: vector<vector<char>>sector; and that gets rid of the rest of my errors. EDIT: I've made sector an array of pointers as someone suggested, and still get three errors: EDIT: I have edited the program, but it has not fixed all of the errors: I have this section of a progra...

Can I use a Perl constant in the glob operator?

I'm parsing XML files with something like: while (<files/*.xml>) { ... } I want to use a constant to 'files', say use constant FILES_PATH => 'files'; while (<FILES_PATH/*.xml>) { ... } I hope you understand the idea, and can help me :).. Thank you in advance. ...

Why does C# not allow const and static on the same line?

Why does C# not allow const and static on the same line? In Java, you must declare a field as 'static' and 'final' to act as a constant. Why does C# not let you declare const's as final? I make the further distinction that in Java, every interface is public and abstract, whether this is explicitly declared or not. Aren't const's ef...

What to define Predefined Constants as.

I have a database class that automatically sets up a connection to the database and does some basic input filtering and whatnot. I am looking at setting some predefined constants to adjust the behavior of the class methods. What should I set the values of the constants as? Since the values will never be referred to, or compared, direc...

Java - Is This Good Programming Practice?

Hi folks, Just wondering if the following is considered to be good programming practice or not? I like to keep my individual source files as concise and uncluttered as possible, but I'm wondering what more experienced coders would think of it. I especially like the idea of the Settings.java class to keep all of my "Magic Numbers" in th...

Can you require a function parameter to be a static constant of the function's Class?

Let's say I have a Custom Event Class, and it has several Event types stored in static Constant: package customEvents { public class { public static const DISAPPEAR_COMPLETELY:String = "disappearCompletely"; public static const SIT_DOWN:String = "sitDown"; public static const STAND_UP:String = "standUp...

Javascript: constant properties

Hey, In javascript, can I declare properties of an object to be constant? Here is an example object: var XU = { Cc: Components.classes }; or function aXU() { this.Cc = Components.classes; } var XU = new aXU(); just putting "const" in front of it, doesn't work. I know, that i could declare a functi...

Constants in a C# Web Application

Does it make sense to create a constant for the value of a penny? For example, if I needed to decrement an amount by a penny. Do you think it is more readable if the code said: amount -= Constants.StandardAmounts.Penny Or should I not even bother and just use .01. ...

How do I declare MAX_DOUBLE in VB6?

According to the MSDN help for VB6 Floating-point values can be expressed as mmmEeee or mmmDeee, in which mmm is the mantissa and eee is the exponent (a power of 10). The highest positive value of a Single data type is 3.402823E+38, or 3.4 times 10 to the 38th power; the highest positive value of a Double data type is 1.7976931348623...

.NET enumerations of symbolic constants for string values

I have a list of rather meaningless codes that I'm processing with a VB.NET Windows application. For the business logic I'm writing to process those codes, I'd like to use meaningful constants (like ServiceNotCovered or MemberNotEligible) instead of the original codes (like "SNCV" and "MNEL"). As far as I can tell, Enums can only map to...

Declaring a Const Variable in R

I'm working in R, and I'd like to define some variables that I (or one of my collaborators) cannot change. In C++ I'd do this: const std::string path( "/projects/current" ); How do I do this in the R programming language? Edit for clarity: I know that I can define strings like this in R: path = "/projects/current" What I really wa...

constants and pointers in C

I wanted to change value of a constant by using pointers. Consider the following code int main() { const int const_val = 10; int *ptr_to_const = &const_val; printf("Value of constant is %d",const_val); *ptr_to_const = 20; printf("Value of constant is %d",const_val); return 0; } As expected the value of consta...

Are string constants overrated?

It's easy to lose track of odd numbers like 0, 1, or 5. I used to be very strict about this when I wrote low-level C code. As I work more with all the string literals involved with XML and SQL, I find myself often breaking the rule of embedding constants in code, at least when it comes to string literals. (I'm still good about numeric ...

Can I get CONST's defined on a PHP class?

I have several CONST's defined on some classes, and want to get a list of them. For example: class Profile { const LABEL_FIRST_NAME = "First Name"; const LABEL_LAST_NAME = "Last Name"; const LABEL_COMPANY_NAME = "Company"; } Is there any way to get a list of the CONST's defined on the Profile class? As far as I can tell,...

Storing string values as constants in the same manner as Enum

I know there is a way to make enum work for string types with conversions galore - the code doesn't look pretty. Does anyone know of any way to have something like this: public SOMESTRUCTURE SessionKeys : string { value1 = "value1key", value2 = "value2key", name = "name" } so later in my code I could refer to it as: ...

How can I define constants in a Template Tookit template in a Catalyst app?

I want to use a constant in my TT template. In HTML::Mason (my previous templating engine of choice) I could do: <%once> use MyApp::Constants qw(CONSTANT); </%once> How can I do this in Template Toolkit? As mentioned in the title this is a Catalyst app so I was thinking I could put the constants in the stash but that seems a bit awkwa...

Where should I store reused static string constants in Flex application?

I have two Cairngorm MVC Flex applications (a full version and lite version of the same app) that share many Classes. I have put these Classes into a Flex Library Project that compiles as an SWC. Both applications use some static String constants. Right now, I am storing these in the ModelLocator: package model { [Bindable] publ...