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

4
votes
2answers
66 views

Splitting a list by indexes

I am trying to build an efficient function for splitting a list of any size by any given number of indices. This method works and it took me a few hours to get it right (I hate how easy it is to get ...
4
votes
2answers
41 views

Page loader function

This is the function which I wrote and am currently using in my project. I want to know if there is a better way to write it: ...
8
votes
5answers
408 views

Similar methods using loops

Is it recommended to combine two similar methods into one? ...
6
votes
5answers
796 views

Project Euler #3 - largest prime factor

I was going through the Project Euler problem #3 and made a program to solve it. The problem is as follows: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of ...
6
votes
2answers
168 views

Pattern to avoid Variable Functions?

I have some PHP code where I use Variable functions to call the right function. I need to build a chart array (for example), and the chart array that comes out has a fixed format. But the data that ...
10
votes
1answer
309 views

When should I consider the number of my method arguments too big?

I'm writing a simple Pong game, I have a method bounce() that makes everything run: the ball, the paddles, score etc. and it uses 12 arguments: 3 counters, 2 ...
4
votes
2answers
411 views

How do I avoid duplicated code in these overloaded functions?

I have the following overloaded functions. All the code is the same as except for their format (%s v.s %lu), so I couldn't use ...
5
votes
1answer
42 views

Eliminating repetitiveness in code to test hash functions

I usually take my school code as a playground to mess around with things. I was given a bunch of premade hash functions and had to test their output and find when they reach a specific lower range. ...
1
vote
1answer
42 views

Optimising and consolidating multiple PHPMailer functions

So the two functions below both send emails via PHPMailer but both hold different messages (which use different data from the db). I was just wondering (as I plan to use PHPMailer more) a way to ...
1
vote
1answer
32 views

Test 2 time ranges to see if they overlap

I am doing a project for school and had to create a function to check if 2 time ranges overlap. I searched the net a bit but failed to find a simple function to do that. I played around a bit with my ...
4
votes
2answers
105 views

Implementation of atoi()

I implemented the atoi() function! Here is my code: ...
8
votes
1answer
102 views

PDO sign up function inserting data into multiple tables

This is a sign up function called on form submission. It firstly inserts key user data into the users table. If successful, secondary data is then inputted into ...
4
votes
1answer
53 views

Fix base64 data URI scripts function

So I noticed Chrome has quirky behaviour when it encounters script tags whose src is a base64 value. I decided to write a quick ...
3
votes
1answer
56 views

Using classes vs. using functions

I am trying to learn how to tell if my code will be better off creating a class as opposed to using many functions. I am a new Python programmer trying to get the hang of when classes should be ...
1
vote
1answer
103 views

Test whether or not a 4x4 matrix is a magic square

Here is what I have. I have it outputting most of the sums just so I can check there values. I think the problem is with the value of the elements in the array storing the column sums. I would greatly ...
0
votes
2answers
38 views

Trying to convert an extended Array.prototype to a function

I got a random image rotator working by using the following script (demo). But I was told that it is a bad practice to extend Array.prototype. And it does. It ...
7
votes
1answer
151 views

Command line reverse polish calculator

Write the program expr, which evaluates a reverse Polish expression from the command line, where each operator or operand is a separate argument. For ...
3
votes
2answers
172 views

Return value when the requested variable returns null

I have a method that returns a list from a html page: ...
6
votes
1answer
54 views

Functions that converts day of year to month and day and reverse with error checking

There is no error checking in day_of_year or month_day. remedy this defect. Here is the solution: ...
1
vote
1answer
40 views

Reducing multiple function calls [closed]

I can't quite figure out the best way to approach this. So I have a validation function that contains various other functions inside of it for validating email, phone and zip. This works fine but it ...
1
vote
0answers
56 views

Checkbox Group Function and Usage

In CodeIgniter, I have created function (helper) to populate, store and retrieve checkbox group. I just wonder if I have written code is in proper way and optimized or needs some more finishing? ...
7
votes
1answer
85 views

implementations of strncmp, strncat, strncpy

Write versions of the library functions strncpy, strncat and strncmp, which operate on ...
8
votes
2answers
108 views

Advice needed for scopes in JavaScript

I would like to connect this "JS" to Bugzilla (example: bugzilla.mozilla.org or landfill.bugzilla.org). I started to learn JS language today and I would like to ask you: How can I not do bad ...
5
votes
1answer
50 views

Shorten a sorting function

I have this function: ...
6
votes
1answer
126 views

Parsing function is 50 lines long

This is a parsing function that will at tildes (~) to end of search terms in certain circumstances. Example an inputs and outputs: Input: Output: name:(john doe) ...
6
votes
3answers
84 views

Functions that return a variable

I'm simple looking for what the general preference is between the below options: anon function directly to variable ...
3
votes
2answers
71 views

Merging the results of two functions

I have a class which extends another class and override one of its parent methods. ...
7
votes
3answers
104 views

Finding an element in a list

I'm kind of new to Python. So, I wonder which method is better to use in a function to find an element in a list. First: ...
3
votes
0answers
64 views

C++ class “overload” using variadic templates and wrapped function pointers

I'm using C++11 and I have the following problem (pseudo C++): ...
3
votes
5answers
251 views

How can I reduce repetition of these three similar functions? [closed]

I have 3 functions which look like this (simplified): ...
3
votes
1answer
59 views

Math Skills Game Advice

I think my code works pretty well, although I'm biased: http://jsfiddle.net/AHKb4/2/ Basic Overview: I'm working on building a math skill game, where the objective is to drag and drop div's to a ...
1
vote
2answers
96 views

Is calling a function from within another to alleviate code duplication the best solution?

I am writing up a class to handle various templates to be used in a web application. Each template contains various placeholders which will need to be replaced at the time of the build. I a wondering ...
3
votes
1answer
100 views

I'm torn between conditionals and abrupt return functions

Which one of these two is better? This one: ...
1
vote
3answers
130 views

Checking success on functions in C/C++ [closed]

I am trying to understand best practices for C\C++ functions which retrieve data but must also give success/failure information. Which is better, or is something different all together the correct ...
7
votes
5answers
490 views

Is `if( hidden ) return;` an antipattern?

Sometimes, when you're doing something like displaying a bunch of elements, you can avoid running a function entirely if an object is hidden. So you can either ...
0
votes
2answers
136 views

Counting the even digits in a number [closed]

I made a function to count the even digits in a number and when I enter a number that doesn't include any even digits. I need some one to tell me why and how to fix this. And please be simple in the ...
2
votes
2answers
126 views

Deeper abstracting of code into functions

I created a quiz using the module pattern. My code is as follows: ...
1
vote
2answers
77 views

Scanning an int variable

I have attemped to define a function which scan an int value in a specified range and returns that value. The lower bound is the lower of the two parameters, the upper bound is the larger of the two ...
2
votes
1answer
61 views

Calling multiple functions in image upload form

I have an image upload form with which I call multiple functions before uploading the file such as checking the size and dimensions, and that it is in a valid image. The code works, but calling the ...
3
votes
1answer
72 views

Help with optimizing current data pulling fuctions

Here is what the below code does: The first function, sqlPull() connects to a local MySQL database and pulls the last 20 rows from the database every 5 seconds. The data coming in is a list of ...
2
votes
1answer
57 views

Improving my invoice generator

In this function, the copy (Write XML) is inside, but I want it to be separated from the function. How can I improve this function? ...
0
votes
2answers
141 views

Which loop code is better practice?

def minval(xs): minum = xs[0] for i in range(len(xs)): if xs[i] < minum: #difference in code: xs[i] minum = xs[i] return minum ...
1
vote
2answers
58 views
4
votes
1answer
120 views

Generalized is() type-checking function for JavaScript

In a complex library I've been working on, I got pretty tired of all of the individual type functions and operators to determine whether I was working with an object or piece of data of a given type. ...
0
votes
2answers
136 views

Extending DOM elements with prototype for easier function execution

So I've creating a small library of JavaScript functions that I will be using. Some are for UI functions others are to return something. Below I will post two codes, I am wondering if this method is ...
1
vote
1answer
128 views

Feedback on a small PHP function that generates JSON data

I wrote a PHP function that generates JSON data to populate a line graph. Through jQuery, my code uses a GET request to the PHP script to fetch the JSON data. An example of the JSON data is as ...
1
vote
1answer
73 views

Parsing function review. How to improve it?

I've written a function to parse configuration files, it doesn't handle file opening, instead it takes an array with the file contents, tries to find fields based on an array containing the fields' ...
0
votes
1answer
61 views

AppEngine get/post on webapp2.RequestHandler

I was receiving 405 method not supported errors on get requests to my save controller, so I created a ...
2
votes
1answer
256 views

Matrix Transpose Function in C - Improve Performance

I have a matrix transpose function that takes arrays with a possibly different number of rows and columns. How to improve performance and code quality? ...
3
votes
1answer
110 views

Python Code Cleanup/Optimization

I am trying to clean up and make the following code more efficient - https://gist.github.com/eWizardII/6757364 ...