static

Ruby thread-safe class variables

I have a number of models that load a collection of strings, based on the user's i18n locale. In order to simplify things, each model that does so includes the following module: module HasStrings def self.included(klass) klass.extend ClassMethods end module ClassMethods def strings @strings ||= reload_strings! e...

Is it possible to generate a global list of marked strings at compile time/runtime?

So, I'm working on translating my C++ app into multiple languages. What I'm currently using is something like: #define TR(x) (lookupTranslatedString( currentLocale(), x )) wcout << TR(L"This phrase is in English") << endl; The translations are from a CSV file which maps the english string to the translated string. "This phrase is in...

Portable way to link statically against one of the libraries

I am creating a utility which depends on libassuan aside other depends. While these ‘others’ provide shared libraries, libassuan comes with static one only. libassuan comes with simple libassuan-config tool which is meant to provide CFLAGS & LDFLAGS for the compiler/linker to use. These LDFLAGS refer to the library as -lassuan. The res...

C++ privately contructed class

How can I call a function and keep my constructor private? If I make the class static, I need to declare an object name which the compiler uses to call the constructor, which it cannot if the constructor is private (also the object would be extraneous). Here is the code I am attempting to use (it is not compilable): I want to keep the ...

Initializing static array of strings (C++)?

I can't for the life of me figure out how to do this properly. I have a class that needs to store some constants (text that corresponds to values in an enum type) - I have it declared like this (publicly) in my class: const static char* enumText[]; And I'm trying to initialize it like this: const char* MyClass::enumText[] = { "A", "...

What's the correct alternative to static method inheritance (C#)

I understand that static method inheritance is not supported in C#. I have also read a number of discussions (including here) in which developers claim a need for this functionality, to which the typical response is "if you need static member inheritance, there's a flaw in your design". OK, given that OOP doesn't want me to even think a...

C++: Hide base static member

In C++, is it possible to have a child class "hide" a base class' static fields and methods? (i.e. A has a field named ABC of type int, B:A and B has a field named ABC of type int) ...

Java Thread using static or non-static nested class

I've encountered a very strange problem. My program looks like this: class Outter{ class Inner extends Thread { public void run(){ // do something } } public void func() { new Inner().start(); // Thread.sleep() for a while to see if the above thread has fin...

C++ static operator overloading

Is it possible to overload C++ class operators in the static context? e.g. class Class_1{ ... } int main() { Class_1[val]... } ...

PHP: Use variable name to call static function on Singleton Object

I need to call a static function from an object using the Singleton design, but using a variable as the class name. The best way, $class::getInstance();, is only available in PHP 5.3, and the other way I found, call_user_func(array($class, 'getInstance'));, results in the maximum execution time being breached. Does anyone know why this ...

C# non-persistent `static` keyword?

Hi, I come from a C/C++ background and am having trouble doing some things in C#. My problem right now is that I need a static keyword that works like in C++. So that the property is global to all instances of the class, which is what C#'s does. But what I don't want is the persistence in C#(/ASP.NET). I want the static property global t...

Alternatives to CAT.NET for website security analysis

I'm looking for an alternative tool to CAT.NET for performing static security scans on .NET code. Currently the CAT.NET tooling/development is at a somewhat fragile stage and doesn't offer the reliability that I'm looking for. Are there any alternative static code analyzers that you use for detecting security issues? ...

Design problem with nearly static data

I am developing an interpreter of a simple programming language. There are tree-structured dynamic data, where each of the data nodes has an associated (owned) type-object. There are several kinds of the types - ListType, StructType etc. - and one special - TypeRef. The TypeRef holds a name (a string) which refers to some concrete type...

Which is the best approach?

I have a question regarding struts. I have a HashMap which has nearly 50 entries. Now I have to define this map inside an action class, say TestAction. As you know, this action class extends the Action class. Now my doubt is fundamental: Should I load the map as static? What are the advantages of loading this Map static? If I am g...

Are fluid websites worth making anymore?

Hey guys, I'm making a website now and I am trying to decide if I should make it fluid or not. Fixed width websites are much easier to make and also much easier to make them appear consistent. To be honest though, I personally prefer looking at fluid websites that stretch to the full width of my monitor. My question comes from the fact...

private final static attribute vs private final attribute

In java, what's de difference between: private final static int NUMBER = 10; and private final int NUMBER = 10; both are private and both are final, the difference is the static attribute. What's better to use? ...

Should a "static final Logger" be declared in UPPER-CASE?

In Java, static final variables are constants and the convention is that they should be in upper-case. However, I have seen that most people declare loggers in lower-case which comes up as a violation in PMD. e.g: private static final Logger logger = Logger.getLogger(MyClass.class); Just search googleor SO for "static final logger" ...

Assigning to static readonly field of base class

public class ClassA { public static readonly string processName; } pubic class ClassB : ClassA { static ClassB() { processName = "MyProcess.exe"; } } I am getting an error while compiling the above C# code. The error says -- "A static readonly field cannot be assigned to (except in a static constructor or a ...

When are static C++ class members initialized?

There appears to be no easy answer to this, but are there any assumptions that can be safely made about when a static class field can be accessed? EDIT: The only safe assumption seems to be that all statics are initialized before the program commences (call to main). So, as long as I don't reference statics from other static initializa...

Can I call a static method inside another method?

fundamental question: How can I call a static method inside another method. Please help!! public static class Class1 { public static string RenderCompareStatus() { bool isFound = Class1.Found(id); } private static bool Found(string id) { } //Error message: does not contain definition for Found ...