I have been going back and forth between C# and Java for the last 8 years.
One thing that strikes me is that I have completely stopped using the "Template Method" design pattern in C#. Actually, in C# I Have come to think of this pattern as an anti-pattern.
http://en.wikipedia.org/wiki/Template_method_pattern
Coming back to Java, I ...
At the moment, I have some functions which look like this:
private bool inFunction1 = false;
public void function1()
{
if (inFunction1) return;
inFunction1 = true;
// do stuff which might cause function1 to get called
...
inFunction1 = false;
}
I'd like to be able to declare them like this:
[NoReEntry]
public vo...
I am thinking it is a best practice to declare them as static, as it makes them invisible outside of the module.
What are your thoughts on this?
...
Why main must be declared as if it has external linkage?
Why it should not be static?
what is meant by external linkage??
...
I have the following code:
var address;
getAddress(0,0);
function getAddress(latlng)
{
if (latlng != null)
{
geocoder.getLocations(latlng,
function(addresses)
{
if(addresses.Status.code == 200)
{
address = addresses.Placemark[0].address.toString();
alert(address); // Outputs something :...
I write a Text Editor with Java , and I want to add Undo function to it
but without UndoManager Class , I need to use a Data Structure like Stack or LinkedList but the Stack class in Java use Object parameters e.g : push(Object o) , Not Push(String s)
I need some hints or links .
Thanks
...
What is a generic list manipulation function in C?
(I saw this when I was going through some materials.)
What is the difference between this function and a function which can accept elements of any kind?
Are they same...? How can we implement them individually if they are not same?
...
I'm writing a global error handling "module" for one of my applications.
One of the features I want to have is to be able to easily wrap a function with a Try{} Catch{} block, so that all calls to that function will automatically have the error handling code that'll call my global logging method. (To avoid polluting the code everywhere ...
I'm trying to do the following in python:
In a file called foo.py:
# simple function that does something:
def myFunction(a,b,c):
print "call to myFunction:",a,b,c
# class used to store some data:
class data:
fn = None
# assign function to the class for storage.
data.fn = myFunction
And then in a file called bar.py:
import f...
Is there any way to have a look at signatures of anonymous functions in ActionScript 3 during runtime?
I would like to validate Function objects passed in as arguments to other functions and make sure that they accept the correct number of arguments (with the correct types) and return a value of the correct type.
flash.utils.describeTy...
I'd like to call a function in python using a dictionary.
Here is some pseudo-code:
d = dict(param='test')
def f(param):
print param
f(d)
This prints {'param': 'test'} but I'd like it to just print test.
I'd like it to work similarly for more parameters:
d = dict(p1=1, p2=2)
def f2(p1,p2):
print p1, p2
f2(d)
Is this pos...
I am trying to find a way to get the source code for (user defined) PHP functions in a string.
For normal code this is easy, using reflection I can find the file and linenumbers where the function is defined, then I can open the file and read the function source code.
This will not work if a function is defined in eval'd code. I do not...
Not many are aware of this feature, but Python's functions (and methods) can have attributes. Behold:
>>> def foo(x):
... pass
...
>>> foo.score = 10
>>> dir(foo)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__get__', '__getattribute__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce_...
I'm trying to create a function which takes an array as an argument, adds values to it (increasing its size if necessary) and returns the count of items.
So far I have:
int main(int argc, char** argv) {
int mSize = 10;
ent a[mSize];
int n;
n = addValues(a,mSize);
for(i=0;i<n;i++) {
//Print values from a
}...
A bit of a neophyte haskell question, but I came across this example in Haskell's tutorial examples. For "find the last element of a list" there are some obvious versions, like
last' [x] = x
last' (_:xs) = last' xs
But I can't make sense of an alternate version presented:
myLast' = foldr1 (const id)
So, in trying to make sense o...
Hi, I have no clue about trigonometry, despite learning it in school way back when, and I figure this should be pretty straightforward, but trawling through tons of trig stuff on the web makes my head hurt :) So maybe someone could help me...
The title explains exactly what I want to do, I have a line:
x1,y1 and x2,y2
and want a funct...
Here's the deal. I have a big class hierarchy and I have this one method that is extended all the way through. The method always has to look at one or two more variable at each new level and these variable depend on the actual class in the hierarchy. What I want to do is check those two extra variables then call the superclass's version ...
I have a Java method which returns an array of doubles. I would then like to store these values in individual variables in the calling function. Is there an elegant way of doing this in Java.
I could write it as this:
double[] returnValues = calculateSomeDoubles();
double firstVar = returnValues[0];
double secondVar = returnValues[1];...
Hi
I have a table that looks a bit like this actors(forename, surname, stage_name);
I want to update stage_name to have a default value of
forename." ".surname
So that
insert into actors(forename, surname) values ('Stack', 'Overflow');
would produce the record
'Stack' 'Overflow' 'Stack Overflow'
Is this possible?
Thank...
Routines, procedures, methods - whatever you call them, they are important building blocks for us developers. What single characteristic would you rate as the most important one?
(By providing one characteristic per answer, it is possible to vote for them individually. I.e. the purpose of this question is not to decide single out one ch...