Tagged Questions

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

0
votes
2answers
53 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
129 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
45 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
156 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
43 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 = ...
4
votes
3answers
172 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
81 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 ...
5
votes
2answers
127 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
73 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 ...
0
votes
2answers
93 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
45 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
151 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
207 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
61 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
68 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
77 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
96 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
60 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
69 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
57 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
192 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
77 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
145 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
136 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
143 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
73 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
150 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
185 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
312 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
108 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
234 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
1k 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
276 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
679 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
183 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
93 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 ...
3
votes
2answers
174 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 ...
0
votes
1answer
237 views

Is my login function secure ? how to improve it?

Using cakePHP, I would love to have your point of view about this large source code, i am not sure if its enought secure. sha1() will be removed with another script. I found this large script can be ...
4
votes
3answers
2k views

Min / Max function of 1D array in C / C++

Due to software constraints, I cannot use the standard libraries, math.h,algorithm, templates, inline, or boost. I am also using standard C (ISO C99) such that array is not a reserved keyword like it ...
10
votes
3answers
447 views

Fastest Parameter Passing in delphi 7?

I have a function that accepts a big amount of data as a parameter (sometimes 1 megabyte) I was thinking which would be the fastest way to pass that data, dunno if I got this right, but here is what I ...
2
votes
1answer
272 views

Passing anonymous functions and getting variables from an outer scope in php

I'm doing something quite strange. I'm trying to create a tiny system for creating templates inline in php, so that I can refactor by creating multiple templates in the original script, and ...
4
votes
1answer
208 views

Python, WeakBoundMethod

I've written this small class in Pyhon that wraps bound methods but does not prevent the deletion of self. Do you have any though on my code? Do you think I handle errors appropriately? Is it missing ...
7
votes
6answers
451 views

What looks better in java

I wonder what is better code practice or just what looks better in Java. Version 1: protected Boolean doSomething(int amount) { if (amount < 1) return false; return ...
2
votes
2answers
85 views

Where to check?

Requirement: If the bookshop manager field changes from A to B, I need to email the person B saying that the new Bookshop has been allotted to him and he has to do certain activities. Here is my ...
2
votes
2answers
477 views

Setting variables inside an if else if statment and improving my javascript/jquery code

I refactored/rewrote my code to produce what is below and I am trying to work out if there is a more efficient way of doing it i.e. less lines of code and quicker etc. I am also wondering if it is a ...
2
votes
2answers
336 views

Functions for scanning command line options

I know that getopts is available but I wanted to write my own as a way of improving my bash. Below I show two function definitions and an example of the use of them in a bash script. Finally I show ...
2
votes
2answers
347 views

PHP and Custom Functions

I am new to the world of coding as well as XHTML and PHP. As a way to gain more experience as well as to put theory into practice including a way to challenge myself, I put together the following code ...
4
votes
2answers
705 views

Function pointers and switch statements

I feel like I can make my switch statements more elegant with a function pointer, i.e. I'd like to set the digestLength and a pointer to a function in the same switch statement instead of setting the ...
4
votes
2answers
691 views

Do I always have to return something in an anonymous function?

I have inherited this snippet of jQuery JavaScript and am currently brushing up on my jQuery. NetBeans IDE complains that Anonymous function does not always return a value. So there is not always an ...
17
votes
7answers
989 views

Is_numeric_array() missing!

I found that in PHP (or i probably can't find it) a proper is_numeric_array($array) function is missing. So i created one. The problem is that i don't think it's great and i don't know how to improve ...