body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I have written a few <em>simple-to-be-used</em> methods in Java 8, and am wondering what could be improved upon those:</p> <pre><code>public static &lt;E, R, C extends Collection&lt;? extends R&gt;&gt; C transform(final Collection&lt;E&gt; collection, final Function&lt;? super E, ? extends R&gt; mapper) { try {...
[]
[ { "body": "<p>I see the Supplier-less option as being a very broken one. Consider the following code:</p>\n\n<pre><code>transform(linkedList.sublist(0, linkedList.size() / 2), i -&gt; (i + 1) + \"-\" + i);\n</code></pre>\n\n<p>Or, any of the other collections that do not have a meaningful default constructor:</...
{ "AcceptedAnswerId": "47971", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T11:22:14.303", "Id": "47967", "Score": "10", "Tags": [ "java", "type-safety", "factory-method" ], "Title": "Methods creating transform functionality on Collections" }
47967
<p>Inspired by <a href="https://stackoverflow.com/questions/23213332/bash-shell-simulation-in-browser">this question on Stack Overflow</a>, I've attempted to code such animation, mostly to get some more practice with async, promises and Q.js:</p> <p><a href="http://codepen.io/Kos/pen/ClqeJ?editors=001" rel="nofollow n...
[]
[ { "body": "<p>This stuff is hard to get right, at this point good promise driven code seems more like an art than engineering.</p>\n\n<p>From a CodeReview perspective, your code is fairly easy to follow, except for one thing which got me stumped for a little while, <code>row_complete</code> should really be nam...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T11:32:41.153", "Id": "47970", "Score": "2", "Tags": [ "javascript", "asynchronous", "promise", "animation" ], "Title": "Promise-driven animation" }
47970
<p>I have made an <code>any</code> class in C++, base loosely on <code>boost::any</code>, but written differently. I am checking to see if I have done it correctly and that there are no mistakes in it:</p> <pre><code>class any { public: any() : dt(new data&lt;void *&gt;(0)) { } templat...
[]
[ { "body": "<blockquote>\n <p>I am checking to see if I have done it correctly and that there are no mistakes in it:</p>\n</blockquote>\n\n<p>What have you done to test this class? You might want to write some unit-tests.</p>\n\n<hr>\n\n<p>I think I see at least one bug: the destructor ...</p>\n\n<pre><code> ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T13:08:24.647", "Id": "47975", "Score": "11", "Tags": [ "c++", "reinventing-the-wheel" ], "Title": "'any' class implementation" }
47975
<p>I have a long command that I am building with shovels (<code>&lt;&lt;</code>), with the intention of eventually running <code>system(command)</code>. I'd like to log the command string, to make sure it is built properly, right before I execute the command. However, the command has to contain account credentials that...
[]
[ { "body": "<p>You seem to be repeatedly performing a lot of operations on both 'command' and 'public' together. The way these variables are related make me think they should actually be part of the same object. For example:</p>\n\n<pre><code>class Command\n attr_reader :command, :loggable\n\n def initialize(c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T14:40:16.093", "Id": "47978", "Score": "11", "Tags": [ "ruby", "strings", "security", "logging", "child-process" ], "Title": "Pretty way of keeping sensitive info out of a...
47978
<p>Which one is more verbose?</p> <pre><code>private bool? _hasChangesToReconcile; public bool HasChanges() { if (!_hasChangesToReconcile.HasValue) { if (Model != null) { using (var broker = _documentBrokerDelegateFactory()) { return broker.Value.HasSec...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T14:54:13.487", "Id": "84155", "Score": "1", "body": "Your nullable boolean can be null, obviously, which means it has three possible states, while your enum only has two. What was your intent?" }, { "ContentLicense": "CC BY-...
[ { "body": "<p>in the first code block you have code that is unreachable</p>\n\n<pre><code>using (var broker = _documentBrokerDelegateFactory())\n{\n return broker.Value.HasSectionChanges(Model.Id);\n _hasChangesToReconcile = broker.Value.HasSectionChanges(Model.Id);\n}\n</code></pre>\n\n<p><code>hasChange...
{ "AcceptedAnswerId": "47983", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T14:48:38.950", "Id": "47979", "Score": "-7", "Tags": [ "c#" ], "Title": "Creating Enum vs Nullable bool for readability?" }
47979
<p>Here is my Python implementation of a simple fractions class:</p> <pre class="lang-python prettyprint-override"><code>class frac: def __init__(self, a,b): self.a = a self.b = b def __add__(self, x): return frac(self.a*x.b + self.b*x.a, self.b*x.b) def __mul__(self, x): ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-29T13:54:20.767", "Id": "85110", "Score": "0", "body": "You might consider [accepcting](http://codereview.stackexchange.com/help/someone-answers) the most helpful answer by clicking the check mark below the voting buttons." } ]
[ { "body": "<p>If you want to produce correct results, you should simplify after each operation. Euclid's algorithm is very fast in finding the GCD, and very simple to code. If you have a function like:</p>\n\n<pre><code>def gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n</code></pre>\n\n<p>The...
{ "AcceptedAnswerId": "47995", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T15:48:14.380", "Id": "47984", "Score": "4", "Tags": [ "python", "integer" ], "Title": "fractions data type -- when to reduce?" }
47984
<p>I want to print a lot of the same characters and I don't want to use a for loop and I'm also looking for a way to do it as less lines as possible. Even better I would like to be able to store that string in a static variable to use again and again.</p> <p><strong>This is how I currently do it (ugly but at least no ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T16:05:12.990", "Id": "84177", "Score": "2", "body": "SO dupe : http://stackoverflow.com/a/1235184/7602" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T16:08:54.823", "Id": "84179", "Score": "0...
[ { "body": "<p>I wouldn't call this ugly:</p>\n\n<blockquote>\n<pre><code>System.out.println(\"----------------------------------------\"\n + \"----------------------------------------\"\n + \"----------------------------------------\");\n</code></pre>\n</blockquote>\n\n<p>There's...
{ "AcceptedAnswerId": "47990", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T15:55:10.270", "Id": "47986", "Score": "17", "Tags": [ "java" ], "Title": "Printing 80 (or more) times the same character" }
47986
<p>Please help me to simplify the script below. It has a lot of variables and a lot of values are getting assigned to them. Can I make it simpler?</p> <p>It has to calculate the percentage of 3 test forms: pre, post and final.</p> <pre><code>DECLARE @tablefinal TABLE ( RowID1 INT IDENTITY(1,1), _CourseIDD in...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-22T01:16:56.413", "Id": "88685", "Score": "3", "body": "Can you post your execution plan? This is a pretty complicated transaction and being we don't have access to the database it's a bit difficult to pinpoint where it could improve."...
[ { "body": "<p>To sum up what this script does, just for the sake of simplicity:</p>\n\n<ol>\n<li><p>Declare a result set table variable <code>@tablefinal</code>.</p></li>\n<li><p>Declare variables for a counter, and for courses, and a commented out <code>@STUDENT_ID</code> (likely for testing purposes).</p></li...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-07T08:55:36.313", "Id": "48001", "Score": "3", "Tags": [ "sql", "sql-server" ], "Title": "Calculating percentage of 3 test forms" }
48001
<p>I am building a new system that is using some tables from an old system.</p> <p>For each user on this new system, I need to go to the old system and total up their sales. Currently it takes between 2-5 minutes to load.</p> <pre><code>public static List&lt;DailyTeamGoal&gt; GetListDailyTeamGoals(int teamId) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T19:20:36.323", "Id": "84219", "Score": "2", "body": "Is there an index on `Orders` including columns `DateCompleted`, `Status`, `Kiosk` and `SalesRepID`? How many rows are we talking about? Have you profiled anything to see where th...
[ { "body": "<p>I won't comment about the fact that this is a <code>static</code> method in what's possibly a <code>static</code> &quot;helper&quot; class and that it would be much prettier in a <em>service</em> class <em>instance</em>... but I just did.</p>\n<p>The method is doing way too many things.</p>\n<bloc...
{ "AcceptedAnswerId": "48005", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T19:11:51.677", "Id": "48002", "Score": "5", "Tags": [ "c#", "performance", "linq", "entity-framework", "asp.net-mvc-4" ], "Title": "Calculating total sales from each me...
48002
<p>I use 'GROUP_CONCAT' to get comma separated lists of a person's educational background. Included in those lists are the type of degree, major, issuing establishment, and year received. <code>degreeType</code> is a required field and cannot empty. Prior to looping, I split the lists into arrays, like so:</p> <pre...
[]
[ { "body": "<p>Your script is alright, there are just some minor issues:</p>\n\n<p>1.) If string is enclosed inside <code>\"\"</code> then PHP interpreter checks whether there are some variables or not, if string is enclosed inside <code>''</code> PHP interpreter does not check it. </p>\n\n<p>2.) You forgot to d...
{ "AcceptedAnswerId": "48006", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T19:14:21.557", "Id": "48003", "Score": "3", "Tags": [ "php", "array" ], "Title": "Is there a more elegant solution than this spaghetti code without completely revamping the whole p...
48003
<p>I wrote a Player package in Go. It builds correctly, but I would love a review on what I did and did not do "the Go way". I'm new to coding in the language, although I've gotten about halfway through Ivo Balbaert's "The Way To Go".</p> <p>The code consists of a struct and a bunch of setters and getters for the stru...
[]
[ { "body": "<p>This is fairly bare-bones as far as packages go, but there are thing that can be improved here.</p>\n\n<p>Firstly, to create a player object, someone is going to need to do the equivalent of:</p>\n\n<pre><code>player := new(Player)\nplayer.SetPlayer(...)\n</code></pre>\n\n<p>This is a bit annoying...
{ "AcceptedAnswerId": "48243", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T21:04:57.593", "Id": "48012", "Score": "5", "Tags": [ "beginner", "game", "go" ], "Title": "Wrote a package in Go. What did I do wrong? What did I do right?" }
48012
<p>I'm pretty new to Go, and I do not know the best or idiomatic ways to do most of the stuff, so I'd appreciate feedback on how to make my code better, faster or more idiomatic.</p> <p>My program is a set of methods/functions to parse an infix notation expression then convert it to reverse polish notation using Dijks...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T22:48:50.303", "Id": "48015", "Score": "4", "Tags": [ "optimization", "parsing", "converting", "go", "math-expression-eval" ], "Title": "Parsing an infix notation expressi...
48015
<p>Here is my solution to Project Euler 23: Non Abundant Sums. I know I'm doing the <code>Divisors</code> function brute force, but I can't seem to get it to work any other way. Any improvements are welcome.</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; //Calculates divisors void Divisors(unsigned ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T03:04:02.247", "Id": "84252", "Score": "0", "body": "Clean and well structured code, but your `Divisors` code populates a `vector` that is thrown away by `SumOfDivisors`. Combining those, retaining only the sum would eliminate the ...
[ { "body": "<p>I would recommend the following changes:</p>\n\n<ul>\n<li><p>Math is your friend. Factorize the number into prime powers (a precalculated table of primes is of immence value for a lot of Project Euler problems), and use a formula from <a href=\"http://en.wikipedia.org/wiki/Divisor_function\">this<...
{ "AcceptedAnswerId": "48018", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T22:54:59.443", "Id": "48016", "Score": "8", "Tags": [ "c++", "c++11", "programming-challenge" ], "Title": "Project Euler 23: Non Abundant Sums" }
48016
<p>In an effort to rid my code of jQuery, I wrote a custom global event management/handling system. I was expecting this to be hard as, from what I've read, most people don't create their own. It's far simpler than most libraries I've seen. Is there a flaw in this method? What are the benefits of using something like <...
[]
[ { "body": "<blockquote>\n <p>I was expecting this to be hard as, from what I've read, most people don't create their own</p>\n</blockquote>\n\n<p>Actually, there are <a href=\"https://www.google.com/search?q=js%20pub-sub%20libraries\">more people who create event emitters than you think</a>. I'm one of them, a...
{ "AcceptedAnswerId": "48025", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-23T23:22:23.827", "Id": "48017", "Score": "13", "Tags": [ "javascript", "event-handling" ], "Title": "Simple event management system" }
48017
<p>I'm implementing some basic algorithms in Go as an introductory exercise. Here are four different algorithms to find the Nth Fibonacci number.</p> <p>I'm looking for general feedback, but I'm specially interested in the Go idiom. Are the algorithms implemented idiomatically? If not, how can I correctly use the Go i...
[]
[ { "body": "<p>For <code>tailHelper()</code>, the <code>term == 1</code> case is superfluous and should be eliminated.</p>\n\n<p>In <code>fibonacciBinet()</code>, the quantity \\$\\frac{1 + \\sqrt{5}}{2}\\$ appears twice. Since that quantity is known as the <a href=\"http://en.wikipedia.org/wiki/Golden_ratio\" ...
{ "AcceptedAnswerId": "48077", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T02:28:32.067", "Id": "48020", "Score": "7", "Tags": [ "algorithm", "go", "fibonacci-sequence" ], "Title": "Four algorithms to find the Nth Fibonacci number" }
48020
<p>I have been teaching myself Python 3. I watched a video on YouTube entitled "stop writing classes". The Gtable class doesn't even have an init function, so I can't help but wonder if I should have done something different. Also as someone teaching themselves a language for the first time I would really appreciate an...
[]
[ { "body": "<p>So there are a few improvements that I can see in your code, mainly in the <code>create</code> function.</p>\n\n<hr>\n\n<p>When reading a file, use the <code>with</code> keyword. This will open the file and, once the program leaves that scope, the file will automatically be closed.</p>\n\n<p>I wou...
{ "AcceptedAnswerId": "48032", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T04:28:24.130", "Id": "48022", "Score": "5", "Tags": [ "python", "python-3.x", "hash-map" ], "Title": "Geometry table for use in regexes" }
48022
<p>This is intended as something of a comparative study. I'm including not just one, but two separate implementations of code to implement the Project Euler problem to sum the even Fibonacci numbers up to 4,000,000. The first is a very C-like implementation. The second attempts to make much more use of modern C++. To d...
[]
[ { "body": "<p>Sorry if I sound Fortranish. Project Euler is about math, not programming.</p>\n\n<p>A Fibonacci number is even if its index is \\$3n+2\\$. A Binet's formula reduces their sum to the sum of 2 geometric progressions. That, and some error estimation, is pretty much it.</p>\n", "comments": [ ...
{ "AcceptedAnswerId": "48030", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T04:39:12.740", "Id": "48023", "Score": "8", "Tags": [ "c++", "fibonacci-sequence", "comparative-review" ], "Title": "Another even Fibonacci numbers implementation" }
48023
<p>I just made a working implementation of calculating a string's length, but I'm not exactly sure it's the most efficient way. I divide the string up in blocks of four bytes each (32 bits), and add 4 to EAX. Once I hit a completely NULL block, I roll back the count of EAX by 4 bytes, and then calculate the final block...
[]
[ { "body": "<p>I have a number of comments that I hope you find helpful. </p>\n\n<h2>Code comments</h2>\n\n<p>First, your code is generally well commented and I had little difficulty in understanding what the code was doing or why. That's a good thing. A few minor points, though. First, your comment for the ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T11:09:06.430", "Id": "48034", "Score": "7", "Tags": [ "strings", "assembly" ], "Title": "String length calculation implementation in Assembly (NASM)" }
48034
<p>Please review this code.</p> <pre><code>import java.util.Scanner; import java.util.* ; public class LMComplex { Scanner name = new Scanner(System.in); Scanner age = new Scanner(System.in); Scanner gender = new Scanner(System.in); Scanner height = new Scanner(System.in); String usrname; String usrage; String usr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T11:35:35.770", "Id": "84280", "Score": "6", "body": "Format your code (indent blocks) for easy reading." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T11:37:12.803", "Id": "84282", "Score": "...
[ { "body": "<p>Indenting is the first part of common practice that you should consider when sharing your code with anyone. Here is your code, which I have put though the 'standard' indenting function of Eclipse:</p>\n\n<pre><code>import java.util.Scanner;\n\npublic class LMComplex {\n Scanner name = new Scann...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T11:15:20.787", "Id": "48035", "Score": "14", "Tags": [ "java", "beginner" ], "Title": "Questions & Responses: Let me tell you about you" }
48035
<p>I have code below which is set to check the date of <code>DateToComplete</code>, and if the date is 2 weeks or more ago, change the status of Complete from 3 to 2.</p> <p>Is this the best way?</p> <pre><code>USE [DB] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO Create PROCEDURE [dbo].[spChanger] AS BEGIN ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T15:51:27.003", "Id": "84329", "Score": "1", "body": "I removed the .net tag because this looks like a T-SQL CREATE PROCEDURE script, but the presence of `Date.Now.AddDays(14)` makes me wonder... is this working as it should?" }, ...
[ { "body": "<blockquote>\n<pre><code>Create PROCEDURE [dbo].[spChanger] \n\nAS\nBEGIN\n\nExecute ('UPDATE [TblActions] SET Complete = 2 WHERE DateToComplete &lt; Date.Now.AddDays(14) AND Complete = 3' )\n\nEND\n</code></pre>\n</blockquote>\n\n<p>Your casing is inconsistent. If you prefer UPPERCASE keywords, stic...
{ "AcceptedAnswerId": "48068", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T12:13:37.863", "Id": "48044", "Score": "2", "Tags": [ "sql", "stored-procedure" ], "Title": "Execute edit in a stored procedure based on database value" }
48044
<p>I am learning PDO. I have a class - User...</p> <pre><code>class User { protected static $table_name="users"; public $id; public $first_name; public $last_name; public function pdo_create() { global $handler; $sql = " INSERT INTO users (first_name, last_name)"; $sql .=...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T12:23:58.130", "Id": "84290", "Score": "1", "body": "Welcome to Code Review! Working code is exactly what we're about!" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T12:30:55.507", "Id": "84291",...
[ { "body": "<p>Your design is flawed in the following way:</p>\n\n<p><strong>DO NOT USE GLOBAL.</strong></p>\n\n<p>It is not OO programming and you shouldn't be calling it if you are using PDO - pass your PDO through your function or as part of your user constructors. (see <strong>SOLID</strong> design patterns)...
{ "AcceptedAnswerId": "48046", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T12:15:35.620", "Id": "48045", "Score": "4", "Tags": [ "php", "pdo" ], "Title": "Evaluation of insert method from within a class using PDO" }
48045
<p>I wrote this script as a way to backup and/or download quickly a set of repos or gists from a user. I don't have any major concerns but I'm a noob at bash scripting, and I've been scouring the internet putting these pieces together. I would love for someone to take a look and let me know best practices or problems...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T22:37:12.807", "Id": "84391", "Score": "0", "body": "Only glanced for a second but `if [[ \"$(some command)\" ]]; then` is very redundant when you want to depend on the commands return value. `if some command; then` works just fine....
[ { "body": "<p>It's not a bad attempt, though full of duplicated code and some bad practices.</p>\n\n<h3>Checking if a program exists</h3>\n\n<p>You do this kind of thing several times:</p>\n\n<blockquote>\n<pre><code># Check if git is installed, if not bail\nif [[ ! \"$(type -P 'git')\" ]]; then\n printf \"$...
{ "AcceptedAnswerId": "60212", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T14:11:21.143", "Id": "48050", "Score": "8", "Tags": [ "bash", "console", "git", "curl" ], "Title": "Bash script to clone all public repos or gists for a specified user, opt...
48050
<p>I have written some code to track buffs as a side addition to the popular game <a href="http://leagueoflegends.wikia.com/wiki/Buff" rel="noreferrer">League of Legends</a>.</p> <p>My code is incredibly repetitive and I also have the issue of not being able to track multiple buffs, although that might not be on topic...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T14:45:11.353", "Id": "84310", "Score": "2", "body": "You do know, something like that already exists? http://blog.overwolf.com/releases/overwolf-version-0-33-199-released" }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[ { "body": "<p>You could pull out the <code>while</code> loop of each function and make it its own function. Something like this</p>\n\n<pre><code>private static void Countdown(long startTime, long endTime, string finalMsg){\n while (System.currentTimeMillis() / 1000 &lt; endTime) {\n while (startTime ...
{ "AcceptedAnswerId": "48072", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T14:26:42.947", "Id": "48051", "Score": "26", "Tags": [ "java", "game", "timer" ], "Title": "Countdown Code: 'League of Legends'" }
48051
<p>I'm pretty new to Perl (<em>and multithreading</em>), so I was wondering if someone would be willing to take a look at my script and give me any tips on increasing performance.</p> <h2>Motivation</h2> <p>The script is designed to build several hundred C++ components, using multiple threads (one per component)</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T14:54:40.007", "Id": "84311", "Score": "2", "body": "It appears you may be using GNU `make`. What advantage are you're hoping to get beyond that obtained from using something like `make -j16`?" }, { "ContentLicense": "CC BY...
[]
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T14:44:21.753", "Id": "48055", "Score": "4", "Tags": [ "performance", "beginner", "multithreading", "perl" ], "Title": "Building hundreds of C++ components using multiple threa...
48055
<p>I am receiving the JSON from WebService and populating <code>ExpandoObject</code> from this one:</p> <pre><code> var converter = new ExpandoObjectConverter(); var jsonObject = JsonConvert.DeserializeObject&lt;ExpandoObject&gt;(json, converter); </code></pre> <p>The JSON object is quite complex and in order to fin...
[]
[ { "body": "<p>First, I don't see any reason for using <code>ExpandoObject</code> in your code. The same result could be achieved with cleaner code using <code>JObject</code>s.</p>\n\n<p>Second, what would help if you could express your query using “LINQ to null”. Basically, treat <code>null</code> as an empty c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-18T11:26:16.463", "Id": "48059", "Score": "2", "Tags": [ "c#", "json" ], "Title": "Is there a proper way to query ExpandoObject?" }
48059
<p>I am currently developing a touchless lightswitch via a Raspberry Pi, an ultrasonic module and a nice radio module.</p> <p>However, I am quite a beginner in Python and it was a hard time (at least for me) to accomplish my goal. Whenever the measured distance is falling below the limit the switch is triggered "on" (...
[]
[ { "body": "<p><code>MeasureDistance</code>. The way it is written, sometimes it measures the duration of the signal, sometimes the (desired) time for the echo to arrive (consider what happens if you enter the first <code>while</code> loop). Suggestion:</p>\n\n<pre><code>def MeasureDistance():\n StartTime = t...
{ "AcceptedAnswerId": "48089", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T19:22:34.787", "Id": "48081", "Score": "10", "Tags": [ "python", "beginner", "timer", "raspberry-pi" ], "Title": "Touchless lightswitch with Raspberry Pi" }
48081
<p>The old code I had before was atrociously slow but after some advice and research I was able to take a 2-5 minutes run time down to about 5-30 seconds. That is acceptable, but still looking to have it run as quickly as possible.</p> <p>I'm still cleaning it up, like there shouldn't be two seperate PP entities cal...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T23:13:05.717", "Id": "84394", "Score": "0", "body": "Is this faster? `abs( o.DateCompleted - (dtStartDate + 0.5) ) < 0.5`" } ]
[ { "body": "<p>You are calling queries in a for-loop for each day. Database queries are slow compared to C# code execution. Send only one query to the DB for the whole range of days.</p>\n\n<p>You can do the grouping by day either as DB query or query the ungrouped records and group using LINQ-to-Objects later.<...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T19:58:03.330", "Id": "48082", "Score": "5", "Tags": [ "c#", "performance", "linq", "entity-framework", "asp.net-mvc" ], "Title": "Getting list of daily team goals" }
48082
<p>I have a data structure that uses a <code>Dictionary&lt;ID,TimeSeries&gt;</code> to hold time series for different products. <code>TimeSeries</code> is implemented as something holding an array of <code>Point</code>, which contain a <code>DateTime</code> and a <code>double</code>.</p> <p>Its interface is:</p> <pre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T21:36:12.750", "Id": "84376", "Score": "0", "body": "I'm having a hard time telling what this is supposed to do without `Min` and `FindFirstDivergenceTime`, so IMO they are quite relevant. Also, this doesn't look like it would compi...
[ { "body": "<p>Before getting to your question about reducing the duplication, there's another issue I'd like to point out first. The use of <code>default(DateTime)</code> as a check for the absence of a value is incorrect and misleading. <code>default(DateTime)</code> is a <em>valid</em> date. However unlikely ...
{ "AcceptedAnswerId": "48153", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-24T21:07:34.757", "Id": "48084", "Score": "3", "Tags": [ "c#", "datetime" ], "Title": "Matching items in different arrays and performing operations on them" }
48084
<p>I asked a math question and was hoping someone could have a look at the code for me as well. Unfortunately you might have to go look at the original question <a href="https://math.stackexchange.com/questions/767888/math-for-future-value-of-growing-annuity">here</a>.</p> <pre><code>protected void ButtonCalRetire_Cli...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T01:12:17.287", "Id": "84400", "Score": "2", "body": "Separate the formulaic bits into its own method from the bits which react to and update the UI. Your concerns are then separated and easier to maintain." } ]
[ { "body": "<h1>Naming conventions</h1>\n\n<p>As you will have noticed from the coloring: you're not following naming conventions. Variables inside a method are lowerCamelCase which means this</p>\n\n<pre><code>FVc\n</code></pre>\n\n<p>becomes this</p>\n\n<pre><code>fvC\n</code></pre>\n\n<h1>Naming</h1>\n\n<p>Yo...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T00:33:26.920", "Id": "48091", "Score": "3", "Tags": [ "c#", ".net" ], "Title": "Retirement-saving calculator" }
48091
<p>I am trying to process an audio library file which is about 350 KB. My application processes each song on the file gets its meta-data and displays it in a List Box.</p> <p>The problem is that it takes too much time (about 1-2 mins). I need to make it faster like in the Windows Media Player. I tried to make it fast...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T00:58:11.617", "Id": "84399", "Score": "1", "body": "Can you clarify a little about your two \"approaches\"? From a first glance they don't seem to do the same, why exactly are they considered an alternative? And since you know one ...
[ { "body": "<p>Instead of loading the entire XML file, you can use XStreamingElement and xmlReader to reduce the memory foot print. As your playlist grows, large xml file will become a problem. The following MSDN link describes it <a href=\"http://msdn.microsoft.com/en-us/library/bb387013.aspx\" rel=\"nofollow\"...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T00:37:10.340", "Id": "48092", "Score": "2", "Tags": [ "c#", "performance", "xml", "wpf", "audio" ], "Title": "Optimizing playlist processing" }
48092
<p>At the moment is my code secure for SQL injections and so forth? I still need to hash passwords and make sure fields are valid and so forth. </p> <pre><code>&lt;?php try{ $handler = new PDO('mysql:host=localhost;dbname=s','root', '*'); $handler-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T05:09:08.570", "Id": "84427", "Score": "2", "body": "SQL attack has been over asked both here and on stackoverflow: http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php, and http://stackoverflow.com/questi...
[ { "body": "<p>It is safe.</p>\n\n<p>You can improve your code like this:</p>\n\n<ul>\n<li>no need to use closing <code>?&gt;</code> in case that you are not outputting any HTML / or something else after your PHP code</li>\n<li>no need to use <code>\"\"</code> to wrap strings in case that you don't have any vari...
{ "AcceptedAnswerId": "48139", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T01:52:54.630", "Id": "48095", "Score": "6", "Tags": [ "php", "mysql", "security", "pdo", "authentication" ], "Title": "Preventing SQL Injection in user registration rou...
48095
<p>I am not sure if I should be using recursion or not or if it even helps in increasing the performance of my algorithm. I feel as though I am creating and replacing too many arrays by calling my inner <code>rotate()</code> function.</p> <p>Should I add a check to convert rotation <code>-270</code> to <code>90</code>...
[]
[ { "body": "<p>The <code>n</code> parameter is redundant, as it should be possible to deduce the matrix dimensions from <code>matrix</code> itself, using <code>matrix.length</code> and <code>matrix[0].length</code>. You seem to have made the assumption that <code>matrix</code> is square — you should either docu...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T02:08:40.777", "Id": "48097", "Score": "4", "Tags": [ "javascript", "optimization", "matrix" ], "Title": "Matrix rotation efficiency" }
48097
<p>I understand that account details should be stored using a much more secure method, but this is only a demonstration script I've made to store login credentials and remember a user wishes to remain logged in using <code>localStorage</code> rather than <code>sessionStorage</code>.</p> <p>Could anyone show me how I m...
[]
[ { "body": "<h1>Separate UI from logic</h1>\n\n<p>You might want to keep the logic for localStorage handling separate from the DOM fetching logic. That way, your system for handling the local storage can easily be detached and reused elsewhere without that extra baggage. Also works the other way around, when you...
{ "AcceptedAnswerId": "48108", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T02:15:07.390", "Id": "48098", "Score": "5", "Tags": [ "javascript", "html5", "authentication" ], "Title": "Can this localStorage login script be written more efficiently?" }
48098
<p>Recently I had someone describe a "Time Machine" service to me; that is, a service that could be used to change how a chunk of code perceives time.</p> <p>Normally through calls to DateTime.Now and other DateTime statics, time is directly tied to the system clock. A Time Machine service is used instead of the stati...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T02:58:29.087", "Id": "84411", "Score": "9", "body": "Just clicked the link. 137 lines of code, too long? Meh, we review twice as much for breakfast! Feel free to put it all in and have the *implementation* reviewed as well!" }, ...
[ { "body": "<p>I like it.</p>\n\n<p>For some <em>very specific cases</em> where a class needs to be tested and <em>its functionality depends on what <code>System.DateTime.Now</code> returns</em>, then you need an <em>abstraction</em> to wrap the static method calls, if you want to be able to write unit tests tha...
{ "AcceptedAnswerId": "48102", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T02:22:05.073", "Id": "48100", "Score": "6", "Tags": [ "c#", ".net", "datetime" ], "Title": "Time Machine service" }
48100
<p>I've implemented the following <code>nub'</code> or "give distinct elements of list" function:</p> <pre><code>nub' :: (Eq a) =&gt; [a] -&gt; [a] nub' [] = [] nub' xs = nubHelper xs [] nubHelper :: (Eq a) =&gt; [a] -&gt; [a] -&gt; [a] nubHelper [] acc = acc nubHelper (y:ys) acc = if(contains y acc) ...
[]
[ { "body": "<p>For the \"official\" answer, you can go straight to the <a href=\"http://www.haskell.org/ghc/docs/6.12.1/html/libraries/base-4.2.0.0/src/Data-List.html#nub\">GHC source for <code>nub</code></a>:</p>\n\n<pre><code>nub :: (Eq a) =&gt; [a] -&gt; [a]\nnub l = nub'...
{ "AcceptedAnswerId": "48104", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T02:43:19.493", "Id": "48101", "Score": "9", "Tags": [ "haskell", "reinventing-the-wheel" ], "Title": "Implementing nub (distinct)" }
48101
<p>This code basically saves an uploaded file to the server. I am wondering if there is anything that I can do to tighten this code up. I am very new to F# so I'm still having trouble breaking away from the C# way of doing things.</p> <pre><code>/// Create file paths /// Returns a tuple (server path * link path * fi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T14:08:58.563", "Id": "84486", "Score": "1", "body": "It looks fine to me. I'd probably define a type for `createPath`'s return value instead of using a 3-tuple. The only other observation is it's unnecessary to check if a directory ...
[ { "body": "<p>I think that you're using comments unnecessarily. If you set a variable called <code>fileNumber</code>, the comment <code>// get file number</code> doesn't tell the reader anything new and only clutters the code.</p>\n\n<hr>\n\n<pre><code>// directory check\nlet pathExists() = Directory.Exists(ser...
{ "AcceptedAnswerId": "48245", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T03:32:30.317", "Id": "48106", "Score": "4", "Tags": [ "beginner", "f#", "http" ], "Title": "Server code to save uploaded files" }
48106
<p>I was a TA for a first-year Java programming course this year. As a very simple example of iterables/iterators, I wrote the following code for the students. I am curious if any styling or other improvements can be made.</p> <pre class="lang-java prettyprint-override"><code>import java.util.NoSuchElementException; i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T04:20:10.063", "Id": "84422", "Score": "6", "body": "how 'bout `@Override` annotations?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-05-01T21:00:41.513", "Id": "160396", "Score": "0", "body":...
[ { "body": "<h2>Variables</h2>\n\n<p>I understand why you have the <code>Range.this.end</code> and <code>Range.this.start</code> to avoid confusion about where those variables come from... If you need the <code>Range.this</code> as part of the teaching exercise, then sure. Otherwise, I would recommend three thin...
{ "AcceptedAnswerId": "48114", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T04:17:32.457", "Id": "48109", "Score": "45", "Tags": [ "java", "iterator", "interval" ], "Title": "Simple Example of an Iterable and an Iterator in Java" }
48109
<p>I'm trying to implement a template that takes a container as parameter. The template has a <code>getnext</code> method that cycles through the elements in the parameter. Take note that I'm not using C++11.</p> <p>Header:</p> <pre><code>#pragma once template&lt;template&lt;class, class&gt; class TContainer, class ...
[]
[ { "body": "<p>A few remarks:</p>\n\n<ul>\n<li><p>Try to avoid <a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\"><code>using namespace std</code></a>.</p></li>\n<li><p>In <code>Processor</code>, you should also explicitly call the constructor of the vector...
{ "AcceptedAnswerId": "48133", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T04:18:13.157", "Id": "48110", "Score": "4", "Tags": [ "c++", "template", "c++03" ], "Title": "Using a template to cycle through a sequence of containers" }
48110
<p>If I have a number of different classes which manage certain tests. At the moment I have to launch each test individually which results in a lot of <code>if</code> statements.</p> <p>I wonder if there is a way of putting all of these in a loop to manage the launching of each test and retrieving of results more clea...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T07:26:42.523", "Id": "84445", "Score": "2", "body": "Could you give some more context? Are you testing software or an actual car? Why would you not run every test always?" }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[ { "body": "<p>The params for testing are different from each object, so I think this part should be put in the classes and present a uniform interface, this is what classes are about.</p>\n\n<p>I suggest 2 versions: either you only put the params needed for test in the classes, or (better in my opinion), you pu...
{ "AcceptedAnswerId": "48135", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T06:07:54.753", "Id": "48118", "Score": "3", "Tags": [ "python", "classes", "unit-testing", "python-2.x" ], "Title": "Loop cleanly through different classes" }
48118
<p>I have written a Java class to replace text in file. The file contains database configurations and is as follows:</p> <pre><code>test.properties #local db.url=jdbc:oracle:thin:@localhost:test #db.user=testa #db.password=testa db.user=testb db.password=testb #db.user=testc #db.password=testc </code></pre> <p><...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T07:08:49.330", "Id": "84444", "Score": "4", "body": "Rather than editing a file programmatically, consider keeping several configuration files, and copying the appropriate one into place to activate it. It's much simpler that way!"...
[ { "body": "<p>Actually, this can be more generic.</p>\n\n<p>Instead of hard-coding your map; fill it from your properties file.<br>\nSo change your prop file to : </p>\n\n<pre><code>#db.id=a\n#db.user=testa\n#db.password=testa\n\ndb.id=b\ndb.user=testb\ndb.password=testb\n</code></pre>\n\n<p>Fill your map like ...
{ "AcceptedAnswerId": "48126", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T06:36:45.910", "Id": "48122", "Score": "11", "Tags": [ "java", "file", "io" ], "Title": "File editing program" }
48122
<p>I wrote this code to handle logged in users. The session IDs will be stored in cookies. I would like to know if it's usable or if there are security problems.</p> <p>It uses a 64bit id and another 64bit validation ID. Perhaps this is a bad idea, but here's what I thought: if someone tries to carry a brute force att...
[]
[ { "body": "<p>I am going to be very urandom here.</p>\n\n<ol>\n<li><p><code>ids[i] = table[random]</code> badly decreases the entropy. Instead of 64 random bits, your ID has less than 48.</p></li>\n<li><p>Can you elaborate on a use case, especially how the validation ID is used.</p></li>\n<li><p>As much as I am...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T06:44:26.597", "Id": "48123", "Score": "4", "Tags": [ "c", "security", "session" ], "Title": "Session manager for logged in users" }
48123
<p>I had a rather large method in one public class that I refactored into 2 helper classes. The thing is though, that those 2 helper classes have dependencies. I refactored them into helper classes so I could mock and test them easily, which worked out perfectly.</p> <p>However, the thing is I don't want to have to re...
[]
[ { "body": "<p>I don't see anything wrong with your implementation - if it works for you, and does not interfere with the system - go for it!</p>\n\n<p>I will even go further and claim that the guard conditions in your internal constructor are redundant because the constructor will only be used by the single pub...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T08:05:33.873", "Id": "48129", "Score": "3", "Tags": [ "c#", "design-patterns", "dependency-injection" ], "Title": "Using Poor Man's DI to inject helper class dependencies" }
48129
<p>Resharper complain if you have code like this:</p> <pre><code>border-width: 0px 1px 1px 0px; </code></pre> <p>and insists that units should be removed from zeroes as they are redundant. They are redundant, that is absolutely true, but I don't like inconsistency that is introduced by removal of units. You get code ...
[]
[ { "body": "<p>0cm, 0px or 0x corresponding to 0, it doesn't need unit if it's of the same order of magnitude. 0px * 10cm is the same than 0 * 10cm.\nIn this case border-width corresponding to length's order of magnitude it's not necessary to precise the units.</p>\n\n<p>Moreover, for my part, I never specifies ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T08:52:04.667", "Id": "48132", "Score": "1", "Tags": [ "css", "visual-studio" ], "Title": "Resharper: Unit of measure is redundant" }
48132
<blockquote> <p><strong>Problem:</strong></p> <p>The fraction \$(\dfrac{49}{98})\$ is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that \$(\dfrac{49}{98}) = (\dfrac{4}{8})\$, which is correct, is obtained by cancelling the 9s.</p> <p>We shall...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T13:22:39.733", "Id": "84481", "Score": "0", "body": "Note for reviewers : the `start = timer()` is a mistake. Keeping the code in the answer as it is unless a mod thinks it's better to change it." } ]
[ { "body": "<p>Firstly, you set <code>start</code> at the top of the script (which is OK). However, you <strong>reset</strong> <code>start</code> right before your final calulation:</p>\n\n<pre><code># This will only time the execution of one statement!\nstart = timer()\nans = product_of_fractions[1] / product_o...
{ "AcceptedAnswerId": "48147", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T10:22:46.873", "Id": "48137", "Score": "8", "Tags": [ "python", "optimization", "programming-challenge" ], "Title": "Project Euler Problem 33 - digit canceling fractions" }
48137
<p>When it come to security I try to be to better as possible but I don't have the knowledge.</p> <p>According to what I read on-line my following code should be good but I could use some of your comment/critic/fixes</p> <p>Here is a simple class just to example how I would do a login. Does it look secure enough?</p...
[]
[ { "body": "<p>I'm not sufficiently familiar with PDO to say more on your database access than that you don't seem to have any injection vulnerabilities. However, there are a few things which I would do differently.</p>\n\n<h3>Salt entropy</h3>\n\n<p>There are two things which strike me as odd about your salt ge...
{ "AcceptedAnswerId": "48164", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T13:44:43.690", "Id": "48146", "Score": "6", "Tags": [ "php", "mysql", "security" ], "Title": "Is this user login secure?" }
48146
<p>Using <a href="https://codereview.stackexchange.com/questions/43111/a-generic-memorycache-class">this question</a> as a base, and using some of the advice in the answers, I wanted to build out something that would be generic, thread-safe, and easy to use for at least one current and several future projects.</p> <p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-09-19T19:02:48.263", "Id": "265858", "Score": "0", "body": "I am providing a small suggestion. Please invert your `if` statements. It's easier to return from a quick `if` than to wrap the contents of entire methods in them. Makes code mor...
[ { "body": "<p>Short version: it looks like you're just trying to get a per-type ObjectCache. That's a basic singleton pattern, so I'm unsure what you're trying to gain through all this extra cruft in the class. If it were me, I would consider the following code:</p>\n\n<pre><code>public static class GlobalTyped...
{ "AcceptedAnswerId": "48267", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T13:56:49.510", "Id": "48148", "Score": "15", "Tags": [ "c#", "thread-safety", "generics", "cache" ], "Title": "Generic, thread-safe MemoryCache manager for C#" }
48148
<p>I'm using the following structure:</p> <pre><code>class Map { public List&lt;List&lt;Point&gt;&gt; points; public List&lt;Base&gt; bases; } </code></pre> <p><code>Point</code> and <code>Base</code> are over-normal sized classes (has more than 30 attributes).</p> <p>And I'm iterating this <code>Map</code> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T14:10:39.203", "Id": "84487", "Score": "3", "body": "Unless I'm very mistaking, both an array and `List<T>` have O(1) lookup time so there will be no difference in performance. If there is anything we can say with respect to perform...
[ { "body": "<p>I think speed will only increase a bit, if at all, if you use arrays (The List implementation you use may already use an array).\nBut you will reduce memory consumption if you switch to an array based implementation if you reduce the number of objects used this way.</p>\n\n<p>You should profile bo...
{ "AcceptedAnswerId": "48169", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T13:59:04.510", "Id": "48150", "Score": "6", "Tags": [ "c#", "performance" ], "Title": "Any performance difficulties related to List<Type>?" }
48150
<p>Should the following <code>GetPhysicalFileLocation()</code> method in the <code>Car</code> class have its own Service Layer?</p> <pre><code>public class Car { public int id; public string model; public int year; public IList&lt;Pic&gt; lstCarPics; } </code></pre> <p>Then we have the respective clas...
[]
[ { "body": "<p>The convention for public fields and properties in c# is <code>PascalCasing</code>. This would make the following:</p>\n\n<pre><code>public class Car\n{\n public int Id; //{ get; set; } this makes it a property.\n public string Model;\n public int Year; \n public IList&lt;Pic&gt; LstCa...
{ "AcceptedAnswerId": "48163", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T15:22:46.480", "Id": "48158", "Score": "2", "Tags": [ "c#", "design-patterns" ], "Title": "Is this method a good candidate for a service layer?" }
48158
<p>I've been working with PHP for a while now, but unfortunately haven't delved into the OO side of it until recently. I've been reading up on <a href="http://en.wikipedia.org/wiki/Separation_of_concerns" rel="nofollow">separation of concerns</a> and OOP best practices, and I think I have an idea of what is expected, ...
[]
[ { "body": "<p>Your <code>profile.php</code> file is doing way too much. A good test to see if you are adhering to the Separation of Concerns principle is: Do one thing, and do it well.</p>\n\n<p>It seems <code>profile.php</code> is doing the following things:</p>\n\n<ol>\n<li>Gathering information from the HTTP...
{ "AcceptedAnswerId": "48179", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T16:19:40.390", "Id": "48165", "Score": "2", "Tags": [ "php", "object-oriented", "pdo" ], "Title": "Is this following Separation of Concerns and PHP OOP standards?" }
48165
<p>Another piece of Roslyn-based code, this time a <code>CodeFixProvider</code>. </p> <p>I'm looking for feedback on Roslyn-specific code: </p> <ul> <li>Am I using the <code>SemanticModel</code> correctly?</li> <li>Are there any codeflows I have overlooked that might cause issues?</li> <li>Am I violating any best pra...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T18:09:31.713", "Id": "84550", "Score": "0", "body": "Removed a line of code that was a leftover from experimenting." } ]
[ { "body": "<p>I know nothing about rosyln, so there would be someone better to check that, however...</p>\n<h1>Analyzer</h1>\n<ul>\n<li>You create <code>Description</code>, <code>MessageFormat</code> &amp; <code>Category</code> as static strings but only use them in the constructor of <code>Rule</code>. I don't...
{ "AcceptedAnswerId": "48433", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T17:13:02.593", "Id": "48170", "Score": "7", "Tags": [ "c#", "roslyn" ], "Title": "CodeFixProvider that instantiates collections" }
48170
<p>I'm new to OOP PHP and I created a simple input helper class. And was wondering if it's good? Are my dependencies good?</p> <p>Also the reason I'm not throwing an exception with the get method is that I will mainly use this class for form validation purposes.</p> <p>I'll take any suggestion for improvement!</p> <...
[]
[ { "body": "<p>In Java and C# you can simply put </p>\n\n<pre><code>return !empty($this-&gt;_source);\n</code></pre>\n\n<p>and</p>\n\n<pre><code>return isset($this-&gt;_source[$input]);\n</code></pre>\n\n<p>since the evaluation of that is a boolean by itself and thus there is no need for the additional ternary o...
{ "AcceptedAnswerId": "48172", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T17:14:59.137", "Id": "48171", "Score": "1", "Tags": [ "php", "object-oriented" ], "Title": "Does my input helper class look good?" }
48171
<p>I don't know that my title describes the code I want reviewed. Hopefully the code is explanatory.</p> <p>I have an abstract parent class with two children. The parent listens to some hardware notifications and, when the appropriate hardware is connected/removed/fried in butter etc.., raises an event to its children...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T17:56:43.723", "Id": "84544", "Score": "0", "body": "Are `DeviceChild1` and `DeviceChild2` *actual* class names?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T17:57:18.603", "Id": "84545", "...
[ { "body": "<p>The events in the base class don't follow the standards:</p>\n\n<pre><code>public event Action&lt;TEventArgs&gt; DeviceArrived;\npublic event Action&lt;TEventArgs&gt; DeviceRemoved;\n\nprotected event Action&lt;string&gt; DeviceArrival;\nprotected event Action&lt;string&gt; DeviceRemoval;\n</code>...
{ "AcceptedAnswerId": "48180", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T17:51:07.673", "Id": "48174", "Score": "5", "Tags": [ "c#", "generics", "inheritance", "event-handling" ], "Title": "Having children call parent's public events with data g...
48174
<p>I have implemented stochastic gradient descent in matlab and I would like to compare my results with another source but the error I am getting is higher (I am using squared error). I am worried I am misunderstanding the algorithm or have a bug. I have done trial and error parameter tuning, and am quite confident I h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T13:01:41.640", "Id": "84643", "Score": "0", "body": "One thing you could try is to keep the error data at each iteration and make a plot to see if you are converging to the error value of the comparison." }, { "ContentLicens...
[ { "body": "<p>You probably do not need help with this question anymore (looks like it's been a year), but I thought I'd point something out in case someone else finds it useful. I think your squared loss expression should be \\$(w'*x - y)^2\\$ and the derivative of that with respect to \\$x\\$ is: \\$2*(w'*x-y)...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T18:10:41.753", "Id": "48175", "Score": "0", "Tags": [ "algorithm", "matlab", "machine-learning" ], "Title": "Stochastic gradient descent squared loss" }
48175
<p>This gallery uses the Orbit gallery from the Foundation framework (version 3). I've set it up so that on smaller screens it appears as an accordion.</p> <p>It works just fine, but is there a more concise way this could've been written? Perhaps in an object oriented way?</p> <p><strong>The script:</strong> </p> <p...
[]
[ { "body": "<p>The most important bit here is the resize handler, since it fires many times per scroll.</p>\n\n<pre><code>//Run on document ready\n$(function () {\n\n // Cache the slider jQuery object\n var slider = $('#slider');\n\n // Pass in the existing reference. Explanation after the code\n act...
{ "AcceptedAnswerId": "48191", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T18:30:53.857", "Id": "48177", "Score": "3", "Tags": [ "javascript", "jquery", "object-oriented" ], "Title": "How could I have approached this responsive image gallery different...
48177
<blockquote> <p>Given a "folder" which contains many "files," each file contains a time-table of trains, which stations they halt on and what time, per day.</p> <pre><code>File-1 for day-1 Train1 [station1, &lt;1 - 3&gt; ] [station2, &lt;5 - 6&gt; ] Train2 [station1, &lt;10 - 12&gt;] [station3, &lt;15 - 18&...
[]
[ { "body": "<p>Quick review, but still good coding like usual.</p>\n\n<h2>Naming :</h2>\n\n<pre><code>int i = 0; // ctr for start time array\nint j = 0; // ctr for end time array\n</code></pre>\n\n<p>Isn't it better to call them <code>pointerStartTime</code> and <code>pointerEndTime</code>?<br/>\nIt helps you ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T18:32:55.290", "Id": "48178", "Score": "3", "Tags": [ "java", "algorithm", "hash-map" ], "Title": "Trains scheduled, find max platforms per stations" }
48178
<p>I have to update a class property with the method name and then call a method that executes some code based on this property. The code is the same in both methods, but I am not seeing a way to remove this code duplication. I am trying to avoid using a parameter.</p> <pre><code>public function register(){ $this-...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T19:19:11.417", "Id": "84564", "Score": "0", "body": "Why are you trying not to use a parameter ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T19:21:54.110", "Id": "84567", "Score": "0", ...
[ { "body": "<p>Short version: <strong>Use a parameter!</strong></p>\n\n<pre><code>public function handleOperation($action) {}\npublic function register() { $this-&gt;handleOperation(\"register\"); }\npublic function unregister() { $this-&gt;handleOperation(\"unregister\"); }\n</code></pre>\n\n<hr>\n\n<p>Slightly...
{ "AcceptedAnswerId": null, "CommentCount": "18", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T19:10:27.043", "Id": "48181", "Score": "2", "Tags": [ "php" ], "Title": "Find a better logic to remove duplicated code from two different methods" }
48181
<pre><code>from time import time def baseRandom(): return hash(str(time())) def randFromZero(maximum): return baseRandom() % maximum def randRange(minimum, maximum): return randFromZero(maximum - minimum) + minimum </code></pre> <p>I ask what's wrong because it seems so simple and stupid. This is someth...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T19:24:40.463", "Id": "84569", "Score": "0", "body": "How are you intending to use the \"random\" output? Why aren't you using the builtin random functions?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04...
[ { "body": "<p>It looks like you're relying on running this on a system where the granularity of the time() function is smaller than the amount of time it takes to execute baseRandom(), do what you want with the results, and come back to call baseRandom() again. If not, you'll get more repeating numbers than yo...
{ "AcceptedAnswerId": "48186", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T19:11:44.697", "Id": "48182", "Score": "3", "Tags": [ "python", "python-3.x", "random", "reinventing-the-wheel" ], "Title": "Random number generator based on a hash of the ...
48182
<p>I've benchmarked my program, and have discovered that the single function taking the most time is the one that does the following.</p> <ul> <li>Takes string that is a delimited list, and splits it into individual strings (Within the program, the individual strings are called statements)</li> <li>Looks at the indivi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T19:33:35.027", "Id": "84574", "Score": "1", "body": "If I understand correctly. You can store all your library statement words in a dictionary and look them up." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
[ { "body": "<p>You're just looking to find any <code>textStatement</code>'s that exist in <code>Library.Statements</code>? A <code>HashSet</code> will make easy work of this:</p>\n\n<pre><code>IEnumerable&lt;string&gt; splitInputStatements = SplitStatements(data);\nHashSet&lt;string&gt; inputStatements = new Has...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T19:21:08.793", "Id": "48183", "Score": "3", "Tags": [ "c#", "strings" ], "Title": "Increase performance of string matching function" }
48183
<p><strong>Background information</strong></p> <p>I've been asked to write a little Perl script that allows genomic data to be screened against reference files in order to determine locations of specific mutations.</p> <p>The input file format look like this (information are tab-separated). <strong>In the script it's...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T20:20:57.043", "Id": "84587", "Score": "0", "body": "When I run your script, the output contains two lines both for KB668289: one for location 903 and the other for 1224. Is it correct? Your descriptions seems to indicate that onl...
[ { "body": "<h1>Style Guides</h1>\n\n<p>The Perl community does not have a single universal style – there is more than one way to do it. But sometimes, consistency isn't a bad thing either. Here are the three important cornerstones of Perl style:</p>\n\n<ul>\n<li>A <a href=\"https://metacpan.org/pod/distribution...
{ "AcceptedAnswerId": "48197", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T19:44:41.380", "Id": "48184", "Score": "4", "Tags": [ "perl", "csv", "bioinformatics", "join" ], "Title": "Data screening using Perl" }
48184
<p>I have finally finished creating my first real project. It's just a simple music player that can provides the user with the latest music from any site (as long as it contains MP3 files) he provides in the settings file. It can play it, download it and has an simple settings file from which the user can: add/change...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-07T18:45:47.043", "Id": "86408", "Score": "0", "body": "I updated the code [here](http://codereview.stackexchange.com/questions/49128/bash-music-player-2) .." } ]
[ { "body": "<p>Whitespace is not a precious resource: your code is <strong>far</strong> too dense for my taste</p>\n\n<ul>\n<li>fewer semicolons, more newlines.</li>\n<li>try to limit your line length to 90 chars for readability</li>\n</ul>\n\n<p>You rely upon the presence of ~/Music, but never test that it exis...
{ "AcceptedAnswerId": "48520", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T20:15:35.817", "Id": "48187", "Score": "5", "Tags": [ "beginner", "bash", "shell", "unix", "audio" ], "Title": "Bash Music Player" }
48187
<pre><code> \0 / \ a b-a-t-s /|\ m s t </code></pre> <p>which contains [am, as, at, bat, bats]</p> <p>The goal I'm trying to reach is to iterate through the trie to find if there's a next word or not, then if so get that word.</p> <p>I would like to know your opinion on my approach.</p> <p>The goal for this...
[]
[ { "body": "<p>This doesn't look too bad to me, though it would be nice to have the full source code that I could run. I'll comment on the things that stand out to me, though.</p>\n\n<p><strong>Unncessary logic</strong></p>\n\n<pre><code>public boolean hasNext() {\n if (position &lt; this.trie.nodeCount()) re...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T20:50:36.867", "Id": "48190", "Score": "5", "Tags": [ "java", "trie" ], "Title": "Trie string iterations" }
48190
<p>Please treat this as a interview at a top tech firm, and share your thoughts on how you think I did. Be honest, and leave no stone unturned.</p> <blockquote> <p>Problem:</p> <p>Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such tha...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-08-13T23:03:13.650", "Id": "259198", "Score": "0", "body": "From: https://leetcode.com/problems/word-ladder/" } ]
[ { "body": "<p>First of all, I really liked that your logic doesn't need to compare lengths: as soon as a match is found, it must be one of the shortest lengths, nice! And when the <code>end</code> is unreachable, the method returns 0, an impossible answer (since a valid length must be >= 1), so that's good too....
{ "AcceptedAnswerId": "48215", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T21:02:49.650", "Id": "48192", "Score": "9", "Tags": [ "java", "algorithm", "interview-questions" ], "Title": "Finding the length of shortest transformation sequence from start ...
48192
<p>I'm wondering what the best way of initializing variables so that I don't over use the garbage collector with a <code>for</code>-loop. Assuming the variable is only used inside the <code>for</code>-loop. Is it better to declare the variable outside of the <code>for</code>-loop?</p> <pre><code>public void foo() { ...
[]
[ { "body": "<p>For the Garbage Collector, it doesn't matter at all. You don't <em>create</em> the object. You just use an object reference to it in the above code.</p>\n\n<p>The String object itself is still stored in the <code>Person</code> class and is therefore not garbage-collected until it is changed inside...
{ "AcceptedAnswerId": "48194", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T21:07:35.853", "Id": "48193", "Score": "4", "Tags": [ "java", "performance", "garbage-collection" ], "Title": "How do I avoid over-using the garbage collector?" }
48193
<blockquote> <p>Write a function that takes two parameters:</p> <ol> <li>a <code>String</code> representing a text document</li> <li>an integer providing the number of items to return</li> </ol> <p>Implement the function such that it returns a list of Strings ordered by word frequency, the most freq...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T06:46:34.643", "Id": "84618", "Score": "0", "body": "Nicely done for homework." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T01:06:02.970", "Id": "84733", "Score": "0", "body": "Lets say...
[ { "body": "<p>There are a number of things in here you have done well, and your algorithm is good. I like that you have created an object to contain the frequency. Using the HashMap is the right solution too.</p>\n\n<p>Overall, the OOP, and algorithm is good, but.... the presentation is messy, and there's a cou...
{ "AcceptedAnswerId": "48203", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T22:20:23.163", "Id": "48198", "Score": "10", "Tags": [ "java", "algorithm", "strings", "sorting" ], "Title": "Count frequency of words in a given file" }
48198
<p>From the command line, I can easily find the path to <code>rubygems.rb</code></p> <pre><code>$ gem which rubygems /usr/lib/ruby/1.9.1/rubygems.rb </code></pre> <p>and from a Ruby script I can also do this</p> <pre><code>require 'rubygems/commands/which_command' wc = Gem::Commands::WhichCommand.new puts wc.find_pa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T08:26:47.897", "Id": "84623", "Score": "0", "body": "Don't you think this question should go on SO?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T09:01:37.173", "Id": "84629", "Score": "0", ...
[ { "body": "<p>Whether a simpler solution exists depends on what your motivation is.</p>\n\n<p>Let's look inside the implementation of <code>Gem::Commands::WhichCommand#find_paths</code>.</p>\n\n<pre><code> def find_paths(package_name, dirs)\n result = []\n\n dirs.each do |dir|\n Gem.suffixes.each do...
{ "AcceptedAnswerId": "48202", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T23:21:58.477", "Id": "48200", "Score": "3", "Tags": [ "ruby", "file-system", "modules" ], "Title": "Return path to rubygems.rb" }
48200
<blockquote> <p>145 is a curious number, as \$1! + 4! + 5! = 1 + 24 + 120 = 145\$.</p> <p>Find the sum of all numbers which are equal to the sum of the factorial of their digits.</p> <p><strong>Note:</strong> as \$1! = 1\$ and \$2! = 2\$ are not sums they are not included.</p> </blockquote> <p>I can't fi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T23:58:07.383", "Id": "84601", "Score": "0", "body": "Please remember to tag these questions with [programming-challenge] and [optimization]." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T04:23:14.57...
[ { "body": "<p>I'm not aware of any mathematical way to establish the upper bound for the search space (I used the same upper limit as you did). However, there are some optimizations you can make:</p>\n\n<ol>\n<li><p>Use integer math throughout instead of converting to a string, extracting the digits, then conve...
{ "AcceptedAnswerId": "48232", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-25T23:46:40.610", "Id": "48201", "Score": "6", "Tags": [ "python", "optimization", "programming-challenge" ], "Title": "Project Euler 34 - digit factorials" }
48201
<p>So, generally when I write iOS code, I will start with a lot of calls to <code>NSLog</code>, which is a macro that with print the string you send it to the console.</p> <p>There's a few problems with this.</p> <p>First of all, whether you know it or not, you can see what's being printed to an iOS device's console ...
[]
[ { "body": "<p>The easiest way to avoid the extraneous function is going to be to use a function directly rather than using a macro. You do unfortunately have to drop down to a bit of C, but luckily since ObjC integrates rather pleasantly with C, it proves to not be very painful. The only C part is the use of th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T01:29:06.330", "Id": "48204", "Score": "9", "Tags": [ "objective-c", "logging" ], "Title": "Creating a better NSLog" }
48204
<p>I wrote this program to match square brackets as part of a Brainf**k interpreter. I'm aware that it gets caught in an infinite loop if brackets are entered like this: <code>][</code>.</p> <ol> <li>Are there any performance improvements I can make?</li> <li>Should I change any variable names?</li> <li>Are there othe...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T08:56:04.763", "Id": "84628", "Score": "1", "body": "I would not scan backwards for the open brace. When you hit an open brace push the current position onto the stack. When you hit a close brace pop the value and just move the inst...
[ { "body": "<p>Do not use <code>strlen()</code> in <code>for</code> loops. <code>strlen()</code> walks over the string every time you call it. </p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T03:42:28.807", "Id": "84611", "Score": "0...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T01:56:15.907", "Id": "48205", "Score": "5", "Tags": [ "c", "validation" ], "Title": "Matching square brackets" }
48205
<p>In the last 2 years or so, I've learned a great deal about how to write better Scala code, but I know that I've barely scratched the surface. This is part of a library that I've been using. It has evolved a great deal since the first version and I'm curious to see how many mistakes I'm still making. I am particularl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T12:46:39.983", "Id": "84642", "Score": "0", "body": "The [Netflix reactive programming library](https://github.com/Netflix/RxJava/tree/master/language-adaptors/rxjava-scala) does something similar. The whole approach is somewhat di...
[ { "body": "<p>Your whole design looks very mutable, but because I don't know your domain or the libraries you use I can't say to what extend it makes sense to functionalize it. Some thoughts while looking through the code:</p>\n\n<p>Always specify return types for public members (even consider <code>Unit</code>...
{ "AcceptedAnswerId": "48218", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T04:58:19.427", "Id": "48210", "Score": "8", "Tags": [ "scala" ], "Title": "Event dispatcher" }
48210
<p>I'm creating a Space Invaders game, and graphics sprites in it are defined as 2D arrays of colors. </p> <p>It seems like it's going to be cumbersome declaring these arrays the way I currently am:</p> <pre><code>//This creates an inverting red/blue cross animation public Sprite myFirstAnimation() { Sprite frame...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T05:21:45.287", "Id": "84615", "Score": "1", "body": "... It seems like, using a bit of code that will convert bitmaps into my 2d array is what I'm going to want." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2...
[ { "body": "<p>You're trying to store data in code. While that is not bad idea by itself, you shouldn't overuse it and I think that's what you're doing here.</p>\n\n<p>If your data is bitmaps, store them in some bitmap format (BMP or maybe PNG) and then load them into your program from that. As an additional adv...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T05:11:40.903", "Id": "48211", "Score": "4", "Tags": [ "c#", "array" ], "Title": "Declaring a large number of 2D arrays to be used as 2D graphic sprites" }
48211
<p>This code is for a simple 2D tile-based game. <code>x1</code> and <code>y1</code> are the mouse coordinates in the world. <code>entity-&gt;x1</code> and <code>entity-&gt;y1</code> is the point where the player is, the shot origin.</p> <p>I would like to know how to keep the current output while simplifying the code...
[]
[ { "body": "<p>I have a few remarks:</p>\n\n<ul>\n<li><p>You may have a problem with this line of code:</p>\n\n<pre><code>float slope = (y1 - entity-&gt;y1) / (x1 - entity-&gt;x1);\n</code></pre>\n\n<p>If <code>entity</code> is already at the longitude <code>x1</code>, this will cause a division by 0. Such a div...
{ "AcceptedAnswerId": "48262", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T06:23:30.467", "Id": "48212", "Score": "12", "Tags": [ "optimization", "algorithm", "c" ], "Title": "Optimize code to track player shot" }
48212
<p>The Greed game, from Ruby Koans, where you roll up to 5 dice:</p> <blockquote> <p>A set of three ones is 1000 points. A set of three numbers (other than ones) is worth 100 times the number.</p> <p>A one (that is not part of a set of three) is worth 100 points. A five (that is not part of a set of three) is worth 50 ...
[]
[ { "body": "<p>I think your code is very nice, succinct, and ruby-like.</p>\n\n<p>Two minor issues - </p>\n\n<p>Your <code>bonus</code> code is a bit over-sophisticated, which makes it not very readable, and quite brittle. Although it won't fit in one line - a <code>case</code> solution will be more suitable her...
{ "AcceptedAnswerId": "48216", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T06:43:10.810", "Id": "48213", "Score": "7", "Tags": [ "ruby", "dice" ], "Title": "RubyKoans: Greed dice scoring" }
48213
<p>I'm trying to display data from Keen.io we're collecting from an iOS app where we report what devices of ours the app is used to communicate with. In particular I'm trying to find where there are more than one of our device.</p> <p>An entry from the Keen collection looks like:</p> <pre><code>{ "iOS_OpenUDID": "h...
[]
[ { "body": "<p>Nice work, @parsley72! This is a really clever mashup, no reason to suspect it's \"not good\" or even \"awful\" :)</p>\n\n<p>[Keen IO employee here, fwiw]</p>\n\n<p>One characteristic worth considering is reusability, but since this seems to be a fairly specialized bit of code I wouldn't spend too...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-04-26T07:37:35.130", "Id": "48214", "Score": "6", "Tags": [ "javascript" ], "Title": "Detect multiple devices in Keen.io collection" }
48214
<p>I have a private method that is called from the constructor to instantiate a bunch of objects.</p> <p>I can do it two ways.</p> <pre><code> private Monster[,] createMonsters() { Monster[,] myMonsterArray = new Monster[8, 6]; for (int i = 0; i &lt; 8; i++) { myMonsterArra...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T09:59:51.420", "Id": "84633", "Score": "2", "body": "I was set off by the fact that you have *camelCase* method names, whereas I thought that they would be *PascalCase* in C#." }, { "ContentLicense": "CC BY-SA 3.0", "Cre...
[ { "body": "<p>Consider it is just an initializer and will only be used this once, there is no need to make it explicitly return the data when you can just set it directly.</p>\n\n<p>Therefore the second approach would be my approach as well.</p>\n\n<h1>Naming</h1>\n\n<p>Method names are UpperCamelCase in C# so ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T09:44:44.217", "Id": "48219", "Score": "23", "Tags": [ "c#", "constructor", "comparative-review" ], "Title": "When a constructor calls a helper function, should the helper mutate ...
48219
<p>I need to implement some functionality of the otherwise monolithic application via DLL that is loaded at runtime. (Think about a customized DLL -- different for each customer.) </p> <p>The Visual C++ from VS 2013 is used.</p> <p>The application gets the full name name of the DLL. The function to be called has a fi...
[]
[ { "body": "<p>Short answer: No, but I won't hold it against you. ;)</p>\n\n<p>I'd suggest reading up on using C++ with DLLs in a compatible fashion, and would suggest this <a href=\"http://www.codeproject.com/Articles/28969/HowTo-Export-C-classes-from-a-DLL#CppMatureApproach\" rel=\"nofollow\">excellent article...
{ "AcceptedAnswerId": "48235", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T13:31:01.350", "Id": "48224", "Score": "4", "Tags": [ "c++", "windows" ], "Title": "Calling a function from a dynamically loaded DLL" }
48224
<p>Let's say you want to increment the cells around the position <code>(x,y)</code> in a square matrix <code>m</code> of size <code>T</code>.</p> <p>I've written the same code in a few languages. Here's the JS syntax version :</p> <pre><code>if (x&gt;0) { if (y&gt;0) m[x-1][y-1]++; m[x-1][y]++; if (y&lt;T...
[]
[ { "body": "<p>Create an array of the offsets you want to change in your code.</p>\n\n<pre><code>var offsets = new Array();\nfor (var x = -1; x &lt;= 1; x++) {\n for (var y = -1; y &lt;= 1; y++) {\n if ((x != 0) || (y != 0)) {\n offsets.push({ x: x, y: y });\n }\n }\n}\n</code></pr...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T15:21:16.017", "Id": "48231", "Score": "6", "Tags": [ "javascript", "performance", "matrix" ], "Title": "Increment the neighbors of a cell in a matrix" }
48231
<p>I'm using MVP pattern for a payroll system as my final year project. There are about 16 entity classes (like <code>employee</code>, <code>client</code>, <code>salary</code> etc.) in the analyzed problem and I have designed the solution as follows…</p> <ul> <li>Number of UIs (Views) – 18 </li> <li>Separate Presenter...
[]
[ { "body": "<blockquote>\n <p><strong>View</strong></p>\n</blockquote>\n\n\n\n<blockquote>\n<pre><code>//Even handlers \npublic event EventHandler DataChanged;\npublic event EventHandler Save;\npublic event EventHandler Search;\n</code></pre>\n</blockquote>\n\n<p>Comments like this only clutter up the code, the...
{ "AcceptedAnswerId": "48263", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T15:27:40.023", "Id": "48233", "Score": "2", "Tags": [ "c#", ".net", "winforms", "dependency-injection", "mvp" ], "Title": "MVP Pattern used in a payroll solution" }
48233
<p>I have some code:</p> <pre><code> $matchingEvents = []; foreach( $this-&gt;recurringEvents as $event ){ if( $event['RCE_Type'] === 'Month' &amp;&amp; $event['RCE_Day'] === $dayOfMonth ){ array_push( $matchingEvents, $event ); } else if( $event['RCE_Type'] === 'Week' &amp;&amp; $event['RCE_Day'] ===...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T19:35:33.423", "Id": "84693", "Score": "1", "body": "You can improve the readability of the (||) version by judicious use of white space to express the tree of connectives. Use the mathematical structure to your advantage. Don't f...
[ { "body": "<p>You could move the matching test to a separate method, like this:</p>\n\n<pre><code>private function is_matching_day( $event, $dayOfWeek, $dayOfMonth ) {\n\n if ( $event['RCE_Type'] === 'Month' &amp;&amp; $event['RCE_Day'] === $dayOfMonth )\n return true;\n\n return $event['RCE_Type']...
{ "AcceptedAnswerId": "48299", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T15:29:21.870", "Id": "48234", "Score": "3", "Tags": [ "php" ], "Title": "Complex boolean logic vs DRY" }
48234
<p>I wrote a solution to the popularized <a href="http://en.wikipedia.org/wiki/Fizz_buzz" rel="nofollow">FizzBuzz</a> problem in Haskell to see how a functional solution looks. I'm more or less happy with my solution, except for the definition of <code>list</code>. It just looks sort of contorted. </p> <p><em>Are the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T19:15:15.453", "Id": "84688", "Score": "1", "body": "Instead of `foldl1 (++)` use `concat`" } ]
[ { "body": "<p>You write:</p>\n\n<pre><code>map snd . filter ((==0) .fst) $ map (first (mod x)) table\n</code></pre>\n\n<p>To make it clearer that we have three operations applied one after another, I would rather write:</p>\n\n<pre><code>map snd . filter ((==0) .fst) . map (first (mod x)) $ table\n</code></pre>...
{ "AcceptedAnswerId": "48246", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T16:08:15.757", "Id": "48240", "Score": "3", "Tags": [ "haskell", "fizzbuzz" ], "Title": "Improving a Haskell FizzBuzz Solution" }
48240
<p>I coded a php chat that stores the text in a txt file and retrieves it, and I want to know if XSS can get past it or if someone can replace <code>xhr.open("POST","uhh.php");</code> with something that contains the same php code but without <code>htmlspecialchars</code> or something like that. What are the vulnerabi...
[]
[ { "body": "<p>For the XSS part, here's some resources. It would be better off if I just referenced them rather than write the entire thing down. The second one might be the one you want:</p>\n\n<ul>\n<li><a href=\"https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet\" rel=\"nofo...
{ "AcceptedAnswerId": "48272", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T18:00:39.900", "Id": "48254", "Score": "3", "Tags": [ "javascript", "php" ], "Title": "Can XSS or anything else get through this?" }
48254
<p>As many may know, I am developing a Trading Card Game for the <a href="https://codereview.meta.stackexchange.com/questions/1600/code-challenge-2">Coding Challenge</a>.</p> <p>I have just completed the <code>Field</code> class and have not used it in practice yet, so all theoretical and looking for a review.</p> <p...
[]
[ { "body": "<p>First, I don't think <code>Field</code> is a good name – it is really generic and doesn't reveal any information.</p>\n\n<p>Now a few notes on your unit tests:</p>\n\n<p>Instead of duplicating the setup <code>Field field = new Field(6)</code> in every test, you could use a <code>@Before</code> ann...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T18:02:33.970", "Id": "48255", "Score": "5", "Tags": [ "java", "game", "community-challenge" ], "Title": "Field class used by my trading card game" }
48255
<p><a href="http://projecteuler.net/problem=33" rel="nofollow">Problem 33</a> in Project Euler asks:</p> <blockquote> <p>The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by canceling th...
[]
[ { "body": "<p><strong>Array multiple assignment</strong><br>\nYou pass arrays around, and you find yourself calling for <code>x[1]</code> and <code>x.last</code> - this is very unreadable, and brittle.<br>\nRuby allows you to implicitely assign elements of the array to parameters in your block according to its ...
{ "AcceptedAnswerId": "48266", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T18:34:57.063", "Id": "48256", "Score": "3", "Tags": [ "ruby", "functional-programming", "mathematics", "programming-challenge", "combinatorics" ], "Title": "Curious fra...
48256
<p><em>Lately, I've been, I've been losing sleep<br> Dreaming about the things that we could be<br> But baby, I've been, I've been praying hard,<br> Said, no more counting dollars<br> We'll be counting stars, yeah we'll be counting stars</em><br> (<a href="https://www.youtube.com/watch?v=hT_nvWreIhg" rel="noreferrer">O...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T21:44:17.810", "Id": "84711", "Score": "3", "body": "Malachi only has 534? That surprised me." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-06T14:44:26.493", "Id": "86185", "Score": "1", "...
[ { "body": "<p>I can't see any reason why you would need to pop elements off the arrays returned from <code>.select()</code> -- you could just do something like </p>\n\n<pre><code> message_soup.select('.times')[0].string\n</code></pre>\n\n<p>Either approach will throw an exception if the message doesn't contain ...
{ "AcceptedAnswerId": "49074", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T19:14:16.450", "Id": "48258", "Score": "44", "Tags": [ "python", "python-3.x", "stackexchange", "web-scraping", "beautifulsoup" ], "Title": "We'll be counting stars" }
48258
<p>Please, have a look at the previous (bad) implementation and the review <a href="https://codereview.stackexchange.com/q/48224/16189">here</a>.</p> <p>After reading the suggested article at <a href="http://www.codeproject.com/Articles/28969/HowTo-Export-C-classes-from-a-DLL#CppMatureApproach" rel="nofollow noreferre...
[]
[ { "body": "<p>Certainly a better approach that the original. Only one 'flaw' that I noticed:</p>\n\n<ul>\n<li>You ignore the return value from your <code>convert</code> function.</li>\n</ul>\n\n<p>But I do have a couple of comments:</p>\n\n<ul>\n<li>You may want to consider making <code>line</code> a <code>cons...
{ "AcceptedAnswerId": "48768", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T19:20:41.313", "Id": "48260", "Score": "4", "Tags": [ "c++", "windows" ], "Title": "Calling a function from a dynamically loaded DLL (version 2)" }
48260
<p>I'm new at Caliburn Micro and the MVVM pattern.</p> <p>I have 3 views (with its corresponding viewmodels):</p> <ul> <li><code>AppView</code></li> <li><code>ClientsView</code></li> <li><code>EditClientView</code></li> </ul> <p><code>AppView</code> is my main page with a <code>TabControl</code> inside. The child vi...
[]
[ { "body": "<p><strong>Naming</strong></p>\n\n<p>You should use PascalCase to name methods and types. You do this most of the time, but slip up with <code>modClienteViewModel</code></p>\n\n<p>Your parameters should be in camelCase. Again, you do this most of the time, but slip up with <code>TipoVista</code> in y...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T19:22:33.360", "Id": "48261", "Score": "5", "Tags": [ "c#", "mvvm" ], "Title": "Caliburn Micro communication between list and edit viewmodels" }
48261
<p>I just started learning about the MVC architecture. And I started to create my own MVC framework to how I like it the most.</p> <p>Here I've got the index.php, indexcontroller.php and view.php. I'm not too sure if what I am doing is right, or with best practices. So I would like to know if there is anything I misse...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T23:43:19.177", "Id": "84896", "Score": "0", "body": "Best way to see if it's up to standard is to see how easy it is to add new views." } ]
[ { "body": "<p>MVC approaches differ between languages, platforms and frameworks. They are usually termed \"MV* frameworks\" because they don't exactly follow <a href=\"https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller\" rel=\"nofollow\">strict MVC</a>. But we call them MVC nonetheless.</p>\n\n...
{ "AcceptedAnswerId": "48297", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T20:53:36.860", "Id": "48269", "Score": "0", "Tags": [ "php", "object-oriented", "design-patterns", "mvc" ], "Title": "Is my first MVC architecture set up to standards?" }
48269
<p>(Method signature is given with parameters)</p> <p>Try to visualize me writing this code at an interview, and please be brutal while judging it.</p> <blockquote> <p><strong>Problem:</strong></p> <p>Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a ...
[]
[ { "body": "<p>I don't believe you program is \\$O(n)\\$ because you recursively call <code>wordBreakHelper</code> in a loop, which I believe actually makes this an exponential time algorithm. This is because your \\$O(n)\\$ loop potentially run \\$O(n)\\$ times (\\$O(n^n)\\$).</p>\n\n<p>Two quick comments on th...
{ "AcceptedAnswerId": "48280", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T21:32:28.590", "Id": "48274", "Score": "9", "Tags": [ "java", "algorithm", "interview-questions" ], "Title": "Breaking of a sentence" }
48274
<p>I'm writing a simple xHTML parser which parses a data without nested tags.</p> <p>Example input code will look like:</p> <pre><code>&lt;h2&gt;Header&lt;/h2&gt; &lt;p&gt; atsatat &lt;/p&gt; &lt;h2&gt;asdsaad&lt;/2&gt;&lt;p&gt;s32532235&lt;/p&gt; </code></pre> <p>I've wrote the following code:</p> <pre><code>#in...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T22:36:35.013", "Id": "84723", "Score": "1", "body": "Too many pointers. You should try to replace them by standard library classes whenever possible :p" } ]
[ { "body": "<ul>\n<li><p>Although optional, you can keep your <code>#include</code>s organized (alphabetically, for instance) so that it's easier to locate an individual one or to determine if you've already included a particular one.</p></li>\n<li><p>You've included <code>&lt;sstream&gt;</code>, but I don't see...
{ "AcceptedAnswerId": "48276", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-26T21:38:34.553", "Id": "48275", "Score": "5", "Tags": [ "c++", "optimization", "beginner", "parsing", "node.js" ], "Title": "Optimizing simple xHTML parser" }
48275
<p>I was doing this easy challenge "Counting Minutes I" from Coderbyte.com where you just calculate the number of minutes between two given times. </p> <p>The second time is always after the first, although it may look to be before but mean it's during the next day. </p> <p>The format of their test cases is <code>"ho...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-11-07T14:48:32.930", "Id": "532554", "Score": "0", "body": "how come 11.5 hours = 1425 minutes. ?" } ]
[ { "body": "<p>In <code>to24HourTime()</code>, <code>pos</code> doesn't need to be passed by reference as it's not being modified. Just pass it by value.</p>\n\n<p>Instead of passing <code>hourToConvert</code> by reference (which <em>is</em> being modified), you can just pass by value and then return the result...
{ "AcceptedAnswerId": "48318", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T00:06:31.043", "Id": "48284", "Score": "6", "Tags": [ "c++", "strings", "datetime", "converting", "stream" ], "Title": "Better way to repeatedly use istringstream in \"...
48284
<p>I'm trying to improve my understanding of recursive and iterative processes. I've started with SICP, but have branched off to try and find a few exercises when I started having difficulty. Currently I've been looking at a series of posts on the subject by <a href="http://blog.moertel.com/posts/2013-05-11-recursive-t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T02:30:27.953", "Id": "84738", "Score": "2", "body": "To understand recursion, click here: https://codereview.stackexchange.com/questions/48288/understand-recursion" } ]
[ { "body": "<p>Ahhhh. Okay.</p>\n\n<p>That the issue here is that if the process takes a right branch at node Foo, it needs to store a reference to Foo in the event that it fails to find a child node which is less-than or equal. That reference effectively lives in the stack-calls which occur in inside the calls ...
{ "AcceptedAnswerId": "48296", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T00:59:07.243", "Id": "48288", "Score": "1", "Tags": [ "python", "recursion", "iteration" ], "Title": "Understand recursion" }
48288
<p>I have an Excel sheet with lot of rows with data. I am separating it into 2 sheets with some condition satisfies.</p> <p>This is taking too much time. How can I improve the speed? Please suggest any changes to my code.</p> <pre><code>Dim bmver As Object(,) = New Object(i20, 36) {} Dim bmhor As Object(,) = New Ob...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T02:41:40.943", "Id": "84741", "Score": "0", "body": "What's `i20`'s value?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T15:48:51.677", "Id": "84963", "Score": "0", "body": "If I remembe...
[ { "body": "<p>Excel interoperability is inherently slow - you have the .NET runtime talking to a COM object model through COM interop, there's a performance penalty just for doing that.</p>\n\n<p>Hence, you should strive to reduce the number of times you're accessing the worksheet cells, be it to read or to wri...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T01:56:07.707", "Id": "48291", "Score": "4", "Tags": [ "performance", "vb.net", "excel" ], "Title": "Excel sheet code is taking too much time" }
48291
<blockquote> <p>Given set of words that are lexicographically sorted, return lexicographic order.</p> <p>E.g:</p> <pre><code>abc acd bcc bed bdc dab </code></pre> <p>The order of letters for the given example would be</p> <pre><code>a-&gt;b-&gt;c-&gt;e-&gt;d </code></pre> <h1>Time:</h1> <p><st...
[]
[ { "body": "<p>You code has lots of strengths. Its main weakness is the lack of explanation for the algorithm. </p>\n\n<ol>\n<li><p>Why are you building the reverse graph? A reverse post order visiting of the graph is a topo sort order. Just get the post order and then reverse it! Saves lots of effort and sp...
{ "AcceptedAnswerId": "48300", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T02:11:13.400", "Id": "48292", "Score": "3", "Tags": [ "java", "algorithm", "strings" ], "Title": "Return the lexicographic order" }
48292
<p>Let's say that I have a view, whose purpose is to show a table with some information about a person entity. The view contains a form with an input element that the user can use to add a new person to the table by entering its name. </p> <p>My question is: In this scenario, is there a convention about where to put h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T02:55:02.773", "Id": "84742", "Score": "3", "body": "It is preferable that you do not undo edits unless they vandalize the post or modify the original code. Since that was not the case here, I'm going to rollback to the previous ed...
[ { "body": "<p>When you are iterating over the collection of people, it probably does make sense to keep the hidden fields within the loop. I would try to keep them grouped together in that first td, with a hidden field per line, so that they are easily noticeable when scanning the source.</p>\n\n<p>If I weren't...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T02:42:32.467", "Id": "48294", "Score": "5", "Tags": [ "c#", "asp.net-mvc-4" ], "Title": "Where to put hidden fields when displaying entities properties in a table?" }
48294
<p>I have snapshots (photos) that I load off my camera's memory card, and store in a folder. Sometimes I have videos, and occasionally plain audio too (the camera can record just sound).</p> <p>Additionally, my wife, and kids have their point-and-shoots too.</p> <p>I have a workflow where I dump the photos on to a de...
[]
[ { "body": "<p>Your <code>if</code> conditions can be simplified. Instead of this:</p>\n\n<pre><code>if ( `tcsh -f -c \"ls -1 DSC*.jpg &gt;&amp; /dev/null\" &amp;&amp; echo yes` == \"yes\" ) then\n</code></pre>\n\n<p>You could write like this:</p>\n\n<pre><code>if ( `ls DSC*.jpg &gt;&amp; /dev/null &amp;&amp; ec...
{ "AcceptedAnswerId": "48311", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T02:43:12.770", "Id": "48295", "Score": "6", "Tags": [ "image", "shell", "tcsh" ], "Title": "Directory of Snapshots" }
48295
<p>I've the following code:</p> <pre><code> protected Dictionary&lt;NpInfoHelper, object&gt; Informer; protected override void OnInit(EventArgs e) { if (Session.Keys.Count == 1) { Session.Abandon(); Response.RedirectPermanent("~/Pages/Login?e=true", true); } ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T04:47:32.673", "Id": "84750", "Score": "3", "body": "Well, I can't say much about ASP.NET, but that kind of repetition implies you should either have the backend classes all derive from one class (whose OnItit does what your init do...
[ { "body": "<p>Per the comment, what you probably want is an abstract class <code>MyAppPage</code>:</p>\n\n<pre><code>abstract class MyAppPage : Page {\n protected Dictionary&lt;NpInfoHelper, object&gt; Informer;\n protected override void OnInit(EventArgs e)\n {\n if (Session.Keys.Count == 1)\n ...
{ "AcceptedAnswerId": "48301", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T04:13:35.843", "Id": "48298", "Score": "5", "Tags": [ "c#", "asp.net" ], "Title": "Can my code be made into one?" }
48298
<p>I have a form that requires the user to select photos to be included in their portfolio before they can proceed to use the app for the first time.</p> <p>I don't want to spend the rest of my life implementing a custom file browser, so I've decided to just use the FolderBrowserDialog to allow them to select a folder...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T06:08:03.570", "Id": "84759", "Score": "1", "body": "Since it is a winform application so I would rather change its UI. Most of the applications that I have come across offers a \"Add More\" button to do the same." }, { "Con...
[ { "body": "<p>I'm typically not a user of the <code>continue</code> statement but here is one alternative using this method. In this case it may be a simpler implementation and removes the need for any extra local variable.</p>\n\n<pre><code>private void Main_Shown(object sender, EventArgs e)\n{\n /* Let th...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T05:32:49.723", "Id": "48302", "Score": "5", "Tags": [ "c#", "optimization", ".net", "winforms" ], "Title": "Keep asking the user [after performing an action] until they wish t...
48302
<p>I have been attempting to learn Scala lately and so have produced a couple of different sorting algorithms to build up my basics.</p> <p>I think I have been lucky with the methods returning exactly what I have wanted, but for MergeSort I have implemented recursive methods that could return one of two different valu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T12:39:37.953", "Id": "84793", "Score": "1", "body": "I don't understand what you mean with \"temporary values\". Can you highlight the lines you mean and explain more how the code should look in the end?" }, { "ContentLicens...
[ { "body": "<p>The expression <code>merge(x,y)</code> will always return a value. <code>val r = merge(x,y)</code> stores the value so that you can use it again.</p>\n\n<p>You could write your code </p>\n\n<pre><code>var leftTemp = mergeSort(left);\nvar rightTemp = mergeSort(right);\n\nvar result = merge(leftTemp...
{ "AcceptedAnswerId": "48570", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T08:16:28.133", "Id": "48305", "Score": "3", "Tags": [ "scala", "sorting", "mergesort" ], "Title": "Is there a better way to return values with merge sort?" }
48305
<p>Can you please verify my approach?</p> <pre><code>using System; /* * In Factory pattern, we create object without exposing the creation logic. * In this pattern, an interface is used for creating an object, * but let subclass decide which class to instantiate. * */ namespace FactoryMethod { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-28T15:13:12.893", "Id": "84957", "Score": "0", "body": "You can also choose to use exceptions to make it more robust. Like in your code anyone can ask for \"Rose\" tree and still get banana tree." } ]
[ { "body": "<p>I personally would not rely on using magic strings.</p>\n\n<blockquote>\n <p>Magic strings are where you have taken something like a class/method/variable name and written it within a string, which is then used to identify the appropriate class/method/variable</p>\n</blockquote>\n\n<p>This makes ...
{ "AcceptedAnswerId": "48316", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T08:31:54.073", "Id": "48308", "Score": "8", "Tags": [ "c#", "factory-method" ], "Title": "Factory Method implementation" }
48308
<p>I'm working through Yet Another Haskell Tutorial. One of the exercises is to prompt the user to enters numbers, entering a 0 to quit. The program should then both sum and multiply all the given numbers, and then display the factorial of each. </p> <p>It works, but it's obviously sloppy, with some functions doing mo...
[]
[ { "body": "<p>You should definitely separate the calculation from formatting the output. One of Haskell's key strengths is being able to compose functions. By confounding the definition of your function with the presentation of it's return value, you lose the ability to reuse it elsewhere. For instance, if you ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T08:32:39.203", "Id": "48309", "Score": "1", "Tags": [ "haskell", "io" ], "Title": "Idiomatic IO in Haskell" }
48309
<pre><code>public class DataBaseHandler extends SQLiteOpenHelper { private static String DATABASE_NAME = "UnitDatabase"; private static String MEASUREMENT_TYPE_TABLE = "measurement_types"; private static String idCol = "id"; private static String typeCol = "type"; private static int DATABASE_VERSIO...
[]
[ { "body": "<p>You have some constants in your code. Why are they not final? Also the naming for <code>idCol</code> and <code>typeCol</code> is confusing me. Why not <code>ID_COLUMN</code> and <code>TYPE_COLUMN</code>. </p>\n\n<p>Same also goes for <code>measurementTypes</code> these all are constants. Name and ...
{ "AcceptedAnswerId": "48370", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-27T09:42:02.023", "Id": "48312", "Score": "6", "Tags": [ "java", "android", "database", "sqlite" ], "Title": "Database data insertion" }
48312