A function (also called a procedure, method, subroutine, or routine) is a portion of code intended to carry out a single, specific task.

learn more… | top users | synonyms

1
vote
0answers
41 views

WordPress Functions.php file review

I am making a WordPress "framework" for myself. Looking at the functions.php file file, is there redundant or bad code that could be changed or some code that could be good to add? The functions.php ...
4
votes
2answers
82 views

I know I'm not doing these methods right

I'm having difficulty understanding the implementation of methods in classes. I'm pretty sure I'm not doing this the correct way. Can anyone show me the way it should be done. This code works by ...
0
votes
1answer
79 views

If statements in validating different form data types

I am using if statements within my functions to validate form fields and then on the isset event. I want to be able to create many different functions to validate various fields groups and it seems ...
1
vote
1answer
73 views

Scala: What takes precedence: Readability or Elimination of Side Effects

I have a method: def removeExpiredCookies(jar: CookieJar): CookieJar = { val currentDate = System.currentTimeMillis / 1000L jar.filter(_._2._2 > currentDate) } You use said method ...
1
vote
1answer
110 views

Should I use a class as a class factory in Python?

As a bit of a learning project, I decided to take the concept of proxying objects a bit further and extend it to creating proxy classes which create proxy'd objects. I originally found the idea of ...
-1
votes
1answer
33 views

How do I make print function refer to something in a function without calling the function again? [closed]

So here is my code to find the number of weeks between two dates. How can I make the output print "There are 'x' weeks until 'future date'" without calling the futureDate() function? from datetime ...
0
votes
0answers
49 views

Please review this mapreduce code that builds a too large index

There's some problem with this code, it builds a too large index (of 16 000 entities when the expected size is 3700): def index(entity): try: edge = datetime.datetime.now() - ...
1
vote
2answers
54 views

How can I make an easy to understand subtraction accumulator?

I'm currently following the tutorials over at RubyMonk, and one of the problems I need to solve is to write a subtract function that would meet these conditions: invoking subtract(4, 5) should ...
1
vote
1answer
44 views

Python simple function - evaluating arguments

Think of the numpad number layout. hvd = horizontal, vertical or diagonal coord = 1,2 or 3 if horizontal or vertical and 1 or 2 if diagonal (1 is up, 2 is down)... hello('v', 2) - Asking for the ...
2
votes
0answers
130 views

PHP - faster/better implementation of is_dir function for FTP/FTPS connections?

I'm implementing an is_dir() function to determine if a given item is a directory or a file for FTP/FTPS connections. Currently, I have two methods: one using PHP's FTP wrapper for the is_dir() ...
0
votes
3answers
75 views

Review: Compare two Anagrams words in C

A simple attempt by me to test whether two words are anagrams or not. Here is the code: #include <stdio.h> #include <ctype.h> #define CH_LEN 15 #define N 26 int main(void) { char ...
2
votes
1answer
83 views

Iterative Collatz with memoization

I'm trying to write efficient code for calculating the chain-length of each number. For example, 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1. It took 13 iterations ...
0
votes
2answers
101 views

How to name this function?

The sample code is like this: def a_func(parent_node, child_node): parent_node.add(child_node) // check validity return child_node node1 = a_func(pnode, Node(attr_x = "a new node") node2 ...
0
votes
2answers
124 views

PHP PDO Custom class ple

i created a database class from a good tutorial and wanted to put it up here so it would get in some search results. it took me about 2 days to find it. also i added a few custom functions to it.. ...
0
votes
2answers
154 views

A better way of writing a PHP function

As the title says, I'm looking for a better way of writing the following PHP function as it's a very very long one. It's part of a bigger class and I'm trying to keep the amount of code as little as ...
1
vote
3answers
54 views

Function calls as parameters for other functions

I am in two minds about function calls as parameters for other functions. The doctrine that readability is king makes me want to write like this: br = mechanize.Browser() raw_html = br.open(__URL) ...
1
vote
2answers
289 views

What design pattern to use on this case

