The selected meta tags will be burninated in phases, based on usefulness. This post will be updated as burninations are done, up until the question is tagged as status-completed.
Phase 1: status-completed
refactoring
clean-code
code-smell
Phase 2: status-completed
style
code-organizatio...
Suppose you have a method on a class that looks like this:
MyClass.prototype.pretty = function(tree){
return "[Tree " + (function go(tree){
return this.isLeaf(tree)
? tree.toString()
: "(" + go(this.left(tree)) + " "
+ go(this.right...
I am trying to put an integer inside the array by subtracting the initialized value in every loop. This code seems right for me, but the compiler always claims that "Index was outside the bounds of the array.". Am I doing something wrong here particularly in itr part?
static void Main()
{
...
Find all nodes of trees, without siblings. This question is attributed to GeeksForGeeks. Looking fr code review, optimizations and best practices.
public class PrintNodesWithoutSiblings<T> {
private TreeNode<T> root;
public PrintNodesWithoutSiblings(List<T> items) {
...
For many of the questions I've looked at, I see people saying that the algorithms or parts of the implementation will be 'slow', but no one seems to follow this up with performance figures for a 'typical' run of their favorite algorithm and/or implementation. If you're going to criticize the run...
I ran it and it's working, but I just want someone to double check that I followed the directions. Any suggestions or corrections will be appreciated.
Assume you have a NSString *str object containing some text. Write a code fragment to create a new string with all substrings "aaa" deleted....
I think you're right. I don't want @"aaaa" to be replaced with @"a". Can't get my head around it how to stop that from occurring. — user347886946 mins ago
@nhgrif +1, but assuming this is his homework and the quoted thing at the top was his assignment, I wonder how he knows "aaaa" or "goaaat" or whatever shouldn't get replaced. Feels like we're not getting the whole picture.
also the indentation in your answer makes me want to strangle someone, is it normal to align it on the colons like that?
@DavidHarkness closure compiler with advanced optimizations will preserve the name create when you write it like that. Those no-op statements in the ctor are there for closure too, going to annotate them later. — DaggMay 25 at 23:34
Yes, that's it
When you see a comment, it has a timestamp next to it. Click that and you get an anchor link. C&P that in chat to get it formatted
This is my first code in C# ever. It compiles and works as intended (not complete), but I want to see what I'm doing right and wrong as a first-timer.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using S...
I have to solve the following problem: Given an array of integers and given an integer value, list all possible numbers frm the array that sums up to the given value.
Example:
Input: array = {1, 2, 2, 3, 4, 5}, int N = 5
Output: {1, 2, 2}, {1, 4}, {5} {2, 3}.
This is my solution:
import java...
I just saw the following JavaScript function in RichFaces:
var curry = function (g, a) {
var _g = g;
var _a = a;
return function (b) {
_g(_a, b);
};
};
Isn't the definition of the local variables _g, _a entirely unnecessary / redundant here as function arguments are imp...
i want to write a program to work out how many semi-magic squares are there.
here is the definition of semi-magic squares
if we define $H_n(t)$ is the number of semi magic squares which satisfy:
the square is n*n dimension
sum of each row elements and sum of each column elements equal to t
...
I'm comparing two variables which I'd like to be printed to the console like so:
==Full Ex Vat==
true
Currently the code to do this is:
print '==Full Ex Vat=='
print case when
@aTotalExVat = @sTotalExVat
then 'true' else 'false' end
which I feel isn't as elegant as it could be.
Any tips?
I'm having a hard time figuring out if the code I wrote is purely combinatorial or sequential logic. I'm designing a simple 16-bit microprocessor (will be implemented on a Spartan 6) and I'm new to Verilog, HDL and FPGAs. The code for the microprocessor is complete, but I'm having second thoughts...
I'm trying to create a code that reads a text file (containing (double) numbers between 0 and 1) and filling up a 3D array/matrix (calling it matrix from now on) with those values. After that is done I need to figure out the current max-value inside this matrix and then look at the values around ...
I have a region on my screen which can display either a grid or a maintenance screen for the selected grid row (when it double click'ed). The mode is managed via Grid-o_Edit.Mode property.
How would you call such a dual aspect element, I'm looking for something nicer than grid-o-edit (other opti...
I am practicing Object oriented design. So I have taken Tic Tac Toe as an example. I have written first all the requirements and then started writing code. I would like to get it reviewed so that I can improve my skill further. Please provide suggestions.
I have placed code at github repo
Ive always just wrote down what i need in the order of importance and gone from there, i was wondering if there was a best practice to structure, if that makes any sense
@CodeX Design: I stink at design. Code structure: Write down the classes you need and determine the connections between them. Code the interface of them first, determine what methods each class should have. That's how I do it.
@nhgrif I can understand that SO separates string and nsstring, but on Code Review? I can't really say that we have that many string questions. Or ObjC questions.
i've just begun creating my first user class. First, i need some clarifications.
If i construct all of my variables in __construct(), am i correct in assuming that i will be able to fetch the object later by returning $this from the public method get_user_object() ?. I'm trying to avoid manually...
@nhgrif There are three questions tagged with strings and objective-c. Before you re-tag though, if you want to do so, I think we could bring it to meta.
There's a massive difference between working with an nsstring and a c-string. Moreover, in Swift, there will be a big difference between working with a nsstring and a string. Just as there's a difference between working with an array and a nsarray.
@CodeX There's always better ways at designing... But you don't always need them in my opinion, maybe experience at some point will tell I'm being dumb now
We do have linked-list but that's mainly because there's so many people that seem to get some kind of strange satisfaction by making implementations of that.
If I have a question in which NSDictionaries are heavily used, I'm tagging it nsdictionary because to answer the question most likely requires some intimate knowledge about how the class works.
@nhgrif I think the question probably needs more knowledge about how Dictionaries work in general than how the NSDictionary-specific class works. If you know how Dictionaries work in general, then you can probably make a qualified guess about how NSDictionary work.
I don't know enough about other languages, but the NS collections all have entire subsets of built-in methods for mutating them into other NS collections.
@SimonAndréForsberg That's implementation-specific, I think linked-list exists because of how it works, not neccessarilly the implementation... I doubt anyone cares about array-list using an array, they want O(1) access time ultimately
1) A strong C-foundation. 2) The ability to read and understand the official documentation on all of the Apple classes.
Because the classes are extremely complete and extremely well documented. Before you spend more than 5 minutes writing some code, you need to check the documentation to make sure there's not a method that will do it all for you. That's Objective-C
A good ObjC programmer working with dictionary has more than just a concept of how dictionaries work. He's got most of the NSDictionary methods memorized and the rest are an Alt-Tab (Cmd-Tab) away.
@nhgrif A good Java programmer working with Map has more than just a concept of how dictionaries/maps work. He's got most of the HashMap methods memorized and the rest are an Ctrl+Space away.
Welcome to Code Review! Unfortunately what you posted here is not a codereview, but an advertisement. I am sure you could tell OP directly, how he can improve his code, and not make him go all the way via twitter, youtube and msdn. Read through other answers to see what we expect from an answer. btw. you can always edit your answer. — Vogel61220 secs ago
@SimonAndréForsberg well It's not a review of op's code it's some: "implement it like [random (anti-)pattern] and write me on twitter if you have problems"
> Entity Framework supports Stored Procedure mappings out of the box and it is possible to implplement a generic repository using the Unit of Work pattern.
^^ That part might be helpful. But it's a comment at best.
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. — BeetDemGuise1 min ago
Given a base path and a list with extensions the task is to list all files:
Two of my solutions are:
from glob import glob
from os import path
EXTENSIONS = ['*.zip', '*.jar', '*.pdf']
DOC_PATH = '/path/to/files'
# Solution1:
files = []
for ext in EXTENSIONS:
files.extend(glob(pat...
I have a function that has two vector parameters. It takes just some elements from the "input vector" and add them to the "output vector". It looks like this:
void foo(const std::vector< MyObj >& myObjsIn, std::vector< MyObj >& myObjsOut)
{
for (size_t i = 0; i < myObjsIn.size(); i++)
{
...
I am practicing Object oriented design. So I have taken Tic Tac Toe as an example. I have written first all the requirements and then started writing code. I would like to get it reviewed so that I can improve my skill further. Please provide suggestions.
I have placed code at this github repo.
...
You've earned the "Necromancer" badge (Answered a question more than 60 days later with score of 5 or more) for "Show days of single week - the right way?". YEAH!
I went with what I know and can use well, not what I know and can't figure the syntax out to make it look good.
so please enjoy the code and prepare to school me (probably in the basics) in C#
public static void Main (string[] args)
{
/* Here are your rules:
"Scissors cuts paper,
...
I was googling thru Perl community to find out appropriate solution for Longest common substring problem. It turns out, that there is no ready-to-use one:
String:LCSS appears to have bugs have been already reported for.
Algorithm::LCSS works with sequences. Thus, it will introduce overhead on s...
return subsiteName + i doesn't look right? what does it return if you run this code? it looks like you haven't actually written the code yet, and don't know if this code will run at all.... — Malachi8 secs ago
I have to solve the following problem: Given an array of integers and given an integer value, list all possible numbers frm the array that sums up to the given value.
Example:
Input: array = {1, 2, 2, 3, 4, 5}, int N = 5
Output: {1, 2, 2}, {1, 4}, {5} {2, 3}.
This is my solution:
import java...
Good news, everybody! We managed to move basically all the furniture (save for one gigantic book shelf we will get later) yesterday, and we are now waiting for the electric company to turn the power back on, hopefully today. They said up to 2 business days so who knows but with luck we will be moved in tonight.
Singletons are evil
Even if you do want to use it, use Lazy<T> instead of manually doing double-checked locking
Best solution would be to leverage IoC container to inject dependencies you need.
@Phrancis All answers have their question as parent.
I do not do C# but I can offer another way of approaching the problem:
As our range of numbers is \$[100\cdot100, 999\cdot999] = [10000, 998001]\$, assume a palindromic number on the form \$abccba\$.
The largest \$abccba < 998001\$ is \$k = abccba = 997799\$. We need to determine if \$k\$ can ...
I wrote my first animation in Java FX and would like a code review.
I created StackPane with Rectangle. Rectangle starts to move inside StackPane to right-bottom direction and changes direction after hitting the StackPane bound.
Please review the code that moves Rectangle. Is it a correct...
I have to write the following method: I have sorted array of integers and in this array every integer repeats twice, except two elements. Find these two elements.
Input: 1, 1, 2, 3, 3, 4, 4, 5
Output: 2, 5
This is my solution in Java:
private static int[] findUniques(int[] arr) {
int[] res...
@skiwi I got Exception in thread "Timer-0" java.lang.IllegalStateException: Not on FX application thread; currentThread = Timer-0 when trying to test the code.
This server require fast decoding of packets from clients, as I am expecting 5000 concurrent clients that is sending packets possibly every second. This is a game server.
I want to see if my implementation is fast enough or there are still room for improvements.
def dataReceived(self, data):
...
I'm sorry but I don't believe this code is working correctly (because of Exception in thread "Timer-0" java.lang.IllegalStateException: Not on FX application thread; currentThread = Timer-0). You ask "Is it a correct implementation of a Java FX animation?" and I don't think this is working as expected as you say. I would love to help you clean up some things in the code, but it is better if you fix the problem first. If you search for "Not on FX application thread" you should find a solution. Please come back and update your code here once you have fixed that problem. — Simon André Forsberg15 secs ago
public class CodeReview implements WorldPeace {
@Override
public void peace() {
CodePeaceUtils.makeCodeNotWar();
}
}
In general the code seems fine and it is not horrible or anything, but I think you could surely have improvements.
High level
Currently your code returns null if audioCursor == null, I think this should be an exception, possibly an existing one, or a custom one. I'm not exactly sure what it doe...
I'm preparing for Java SE 7 Programmer II exam.
In one of the mock exams there was an exercise to name from what threading problem does the code suffer.
This is the code:
public class Test {
public static void main(String[] args) {
final Counter obj1 = new Counter("obj1");
final Counter...
For each number in the list, either
there is no next (at end of src list) - add to result list
the next is different - add to the result list, increment result count (if all answers found, return)
the next is the same; skip next, (add 2 to src pointer)
public int[] findUnique(int[] src){
...
It doesn't really review his code at all, it just gives an alternative?
I'm building a web application using: MVC5 and EF Code First with Repository and Unit of Work Patterns. Till now I have 3 layers:
"Data Layer" which contains the repositories, UOW.
"Services Layer" which has refrence to UOW to implement bussiness logic and bussiness validation.
"Web Layer" whic...
I have come across an article where students used network traffic to draw their university on the country's ipv6 graph. [image]
Your goal is simple to tell but hard to implement. Draw the text MAIL (as it is one of the few words that can be read on a 1D graph) on the cpu graph.
It should look ...