constants

I Want To Optimally Check Defined Constants in PHP

In PHP, depending on your error reporting level, if you don't define a constant and then call it like so: <?= MESSAGE ?> It may print the name of the constant instead of the value! So, I wrote the following function to get around this problem, but I wanted to know if you know a way to do it in faster code? I mean, when I did a speed ...

Anyone know where a good windows constant list lives

I'm trying to set an invalid value to -1.. But I don't like magic numbers.. Anyone know where to find a set of common constants. I'm working in VS6 (ish). I'm trying to read a file from across a network, and I need a bad value for the total file size,so I know if I got valid info on it.. 0 is a valid size so I can't use that. Harper ...

Declaring constants in a project

Hi, I have seen these two approaches for constant declaration which are to be used in the project. Constants in a public module. Constants in a NonInheritable(Sealed) class Does anybody uses any other approach for the constant declartion ? Is there any difference between these approaches, any pros and cons ? Thanks. ...

constant values in Rails

I have some data that I want to store somewhere in my Rails app because I use it for generating form fields, checking a submitted form to ensure its values are valid, etc. Basically, I want the data in one location because I make use of it in several places. Previously, I was defining an initialize method in my controller and initializ...

Java icon constants - Are static constants ok?

I have a number of icons used throughout an application - let's take ok/cancel icons as an example. At the moment they might be a tick and a cross (tick.png, cross.png) but I may want to replace them in future. Also, I would like to keep the resource path in one place. Is this ok: public class Icons { public static Icon OK = new Im...

How to get a c++ constant pointer equivalent in Java?

When I pass an immutable type object(String, Integer,.. ) as final to a method I can achieve the characters of a C++ constant pointer. But how can I enforce such behavior in objects which are mutable? public void someMethod(someType someObject){ /* * code that modifies the someObject's state * */ } All I want is to prevent som...

C# - are all Enum constants?

Are all Enum enumerations constants? Do they get converted to their value at compile-time, or at run-time? ...

Why Can't I Have "public static const string S = "STUFF"; In My Class

When trying to compile my class I get an error: The constant 'NamespaceName.ClassName.CONST_NAME' cannot be marked static. at the line: public static const string CONST_NAME = "blah"; I could do this all of the time in Java. What am I doing wrong? And why doesn't it let me do this? ...

RDoc CONSTANT comments?

In RDoc, is there any way to show constant comments? I would like to comment a constant in a project of mine but and realizing that they dont show up in the RDoc output. I checked documentation which is likely to have comments for their constants, but never saw any (http://www.ruby-doc.org/core/classes/Math.html). It's possible that the...

Why does C# limit the set of types that can be declared as const?

Compiler error CS0283 indicates that only the basic POD types (as well as strings, enums, and null references) can be declared as const. Does anyone have a theory on the rationale for this limitation? For instance, it would be nice to be able to declare const values of other types, such as IntPtr. I believe that the concept of const is ...

How can I embed unicode string constants in a source file?

Hi all: I'm writing some unit tests which are going to verify our handling of various resources that use other character sets apart from the normal latin alphabet: Cyrilic, Hebrew etc. The problem I have is that I cannot find a way to embed the expectations in the test source file: here's an example of what I'm trying to do... /// //...

DRY between Production and Test Code Constants

I normally try to avoid duplication and adhere to the DRY principle. However, I'm wondering about a case like this: public class Feature { final static String FEATURE_LABEL = "blah"; public void doSomething() { ... } ... } public class FeatureTest { ... @Test public void doSomethingShouldMakeSomethingHappen() {...

How to define 64 bit constants in VB?

In Visual Basic Friend Const xxx As UInt64 = 400 * 365 * 24 * 60 * 60 ''// Number of secs in 400 years This fails with the error constant expression not representable in type integer The problem is 400 * 365 * 24 * 60 * 60 is larger than 2^32 I would have thought that by declaring the constant to be UInt64 that it would be OK to a...

using a magic contant class to return file path of calling class

Hi I've been using the following to return filepath and line number of a method echo (__METHOD__) . "() - ln : " . (__LINE__) . "<br />"; I'd really like to update this to a class (say comment.php) class comment { public static function show() { echo (__METHOD__) . "() - ln : " . (__LINE__) . "<br />"; } } th...

For one of my models, I have a few instances that should be auto-populated. How do I handle this?

I have to be specific for this to make sense. In my application I have a model called theme which contains widget color theme information. We provide a few themes, but mainly rely on the user to create their own themes. So the question is: where do I store my themes? If I store them in the theme database, then anytime I switch databas...

In C# how do you accomplish the same thing as a #define

Coming from a C background I'm used to defining the size of the buffer in the following way: #define BUFFER_SIZE 1024 uint8_t buffer[BUFFER_SIZE]; How would you do the accomplish the same thing in C#? Also does the all-caps K&R style fit in with normal C# Pascal/Camel case? ...

PHP Constant doesn't exist: Notice

Hi, I'd like to use constants as config variables within my PHP applications, only when an constant doesn't exist (for whatever reason) it throws me an notice but i'd like that to be a error (or exception) just like when i try to echo a not existing variable. Is that possible without using a seperate function for getting constant value...

What is the significance of starting constants with 'k'?

I'm teaching myself Objective-C and I noticed in a lot of books and examples the use of 'k' and camel-casing in constant definition, e.g. #define kMyConstant 0 What is the significance of the 'k'? Is this unique to Objective-C style, or common to C in general? Why the deviation from (what I've always thought as a best practice) K_MY...

Are there any constants in the .NET framework for the different web method types (GET, PUT, POST, DELETE, HEAD)?

I just noticed while creating a RESTful WCF service that the Method parameter on the WebInvoke attribute is case sensitive (CAPS required). So, [WebInvoke(Method = "Delete")] is not equal to [WebInvoke(Method = "DELETE")] This mistake was causing a ProtocolException: System.ServiceModel.ProtocolException: The remote server ret...

Why isn't String.Empty a constant?

In .Net why is String.Empty read only instead of a constant? I'm just wondering if anyone knows what the reasoning was behind that decision. ...