body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I'm working my way through <em>The Java Programming Language, Fourth Edition - The Java Series</em>. This is Exercise 13.3:</p> <blockquote> <p>As shown, the delimitedString method assumes only one such string per input string. Write a version that will pull out the delimited strings and retun an array.</p> </bl...
[]
[ { "body": "<p>If I had to put a number on your code it would be a 8 out of 10. You did good here. Since it is so good I am going to be nitpicking a few things. First is your test. You are comparing arrays but using <code>assertEquals</code>. Instead you need to change that to <code>assertArrayEquals</code> (pro...
{ "AcceptedAnswerId": "32934", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-19T16:04:56.567", "Id": "32926", "Score": "4", "Tags": [ "java", "strings" ], "Title": "Critique of Delimited String Method" }
32926
<p>It's not finished yet, but I want to know if the structure and the classes are ok and what can I change. Feel free to say anything.</p> <p>To be more specific, I want to know what you think about the login function in the <code>Login_Controller</code> class:</p> <pre><code>public function login() { i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T10:17:07.147", "Id": "52898", "Score": "0", "body": "I don't think you get the point of MVC :(" } ]
[ { "body": "<p>They are ok, but I would still do some things differently.</p>\n\n<ol>\n<li>I would instead throw exceptions.</li>\n<li>Instead of <code>if</code> <code>else</code> within your action, I would use a validator with rules.</li>\n<li>Instead of using <code>$_POST/$_GET directly</code>, I would saniti...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-19T16:58:10.747", "Id": "32928", "Score": "2", "Tags": [ "php", "mvc", "url-routing", "framework" ], "Title": "Basic login with router" }
32928
<p>Any way to make this more concise/efficient? </p> <pre><code>// Write a loop that reverses the elements of an array. #include &lt;iostream&gt; #include &lt;iomanip&gt; const int SIZE = 10; void reverse(int iArrayRef1 []); void display(int iArrayRef2 []); int main() { int iArray[SIZE] = { 1, 2, 3, 4, 5, 6, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-19T19:38:41.063", "Id": "52672", "Score": "0", "body": "I don't see much wrong. I only wonder why you call the argument ``iArrayRef1`` in ``reverse`` and ``iArrayRef2`` in ``display``. One other minor thing: ``++index`` is slightly fas...
[ { "body": "<p>For an implementation without the STL, this is pretty good. There's no risky memory-management going on with the raw pointers, and your sorting isn't needlessly slow (compared to bubble sort). I'll base my review on the STL anyway (for future reference), along with some other general tips.</p>\n...
{ "AcceptedAnswerId": "32932", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-19T19:28:45.583", "Id": "32931", "Score": "4", "Tags": [ "c++", "optimization", "array" ], "Title": "Reversing the elements of an array" }
32931
<p>I frequently have patterns as below, usually not this simple, which require me to first code a working solution for a single test case, and then to refactor the code to make it more concise. See the first incarnation below, then the final code. I'm looking to see what other techniques some use to skip the initial st...
[]
[ { "body": "<p>I would write the loop like this:</p>\n\n<pre><code>for i, j, move in list_of_moves:\n assert(0 &lt;= i &lt; 3 and 0 &lt;= j &lt; 3 and move in 'XO')\n board[j][i] = move\n</code></pre>\n\n<p>or maybe:</p>\n\n<pre><code>VALID_MOVES = 'XO'\nfor i, j, move in list_of_moves:\n assert(0 &lt;=...
{ "AcceptedAnswerId": "32936", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-19T20:06:44.087", "Id": "32933", "Score": "0", "Tags": [ "python" ], "Title": "Faster track to recognizing patterns in looping through nested sequences" }
32933
<p>Please review my code/code quality.</p> <pre><code>var textarea = document.getElementById("textarea"), inputFile = document.getElementById("input-file"), prtHelper = document.getElementById("prt-helper"), overlay = document.getElementById("overlay"), help = document.getElementById("help"), ...
[]
[ { "body": "<p>A quick glance,</p>\n\n<p><strong>Code has a lot of global variables</strong></p>\n\n<p>Either namespace it or wrape it so it is in its own scrope and not in window scope.</p>\n\n<p><strong>Attaching Events directly to elements</strong></p>\n\n<p>You should be attaching events with <a href=\"https...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-19T20:20:31.623", "Id": "32935", "Score": "2", "Tags": [ "javascript" ], "Title": "JavaScript online TextEditor" }
32935
<p>Given a sorted array of <em>N</em> elements, I need to find the absolute sum of the differences of all elements.</p> <p>Given 4 elements (1, 2, 3 and 4):</p> <blockquote> <p>|1-2|+|1-3|+|1-4|+|2-3|+|2-4|+|3-4| = 10</p> </blockquote> <p>Here is my code in Java:</p> <pre><code>List&lt;Integer&gt; a = new ArrayLi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-19T22:08:33.450", "Id": "52683", "Score": "0", "body": "1. What is `min`? 2. Don't you need `abs` somewhere? 3. Do we know anything about the numbers in the array (i.e., their span, distribution,...)? 4. Setting `j=i+1` instead of `j=i...
[ { "body": "<p>Let's see this mathematically. I am assuming that <code>a</code> is an ascendingly sorted array. I start with indexes from 1, to get better readability (by avoiding <code>n-1</code> as often as possible).</p>\n\n<p>We want the following sum:</p>\n\n<p>$$\\begin{array}{l@{}l@{}l@{}l}\n\\sum_{i=1}^{...
{ "AcceptedAnswerId": "32938", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-19T21:10:22.067", "Id": "32937", "Score": "7", "Tags": [ "java", "algorithm", "complexity" ], "Title": "Simplify function to sum the absolute value of the difference between all p...
32937
<p>I have an Access database that I'm converting to SQL Server 2008. One of the queries in the database uses the LAST function. The table has a AutoNumber ID so true order is simple.</p> <blockquote> <pre><code>SELECT tbl_unit.unit, LAST(tbl_unit.date) AS Date, LAST(tbl_unit.mileage) AS Mileage FROM...
[]
[ { "body": "<p>Have you Tried this?</p>\n\n<pre><code>SELECT Unit, [Date], Mileage\nFROM tbl_unit\nWHERE tbl_unit.id = (SELECT MAX(id) FROM tbl_unit)\n</code></pre>\n\n<p>OR </p>\n\n<pre><code>SELECT Unit, [Date], Mileage\nFROM tbl_unit\nWHERE tbl_unit.Date = (SELECT MAX(Date) FROM tbl_unit)\n</code></pre>\n\n<p...
{ "AcceptedAnswerId": "33209", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T04:06:47.060", "Id": "32940", "Score": "3", "Tags": [ "sql", "sql-server", "ms-access" ], "Title": "Code conversion from Access to T-SQL" }
32940
<p>In some programming languages, copying a variable may be implemented as either a copy by value or a copy by reference. When it is copied by reference, a reference to the data will be assigned, and the underlying data is not copied. Often, object datatypes will be copied by reference by default (for example, in Java)...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T06:02:53.027", "Id": "32941", "Score": "0", "Tags": null, "Title": null }
32941
A reference is a value that enables a program to indirectly access a particular datum, such as a variable or a record, in the computer's memory or in some other storage device.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T06:02:53.027", "Id": "32942", "Score": "0", "Tags": null, "Title": null }
32942
<p>I have a matrix transpose function that takes arrays with a possibly different number of rows and columns.</p> <p>How can I improve performance and code quality?</p> <pre><code>void matrix_transpose(float *matrix, int rows, int columns) { int current_row; int current_column; float temp; float buffe...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T19:57:05.683", "Id": "52735", "Score": "1", "body": "Try a [XOR swap](http://en.wikipedia.org/wiki/XOR_swap_algorithm)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T19:59:19.963", "Id": "52736"...
[ { "body": "<ol>\n<li>The call can apparently fail if the matrix supplied is larger than the internal buffer in the function. Yet there is no indication that this was the case. <code>matrix_transpose</code> should return an error code indicating the result of the operation.</li>\n<li><code>float buffer[MATRIX_TR...
{ "AcceptedAnswerId": "32952", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T06:06:05.007", "Id": "32944", "Score": "2", "Tags": [ "performance", "c", "matrix" ], "Title": "Matrix transpose function" }
32944
A wrapper is an OOP technique where an object encapsulates (wraps) another object, hiding/protecting the object and controlling all access to it.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T06:18:20.473", "Id": "32946", "Score": "0", "Tags": null, "Title": null }
32946
Consider whether your question would be better asked at CrossValidated, a Stack Exchange site for probability, statistics, data analysis, data mining, and machine learning. Code Review questions on statistics should be about implementation and working program review, not about theoretical discussions of statistics or ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T06:21:14.970", "Id": "32948", "Score": "0", "Tags": null, "Title": null }
32948
In computing, input/output, or I/O, refers to the communication between an information processing system (such as a computer) and the outside world (possibly a display, an information storage system, or another information processing system).
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T06:29:36.323", "Id": "32950", "Score": "0", "Tags": null, "Title": null }
32950
<p>I have two admin groups - VCS, and VPN. For each group, I need to get the list of all the people in that group, along with their IDs.</p> <p>What is the best way to do this? Could you please suggest if it is good enough?</p> <p>Also, should I use a map to store the data instead of creating a new object <code>GetA...
[]
[ { "body": "<p>Well my first gut reaction is that I don't like what I see. Here is why though and hopefully that will help you understand why I feel this way. First is with the naming convention. GetAdminInfo is a verb. Classes are nouns. This is true in all of mainstream OO languages. Therefore a more appropria...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T08:10:48.347", "Id": "32953", "Score": "3", "Tags": [ "java", "beginner", "oracle", "jdbc" ], "Title": "Getting list from an Oracle database and storing it in an object" }
32953
<pre><code>class MyClass{ static Integer carry = 0; public static void main(String args[]){ String s1 = "7654729850328997631007285998163550104"; String s2 = "5980139243970186632651869926335829102"; add(s1, s2); } public static void add(String a, String b){ ArrayList&lt;S...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T08:51:30.297", "Id": "52702", "Score": "2", "body": "Use `BigInteger` instead." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T08:54:32.663", "Id": "52703", "Score": "0", "body": "i forgot...
[ { "body": "<p>Loop structure's OK, logic's reasonably good. There is obviously a Java library alternative of <code>BigInteger</code>, but I assume you knew that. Some efficiency issues with excessive toString() and string-ification of what could be character operations.</p>\n\n<p>Here are some tips:</p>\n\n<ol>...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T08:57:29.193", "Id": "32954", "Score": "7", "Tags": [ "java", "integer" ], "Title": "Adding two big integers represented as strings" }
32954
<p>I have written code, but I don't like it, it seems very ungeneralized. I want to make it more abstract and universal and independent of type.</p> <p>I have the task to write programm, which can operate with multi level list. List should be done on array of void pointers. Data structure should be roughly like on the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T15:54:49.000", "Id": "52722", "Score": "1", "body": "Linking to GitHub is helpful, but by the rules of this site, you must include code to be reviewed in the question itself, or at least the most important parts of the code. Also, i...
[ { "body": "<p>This looks a lot like <em>c with classes</em> rather than <em>c++</em>. </p>\n\n<ol>\n<li>If you are using void pointers in C++, you are probably doing something wrong. You <code>pointerArray</code> class is templated, but you don't use the templates at all. </li>\n<li>A class name should begin wi...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T11:47:37.937", "Id": "32958", "Score": "3", "Tags": [ "c++", "algorithm" ], "Title": "Multi level list based on array of void pointers" }
32958
<p>Per a <a href="http://www.reddit.com/r/dailyprogrammer/comments/1m1jam/081313_challenge_137_easy_string_transposition/" rel="nofollow">Reddit Daily Programming Challenge</a>, I am performing a matrix transposition on a string using JavaScript.</p> <p>Example input: 'The quick brown fox jumped over the lazy dog'</p>...
[]
[ { "body": "<p><a href=\"http://jsbin.com/ihUnUFU/1/edit?js,console\" rel=\"nofollow\">Here you go, with comments.</a></p>\n\n<p>Obviously, in production I would have only a handful of comments and not the exhaustive ones I put here. However this is the sort of points I might make during a code review.</p>\n\n<p...
{ "AcceptedAnswerId": "32976", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T12:37:20.940", "Id": "32963", "Score": "1", "Tags": [ "javascript", "strings", "matrix" ], "Title": "Matrix transposition of a string" }
32963
<p>I need array to store elements, but I don't want to make memory allocations at runtime. So I reuse elements. Some fields are never changes so as I reuse elements I need to assign those fields just once.</p> <p>This is what I wrote, only sceleton, need to add "errors test" etc, but enough to demonstrate the idea:</p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T13:38:16.317", "Id": "52709", "Score": "0", "body": "Are you sure you really can't afford those allocations? Allocations are extremely cheap in .Net and deallocations can be fairly efficient too." }, { "ContentLicense": "CC ...
[ { "body": "<blockquote>\n <p>my question is about idea in general</p>\n</blockquote>\n\n<p>It's flawed, in several ways. </p>\n\n<p><strong>Premature Optimization</strong></p>\n\n<p>The code smell I get is that the whole point is avoiding instantiating and then disposing <code>Array</code> elements. Reasons w...
{ "AcceptedAnswerId": "32973", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T13:08:38.497", "Id": "32964", "Score": "1", "Tags": [ "c#", "array" ], "Title": "array with reusable elements" }
32964
<p>I took a JavaScript challenge to finish a task related to logo of "Breaking Bad" where letters in your first name and last name are spotted with elements of periodic table and its respective atomic number. I wrote the below code, any suggestions to improve performance or any best coding practices </p> <pre><code> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T10:46:44.620", "Id": "52714", "Score": "1", "body": "`for (var i = 0; i < splits.length; i++)` -> `for (var i = 0, maxI = splits.length; i < maxI; ++i)`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30...
[ { "body": "<blockquote>\n <p>Any suggestions?</p>\n</blockquote>\n\n<p>Yes, a few.</p>\n\n<p>First off, split your function into parts (<a href=\"https://en.wikipedia.org/wiki/Single_responsibility_principle\" rel=\"nofollow\">SRP</a>), to separate the view (DOM elements and their values) from the logic (findi...
{ "AcceptedAnswerId": "32967", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T10:41:53.797", "Id": "32966", "Score": "1", "Tags": [ "javascript", "performance", "strings" ], "Title": "Encoding strings using periodic table abbreviations" }
32966
<p>I was receiving <code>405 method not supported</code> errors on <code>get</code> requests to my save controller, so I created a <code>get</code> method which just calls the existing <code>post</code> one as follows:</p> <pre><code>class Save(webapp2.RequestHandler): def get(self): self.post() def ...
[]
[ { "body": "<p>Yes, you can easily alias one method to another:</p>\n\n<pre><code>class Save(webapp2.RequestHandler):\n\n def post(self):\n #...\n\n get = post\n</code></pre>\n\n<p><strong>But</strong> although I don't know anything about your application, you shouldn't alias GET to POST like this: ...
{ "AcceptedAnswerId": "33066", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T14:57:42.710", "Id": "32968", "Score": "0", "Tags": [ "python", "google-app-engine" ], "Title": "AppEngine get/post on webapp2.RequestHandler" }
32968
<p><strong>AccountController Code:</strong></p> <pre><code>public class AccountController : ApplicationController { public AccountController(ITokenHandler tokenStore, IUser user) : base(tokenStore, user){} public ActionResult LogOn() { return View(); } // ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-09-01T15:47:36.220", "Id": "262562", "Score": "0", "body": "Why are you doing this? Looks like you could just use the standard MVC auth module as you don't seem to be adding anything extra?" }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>I'm not much of a web programmer, but I am comfortable with C#. So all of what I have to say is going to be based on styling. As I had posted earlier in a comment to you was to clear out any unused white spaces. It gives the impression that you don't care if there are too many extra white spaces.<...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T15:26:27.653", "Id": "32969", "Score": "2", "Tags": [ "c#", "mvc", "security", "sql-server", "asp.net-mvc-4" ], "Title": "Need reviews for an authentication system" }
32969
<p>I'm just after some sanity checking of this code:</p> <pre><code>public struct function defer(required function job, function onSuccess, function onFailure, function onError, function onTerminate){ var threadId = "deferredThread_#createUuid()#"; local[threadId] = ""; try { cfthread.status = "R...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T16:30:30.900", "Id": "32971", "Score": "3", "Tags": [ "multithreading", "asynchronous", "error-handling", "cfml", "coldfusion-10" ], "Title": "Quick 'n' dirty job defermen...
32971
<p>This is my first try with Python. I wanted to parse some <code>Log4J</code> so I thought it a good opportunity to write my first Python program.</p> <p>The format of the logs I deal with are simply like <code>[INFO BLA 08:00:00] Blabla</code>. Most of the time there are single lines like the above; but sometimes, ...
[]
[ { "body": "<p>Let's see if I understand what's going on with get_filtered_lines() and apply_filter(). First, get_filtered_lines() reads physical lines from the file and strings them together in line_buffer. When we find the beginning of the next logical line ('['), we pass line_buffer off to apply_filter() so t...
{ "AcceptedAnswerId": "48865", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T18:17:30.450", "Id": "32975", "Score": "5", "Tags": [ "python", "beginner", "parsing", "logging" ], "Title": "Review Simple Logparser" }
32975
<p>Here is a program that I've wrote to extract JPEGs from a file. It reads a file that contains the image data and separates it into individual images. </p> <pre><code>import hashlib inputfile = 'data.txt' marker = chr(0xFF)+chr(0xD8) # Input data imagedump = file(inputfile, "rb").read() imagedump = imagedump.spl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T07:55:25.200", "Id": "52785", "Score": "2", "body": "Using only 64 bits of SHA256 is a waste. It's not cryptographically sound anyway, so you [might as well use MD5 or SHA1](http://stackoverflow.com/q/2722943/1157100) for slightly f...
[ { "body": "<p>There <em>is</em> an <a href=\"http://en.wikipedia.org/wiki/JPEG#Syntax_and_structure\" rel=\"nofollow\">End-of-data marker</a> <code>FF D9</code>, but you can't scan for it blindly, because those bytes can also appear within a JPEG image. For example, if the JPEG contains a thumbnail, then <code>...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-20T22:39:29.227", "Id": "32981", "Score": "4", "Tags": [ "python", "image" ], "Title": "JPEG extraction script" }
32981
<p>I'm trying to review this block of code to make sure logic is fine. The first version that I commented will create duplicated order 'my college developer' but I fixed it but "really not sure" I want to make sure my fix it exactly same as commented code </p> <p>the old logic "this code include duplicated"</p> <pre>...
[]
[ { "body": "<p>Not sure if your fixed logic actually works. But I see couple of issues with the code.</p>\n\n<ol>\n<li><p>both if and else block is setting a boolean. But I don't find any use of it in your code. <code>boolean prodPresent = false\n</code></p></li>\n<li><p>How do you get access to <code>items</cod...
{ "AcceptedAnswerId": "33161", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T03:07:36.540", "Id": "32987", "Score": "4", "Tags": [ "java" ], "Title": "compare two logic commented one to my logic java" }
32987
<p>Below is my implementation of an immutable stack class. The reverse function is trying to return a stack with all elements reversed. Is my implementation good? Maybe the reverse function can be faster?</p> <pre><code>public class ImStack&lt;T&gt; { private final T head; private final ImStack&lt;T&gt; tail...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T04:30:17.170", "Id": "52776", "Score": "5", "body": "Stacks typically don't support a `reverse()` operation, since that would violate the last-in, first-out principle, which is the purpose of stacks." }, { "ContentLicense": ...
[ { "body": "<p>Writing an elegant immutable stack is difficult in Java, mainly due to the lack of multiple return values. But your code does look quite fine.</p>\n\n<p>I am comparing your API with <a href=\"http://www.scala-lang.org/api/current/index.html#scala.collection.immutable.Stack\" rel=\"nofollow\">Scala...
{ "AcceptedAnswerId": "32994", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T03:55:04.067", "Id": "32991", "Score": "6", "Tags": [ "java", "stack", "immutability" ], "Title": "How is my implementation of an immutable stack?" }
32991
<p>I've written a function to parse configuration files. It doesn't handle file opening, but instead takes an array with the file contents and tries to find fields based on an array containing the fields' names. If found, it puts the content into its respective place.</p> <p>The only rules it has so far are:</p> <ul>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T10:16:34.990", "Id": "52790", "Score": "0", "body": "IT would be a better idea to use an existing file format (such as json) and use that. It would be better to read from the stream and match dynamically rather than have to read the...
[ { "body": "<p>I'll only address C programming issues in this answer, not the algorithm itself.</p>\n\n<p><strong>Program design and programming practice</strong></p>\n\n<ul>\n<li><p>As a rule of thumb, there is never a reason to use more than two levels of indirection in C programming. More levels than that alw...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T04:05:32.207", "Id": "32992", "Score": "2", "Tags": [ "c", "parsing" ], "Title": "Parsing configuration files" }
32992
<p>I am writing a server that serves an <a href="http://www.w3.org/TR/2012/WD-eventsource-20120426/" rel="nofollow">EventSource</a> data-stream using Python's Twisted. Although this is my first time using Twisted, I hope this part of the code is acceptable.</p> <p>To get the events, the code queries another server. ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T10:59:38.353", "Id": "32995", "Score": "1", "Tags": [ "python", "client" ], "Title": "Using a client from within a server in Python's Twisted" }
32995
<p>I have ChaplinJS View, with template which varies according to the condition. I try to avoid switch statements, but I think it's messy at this moment.</p> <p>What can you advise?</p> <pre><code>var SiteView = View.extend({ region: 'date', autoRender: true, className: 'date-label', containerMethod: ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T12:33:26.717", "Id": "32996", "Score": "2", "Tags": [ "javascript", "backbone.js" ], "Title": "Backbone/ChaplinJS view with various template" }
32996
<p>This was just an experiment to see if I could replicate something like C++ function pointers in Java. Basically, the idea was to have an object which represented a method call, and when you call <code>.invoke()</code> on that object, the method would run.</p> <p>It feels a little sloppy to me, and I feel like ther...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T13:58:31.780", "Id": "52798", "Score": "0", "body": "I just realized that the type of `args` should be `List<Object>` rather than `ArrayList<Object>`, if I'm adhering strictly to Java convention." }, { "ContentLicense": "CC ...
[ { "body": "<p>It seams like there is a lot of work going on there for just a simple concept. I suspect you don't need all the flexibility and structure that this implementation gives you. Instead, I suggest you use a simple interfaces. Here is the <a href=\"http://docs.guava-libraries.googlecode.com/git/javadoc...
{ "AcceptedAnswerId": "33004", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T13:51:55.970", "Id": "32998", "Score": "3", "Tags": [ "java", "generics", "reflection" ], "Title": "How can I improve my Java MethodPointer?" }
32998
<p><a href="http://requirejs.org/" rel="nofollow">RequireJS</a> is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node.</p> <p>It uses the <a href="https://github.com/amdjs/amdjs-api/wiki/AMD" rel="nofollow">Asynchronous Modu...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T14:17:31.653", "Id": "33002", "Score": "0", "Tags": null, "Title": null }
33002
RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T14:17:31.653", "Id": "33003", "Score": "0", "Tags": null, "Title": null }
33003
<p>I wrote a function that dynamically stores statistical data. I tried to clone the functionality of how I had originally written my solution in Bash. Is there perhaps something I could improve, or do better?</p> <p><strong>Bash Solution</strong></p> <pre><code>#!/bin/bash data_set=() while IFS= read -r -p 'Enter s...
[]
[ { "body": "<p>From your bash script, I assume that you expect a proper (no junk) input. In that case, you can just do</p>\n\n<pre><code>while ((c = getchar()) != '\\n') {\n ungetc(c, stdin);\n scanf(\"%lf%*c\", &amp;x);\n printf(\"x = %g\\n\", x);\n}\n</code></pre>\n\n<p>Of course, you'll replace <code...
{ "AcceptedAnswerId": "33054", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T14:50:30.770", "Id": "33005", "Score": "1", "Tags": [ "c", "bash", "io", "floating-point" ], "Title": "Floating-Point data input in Bash and C" }
33005
<p>I have the following piece of java method code:</p> <pre><code>@Override public void applyStates(int timestamp, State[] states) { // Calculate the time diff between current time and the time stamp of the given states. int diff = getNetworkTime() - timestamp; if (diff &lt;= 0) { Log...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T16:24:36.110", "Id": "52809", "Score": "4", "body": "This question appears to be off-topic because the real question is asking “*How can I unit-test side effects and/or specific code paths?*” and is asking for *design help*. There i...
[ { "body": "<p>You've got a Policy abstraction that is asking to be teased out. The Policy provides a method that tests \"is it valid to do this operation now\". In production, the Policy instance checks the time difference to see if it is valid. In test, however, you specify an instance of the policy object ...
{ "AcceptedAnswerId": "33014", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T15:49:03.243", "Id": "33008", "Score": "1", "Tags": [ "java", "unit-testing" ], "Title": "Proper way of a testable method with multiple return points" }
33008
<p>Code review requested to make this code simpler, cleaner, and better. Input array is sorted.</p> <p>This program finds the greatest number smaller than <code>x</code>. So, in an array <code>[10 20 30 40]</code> and <code>x = 25</code>, the output should be 20.</p> <pre><code>public class GreatestValueLesserThanEq...
[]
[ { "body": "<p>That is not a class: it is a collection of functions. A class has attributes (instance variables) and behaviours (methods that perform operations on the data):</p>\n<blockquote>\n<p>A class is a software element describing an abstract data type and its partial or total implementation. An abstract ...
{ "AcceptedAnswerId": "33043", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T16:44:48.823", "Id": "33009", "Score": "6", "Tags": [ "java", "algorithm", "array", "binary-search", "mathematics" ], "Title": "Finding greatest value in array smaller ...
33009
<p>I have inlined temporary <code>FileOutputStream</code> that I am not able to explicitly close.</p> <p>Is that a problem?</p> <pre><code>File raw = new File(uri.getPath()); Bitmap myBitmap = BitmapFactory.decodeFile(uri.getPath()); File compressedPicture = MEUtils.createTemporaryFile(getPackageName()); // see here...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T17:38:21.383", "Id": "52816", "Score": "0", "body": "in C# I would ask if you have tried a `using` block. but I don't know enough about Java. does it have something similar? that would automatically close the connection when it i...
[ { "body": "<p>Yes, you do.</p>\n\n<p>While the garbage collector does close your <code>FileOutputStream</code> (by calling <code>finalize</code>), it is not a good idea to rely on it because it runs unpredictably.</p>\n\n<p>This means that if you do not close your streams explicitly, you may run into a <a href=...
{ "AcceptedAnswerId": "33013", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T17:01:49.483", "Id": "33010", "Score": "5", "Tags": [ "java", "android", "stream" ], "Title": "Do I need to close my FileOutputStreams?" }
33010
<p>I was trying to post this code to a Wikipedia article, but it was soon removed. I then asked about the code in the page's talk section, and some other contributors said that is was "<em>very poor</em>" and that "<em>there are clearly going to be underflows all over the place</em>." What does that mean? What is a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T19:34:05.043", "Id": "52832", "Score": "2", "body": "I wouldn't say that the code is poor at all. I would probably mention the inconsistent braces, and you self asign result in your factorial method, and you don't in your main metho...
[ { "body": "<p>If you're to implement something like this, you should first learn about how these things are done. I hope this doesn't sound too harsh. To explain it better, here is my variant of your code, with comparison to what C computes as e using <code>expl(1)</code>:</p>\n\n<pre><code>#include &lt;stdio.h...
{ "AcceptedAnswerId": "33018", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T18:49:12.790", "Id": "33015", "Score": "39", "Tags": [ "c", "algorithm", "mathematics", "floating-point" ], "Title": "Why is my C program for calculating Euler's constant o...
33015
<p>I recently made a program in Python to open a list of URLs and split the queries into different files. I want to make this code more generic and simple. I am open to suggestions. </p> <pre><code>def parse_file(): # Open the file for reading infile = open("URLlist.txt", 'r') # Read every single line of ...
[]
[ { "body": "<h1>Before We Get Started</h1>\n\n<p>It would be good if you could provide some examples of the URLs that you are looking to parse, I did a cursory search and I couldn't coerce a query result from any that I tried with:</p>\n\n<pre><code>urlparse.parse_qsl(urlparse.urlparse(\"some_url\").query\n</cod...
{ "AcceptedAnswerId": "33039", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T19:17:16.547", "Id": "33016", "Score": "2", "Tags": [ "python", "parsing", "generics", "url", "file" ], "Title": "Opening a list of URLs and splitting the queries into ...
33016
<p>I find myself using this bit of code very often when I am retrieving the results from a Cursor</p> <pre><code>SearchItem searchItem = new SearchItem(); searchItem.setId(cursor.getInt(cursor.getColumnIndex(COLUMN_NAME_ID))); searchItem.setOrigin(cursor.getString(cursor.getColumnIndex(COLUMN_NAME_ORIGIN))); searchIte...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T02:41:53.167", "Id": "52833", "Score": "0", "body": "I see I was voted down. I am always open to hear why this is a bad question" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T03:46:12.590", "Id"...
[ { "body": "<p>I am not completely sure if your question is as easy as it sounds (or if I am missing something), but here's my thought on things.</p>\n\n<p>Using a singleton class for this does not make much sense in my opinion. There's no <strong>state</strong> to be stored, and therefore there's no need for an...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-03T02:28:54.997", "Id": "33017", "Score": "0", "Tags": [ "java", "android" ], "Title": "Reusing Code With Database Cursors" }
33017
<p>I recently wrote a function that replaces every white space with '%20', just for fun (and sharping my coding skills). The input string is terminated with extra white spaces, with the length that the string should have after encoding takes place. For example:</p> <pre><code>input = "Not encoded " //2 white spaces i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T20:58:25.903", "Id": "52843", "Score": "0", "body": "Have you looked at the StringBuilder class? It does away with your 2nd shift-y for loop." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T21:01:12.7...
[ { "body": "<p>Your solution:</p>\n\n<ul>\n<li>copies the whole string twice (1. <code>string.ToCharArray()</code> 2. <code>new string()</code>)</li>\n<li>needs <em>n</em> bytes of extra storage (apart from the input and output; <em>n</em> is the size of the output)</li>\n<li>potentially moves the characters in ...
{ "AcceptedAnswerId": "33029", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T19:51:33.833", "Id": "33020", "Score": "2", "Tags": [ "c#", "performance", "strings" ], "Title": "Function for encoding strings in-place" }
33020
<p>I have a <code>select</code> with 3 options and two <code>datepickers</code>, a start and an end date. Based on the option selected, the date end date can either be any future date or limited to a 30 day date range. In the jsFiddle provided below, when Option 1 is selected, the date range is restricted to 30 days. I...
[]
[ { "body": "<p>From a once over;</p>\n\n<ul>\n<li><p>This code does not do what the tin says:</p>\n\n<pre><code>// If selected start date is later than currently selected\n// end date, set end date to start date + 1 day\nvar date = $('#startDate').datepicker('getDate');\nif (date) { date.setDate(date.getDate() +...
{ "AcceptedAnswerId": "64669", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T20:26:51.703", "Id": "33022", "Score": "2", "Tags": [ "javascript", "jquery", "datetime" ], "Title": "Reduce code handling start and end datepickers" }
33022
<p>I have some code to write <code>Error Logs</code> to different places like <code>Console/SignalR Messages/Text File</code>.</p> <p>The code is as follows:-</p> <pre><code>public class Logger { public void WriteToLog(string message, LogType logType) { switch (logType) { case ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T11:32:17.503", "Id": "52839", "Score": "1", "body": "What is the question?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T11:36:51.090", "Id": "52840", "Score": "0", "body": "@Jean-Franço...
[ { "body": "<p>You should create an interface from which you can make many implementations, e.g. an <code>ILogger</code> interface with <code>Warning</code>, <code>Error</code> methods etc.</p>\n<p>Then you would create an implementation per logging type (one for console, one for SignalR etc). You could then inj...
{ "AcceptedAnswerId": "33026", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T11:30:54.590", "Id": "33023", "Score": "1", "Tags": [ "c#", "object-oriented" ], "Title": "Refactoring based on OPEN CLOSE PRINCIPLE- C#" }
33023
<p>I have a some classes and interface</p> <pre><code>public interface IGeoObject { GeoCoordinate GetGeocoordinate(); } public class User : IGeoObject { public GeoCoordinate GetGeocoordinate() { //... return GeoCoordinate; } } publi...
[]
[ { "body": "<p>You can make <code>GetMinDistance</code> generic:</p>\n\n<pre><code>double GetMinDistance&lt;T&gt;(IList&lt;T&gt; objects, GeoCoordinate position)\n where T: IGeoObject\n{ \n // ...\n}\n</code></pre>\n\n<p>You can use it like this:</p>\n\n<pre><code>List&lt;User&gt; user = ....;\n\nGetMinDista...
{ "AcceptedAnswerId": "33033", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-21T23:13:10.720", "Id": "33031", "Score": "1", "Tags": [ "c#", ".net", "generics" ], "Title": "Covariance in generic collections" }
33031
<p>Following up on <a href="https://codereview.stackexchange.com/questions/32618/listt-implementation-for-vb6-vba">List&lt;T&gt; implementation for VB6/VBA</a>, I'd like some thoughts about the revisited <code>IsTypeSafe</code> function, below.</p> <p>The previous version pretty much implemented VB.net's <code>Option ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-20T13:59:49.873", "Id": "58118", "Score": "1", "body": "reinventing the wheel a bit => the T is very limited though. Instead of all this work you could have used the [vb constants](http://vbadud.blogspot.co.uk/2007/04/get-variable-type...
[ { "body": "<p>This code looks very clean, </p>\n\n<p>It looks like it handles edge cases well.</p>\n\n<p>I especially like the way that if it converts to the specified data type that it does it and doesn't make you convert explicitly. that is very slick!</p>\n\n<p>I would definitely like to see some code that ...
{ "AcceptedAnswerId": "35707", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T02:34:18.370", "Id": "33035", "Score": "7", "Tags": [ "vba", "type-safety", "vb6" ], "Title": "Revisited IsTypeSafe method implementation for \"type-safe\" List" }
33035
<p>Okay, here's a challenge at Coderbyte that completely stumped me. I came up with a solution, but I know it is flawed. </p> <blockquote> <p>Have the function <code>ArrayAdditionI(arr)</code> take the array of numbers stored in <code>arr</code> and return the string true if any combination of numbers in the array c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T03:11:57.193", "Id": "52868", "Score": "0", "body": "Do you require that all remaining numbers add up to the max value or any number of one or more of the remaining numbers add up to the max value? Your question is not quite clear ...
[ { "body": "<p>First, let's fix the two bugs in the code.</p>\n\n<p>If the array would contain only numbers below -100, your code would think that -100 was the greatest number, located at index -1. That would make the rest of the code remove the last item of the array instead of the greatest one, and try to sum ...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T03:04:29.030", "Id": "33036", "Score": "2", "Tags": [ "javascript", "array", "mathematics", "programming-challenge" ], "Title": "Testing if numbers in the array can be added u...
33036
<p>I am currently working on a game and found myself in need of an event handler. I wrote an event handler similar to this one some time ago, but decided to update it using variadic templates (this is my first time using them). I really wanted something with the simple usage that C# events provide. I found some exam...
[]
[ { "body": "<p>In no particular order:</p>\n\n<ol>\n<li><p>Normally, you shouldn't define your own copy and move constructors and assignment operators unless you need special processing in them. Which in your case you don't; the implicitly generated ones will do exactly what you need. So just remove them and wit...
{ "AcceptedAnswerId": "33126", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T03:09:41.227", "Id": "33037", "Score": "4", "Tags": [ "c++", "c++11", "template", "event-handling", "variadic" ], "Title": "Event handler using variadic templates" }
33037
<p>Today I've noticed that the source code for a <a href="http://rosettacode.org/wiki/Four_bit_adder#C" rel="nofollow">Boolean adder</a> is very repetitive, so I wrote a Python script to generate the C source code. The script generates an adder of varying size depending on the length of the added numbers, but the scri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T09:19:45.553", "Id": "53134", "Score": "0", "body": "This code is not ready for review. I'm sure you know how to do better than this!" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T17:02:36.447", ...
[ { "body": "<p>The C code may not look pretty in this particular case because it's designed to run fast, but the Python code should look beautiful because it's designed to be clearly readable to someone unfamiliar with it. There are a number of things you can do to achieve this.</p>\n\n<h1>Smaller functions</h1>...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T03:13:28.907", "Id": "33038", "Score": "7", "Tags": [ "python", "mathematics" ], "Title": "Improving readability of Boolean adder generator?" }
33038
<p>I've been working on implementing a doubly linked list from scratch in Java, and if anyone has time, could you critique it?</p> <pre><code>class Node { Node prev; Node next; int data; public Node(int d) { data = d; prev = null; next = null; } } class LinkedList { No...
[]
[ { "body": "<ol>\n<li><p>Your are creating something similar to <code>java.util.LinkedList</code>, thus it is best practice to use same or similar method names.</p></li>\n<li><p>Your list is sorted. Whenever you search for an element, change this loop:</p>\n\n<pre><code>while (tmpNode != null &amp;&amp; tmpNode....
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T04:44:36.453", "Id": "33040", "Score": "4", "Tags": [ "java", "linked-list" ], "Title": "Java Doubly Linked List" }
33040
<p>I would like a code review to make this code better, clear, and concise. </p> <p>The problem it's solving is as follows:</p> <blockquote> <p>Given a matrix, print the circumference of each of the items. For example:</p> <pre><code>1 2 3 4 5 6 7 8 9 </code></pre> <p>should result in </p> <pre><code>1 : 2...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T09:55:15.083", "Id": "52896", "Score": "5", "body": "Complexity is O(rows * cols). For each matrix element in question, the two innermost for-loops will iterate through at most 8 neighbors (plus itself), regardless of the matrix siz...
[ { "body": "<p>If you like to reduce loops in your code, you can do it similar to this one:</p>\n\n<pre><code>static void printDirection(int [][]m, int r1, int r2, int col1, int col2, boolean cond)\n{\n System.out.print( m[r1][col1] + \" \" );\n\n if (cond) System.out.print( m[r2][col2] + \" \" );\n}\n\npu...
{ "AcceptedAnswerId": "33315", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T06:00:01.950", "Id": "33042", "Score": "3", "Tags": [ "java", "algorithm", "matrix" ], "Title": "Neighbors of a matrix element" }
33042
<p>This is a boggle solver in Java. I would like code reviewers to optimize the code, suggest better coding practices, and help make it cleaner.</p> <p>I am also unsure of the complexity and would appreciate an explanation of it.</p> <pre><code>public final class Boggle { private static final NavigableSet&lt;St...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T08:22:51.950", "Id": "52888", "Score": "3", "body": "Rule of thumb: If you need to suffix your variable names with numbers, you're doing something wrong." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-2...
[ { "body": "<p>According to the <a href=\"http://www.boggle-game.com/rules-boggle.php\" rel=\"nofollow\">rules</a>, you can only use each tile once per word. You haven't attempted to keep track of tile usage.</p>\n\n<p>Consider storing your dictionary using a <a href=\"http://en.wikipedia.org/wiki/Trie\" rel=\"...
{ "AcceptedAnswerId": "33055", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T06:47:05.353", "Id": "33045", "Score": "4", "Tags": [ "java", "algorithm", "recursion" ], "Title": "Boggle solver in Java" }
33045
<p>so, I am pretty new to this game, and am trying to understand javaScript way better than I currently do. I have this block of code, if it is too long to read, then just skip to my question at the bottom...</p> <pre><code> function createCSSRule(selectorName, necessaryProperties){ //add class to control all d...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T07:09:41.967", "Id": "52877", "Score": "0", "body": "why do you build the properties strings programmatically, though they will always be the same ? why not just store already built strings and pick the ones you need ?" }, { ...
[ { "body": "<p>It seems like you are using JavaScript to programmatically change the CSS of your images.</p>\n\n<p>The better approach would be to create all the CSS classes in a CSS file and then just changing the className to that of your CSS class.</p>\n", "comments": [ { "ContentLicense": "...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T07:01:17.160", "Id": "33046", "Score": "1", "Tags": [ "javascript", "jquery", "css" ], "Title": "create a really long string with javaScript more efficiently than this" }
33046
<p>Just ended up with this approach for wp7 (no tag yet), in case someone would find it useful. Also, improvement considerations are welcome.</p> <p>It works with </p> <ul> <li><code>SimpleLogger.WriteLine("JustLine");</code></li> <li><code>SimpleLogger.WriteLine(ObjectToBeCastedToString);</code></li> <li><code>Simpl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T13:35:45.073", "Id": "52909", "Score": "1", "body": "This site is for requesting reviews of your code, not for publishing it." } ]
[ { "body": "<pre><code>(value == null) ? string.Empty : value.ToString()\n</code></pre>\n\n<p>Consider whether something more descriptive would be suitable for <code>null</code>. Maybe something like <code>\"(null)\"</code>.</p>\n\n<pre><code>public static void WriteLine(string format)\n</code></pre>\n\n<p>The n...
{ "AcceptedAnswerId": "33068", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T07:59:48.247", "Id": "33050", "Score": "3", "Tags": [ "c#", "logging", "windows-phone", "windows-phone-7" ], "Title": "Simplest WP7 logger" }
33050
<p>I use the following code to get the changes between two collections. Objects are "joined" using a primary key. Any tips on performance issues or other optimizations appreciated.</p> <pre><code>/// &lt;summary&gt; /// Gets the changes [Deleted, changed, inserted] comparing this collection to another. /// &lt;/summar...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T08:44:34.937", "Id": "52891", "Score": "0", "body": "I'm not posting this as an answer because it doesn't address your actual question of performance but I notice that you are checking if the `local` parameter is null twice and not ...
[ { "body": "<p>I think it looks like good, clear, general purpose code. I don't see any really significant changes to make, but there might be some minor improvements available.</p>\n\n<p>First, allocating default size collections and letting them grow naturally may not work well for large collections. IIRC they...
{ "AcceptedAnswerId": "33139", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T08:05:34.517", "Id": "33053", "Score": "7", "Tags": [ "c#", ".net" ], "Title": "Optimization of comparing two collections and get the changes" }
33053
<p>I have two active records <code>StudentDemographics</code> and <code>StudentWeeklyReport</code> both having <code>has_many</code> relation like this:</p> <pre><code>class StudentDemographics &lt; ActiveRecord::Base has_many :student_weekly_reports, :foreign_key =&gt; :student_id end </code></pre> <p>I have to ch...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T06:07:10.533", "Id": "53025", "Score": "0", "body": "`StudentDemographics` has a `date` field, but `StudentWeeklyReport` doesn't? I would have expected the opposite to be true. Perhaps you could provide more context about the whole ...
[ { "body": "<p>I'd suggest a couple of things:</p>\n\n<ol>\n<li><p>the <code>for i in 0...@distinct.length</code> takes your array's length and uses it to construct a range which it turns into an array again. Not necessarily time consuming but unnecessary and hard to read. Ruby gives you <a href=\"http://apidock...
{ "AcceptedAnswerId": "33073", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T10:29:40.673", "Id": "33058", "Score": "3", "Tags": [ "performance", "ruby", "ruby-on-rails", "database" ], "Title": "Getting student demographics report with ActiveRecord"...
33058
<p>I'm not a Python developper, but I enjoy programming with it, and for a project I wanted to have generators that I can easily index. Using python's slice model is obviously the way to go, and here's the solution I've come up with.</p> <pre><code>class _SubscriptableGenerator(): def __init__(self, generator, *ar...
[]
[ { "body": "<p>The most Pythonic solution would be to use <a href=\"http://docs.python.org/3/library/itertools.html#itertools.islice\"><code>itertools.islice</code></a> from the standard library. For example, like this:</p>\n\n<pre><code>from itertools import islice\n\nclass Sliceable(object):\n \"\"\"Sliceab...
{ "AcceptedAnswerId": "33067", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T10:55:48.243", "Id": "33060", "Score": "8", "Tags": [ "python", "python-3.x", "generator" ], "Title": "Subscriptable/Indexable generator" }
33060
<p>I am trying to setup an odds calculator for a best of 7 series, given independent odds for each event.</p> <p>The following code works, but I would like to add recursion to simplify the end.</p> <pre><code>public class Game { public int No { get; set; } public List&lt;decimal&gt; Odds; public Game(int...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T13:09:52.067", "Id": "52904", "Score": "2", "body": "This is messy. You have Game class defined twice and some code directly in the class definition. Write it in a way, so that people don't have to think what you meant." }, { ...
[ { "body": "<p>This is a clean as I can make it. The last thing I could do would be to replace the hardcoded 7 by a const to make it a little easier to setup best of 5, best of 3, etc...</p>\n\n<pre><code>using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nnamespace ConsoleApplication10\n{\n...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T12:44:34.457", "Id": "33064", "Score": "2", "Tags": [ "c#", "optimization", "recursion" ], "Title": "Optimizing odds calculator" }
33064
<p>Just a wrapper around IsolatedStorageSettings.</p> <p>The only thing i'm not sure about is isoSettings.Save(); Should i call it there? Looking like it works without it, setting [] is enough.</p> <pre><code>class IsoSettingsManager { private static readonly IsolatedStorageSettings isoSettings = IsolatedStorageS...
[]
[ { "body": "<p>When you use your <code>GetProperty</code> method there is no way to find out did you get a real property value or some default value.</p>\n\n<p>It will be more clear if you'll use a standard TryGet pattern here:</p>\n\n<pre><code>public static bool TryGetProperty&lt;T&gt;(string propertyName, out...
{ "AcceptedAnswerId": "33124", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T14:45:52.100", "Id": "33074", "Score": "1", "Tags": [ "c#", "windows-phone", "windows-phone-7" ], "Title": "IsoSettingsManager" }
33074
<p>I am writing a dice roller winforms application using C# 2012 VS. Dice roller is set up for playing Shadowrun tabletop. I feel that there might be too much code going into the GUI, but I am unsure how it should be formatted. I am also very open to general advice. This is my first program I am trying to construct ...
[]
[ { "body": "<p>your <code>Do..While</code> threw me for a loop. I saw the <code>While</code> statement and not the <code>Do</code> statement preceding it and wondered where the code was.</p>\n\n<p>you already set the <code>rand</code> variable to something less than <code>1</code> before the loop, so you should ...
{ "AcceptedAnswerId": "33151", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T14:48:18.580", "Id": "33076", "Score": "12", "Tags": [ "c#", "object-oriented", "random", "gui", "dice" ], "Title": "WinForms dice roller" }
33076
<p>I am getting object of a class AAA from somewhere and I want to add more information in that object. So, I am creating a new class BBB which is derived from AAA. The class BBB has additional field dictionary. I am populating this dictionary in derived class constructor which is taking the Class AAA object and array ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T17:30:04.133", "Id": "52947", "Score": "0", "body": "Can you modify `A`? Does the real `A` have a constructor (apart from the parameterless one)." } ]
[ { "body": "<p>Those lines are managing the properties of A, so they belong in A. I've added a protected copy constructor and used constructor chaining to solve your issue:</p>\n\n<pre><code>public class A\n{\n public int [] prop1 ;\n public string prop2 ;\n public string prop3 ;\n\n public A() {}\n\n prot...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T14:57:39.863", "Id": "33077", "Score": "1", "Tags": [ "c#", "inheritance" ], "Title": "Initialization of Extended class without too much overhead?" }
33077
<p>Please take a look at this query and try to give me any other ideas that will give the exact same results more efficiently.</p> <pre><code>SELECT username FROM users WHERE username NOT IN ( SELECT DISTINCT username FROM users, friends WHERE 'user1' IN (you,friend,username) AND you IN ('user1...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T23:29:17.967", "Id": "52989", "Score": "3", "body": "As with all SQL query optimizations, first run `EXPLAIN SELECT username FROM users WHERE…` and check that the appropriate [indexes](http://use-the-index-luke.com) are in place." ...
[ { "body": "<p>This query will give you the same results</p>\n\n<pre><code>SELECT username FROM users \nWHERE username NOT IN (SELECT you FROM friends WHERE friend = 'user1') \nAND username NOT IN (SELECT friend FROM friends WHERE you = 'user1')\nAND username &lt;&gt; 'user1'\n</code></pre>\n\n<p>and the <a href...
{ "AcceptedAnswerId": "33216", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T16:26:40.630", "Id": "33080", "Score": "5", "Tags": [ "mysql", "sql" ], "Title": "Improve query: find users who are neither friends nor fans of a user" }
33080
<p>I am trying to format my code properly. I have already read the programming standards document and I believe that my code follows these rules. I have also used the <kbd>Ctrl</kbd><kbd>Shift</kbd><kbd>F</kbd> keys in Eclipse which should format the code automatically.</p> <p>Could someone tell me if this looks ok? ...
[]
[ { "body": "<p>Comments rarely go under a piece of code. Move it above it.</p>\n\n<p>Other than that I'd personally also put the opening parenthesis of the \"for\" loop right next to the \"for:</p>\n\n<pre><code>for(char a : det) { }\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount":...
{ "AcceptedAnswerId": "33083", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T16:50:18.267", "Id": "33081", "Score": "3", "Tags": [ "java", "strings", "formatting" ], "Title": "Formatting small string use example" }
33081
<p>I have a fairly simple app set up with couchrest_model to capture data pulled in from vendors to couchdb for later searching and archiving. Each document has a <code>show</code> (the name of the vendor), a <code>datatype</code> (which is limited to seven or eight unique strings), and a <code>pulled_at</code> timesta...
[]
[ { "body": "<p>You can use <a href=\"http://ruby-doc.org/gems/docs/s/samlown-couchrest-1.0.0/CouchRest/Database.html#method-i-get_bulk\" rel=\"nofollow\"><code>CouchRest::Database.get_bulk</code></a> API:</p>\n\n<pre><code>hash[row['key']] = database.get_bulk(row['value']).sort_by(&amp;:pulled_at).reverse\n</cod...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T18:10:08.747", "Id": "33085", "Score": "1", "Tags": [ "ruby", "ruby-on-rails", "couchdb" ], "Title": "How can I make this CouchDB view code more \"correct\"?" }
33085
<p>I'm working on an implementation of <code>MergeSort</code> which sorts a <code>List</code> given as an argument. As follows</p> <pre><code>public class MergeSort implements Sort { @Override public &lt;E extends Comparable&lt;E&gt;&gt; void sort(List&lt;E&gt; list) { final int length = list.size(); ...
[]
[ { "body": "<p>You could do</p>\n\n<pre><code>list.clear(); \nmerge(right, left, list);\n</code></pre>\n\n<p>with</p>\n\n<pre><code>private static &lt;E extends Comparable&lt;E&gt;&gt; List&lt;E&gt; merge(List&lt;E&gt; source1, List&lt;E&gt; source2, List&lt;E&gt; destination) {\n // ...\n destination.add(...
{ "AcceptedAnswerId": "33090", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T18:27:45.307", "Id": "33086", "Score": "1", "Tags": [ "java", "sorting", "mergesort" ], "Title": "MergeSort implementation with java.util.List passed as argument, not returned"...
33086
<p><a href="https://stackoverflow.com/a/17954617/1214743">Answer to Exporting PDF's from SQL Server DB and writing a Map to a Text File</a></p> <p>this was a Question that I asked in StackOverflow and then answered it when I was finished with the project. </p> <p>I would like it reviewed so the next time that I get ...
[]
[ { "body": "<p>One of the biggest issues I see in the code is the large number of <code>IDisposable</code> objects created not in <code>using</code> statements. I've put in some minor changes (idiomatic variable naming, etc.) below, but the important one is to make sure those resources get deterministically disp...
{ "AcceptedAnswerId": "33094", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T18:35:45.670", "Id": "33087", "Score": "5", "Tags": [ "c#", "sql-server", "stream" ], "Title": "Exporting PDF From Database back to PDF Format" }
33087
<p>If you input the number 3 from the keyboard, the program will show this:</p> <pre><code> 0 0 1 0 0 1 2 1 0 0 1 2 3 2 1 0 0 1 2 1 0 0 1 0 0 </code></pre> <p>Here is my code:</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main() { unsigned i,k=0,n; cout&lt;&lt;"n...
[]
[ { "body": "<ul>\n<li><p><a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\"><code>using namespace std</code></a> is not preferred, although not that bad for small programs.</p></li>\n<li><p>Each variable should be declared/initialized on separate lines. Th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T18:39:04.323", "Id": "33088", "Score": "8", "Tags": [ "c++", "algorithm", "formatting" ], "Title": "Printing a diamond of numbers" }
33088
<p>I am pushing an Excel file to the server and then reading it's contents. XLS and XLSX files need to be read differently, but the DLL that I'm using has the EXACT same function calls for both types. If I use a 'dynamic' type, I can save a lot of lines of code and avoid redundancy. However, I've been told many times b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T01:26:06.630", "Id": "53001", "Score": "0", "body": "Don't they have a common interface or base class?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T15:38:38.460", "Id": "53067", "Score": "0...
[ { "body": "<p>The prevalent answer is: No. (Funny enough, working with Office files seems to be a valid exception to the rule).</p>\n\n<p>The problem is that you don't have type validation anymore, and any issues will reveal themselves at run time.</p>\n\n<p>I'd say, if it's a small thing and it won't be touche...
{ "AcceptedAnswerId": "33117", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T23:05:15.853", "Id": "33097", "Score": "1", "Tags": [ "c#", "asp.net-mvc-4" ], "Title": "Using 'dynamic' to save lines" }
33097
<p>I've created an Ajax login for my website but I feel like I can optimize it, but I'm not sure how and where.</p> <p>Questions:</p> <ul> <li>How can I optimize my code?</li> <li>Is the code secure? Any ways to break it (injection, etc)?</li> </ul> <p>Also, when I attempt to log in, it currently takes about 1 secon...
[]
[ { "body": "<p>I've seen quite a few programmers who don't enjoy seeing arrays coming in as arguments into the code (me personally, I'm fine with it as long as there is some sort of documentation that goes with it so you don't forget what the function can and cannot take).</p>\n\n<pre><code>password_hash($passwo...
{ "AcceptedAnswerId": "33819", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-22T23:30:40.680", "Id": "33098", "Score": "1", "Tags": [ "php", "optimization", "php5", "ajax" ], "Title": "How can I optimize my login script?" }
33098
<p>I've made a carousel, which uses a function that is passed a target element, and from this element it adds next, prev, next next, and prev prev classes to its siblings (causing the rotation) - what do they call this, pyramid code?</p> <p>Looking at this code - it works, but can't stand know that there is probably a...
[]
[ { "body": "<p>You can remove the <code>active</code> class along with the other classes, and you can chain the <code>prev</code> and <code>next</code> calls:</p>\n\n<pre><code>var render = function (cont) {\n cont.parent().children().removeClass('active next prev next_next prev_prev');\n cont.addClass('active...
{ "AcceptedAnswerId": "33102", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T00:12:37.977", "Id": "33100", "Score": "1", "Tags": [ "javascript", "jquery", "object-oriented" ], "Title": "Carousel using a function passed a target element" }
33100
<p>New to Go, trying to solve <a href="http://tour.golang.org/#56" rel="nofollow">Tour of Go, Exercise 56</a>, which is about error handling.</p> <p>Can the following error handling method can be further improved?</p> <pre><code>package main import ( "fmt" "math" ) type ErrNegativeSqrt float64 func (e ErrN...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-08T08:29:35.710", "Id": "60702", "Score": "0", "body": "Minor point, but you don't need to wrap the `return 0, ErrNegativeSqrt(f)` in an else block. The `go vet` tool would complain about this." } ]
[ { "body": "<p>I would name the error <code>ErrSqrtNegative</code> instead of <code>ErrNegativeSqrt</code>.</p>\n\n<p><code>Sqrt(0)</code> should not be an error.</p>\n\n<p>In case of error, I would use <code>math.NaN(), ErrSqrtNegative(f)</code> as the return values.</p>\n", "comments": [ { "C...
{ "AcceptedAnswerId": "33116", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T03:13:48.930", "Id": "33104", "Score": "1", "Tags": [ "go", "error-handling" ], "Title": "A Tour of Go, problem #56 - error handling" }
33104
<p>I have a working bloc of code that is a fairly ugly set of for, if and else's. I'm looking to clean it up, but I'm seeking advice on how to do so.</p> <pre><code>public String getContents() { if (Blanks.size() &gt; madLibsContent.size()) { for(int i = 0; i &lt;= Blanks.size() - 1; i++) { if ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-11T16:18:09.897", "Id": "53011", "Score": "2", "body": "First indent it properly. Then only you can proceed further." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-11T16:23:34.027", "Id": "53012", ...
[ { "body": "<p>Where you have the pattern of: </p>\n\n<pre><code>for(int i = 0; i &lt;= madLibsContent.size() - 1; i++){\n if (i == madLibsContent.size() - 1)\n contents += madLibsContent.get(i) + \" \" + Blanks.get(i).getBlankValue();\n else\n contents += madLibsContent.get(i) + \" \" + Blan...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-11T16:17:35.790", "Id": "33105", "Score": "-2", "Tags": [ "java" ], "Title": "Cleaning up a nasty looking loop" }
33105
<p>I use the Repository/Service design pattern in my projects and I have found something that might be a bit redundant. Am I writing any unnecessary code?</p> <p>With that in mind, here is my structure:</p> <pre><code>public class Competition { public int Id { get; set; } [Required] public string UserId { ge...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-10T13:03:43.950", "Id": "53017", "Score": "0", "body": "Why ou not use the UnitOfWork pattern as described in the Martin blog http://martinfowler.com/eaaCatalog/unitOfWork.html just remove the save and the delete methods from the Repos...
[ { "body": "<p>You are on the right track. The separation of business logic (services) and data-access logic (repositories) is a good thing, I strongly recommend this. I created a generic repository implementing the <code>IRepository&lt;TEntity&gt;</code> interface. It's slightly different than yours, but you ge...
{ "AcceptedAnswerId": "33110", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-10T12:38:56.607", "Id": "33109", "Score": "51", "Tags": [ "c#", "design-patterns" ], "Title": "Repository/Service Design Pattern" }
33109
<p>I've been doing bits and bobs with Python for a few years, but I've never took the time to get feedback on what's pythonic and what's not. In the interest of collaborating more with Python programmers, I'd like to make sure my code follows conventions and idioms that the majority of Pythonistas will recognize.</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T06:31:47.740", "Id": "53028", "Score": "0", "body": "I've just noticed I have two different styles for a predicate. One with explicit True or False, one implicit. Whoops." }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[ { "body": "<h3>1. Bugs</h3>\n\n<ol>\n<li><p>You have two locks, one protecting <code>state</code>, and the other protecting <code>timeRemaining</code>. But these locks operate independently. That means that when you update both of these properties:</p>\n\n<pre><code>self.state = self.timeup\nself.timeRemaining ...
{ "AcceptedAnswerId": "33125", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T05:01:01.677", "Id": "33113", "Score": "5", "Tags": [ "python", "timer" ], "Title": "Is this kitchen timer code pythonic?" }
33113
<p>I have to deploy this code that will list all the directories, sub directories and files in it starting from the root. The code works but I am not sure if this is the correct way to list. It should not fail, though.</p> <p>Also, in despite not allowing directories with the name <code>.</code> and <code>..</code>, t...
[]
[ { "body": "<p>well <code>.</code> and <code>..</code> are not directories, thats are navigationpoints of directories, . means go inside a root directory, .. means go one folder back, </p>\n\n<p>you might noticed this already in includes like <code>include ../../../foo/bar.php</code> </p>\n\n<p>also instead of ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T05:06:10.217", "Id": "33114", "Score": "2", "Tags": [ "php", "file-system" ], "Title": "Listing all directories, sub directories and files starting from the root" }
33114
<p>After fumbling around with Ruby for a few weeks I've fallen into a coding pattern that I'm comfortable with. When I create a new class and that class has dependencies, I add a method <code>initialize_dependencies</code> that does the job of creating them. That function is then executed from the constructor.</p> <p>...
[]
[ { "body": "<p>Ruby lets you override methods on existing objects, so you don't need to derive a new one to override it.</p>\n\n<p>If you change the constructor to take the dependency explicitly as a parameter you don't need your initialize method. see <a href=\"https://stackoverflow.com/questions/2273683/why-ar...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T05:16:35.563", "Id": "33115", "Score": "-1", "Tags": [ "ruby" ], "Title": "Are there any glaring issues with the way I write and test my Ruby classes?" }
33115
<p>Can please someone review and give me suggestions for improving this code? I am very new to JavaScript.</p> <p>I need to create a method in JavaScript which will take parameters as </p> <ul> <li><code>DateRange</code> (possible values as <code>Today</code>/<code>This Week</code>/<code>This Month</code></li> <li><...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T07:34:05.800", "Id": "53031", "Score": "1", "body": "Please include your code for review. External links can easily go away." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T08:41:56.503", "Id": "5...
[ { "body": "<p>I see some issues with your code</p>\n\n<ol>\n<li>There's a lot of repetition</li>\n<li>Your return values should be actual <code>Date</code> objects, and perhaps handle the time component too. Formatting the date is outside the function's responsibilities. Who knows how the formatting or use of t...
{ "AcceptedAnswerId": "33137", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T06:19:35.567", "Id": "33118", "Score": "5", "Tags": [ "javascript", "datetime" ], "Title": "Datetime in JavaScript" }
33118
<p>I am unsure if the list could store a large number of messages.</p> <p>There are 50,000 queue messages which I am receiving and assigning to the messages list:</p> <pre><code> var msgEnumerator = msgQueue.GetMessageEnumerator2(); var messages = new List&lt;System.Messaging.Message&gt;(); while(msgEnumer...
[]
[ { "body": "<ol>\n<li>You create a lot of <code>TimeSpan</code> objects which is unnecessary. Just create one <code>timeout</code> variable. Especially since it's used in multiple places. This makes changing the timeout later easier. Otherwise you are bound to forget one place.</li>\n<li>Prefer <code>TimeSpan.Fr...
{ "AcceptedAnswerId": "33122", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T07:39:22.203", "Id": "33121", "Score": "3", "Tags": [ "c#" ], "Title": "Receiving MSMQ messages as a list" }
33121
<p>I'm rewriting a god object with long methods into something much more viewable and pretty. </p> <p>However, I think there is something missing and can be done better. I'm sending examples of one controller and two models in order to get an idea.</p> <p><strong>Controller: Account.php</strong></p> <pre><code>&lt;...
[]
[ { "body": "<p><strong>Disclaimer:</strong> I have never used CodeIgniter, so this will mainly focus on general PHP coding practice.</p>\n\n<p>First of all no comments is better than misleading comments. Take a look at some of the <a href=\"http://www.phpdoc.org/docs/latest/index.html\" rel=\"nofollow\">online r...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T11:11:19.307", "Id": "33127", "Score": "1", "Tags": [ "php", "controller", "codeigniter" ], "Title": "An account activation class" }
33127
<p>I am wondering if I can make these classes a bit more efficient.</p> <p><strong>Test Results</strong></p> <p><em>Single Run</em></p> <ul> <li>Method 1: 5 Columns - Text Query - 81178 Records = 00:00:00.6390366 secs</li> <li>Method 2: 5 Columns - Text Query - 81178 Records = 00:00:00.5360307 secs</li> </ul> <p><e...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T14:48:40.687", "Id": "53057", "Score": "0", "body": "you should try to break this up into several questions." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T16:49:35.100", "Id": "53073", "Scor...
[ { "body": "<p>Use LINQ expression compilation to generate mapping code at runtime. The concept is to generate a method that does <code>obj.Property1 = dataReader[\"Property1\"]; ...</code> dynamically.</p>\n\n<pre><code>public class Converter&lt;T&gt; where T : new()\n{\n private static ConcurrentDictionary&...
{ "AcceptedAnswerId": "33238", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T13:22:48.117", "Id": "33128", "Score": "3", "Tags": [ "c#", "performance", "sql", "sql-server", "asynchronous" ], "Title": "DAL mapping efficiency" }
33128
<p>This is my first attempt at JavaScript, so I am looking to learn. </p> <p>I have a website that has jQuery built in and I wanted to leverage that in the following way:</p> <ol> <li>I want to get a number variable that precedes a certain text string (<code>*n*/portal.css</code>)</li> <li>Get the name of the curren...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T02:30:18.823", "Id": "53110", "Score": "0", "body": "Can you give some sample inputs? It's hard to understand the code when you don't know the input." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T15...
[ { "body": "<p>Basically every duplicated object can be made one object. And maybe use a function so you can call it when required.</p>\n\n<p>If you use an <a href=\"http://en.wikipedia.org/wiki/Immediately-invoked_function_expression\" rel=\"nofollow\">IIFE</a> like below, you can put this code in an external *...
{ "AcceptedAnswerId": "33270", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T16:43:57.390", "Id": "33132", "Score": "3", "Tags": [ "javascript", "jquery", "css", "beginner" ], "Title": "JavaScript and jQuery check for image file and assign CSS" }
33132
<p>I am calling a JS file from a bundle directory like so:</p> <pre><code>&lt;script src="{{ asset('bundles/macppages/js/main.js') }}"&gt;&lt;/script&gt; </code></pre> <p>which loads the JS file into the base.index.twig</p> <p>In that JS file I want to add some custom css via jQuery like this:</p> <pre><code>functi...
[]
[ { "body": "<p>There might be a better way to retrieve the web directory, I would not know. However, there are other things to ponder upon.</p>\n\n<ul>\n<li>Naming : <code>loadBkrndImg</code> -> <code>loadBackgroundImage</code> looks so much better</li>\n<li>Naming : <code>currentBkrndImgNum</code>, enough said....
{ "AcceptedAnswerId": "39195", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T17:51:40.577", "Id": "33134", "Score": "3", "Tags": [ "javascript", "jquery", "image", "symfony2" ], "Title": "Linking to an image asset from a JavaScript file in Symfony 2...
33134
<p>I've just wrote a program in C# for counting sort.</p> <ul> <li>space complexity is O(N+K)</li> <li>time complexity is O(N+K)</li> </ul> <p>I want reviews on my code and any better ways to implement this.</p> <pre><code>namespace SortingSelfCoded { public static class CountingSorter { public stati...
[]
[ { "body": "<p>From a practical use point of view:</p>\n\n<ol>\n<li>I'd use <code>input.Max()</code> (LINQ) to obtain the maximum. Less code to write and does the same.</li>\n<li>While it is ok to use single letter variables for loop counter <code>j</code> is not really a loop counter. It's the index of the curr...
{ "AcceptedAnswerId": "33138", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T18:18:28.703", "Id": "33135", "Score": "3", "Tags": [ "c#", "algorithm", "sorting" ], "Title": "Counting sort review" }
33135
<p>A few things:</p> <ol> <li>I tried to do it with smart pointers because I wanted to learn about them. I'm not sure I made the right choice of type, however (and started to regret it half-way through).</li> <li>This is for school, so some operations were required. I can't change main.cpp or the general layout.</li>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T21:21:15.103", "Id": "53094", "Score": "0", "body": "Spotted 1 Bug and about 5 comments." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-10-17T18:19:40.463", "Id": "122202", "Score": "1", "body"...
[ { "body": "<p>Some comments to the things you have implemented so far:</p>\n\n<ol>\n<li><code>reverse_print</code>: Printing the list in reverse order recursively is an academically interesting solution but if your list is sufficiently long then your stack will explode. Use a <code>std::stack</code> to temporar...
{ "AcceptedAnswerId": "33162", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T19:43:00.767", "Id": "33136", "Score": "6", "Tags": [ "c++", "c++11", "homework", "linked-list", "smart-pointers" ], "Title": "Singly linked-list with smart pointers" }
33136
<p>Usually, <code>AsyncTask</code>s are meant to be one-shot, i.e. you start it, it fetches some data, displays the result and dies. However, I'm now using a long-running <code>AsyncTask</code> to load images as the need arises. So far it's working great, but I'd just like to know if this is good practice &amp; if ther...
[]
[ { "body": "<p>For starters, you should replace your Vector with an ArrayBlockingQueue . Then you can drop the wait and the null check. Can also then remove synchronization on the add method since its handled by the data structure.</p>\n\n<pre><code>private final BlockingQueue&lt;String&gt; pendingURLs = new A...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T22:15:24.780", "Id": "33141", "Score": "1", "Tags": [ "java", "multithreading", "android" ], "Title": "Background image loader AsyncTask" }
33141
<p>Is this code an adequate implementation of the producer/consumer pattern?</p> <p>In computer science, the producer/consumer pattern is a classic example of multithreaded synchronisation. The problem describes some threads called consumers and some threads called producers sharing a common fixed-size queue.</p> <p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T00:20:07.890", "Id": "53102", "Score": "4", "body": "Why would you write your own instead of using `BlockingCollection`? Also, does it seem to work for you?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-1...
[ { "body": "<p>Answering whether or not this implementation is correct would require to know what the specification of the problem is. Now assuming the spec is:</p>\n\n<blockquote>\n <p>Create a queue to which multiple threads can add items and multiple threads can remove item. The queue will hold no more than ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-23T23:01:46.520", "Id": "33142", "Score": "5", "Tags": [ "c#", "multithreading" ], "Title": "Producer/Consumer in C#" }
33142
<p>I have this Book program that contains 2 classes: <code>Book</code> and <code>Library</code>. I have the Book class done, but need some help on the Library class. Please help me check my code. I can provide the Book class if you need it.</p> <p>Instruction here:</p> <blockquote> <p>Fields: A single private Arra...
[]
[ { "body": "<p>Your default constructor Library() initializes the allBook member variable twice, with the same value in each case. Probably not what you had in mind. The immediate fix is to remove the (re) assignment in the default constructor.</p>\n\n<p>Now you have two different constructors that do the righ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T01:45:31.167", "Id": "33148", "Score": "5", "Tags": [ "java", "array", "homework" ], "Title": "Book program with arrayList" }
33148
<p>I've written a method in c# that allows me to do create a dictionary from a passed in object and N lambda expressions that reference that objects properties and methods. It's working the way I want it and seems to perform well, but I'm looking for criticism and seeking to improve the code.</p> <p>Here's an example ...
[]
[ { "body": "<p>Ronnie,</p>\n<p>You have a good starting point for the problem you are trying to solve.</p>\n<p>To answer your concerns:</p>\n<ol>\n<li><p>Is there a better way to work with the expressions that are passed in.</p>\n<p>I think what you have done is fine. You are using Expression to let user specify...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T03:30:06.517", "Id": "33152", "Score": "7", "Tags": [ "c#", "functional-programming", "reflection" ], "Title": "Function that builds dictionary based on lambda params" }
33152
<blockquote> <p><strong>Maze puzzle</strong></p> <p>A 1 in input matrix means "allowed"; 0 means "blocked". Given such a matrix, find the route from the 1st quadrant to the last (n-1, n-1).</p> </blockquote> <p>I would like to get some feedback to optimize and make this code cleaner. Also let me know if O(n!) i...
[]
[ { "body": "<p>First of all I don't think the time complexity is <code>O(n!)</code>. You are doing DFS(unknowingly). So the time complexity would be <a href=\"https://stackoverflow.com/questions/10118580/time-complexity\">O(n + m)</a> and AFAIK you can't solve maze problem less than that unless you are using BFS...
{ "AcceptedAnswerId": "33164", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T05:43:11.980", "Id": "33155", "Score": "2", "Tags": [ "java", "algorithm", "recursion", "matrix", "pathfinding" ], "Title": "Finding a route in maze matrix" }
33155
<pre><code>try { var isSupported = !! new Blob(); } catch (e) { document.body.innerHTML = "&lt;h1&gt;Sorry your browser isn\'t supported :(&lt;/h1&gt;"; } var textarea = document.getElementById("textarea"), inputFile = document.getElementById("input-file"), appname = "notepad", untitled = "untitled.txt", i...
[]
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li>You do not need the <code>\\</code> in <code>\"&lt;h1&gt;Sorry your browser isn\\'t supported :(&lt;/h1&gt;\"</code> because your string is surrounded with double quotes</li>\n<li>I would check immediately whether <code>textarea</code> and <code>inputFile</code> ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T06:50:51.910", "Id": "33157", "Score": "-1", "Tags": [ "javascript", "html5" ], "Title": "Text editing web app" }
33157
<p>I have created a program that allows the user to view/add/delete employees and also view employee payslip, either weekly employee or monthly employee, which is all done in the console.</p> <p>My programme runs fine and does as asked, but I feel it is not OOP. Can anyone suggest any changes to make it more OO?</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T10:57:07.543", "Id": "53136", "Score": "2", "body": "As a start: You have the hierarchy reversed. Normally the main application depends on the Objects...in your case the objects depend on the main application. Every Object *should* ...
[ { "body": "<p>Before we talk about making this program object-oriented, we have more basic issues to cover.</p>\n\n<h1>Basic (Java) Programming</h1>\n\n<h2>Scoping</h2>\n\n<p>Each variable has a <em>scope</em> where it is visible. In Java, variables have <em>block scope</em>, that is, their visibility begins wi...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T10:41:23.327", "Id": "33167", "Score": "4", "Tags": [ "java", "object-oriented" ], "Title": "Managing employee information" }
33167
<p>My function takes the values of the profit (function declared as <code>fieldProfit</code>) and the field score (function declared as <code>fieldScore</code>). If both are above 10, then you earn a badge, hence, <code>innerbadge = 1</code>.</p> <p>But, there's also another condition that must be met: the field or (x...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T12:12:30.593", "Id": "53141", "Score": "0", "body": "Needs documentation!" } ]
[ { "body": "<p>I think we can all agree that that code is hard to read. Rather than treating the dark shaded zone as the union of four rectangles, you would be better off treating it as a square with the centre excluded.</p>\n\n<p>I've used a macro to reduce the verbosity.</p>\n\n<p>In your code, when (<em>x</e...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T10:45:40.500", "Id": "33168", "Score": "0", "Tags": [ "c" ], "Title": "Calculating profit and score, if coordinates fall in a certain region of a field" }
33168
<p>For a Project Euler problem, I made a Ruby roman numeral converter:</p> <pre><code>def romanize(num) digits = { 1000 =&gt; "M", 900 =&gt; "CM", 500 =&gt; "D", 400 =&gt; "CD", 100 =&gt; "C", 90 =&gt; "XC", 50 =&gt; "L", 40 =&gt; "XL", 10 =&gt; "X", 9 =&gt; "IX", 5 =&gt;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T06:49:13.977", "Id": "53209", "Score": "1", "body": "In this case: `|(key, numeral)|` -> `|key, numeral|`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T10:25:47.773", "Id": "53216", "Score":...
[ { "body": "<p>Some notes:</p>\n\n<ul>\n<li>Use 2 spaces for indentation, not 4.</li>\n<li><code>key, numeral = digit</code>: You can unpack block arguments: <code>do |acc, (key, numeral)|</code>.</li>\n<li><code>Concat</code>ing strings is costly, better build an array and finally join it.</li>\n<li>You are usi...
{ "AcceptedAnswerId": "33172", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T12:25:35.430", "Id": "33170", "Score": "4", "Tags": [ "ruby", "project-euler", "converting", "roman-numerals" ], "Title": "Roman numeral converter in Ruby" }
33170
<p>This might be a loaded question, but here goes. I have some code that is very similar between all the methods. I am trying to find a way to accomplish all methods with a generic method/function. I'm not sure if I should be using delegates, and if so how to implement in this specific situation, or if there is a muc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T13:37:51.733", "Id": "53147", "Score": "4", "body": "Observation: you are sharing a lock between all objects in that operation. Frankly, you might as well do it in series rather than parallel. An `Interlocked.Increment` might be a v...
[ { "body": "<p>Here is an example of an update people function and a call to it.</p>\n\n<p>I make no claim to your code being correct, I'm just refactoring to the generic case given the code you posted.</p>\n\n<pre><code> private void UpdatePeople(ConcurrentQueue&lt;pPeople&gt; people, Action&lt;pPeople&gt; ac...
{ "AcceptedAnswerId": "33176", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T13:35:18.227", "Id": "33174", "Score": "2", "Tags": [ "c#", "delegates" ], "Title": "Refactoring Into Generic Methods" }
33174
<p>I have the following code and am wondering if this can be further optimized and also beautified (in order to be more readable) :</p> <pre><code>if( ( subType = entry.getSubType() ) ==null || !(subType.equals("typeA") || subType.equals("typeB")) || ( version&gt;=5 &amp;&amp; (subType.equals("typeA"...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-05-26T13:30:44.557", "Id": "242113", "Score": "0", "body": "@jamal please inform as to which of the criteria were used in order to decide that the question is off-topic? I'm quite eager and curious. That is the specific section of code I ...
[ { "body": "<p>I don't really do Java. But this looks like infrequently executed code that you should be optimizing for readability vs. trying to minimize the number of comparisons.</p>\n\n<p>Imagine being in the position of someone maintaining the code after a directive like <em>\"we've decided not to support ...
{ "AcceptedAnswerId": "33183", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T14:11:53.463", "Id": "33177", "Score": "-1", "Tags": [ "java" ], "Title": "Optimize/Beautify Boolean Statement in Specific Code" }
33177
<p>I'm using Munkres library from <a href="https://github.com/bmc/munkres/" rel="nofollow">https://github.com/bmc/munkres/</a> to calculate maximum profit (reversed problem).</p> <p>What do you think about this coding style?</p> <pre><code>def get_no_of_vowels(str): return sum(str.lower().count(c) for c in "aeiuo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T16:22:48.877", "Id": "53160", "Score": "0", "body": "It seems to be missing the necessary `import` statements." } ]
[ { "body": "<p>I just want to point out two sources of inefficiency:</p>\n\n<p>1) The counting functions, e.g.:</p>\n\n<pre><code>def get_no_of_vowels(str):\n return sum(str.lower().count(c) for c in \"aeiuoy\")\n</code></pre>\n\n<p>This will loop over <code>str</code> 6 times, which is 5 more times than is n...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T15:33:07.267", "Id": "33180", "Score": "1", "Tags": [ "python" ], "Title": "Munkres algorithm in Python: calculating maximum profit" }
33180
<p>I have been looking for an algorithm for splitting a file into smaller pieces, which satisfy the following requirements:</p> <ul> <li>The first line in the original file is a header, this header must be carried over to the resulting files</li> <li>The ability to specify the approximate size to split off, for exampl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T19:44:44.570", "Id": "53185", "Score": "0", "body": "But » it takes about 1 second to finish« I wouldn't call it that slow." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T19:54:20.030", "Id": "53...
[ { "body": "<h3>1. Comments on your code</h3>\n\n<ol>\n<li><p>There's no documentation. What does your program do and how should it be used?</p></li>\n<li><p>Your program is not split up into functions. This makes it hard to test it from the interactive interpreter.</p></li>\n<li><p>The name <code>data.csv</code...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T19:03:05.127", "Id": "33193", "Score": "7", "Tags": [ "python", "performance", "file", "csv", "utf-8" ], "Title": "Splitting a CSV file with headers" }
33193
<p><strong>Problem</strong>: Make a slider, located at the bottom of the page. The slider should be dynamically loaded only when a div (<code>#slider</code>) becomes visible on the screen. Images do not have to load all at once. Load the first two images, then load the third when we switched to the second, and so on.</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T23:26:55.737", "Id": "53195", "Score": "0", "body": "(quote)The slider should be dynamically loaded only when an `unicorn` becomes visible on the screen.(/quote)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2...
[ { "body": "<p>Few things:</p>\n\n<ol>\n<li>You can create a plugin out of it (create divs <code>#slider</code> and <code>#slides</code> - don't use id, but just reference - and add class slider_wrap in code)</li>\n<li>You don't put var before <code>nextImg = new Image();</code></li>\n<li><p>Instead of new Image...
{ "AcceptedAnswerId": "33196", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T19:37:18.550", "Id": "33194", "Score": "1", "Tags": [ "javascript", "beginner", "jquery" ], "Title": "Dynamically loaded slider" }
33194
<p>This is a working stack implementation using a linked list. I'm just curious to know if this is a good way of doing it. Any suggestions are welcome. Can we keep track of the number of elements in the stack using a <code>count</code> variable as used in the code?</p> <pre><code>#include &lt;cstdlib&gt; #include&lt...
[]
[ { "body": "<ul>\n<li><p>At some point, I'd recommend using <code>template</code> here. This will allow you to store any date type, not just <code>int</code>s, in your structure.</p></li>\n<li><p>It'd be better to define <code>node</code> as a <code>struct</code> inside <code>StackusingList</code> as <code>priva...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T19:59:24.810", "Id": "33195", "Score": "14", "Tags": [ "c++", "linked-list", "stack" ], "Title": "Stack implementation using linked list" }
33195
<p>I've written some XSLT where I want to assign values to some variables.</p> <p>Depending on whether or not a condition is met, I want the variable to be populated with a computed value and I want it to have a default value otherwise.</p> <p>I've written the following code that appears to work, but I think that the...
[]
[ { "body": "<p>IMHO your code is fine. The \"problem\" with XSLT variables is that they are NOT variables but more resemble constants: once set they cannot be changed anymore. Also, their scope is restricted to anything that follows their definition until the closing tag. In particular they are NOT visible in an...
{ "AcceptedAnswerId": "33631", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-24T22:39:49.590", "Id": "33200", "Score": "3", "Tags": [ "xml", "xslt" ], "Title": "Conditional assignment in XSLT?" }
33200
<p>I have created a Job Scheduler, and i want some review, new ideas for it.</p> <p><strong>Scheduler.cs</strong></p> <pre><code>public abstract class Scheduler { #region Fields &amp;&amp; Properties private readonly List&lt;Job&gt; _jobs = new List&lt;Job&gt;(); private readonly Random _rand = new Rando...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T11:47:56.813", "Id": "53217", "Score": "0", "body": "“I want to know how could i use Async/Await to wait for a job to finish executing?” This is not the right place to ask that, this site is for reviews of your code only." } ]
[ { "body": "<ol>\n<li>Using <code>Equals(object, null)</code> to test whether an object is null is rather unusual. I can't see any reason in your case why it would be preferred over <code>object == null</code>.</li>\n<li>Why is <code>Parallel</code> a nullable bool? I can't see any code which relies of the tri-s...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T01:06:12.167", "Id": "33207", "Score": "1", "Tags": [ "c#" ], "Title": "Job Scheduler Implementation" }
33207
<p>This is a program that I wrote to add two numbers together that are too large for the C language to store. It stores the numbers as strings instead and processes one digit at a time. But I suspect that the program could be done in fewer steps. In what ways can I reduce the size of my program? Where am I taking mo...
[]
[ { "body": "<p>1) It seems that you assumed length of <code>a</code> and <code>b</code> are the same. But if <code>a</code> has a bigger length than <code>b</code> you don't process all digits! Your loop should go over maximum of lengths of <code>a</code> and <code>b</code> and whenever one operand has no digit ...
{ "AcceptedAnswerId": "35819", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-25T01:36:56.497", "Id": "33208", "Score": "1", "Tags": [ "c", "mathematics" ], "Title": "Reducing steps for long addition program" }
33208