Oh, this makes sense. I was wondering why I kept getting downvotes and negative comments all the time. Thanks for breaking it down for me. As you can see, I'm very new to this. — Pivo1 min ago
I hope that means that he learns what belongs where.
Things you did well
Readability - everything was well organized and spaced neatly.
Initializing variables within your for loops/adhering to the C99 standard (which is the minimum you should abide by in my opinion).
Marking your function arguments as void when you don't take in any parameters.
U...
Your problem is that you should use { } or a ; after the else at the end of your code, btw (where the //do nothing comment is). Please fix that problem and ask instead for how you can improve the code, because I have a desire to really review your code. — Simon André Forsberg1 min ago
I have written the following code as the level rendering part of a game engine I am writing. I am very happy how it works but as it is the background / level graphics made up of individual blocks it needs to be quick.
What it does it look take the graphics from a resource loaded elsewhere and sc...
What do you think mods, should this be re-opened now? He's asking for a review, but the else part hasn't been fixed (although I pointed out the solution in my comment). I'm voting to reopen
I'm within my first few weeks of programming and this is my 1st language. Should I be using different code than what I already chose to write?
Problem:
Write a program that reads 10 numbers and displays distinct
numbers.(i.e. if a number appears multiple times, it is displayed only
o...
I'm not much of a jquery coder except to call a few get values out of class and id and ajax calls. (more of a php coder) however I need to make a checkout system work and one thing I would like to do is to put a loading wait while I send a form through Ajax and then when its finished it would red...
@syb0rg If it's true that people return negative to indicate an error, perhaps they shouldn't: IMO en.wikipedia.org/wiki/Exit_status#References says to return non-zero positive number.
@ChrisW Are you referring to the EXIT_SUCCESS and EXIT_FAILURE? They have their place, but error indicators sometimes need more values in order to be more descriptive. I guess positive values could be used as well.
@syb0rg Yes and no. On one hand, you correctly say to "use strings to hold credit card numbers". But you also said that using a double instead of a float was one of the good things about the code.
@200_success Yeah, I thought about posting an exception there to clarify, but then I assumed he would read on and see that he shouldn't have used a floating-point type at all.
Can I get some pointers/critique/comments on the following model? (p.s. performance seems great... tested all methods up to 10,000 records)
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class o7th_Model extends CI_Model {
private $msg;
private $last_id;
...
I'm within my first few weeks of programming and this is my 1st language. Should I be using different code than what I already chose to write?
Problem:
Write a program that reads 10 numbers and displays distinct
numbers.(i.e. if a number appears multiple times, it is displayed only
o...
The other answers offer great advice, but I have a few minor things to add:
This doesn't seem like a good input prompt:
printf("Give me a number: \n");
Imagine, for a second, if the user briefly forgot what this program is for. If they see this prompt, they'll just input any number.
Instea...
Pivo . you should edit your code, remove the else //do nothing part, and I recommend you also make your indentation correct. When that is done this can be reopened. At the moment your code does not compile. (and you should jump though this hoop ;-) — rolfl ♦1 min ago
Another simple example:
if (wpa_s->mlme.ssid_len == 0)
return -EINVAL;
Why the unary minus? Is this (usually) done for functions that return >0 on success and <(=)0 on failure, or is there some other reason?
> Back in my old Unix days, there was something of a convention that 0 means success, a positive number meant minor problems, and a negative number meant some sort of failure.
This OP is new and may not know how to view revisions.
(Doesn't know how to vote or accept answers: I was wondering about posting on meta-SO asking for an answer I/we could link to which tells people how and why to vote and accept, complete with pictures and hand-drawn circles: I haven't found such a single, complete answer in one place for new users).
The code here will be directly pasted from this project. Quick summary: it is related to a StackOverflow question.
So, basically, all the code below aims to implement CharSequence over a large text file, within the limitation of CharSequence itself (that is, up to Integer.MAX_VALUE chars). All t...
This explains how to accept an answer: [How does accepting an answer work?](http://meta.stackoverflow.com/a/5235/139866)
---
If voting is important I would like a similar answer which includes a picture of how to vote, and explains why.
Sometimes people would like to be able to link to such an answer in a comment, for example when a new user says "thank you" in a comment but their profile shows they have never voted.
@syb0rg By memory, I don't know what NSObject's init does, which is what all objects initialize from, but in init, you're doing exactly what other languages would do in their constructor methods.
For example, in a Rational Number class, I'd have a numerator property and a denominator property. Technically, the numerator could be any value, but the denominator cannot be 0. So in init, I'd set the denominator to 1 by default.
@syb0rg As I understand it, +alloc allocates memory, and -init makes it a useful object. The responsibility is split, so theoretically you could use a different memory allocation strategy.
It seems that users are still using the code-challenge tag for challenge-oriented questions that do not correspond to the site's occasional voted-upon challenges. We already have the programming-challenge tag for off-site challenge programs, but it's understandable that the two tags sound simila...
I'm Pops, a Community Manager at Stack Exchange. Though it saddens me to say it, not just one but two of your existing moderators are stepping down for personal reasons. Over the past week and a half, I've been working on finding replacements, and I'm happy to announce that two avid Code Reviewer...
@syb0rg Honestly? no. But for the sake of argument...I upvoted two, then created a sockpuppet account under which to upvote my own post (though you may have difficulty finding that...)
Just a few notes not mentioned in other answers:
You can typedef your struct right away.
typedef struct
{
int pre_1_idx;
int pre_2_idx;
int pre_3_idx;
} PreMinIdx;
Then initialize it with a more unique name.
PreMinIdx UniqueName;
Use else ifs in your mapping() method. And sinc...
You're initializing but not using local variables like bflag.
Is the user allowed to specify more than one option? Source code for GNU's cat found here says "Yes, multiple options can be specified". So instead of calling a different routine for each option, you should call the same routine for a...
Three possible problems that I see.
dbConnection = New SqlConnection("Data Source=connectionhere\sqlexpress;Initial Catalog=line_log;Integrated Security=True")
You have a hard-coded connection string. If you want a different database location then you need to edit the code. Perhaps it's bett...
I applied for a job and they asked me to write code with the following requirements:
Get a "toolbar offer" description from
http..update.utorrent.com/installoffer.php?offer=conduit. Parse the
bencoded (see http://en.wikipedia.org/wiki/Bencode) response and
extract the URL of the binary...
While reviewing a code the reviewer replied to the coder that, "Strictly do not use ternary operators in super calls "
Is there any rule of thumb like ternary operators should not be used in super calls ?
Solved the ford-fulkerson algorithm, which is too vast to explain it comprehensively here. Check Wikipedia for Ford-Fulkerson and Princeton lecture on Ford-Fulkerson.
Looking for code review, optimizations and best practices. Also I request you avoid mentioning renaming GraphFordFuklerson and u...
Question:
One of Scotland Yard’s most wanted criminal (Mister X) is on the run
and needs to reach a certain destination safely. There are three modes
of transport available for him - By air, by train or by cab. With air
travel, he can go from station i to station i+3. Using a trai...
I have a function initialize_path_statistics(). I have used openMP to make it parallel. I am not sure where certain lines such as
float length_enclosed = Nodes::get_length_enclosed(i);
need additional pragma like #pragma omp atomic.
void Path_Statistics :: initialize_Path_statistics()
{
...
I have written a small program with VBA in excel 2010. It is a self service concession stand where a user enters their ID numbers, log what they bought, and add it to a balance or pay. I would appreciate a code review. Everything seems to be working, but I would like to ensure my code is as eff...
Task:
Given a dictionary of words, and a set of characters, judge if all the
characters can form the words from the dictionary, without any
characters left. For example, given the dictionary {hello, world, is,
my, first, program}, if the characters set is "iiifrssst", you should
retu...
I've been trying to create a calculator to find mass using any and all known equations, the program will also return the steps used to find mass so the user can cheat... er... 'check their work' on physics assignments.
My biggest problem so far (and was solved by much copy-pasta) is the equation...
The following is my code. I am not sure about the place where flush should be used(if it is used at all here)
int Window_Shift :: get_window_shift()
{
int window_shift = INFINITE;
#pragma omp parallel for
for(unsigned int node_id = 0;node_id< no_of_valid_nodes ;node_id++)
{...
How can I test this C program for "efficiency"? The most interesting usage is that it returns negative output for large enough input, otherwise the behavior is about expected e.g. the usage is when compiled:
$ ./a.out 19011
19011 => 19013
Will you suggest how to improve it for portability (uni...
This is self explaining example with usage in doctests:
class Switch(object):
"""
>>> with Switch(1) as case:
... if case(1, fall_through=True):
... print 1
... if case(2):
... print 2
... if case.default:
... print 'default'
...
1
2
...
Just a few notes not mentioned in other answers:
You can typedef your struct right away.
typedef struct
{
int pre_1_idx;
int pre_2_idx;
int pre_3_idx;
} PreMinIdx;
Then initialize it with a more unique name.
PreMinIdx UniqueName;
Use else ifs in your mapping() method. And sinc...
I am just starting out in my clojure journey and I wonder if anybody can point out my beginners mistakes in my function below that simply reverses a list. I know that there is already a reverse function so this is purely for learning.
(defn rev
([l]
(if (= (count l) 1) l (rev '() l)))
([...
Things you did well
Proper use of goto to break out of an inner loop.
Things you could improve
Portability
If you want your program to be as portable as possible, take a look into the AutoTools suite.
Standards
You don't have to return 0 at the end of main(), just like you wouldn't bot...
I'm within my first few weeks of programming and this is my 1st language. Should I be using different code than what I already chose to write?
Problem:
Write a program that reads 10 numbers and displays distinct
numbers.(i.e. if a number appears multiple times, it is displayed only
o...
This question is still not producing the right results.... after numerous attempts....
He made the changes I asked and I indicated I would reopen the question after he did.....
Now, there is still a bunch to review, but his distinct-list calculations are broken in his second-attempt.
(he never actually sets any values in the finallist array
Currently there are two re-open votes....
ahh, Thanks Ducks. I know what to ddo ;-)
Hi again Pivo - it is apparent that the code is still not working. Your own comment that it is 'getting close to the solution', and looking at the code, indicates that there is a real problem.... for example, you are never actually setting any values in finalList, so how can it possibly have the distinct values? Why don't you join us in The 2nd Monitor (CodeReview chat room) and we can work through some issues. — rolfl ♦11 secs ago
I had written a solution for project euler problem 18 in Python 3. It is good in its efficiency but the problem is the readability and I think reuse.
The algorithm used is that at every iteration the maximum for all numbers in a row is calculated starting from the top and going down to find the...
I created a singleton class for managing sound effects on Android. This class will only be instancied and loaded once at the begining, and each activity will use the loaded songs.
I don't know either if this is the good approach for Singleton, nor if this is the good way to play sounds in Androi...
I am going on with refactoring my code base while migrating from Python 2 to Python 3. I am using generators to make reusable components this time as I am more comfortable with them this time then last time. But there are times when I am stuck at their use. Like below example. These two are essen...
I implemented the Atoi function! Here is my code :
int my_atoi(char* pointer)
{
int result=0;
char* pointer1;
multiplier=1;
char sign=1;
if(*pointer=='-')
sign=-1;
pointer1=pointer;
while(*pointer!='\0')
{
if(*pointer>='0' && *pointer<='9')
multiplier=multiplier*10;
pointer=poi...
Let's review the context of this function.
If this function will be called often with a wide range of inputs, then it makes sense to pre-compute a bunch of prime numbers and then just find where the input value is in amongst the pre-coumputed set. When pre-computing the primes the most common wa...
Actually, am going to edit.
With the function extraction, there is no need for do-while.
Things you could improve
Efficiency
As @rolfl stated, you want to use a Sieve of Eratosthenes.
I can't see if you are doing this already, but you should be compiling with your compiler's highest optimization level. With GCC, this would be -O3.
Portability
If you want your program to be as...
You did well, and I tried not to step on yours either .... we point out different things and, a lot of what you say is good criticism for my answer too....
You are criticising style and standards, I focussed on the function extraction and loop structures.
@syb0rg - unfortunately, as a mod ..... .... I still only have 1 vote per answer.... :(
otherwise I would upvote for the answer, and another for the velociraptor
For about five hours now I'm trying to combine the use of jquery.history.js with another script which includes html content from a file $file.php to div#include.
Would be great if I would get some feedback, if there are better ways of doing what I tried, and maybe even someone knows, why my exam...
Find the element the occurs more than n/2 times in an input array, where n is input array length. Looking for code review, optimizations and best practices.
public final class VotingAlgorithm {
// non-instantiable.
private VotingAlgorithm() {}
/**
* Returns the number which...
I have class that implements Set and List. Programs works fine in Java6 and Java7
public class SetList<V> implements Set<V>, List<V>
{
....
}
With Java 8 , this does not compile. Error is
java: class trials.SetList inherits unrelated defaults for
spliterator() from types java.util.Se...
@syb0rg I disagree with all three of your portability points.
Autotools add a lot of complexity for questionable gain. They are good for defining macros that change which function you call, depending on what's available on your system. That's not even a concern for this question.
"Adhere to standards" is too vague to be helpful.
unsigned int is available everywhere, and is no more portable than size_t. However, size_t has the connotation that it represents an array size or something similar, which is not the case here.
A valid portability concern is that a signed int is only guaranteed to hold up to 32767, which may be smaller than the author expects.
Without the function-extraction the do-while loop is the best system... do the work to set found == PRIME_TRUE and then check the condition afterwards in the while part of the do-while.
The function-extraction is a better solution, and thus... well, never mind, let me refresh my thoughts....
You might want to update ideone as well. I just don't understand how your perhapsprime -= 2 got introduced in the first place, since it was never in the original code.
Things you could improve
Variable/Initialization
Where do you declare multiplier? I assume that since it is not declared within the method, it is declared as a global variable. Try to avoid global variables.
The problem with global variables is that since every function has access to these,...
Is this the right way? Any comments on the hash functions? If asked a question like this in an interview, do I need to follow all OOP concepts(because I am using Java)? Like encapsulating the variables by writing getter and setter functions?
import java.lang.reflect.Array;
import java.util.Arra...
@syb0rg Still fails for a maximally negative number on a 2's complement system, but fixing that can be somewhat non-trivial and probably outside the scope the OP contemplates.