static

When is a static constructor called in C#?

When I have class containing a static constructor, is that constructor called when the assembly containing the class is first loaded or when the first reference to that class is hit? ...

Reference Static Methods/Variables in Java from an Instance

Can anyone explain to me why java allows you to access static methods and members from an instance? A bad example, if I have an object called RedShape and it has a static method called getColor() which returns "red", why does java allow you to call the static method from an instance of RedShape? To me this seems to violate some of the co...

Is Resharper's recommendation to make my private method static a good recommendation?

I've recently noticed that when I create private methods that set a few fields in the objects passed to them that Resharper puts up a hint stating that the method can be made static. Here's a greatly simplified example of the sort of method I might have. private void MakeStatusTheSame(MyClass mc, MySecondClass msc) { mc.Status = ms...

How to localise a static website?

For a website I'm doing, I'm only using static content such as HTML, javascript, CSS, images (no PHP or server-side language). I want to be able to localize in English and French, but I'm unsure what would be a good solution. Here are the solutions I have in mind so far: Duplicate HTML pages Pros: simple, SEO friendly Cons: a pain if I...

C#: How does the static object.Equals check for equality?

Say you have two different classes where each have their own implementation of Equals; which one is used? What if only one of them have one? Or none of them? Are any of the following lines equivalent? object .Equals( first, second ) first .Equals( second ) second .Equals( first ) I'm guessing that the first two might be equivalent, bu...

C# class design without using "Internal" or "Static"?

I have a bunch of data I want to instantiate in a class, and for each variable I want to ensure a specific set of methods are also defined. IE: [TypeA] VarA [TypeB] VarB [TypeC] VarC FA1() which is a function of VarA and VarB FA2() which is a function of VarA and VarC FB1() which is a function of VarB and VarA FB2() which is a functio...

Handling static constructor exceptions in a multithreaded application

I have a static class that creates several worker threads in its constructor. If an exception occurs before the workers have been created my Application.ThreadException handler (used to shut the app down if an error not known to be recoverable occurs) triggers normally and everything is fine. Once the first worker thread has been creat...

Static build in QT on Windows Vista

Hello, I am currently running Windows Vista Home Premium, and I have developed an application with my friend using QT Creator. We are now trying to deploy our application as just one executable, so we are trying to do a static build. We have added CONFIG += static in our .pro file. We are using this documentation to help us: http://d...

F# Operator Resolution

Hi, I have a class called Vector which implements a number of operators such as + and properties such as Count. Vector is also subtyped by classes such as DenseVector, SparseVector which inherit from Vector. Now in F# when I write the following let foo (v : #Vector) (w : #Vector) = v + w let bar (v : #Vector) (w : #Vector) = v.Count + ...

C++ singleton vs. global static object

A friend of mine today asked me why should he prefer use of singleton over global static object? The way I started it to explain was that the singleton can have state vs. static global object won't...but then I wasn't sure..because this in C++.. (I was coming from C#) What are the advantages one over the other? (in C++) ...

Static Variable in Web Application

Hello All, It's well known fact that static variable cannot be used in Web Application as it remains static through out application.But,is there any scenario where static variable can be used in Web Application to achieve the functionality? Thanks ...

Static vs. shared libraries for a media player

I'm not going to go into detail on the "media player" part except the fact that it will obviously use plug-ins, which will be a simple dynamic library that is loaded at runtime. Now, I could link those plug-ins dynamically to their dependencies, or I could link them statically. Both have their advantages and disadvantage - I'm not counti...

Static const string won't get initialized

I have some static const strings as private members of my C++ class. I am aware of the declaration in .h and definition (and initialization) in .cpp practice. In the class constructor I invoke a function that uses these static strings. Surprisingly when in constructor, the strings remain uninitialized (empty strings) which is creating a ...

Where can I find static/dynamic code analysis tools for XSLT?

Are there any static or dynamic code analysis tools that analyze XSLT/XSL code? The resources I have been able to find so far are: 1. Oxygen xml editor 2. http://gandhimukul.tripod.com/xslt/xslquality.html which looks faily basic in its capabilities ...

Hybrid static/dynamic Google Map

Ever noticed that when you go to maps.google.com and do a search (say, car wash), it renders a lot of results (represented by small circles) and a few prominent ones (seen as regular-size pins)? Notice how quickly it does this? From what I can tell from analyzing this in Firebug, much of this is generated on the server and sent to the ...

PHP: performance of static methods vs functions

In PHP, (unlike what i originally thought) there an overhead of calling static methods vs simple functions. On a very simple bench, this overhead is over 30% of the calling time (the method just returns the parameter): // bench static method $starttime = microtime(true); for ($i = 0; $i< 10*1000*1000; $i++) SomeClass::doTest($i); ech...

Nginx doesn't serve static

I'm running django on ubuntu server 9.04 Django works well, but nginx doesn't return static files - always 404. Here's the config: server { listen 80; server_name localhost; #site_media - folder in uri for static files location /static { autoinde...

How was the syntax chosen for static methods in Python?

I've been working with Python for a while and I find the syntax for declaring methods as static to be peculiar. A regular method would be declared: def mymethod(self, params) ... return A static method is declared: def mystaticethod(params) ... return mystaticmethod = staticmethod(mystaticmethod) If you don't add the s...

Other than testing, how is Dependency Injection any better than static classes/methods?

Other than testability, what's the big advantage of utilizing D.I. (and I'm not talking about a D.I. framework or IoC) over static classes? Particularly for an application where you know a service won't be swapped out. In one of our c# application, our team is utilizing Dependency Injection in the web web GUI, the service layer, and th...

Static members in VB.NET

I used to write this: Private Sub Example() Static CachedPeople As List(Of MyApp.Person) If CachedPeople Is Nothing Then CachedPeople = New List(Of MyApp.Person) End If ...rest of code... End Sub But then wondered if I could reduce this to: Private Sub Example() Static CachedPeople As New List(Of MyApp.Person) ...rest of code... ...