constants

Best way to use a property to reference a Key-Value pair in a dictionary

This is a fairly trivial matter, but I'm curious to hear people's opinions on it. If I have a Dictionary which I'm access through properties, which of these formats would you prefer for the property? /// <summary> /// This class's FirstProperty property /// </summary> [DefaultValue("myValue")] public string FirstProperty { get { ...

In Delphi 7, why can I assign a value to a const?

I copied some Delphi code from one project to another, and found that it doesn't compile in the new project, though it did in the old one. The code looks something like this: procedure TForm1.CalculateGP(..) const Price : money = 0; begin ... Price := 1.0; ... end; So in the new project, Delphi complains that "left side ca...

What is the difference between const and readonly?

What is the difference between const and readonly and do you use one over the other? ...

What is the best way to implement constants in Java ?

I've seen examples like this: public class MaxSeconds { public static final int MAX_SECONDS = 25; } and supposed that I could have a Constants class to wrap constants in, declaring them static final. I know practically no Java at all and am wondering if this is the best way to create constants. ...

Is there any way to use a "constant" as hash key in Perl?

Is there any way to use a constant as a hash key? For example: use constant X => 1; my %x = (X => 'X'); The above code will create a hash with "X" as key and not 1 as key. Whereas, I want to use the value of constant X as key. ...

Are the values of pi and e available in the .Net framework?

Without calculating them, I mean? ...

Java constants in JSP

Hi, I have a class that defines the names of various constants, e.g. class Constants { public static final String ATTR_CURRENT_USER = "current.user"; } I would like to use these constants within a JSP without using Scriptlet code such as: <%@ page import="com.example.Constants" %> <%= Constants.ATTR_CURRENT_USER %> There appea...

How do I use constants from a Perl module?

If I define a constant in a Perl module, how do I use that constant in my main program? (Or how do I call that constant in the main program?) ...

When to use a private constant?

Is it right to use a private constant in the following situation: Say I have a game with a lives variable and a startingLives variable. At the start of the game I set the lives variable to equal the startingLives variable. This is how I would normally do it: private var lives:int = 0; private var startingLives:int = 3; private functio...

How can I reduce duplication in constants?

I have this Perl script with many defined constants of configuration files. For example: use constant { LOG_DIR => "/var/log/", LOG_FILENAME => "/var/log/file1.log", LOG4PERL_CONF_FILE => "/etc/app1/log4perl.conf", CONF_FILE1 => "/etc/app1/conf...

XAML : Binding textbox maxlength to Class constant

I am attempting to bind a WPF textbox's Maxlength property to a known constant deep within a class. I am using c#. The class has a structure not too dissimilar to the following: namespace Blah { public partial class One { public partial class Two { public string MyBindingValue { get; set; } ...

What are your thoughts on method scoped constants?

For example: public void doSomething() { final double MIN_INTEREST = 0.0; // ... } Personally, I would rather see these substitution constants declared statically at the class level. I suppose I'm looking for an "industry viewpoint" on the matter. ...

PHP Constants: Advantages/Disadvantages

Lately I've been in the habit of assigning integer values to constants and simply using the constant name as a means of identifying its purpose. However, in some cases this has resulted in the need to write a function like typeToString($const) when a string representation is needed. Obviously this is inefficient and unneccesary, but is o...

VB.NET: What's the suffix (type character) for "Byte" numeric constants?

Just out of curiosity: I know I can tell the compiler if I want a value to be interpreted as a certain numeric type, e.g. as Integer (32 bit signed) this way appending an "I" (type character) to the constant value: Private Function GetTheAnswerAsInteger() As Integer Return 42I End Function There's also "S" for Short or "D" for D...

What is the best way to handle constants in Ruby when using Rails?

I have some constants that represent the valid options in one of my model's fields. What's the best way to handle these constants in Ruby? ...

Creating a constant Dictionary in C#

What is the most efficient way to create a constant (never changes at runtime) mapping of strings to ints? I've tried using a const Dictionary, but that didn't work out. I could implement a immutable wrapper with appropriate semantics, but that still doesn't seem totally right. For those who have asked, I'm implementing IDataError...

Is it better in C++ to pass by value or pass by constant reference?

Is it better in C++ to pass by value or pass by constant reference? I am wondering which is better practice. I realize that pass by constant reference should provide for better performance in the program because you are not making a copy of the variable. ...

Dynamic Allocation of Constant memory in CUDA

Hello, I'm trying to take advantage of the constant memory, but I'm having a hard time figuring out how to nest arrays. What I have is an array of data that has counts for internal data but those are different for each entry. So based around the following simplified code I have two problems. First I don't know how to allocate the dat...

Environment constants

Is there an equivalant to Environment.NewLine in DotNet for a Tab character? ...

C# Technique - Getting Constant Values By String

Is there any good way to convert strings like "xlSum", "xlAverage", and "xlCount" into the value they have under Microsoft.Office.Interop.Excel.XlConsolidationFunction? I guess reflection would be slow (if its possible). There are about 10 of these constant values. I was trying to avoid a large switch statement if possible. ...