function

Ways to call a Javascript function using the value of a string variable?

I've seen this technique for calling a Javascript function based on the value of a string variable. function foo() { alert('foo'); } var test = 'foo'; window[test](); //This calls foo() Is this the accepted way to do it or is there a better way? Any cross-browser issues to worry about? ...

Have you written very long functions? If so, why?

Hi, I am writing an academic project about extremely long functions in the Linux kernel. For that purpose, I am looking for examples for real-life functions that are extremely long (few hundreds of lines of code), that you don't consider bad programming (i.e., they won't benefit from decomposition or usage of a dispatch table). Have y...

Convert an integer to a byte[] of specific length

I'm trying to create a function (C#) that will take 2 integers (a value to become a byte[], a value to set the length of the array to) and return a byte[] representing the value. Right now, I have a function which only returns byte[]s of a length of 4 (I'm presuming 32-bit). For instance, something like InttoByteArray(0x01, 2) should r...

What's the most practical way to have "functions in a dictionary" in Java?

Hello folks, When programming with C/C++ or Python I sometimes used to have a dictionary with references to functions according to the specified keys. However, I don't really know how to have the same -- or at the very least similar -- behavior in Java allowing me dynamic key-function (or method, in Java slang) association. Also, I did...

should C++ class "helper functions" be members, free, or anon-namespace free?

So, I have a class. It's a useful class. I like a lot. Let's call it MyUsefulClass. MyUsefulClass has a public method. Let's call it processUsefulData(std::vector<int>&). Now suppose processUsefulData really does two things and I want to refactor it from this: std::vector<int> MyUsefulClass::processUsefulData(std::vector<int>& data) { ...

[PHP] accessing array from other function in a class

i have 2 functions in a class, in the first one i have something like that: public function func1() { $test = array(1,2,3); return $test; } how to copy the contents from $test in the second function? public function func2() { $newarray = $this->func1->test; print_r($newarray); } Sorry, but i have really no idea, how to make this :...

PHP Class error on calling method

Hi, I have a class to connect to my database, strip stuff and return things from a db query. Anyhow, the problem I am having is that I am tryinmg to call runQuery() method but every time I try, I get this error: Fatal error: Call to undefined function runMyQuery() in DatabaseConnector.php line 22 Any ideas perhaps? I know runQuery ...

Fatal error: undefined function - why?

I'm new to object oriented programming in PHP. I included a class and called it, then, inside this class's constructor I'm calling a private function called handleConnections. For some reason, it's giving me a fatal error (undefined function). Any idea why? The class: class Test { function __construct() { handleConnections(...

SQL user-defined functions vs. stored procedure branching

Hello. I currently am working on a legacy application and have inherited some shady SQL with it. The project has never been put into production, but now is on it's way. During intial testing I found a bug. The application calls a stored procedure that calls many other stored procedures, creates cursors, loops through cursors, and many ot...

Function Call Guard

Suppose I have a free function called InitFoo. I'd like to protect this function from being called multiple times by accident. Without much thought I wrote the following: void InitFoo() { { static bool flag = false; if(flag) return; flag = true; } //Actual code goes here. } This looks like a big wa...

Can't I use "DECLARE" in table function ?

Thanks for your message I solved my problem like this ALTER FUNCTION [VEZNE].[fnMakbuzIslemGetir] ( @refNo as int ) RETURNS @tablename TABLE (kontrol1 char(1),key0 numeric(18,0) ,tarih datetime ,hizkod char(12),hizad char(75),ytlhizfiyat decimal(18,2) ,hizmiktar numeric(18,2),ytlhiztutar decim...

PHP language engine

Hello everyone! I'm writing Content Management software in PHP (which should not be bigger then 3kb when minified), but what engine should I use for languages (english, dutch, german, chinese, etc...)? I was thinking of creating a function called function _(){} that reads strings from a file (a .ini file or similar). But does somebod...

Haskell Function Cheat Sheet

Is there a descriptive listing of common Haskell functions in prelude and some of the core libraries such as Data.List and Data.Char? I am just learning Haskell and I find myself frequently performing time-inefficient searches for functions that I know exist but for which I have forgotten the name. Such searches tend to distract my f...

Why is reassigning Object.prototype not working?

Why this is not working? // this one works as I expected, when objSayHello() Object.prototype.objSayHello = function(){alert('Hello,from OBJECT prototype')}; // NOT working ! Object.prototype ={objSayHello: function(){alert('Hello,from OBJECT prototype')}}; objSayHello(); ...

php class call external class

I have a php page that calls and runs a method called pagestart() in a class called construct. Later in that same page I call a different method in a different class. If that different method errors for any reason I would like to have it call the error() function in the construct class. My question is is there a way to call the error() ...

in c: func(void) vs. func()

When a C function does not accept any arguments, does it have to be declared/defined with a "void" parameter by the language rules? PC-Lint seems to have problems when there's nothing at all in the argument-list, and I was wondering if it's something in the language syntax that I don't know about. Edit: I just found a duplicate (back-d...

What is C# equivalent of preg_match_all?

The theme is i opened a file and get all it's data into string and i am matching this string with the regex returning none. But the same regex in PHP is returning values for the same text using preg_match_all. Anyone having a idea? ...

Extern Function???

Simple1.c ------------------------------------ #include"stdio.h" int f1(int x, int y) { printf("%d %d", x, y); return x+y; } ----------------------------------- Simple2.c ------------------------------------ #include"stdio.h" extern int f1(int x,int y); void main() { printf(" %d\n", f1(5,6)); } ----------------------------------- I w...

jquery: follow up html with function?

Hi, I know this doesn't work: $('#section').html($(data), function() { $('#section').fadeIn(); }); How would I go on writing it? It should be simply, but I've been away from jQuery for too long. Thanks! ...

How long should functions/methods should be in average?

Hi there... We've all read excessively long methods or functions, where your eyes end up bleeding when you reach the return statement. We've also seen those one-liner functions that seem pointless... I just wanted to ask: which do you think is the best average length for a function/method? Having into account that every language has it...