I have this code that converts audio to different file formats. import java.io.File; import it.sauronsoftware.jave.AudioAttributes; import it.sauronsoftware.jave.Encoder; import ...
1
vote
2answers
57 views

How to improve decode function

I have the next function: var decode = function(str, result) { var regex = /\d+/, number = regex.exec(str); if (number === null) { return str; } var start = ...
5
votes
3answers
190 views

Calling functions (or invoking methods) in constructor

I had written something like the following, public class ClassName { //private instance variables public ClassName() { //initialize instance variables this.someFunction(); } public void ...
1
vote
1answer
117 views

How can I improve this C style va_args replacement?

I inherited a lot of C code with many ellipsis (variadic) function. So I have a lots of API with the following signature. void getXY(int foo, ...) // many parameters and this is used in this way ...
6
votes
3answers
164 views

Can I use this function to store passwords?

Just wrote this function, wondering if it's secure enough to store passwords in a database: public static function hash($salt, $str) { $salt = md5($salt); $salt = ...
2
votes
1answer
78 views

Single function to read one, read all, or set

I have the below function, it is designed so I can call: $object->temp('one', 1); //add the key `one` to the temp array with value 1 $object->temp('two', 2); //add the key `two` to the ...
1
vote
2answers
104 views

Refactoring functions that generate string with random letters, numbers or mixed chars?

The bellow functions are used to generate a string with random characters, and they have a parameter to specify the string length. The string can be composed of letters, numbers or a conjunction of ...
2
votes
2answers
54 views

Naming of overloaded methods - singular or plural? [closed]

This question is about your opinions and/or existing conventions. Let's say I have an object Basket that store various items in some private property (Basket._items). Now, I want to have a couple of ...
2
votes
1answer
237 views

Arduino based SNES controller wireless transmitter/reciever, code questions

I am building a transmitter and reciever pair for two SNES controllers, as I don't like using long extension cords to get the controllers to reach the couch. I'm using atmega328p's for the avr's, ...
2
votes
2answers
346 views

Best practice for converting minutes and seconds in seconds

I have 2 input fields to input the duration of a CD song. The first input is for minutes and the second is for seconds When submitting the form, I must insert in the db the duration either in seconds ...
2
votes
1answer
69 views

Is it safe to cast a pointer to non-void function into a pointer to void function?

I thought it was a good idea to use this in my C++ projects: class CRAIICall { public: typedef void (WINAPI * FnType)(HANDLE); CRAIICall(HANDLE h, FnType fun) : m_h(h), m_fun(fun) ...
1
vote
1answer
72 views

How to improve a file access permission/deny function?

I've quickly made a function to deny or allow access to files that are only used thru Ajax Calls. Key Generator /** * Generate a key for file access permission * * Function that returns a key to ...
3
votes
1answer
108 views

How to improve function to detect the mime type using an agnostic method?

This function is used to get the mime type of any given file. The intended purpose was to have it working within any of our servers that vary from the latest PHP version down to PHP 4. /** * Get the ...
2
votes
1answer
111 views

How can this function to get a remote file improve?

I've prepared a function using cURL to get a remote file to the local storage: /** * cURL - Get Remove File * * Function using CURL the get a remote file to the local storage. * * @param str ...
2
votes
2answers
61 views

Is this function properly structured, leading to a secure row insertion?

I have the following function to insert a new row into a table: /** * Insert row into the designated table * * Function to add a new row into the designated table * * @param str $table ...
2
votes
1answer
74 views

How to optimize function that checks if a directory is empty when having over a million files inside?

I have the following function to confirm if a directory contains files: /** * Check if the directory is empty * * Function to ascertain if the specified directory contains files. * Comparing to ...
3
votes
1answer
58 views

How does this function look?

What do you think of my function. It is used to change a cyrillic word with a stress marker into the same cyrillic word but with the stress marker seperately represented as a number. As I want to ...
4
votes
3answers
308 views

C Split function review

I started learning C a week ago, and here is my implementation for the split function: char** my_split(const char* str, char delim, int* size) { int index = 0, start; char** results = NULL; ...
1
vote
2answers
86 views

How to improve this PHP function to confirm the presence/create directories?

While preparing an automated process to manipulate files, I've made the following function to check for the base directory and sub-directories presence, as to allow or deny the remaining code to be ...
1
vote
1answer
251 views

Better jQuery function argument with if-statement?

function check_itv(key) { if (key.length){ if(key=="left"){ left_itv = setInterval(left,100); check_left= false; check_right=true; check_up=true; ...
2
votes
5answers
149 views

Buy and Sell game project

it's a buy and sell game, and i revised it, it's still unfinished though, i would appreciate it if someone reviewed again for me. #include<stdio.h> #include<conio.h> ...
-3
votes
1answer
154 views

how can i improve/reduce this code? [closed]

any type of suggestion/correction will do, and i can't seem to get my functions to work or my conditional statements. int buyitem(int x, int y)//* function used to buy an item at any store*// { ...
0
votes
2answers
75 views

May be a memory leak somewhere or allocated memory not freed? [closed]

Here is the entire program, please help me, I've tried everything to find out what exactly is going with the memory. The problem is everything runs perfectly, but there are some extra characters ...
3
votes
2answers
160 views

How to improve these Haskell functions?

This is the algorithm for calculating sun rise/set time at various places on Earth. I took it as an example of multiple functions inside of one top function. (if someone figure out better title, ...
2
votes
1answer
221 views

Refactoring this state machine (upvoting/downvoting)

I have a list of resources which can be voted on. There are 3 voting states: upvoted, downvoted and no vote. In a fashion identical to stackexchange voting, it follows these rules: If you upvote a ...
4
votes
3answers
719 views

Javascript function and global variables

I have a getValue function which just grabs some numbers from an HTML page – How can I access those variables in later functions without passing them down the entire chain of functions? As they sit ...
2
votes
1answer
118 views

Do I need to create more functions? And also, is this code difficult to unit test?

I'm new to production code. And also I'm learning how to test code, I'll use the unittest module that comes with python to do that. One more question, how can I make this code more safe? """ Sync ...
2
votes
1answer
295 views

Refactoring Javascript into pure functions to make code more readable and maintainable

Note: I am very new to Javascript. The code I provided is long but not complicated. The code below works and runs fine. But I would like to seperate it out into logical 'pure' functions to make ...
3
votes
1answer
2k views

How can I shorten my jQuery for Show/Hide Function with Multiple Div IDs?

I've created a sliding panel menu that works (JSFiddle: http://jsfiddle.net/stephmoreland/3BT7t/), but I can't wrap my head around shortening the jQuery for it. Right now, when you click one of the ...
1
vote
4answers
326 views

Reading tokenized numbers from a file

int *getUserInput(FILE *fpin, int *elementCount) { int *userInput; // Load file into buffer int length = fileLength(fpin); char *buffer = (char *) malloc(length * sizeof(char)); int written ...
1
vote
2answers
687 views

calling functions over and over?! improvements needed

Not some much a problem, I am curious to know if my code can be cleaned up here a little. One annoyance is im calling a function three ( 3 ) times. I would like to know how this could be improved, ie: ...
4
votes
1answer
184 views

Is this code efficient?

I was wondering if this was a decent way of handling this function. Please take a look. // Use Less Mixins from Theme Options to adjust Stylesheets before Parsing Less to CSS add_filter( 'less_vars', ...
3
votes
2answers
98 views

Please review my function code for adherence to C standards and whatever else could be improved to it

I am relatively new to C and would like some feedback on a function that I have written, if it adheres to C standards or if there are some other things which I could have done better/differently. The ...
4
votes
2answers
200 views

Cross-post from SO- Palindrome finding function

I didn't know this site existed before now... awesome! I just made a thread here: http://stackoverflow.com/questions/8511620/c-palindrome-finder-optimization #include <iostream> #include ...

1 2