body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I am doubtful about the security of my PHP code. I am new to programming, but want to learn how to secure things, protect my databases from SQL injection, and other best practices. I'd like to know if my databases are safe from attacks with this code.</p> <pre><code>public function __construct( $data = array() ) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-10T20:32:48.840", "Id": "100941", "Score": "0", "body": "Read: http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-10T20:34:59.360...
[ { "body": "<p>Let us review!</p>\n\n<ul>\n<li>Why are you strip_slashing and strip_tagging the username and passwords before they enter the database? Why do you care? (You don't, I'll get to that in the end).</li>\n<li>Calling <code>__construct()</code> inside of another method of the same object is not recomme...
{ "AcceptedAnswerId": "56696", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-10T20:31:37.833", "Id": "56690", "Score": "7", "Tags": [ "php", "object-oriented", "mysql", "security", "sql-injection" ], "Title": "User registration and login" }
56690
<p>I'm looking for a code correctness and best practices review on the following. I created the following in order to prevent using the same code to convert serialized JSON to something more accessible in my <code>HttpHandler</code>s without incorporating this directly into my base handler. I don't always need to post ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-18T17:22:47.060", "Id": "102605", "Score": "0", "body": "What does this mean: \"I don't always need to post over full entities when only a few values are needed.\"? Why wouldn't this go in your base handler?" }, { "ContentLice...
[ { "body": "<p>I'll leave the meat for others, but here are some quick improvements on your indexing methods.<br>\nTry-catch is slow and to be avoided if possible. Here is how I would do it.</p>\n\n<pre><code>/// &lt;summary&gt;\n/// Get Element by index\n/// &lt;/summary&gt;\n/// &lt;param name=\"request\"&gt;H...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-10T21:08:56.467", "Id": "56693", "Score": "4", "Tags": [ "c#", ".net", "json", "http" ], "Title": "HttpRequest.Json collection - like HttpRequest.Form" }
56693
<p>I am new to programming in Python and wrote a simple Blackjack project. I am looking for experienced peers to provide a high level code review about the overall design patterns and proper usages. The code performs as expected and passes all my unit tests so I am mainly looking for feedback on how to make the code mo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-10T21:56:30.343", "Id": "100957", "Score": "1", "body": "Couple minor points on blackjack rules - Dealer usually offers insurance for a visible ace, and I don't see a method for hitting a \"soft\" 17 (17 with an ace involved) for the d...
[ { "body": "<p>Alright, I myself am a Python beginner too. So I'll see what I can review and leave the rest to someone with more experience!</p>\n\n<p>First thing I notice, is how much easier reading your code would be if the classes were in separate files. It'd be much more modular, and in fact it would help se...
{ "AcceptedAnswerId": "56735", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-10T21:45:12.470", "Id": "56695", "Score": "9", "Tags": [ "python", "beginner", "design-patterns", "game", "playing-cards" ], "Title": "Text-based Blackjack game in Python"...
56695
<blockquote> <p>Given <em>n</em> sorted lists, merge them.</p> </blockquote> <p>This is a fairly common question, attributed to plenty of interview question websites.</p> <p>I'm looking for code-review, optimizations and best practices. I'm also verifying complexity to be \$O(n*m*log(n))\$, where <em>n</em> is the...
[]
[ { "body": "<p>Your code deliberately fails on an empty input array. This is an artificial constraint. The code would actually work (or should actually work) except you have the condition that throws an exception:</p>\n\n<blockquote>\n<pre><code> if (a.length == 0) { throw new IllegalArgumentException(\"Array s...
{ "AcceptedAnswerId": "56702", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-10T22:25:34.190", "Id": "56699", "Score": "2", "Tags": [ "java", "algorithm", "heap" ], "Title": "Merge N sorted list" }
56699
<p>I am pretty new to JavaScript, and put together a weather application. I'd like to get some feedback on improvements I could make to the code itself and also possible ways to speed up weather data display.</p> <p>This is a screenshot of the working site:</p> <p><img src="https://raw.githubusercontent.com/meskarune...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T00:47:15.183", "Id": "100984", "Score": "2", "body": "A minor suggestion on the overall design: before trying to access geolocation info, I'd give the user a choice to type in a location or \"discover my location.\" This way they do...
[ { "body": "<ul>\n<li>Some parts of your code are extremely repetitive.</li>\n<li>I also wonder about reloading the page upon switching units, since you could surely just convert them in-place.</li>\n<li>In your first block, what if (somehow) the value in your <code>localStorage</code> is set, but not to <code>\...
{ "AcceptedAnswerId": "56713", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-10T23:51:54.577", "Id": "56705", "Score": "6", "Tags": [ "javascript", "beginner", "json", "api" ], "Title": "JavaScript Weather App" }
56705
<p>This is my first time writing JAVA, and I'm trying to start off on the right track.</p> <p>Using my C++ knowledge, I was able to understand the syntax for the ternary operator, but I'm not sure how it should be approached properly in JAVA. I have used <a href="http://ideone.com/jTItdZ">Ideone</a> to test this, whi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T00:38:45.183", "Id": "100982", "Score": "2", "body": "While this is certainly valid code, this many nested ternaries generally make code harder to read and debug. Generally, I stick with 1 and sometimes if the expression is short, I...
[ { "body": "<p>At first I wasn't sure whether this code would compile correctly (but obviously it does). The reason it does is due to two independent features of Java.</p>\n\n<p>The <code>System.out.println()</code> method has an overload that takes an <code>Object</code> parameter (and then calls <code>String.v...
{ "AcceptedAnswerId": "56732", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T00:18:21.290", "Id": "56708", "Score": "31", "Tags": [ "java", "beginner", "fizzbuzz" ], "Title": "FizzBuzz implementation using the ternary operator" }
56708
<p>I have a method in a class, and its sole purpose is to prepare another class for use:</p> <pre><code>private function createHttpPost($endPoint) { $httpPost = new HttpPost($this-&gt;baseUri . '/' . $endPoint); $httpPost-&gt;setContentType('application/json'); $httpPost-&gt;setAccept('application/json'); ...
[]
[ { "body": "<p>In itself, there's nothing wrong with this code. There really isn't. But there are some things you need to consider:</p>\n\n<ul>\n<li>The method is <code>private</code>, so it's an internal kind of factory, why not use a lazy-loading getter?</li>\n<li>The method is <code>private</code>, that makes...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T01:01:44.167", "Id": "56710", "Score": "2", "Tags": [ "php", "design-patterns" ], "Title": "Factory style pattern in method" }
56710
<p>I'm learning CUDA and wrote a little program which generates prime numbers using the Sieve of Eratosthenes. (I know the limitations of CUDA, specially with memory sizes and limits, but this program is for educational purposes).</p> <p>Questions:</p> <ol> <li>Did I set up the configuration correctly? (did I set <co...
[]
[ { "body": "<p>you shouldn't use the same incrementation variable twice in the same scope, it can get messy and cause weird bugs and you do it with two different incrementing variables, <code>i</code> and <code>j</code>.</p>\n\n<pre><code> uint64_t maxRoot = sqrt(max); // optimization #1 ...
{ "AcceptedAnswerId": "60742", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T01:02:43.777", "Id": "56711", "Score": "16", "Tags": [ "beginner", "c", "primes", "sieve-of-eratosthenes", "cuda" ], "Title": "Generating prime numbers using Sieve of E...
56711
<p>I'm trying to clean up redundant old code, so I'm asking this general question. Since all iOS 7 devices have a front camera, would it be safe to remove the code to check if the device has a front camera? In the past this was necessary as not all devices with iOS 6 had a front camera.</p> <p>It is true that Apple co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T02:46:09.233", "Id": "100996", "Score": "0", "body": "So, what you are asking, really, is whether your app needs to support ios6 ... right?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T03:01:32.553...
[ { "body": "<p>According to the <a href=\"https://developer.apple.com/library/ios/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/DeviceCompatibilityMatrix/DeviceCompatibilityMatrix.html\">iOS Device Compatibility Reference</a>, the iPhone 3GS was the only iOS 6-capable device to lack a front ca...
{ "AcceptedAnswerId": "56715", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T02:14:51.877", "Id": "56712", "Score": "13", "Tags": [ "objective-c", "ios" ], "Title": "Is it still necessary to check for a front camera?" }
56712
<p>Example cases:</p> <p>Need to add <code>x=1</code>, <code>y=2</code> and <code>querystring</code> variables to the following URLs:</p> <ul> <li><a href="http://www.foo.com/blah/blah?test=1&amp;abc=2" rel="nofollow">http://www.foo.com/blah/blah?test=1&amp;abc=2</a></li> <li><a href="http://www.foo.com/blah" rel="no...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T04:46:30.220", "Id": "101005", "Score": "1", "body": "You never use `$http_host`. Besides, [your code is broken](http://ideone.com/XmQmad). Please fix it so we can reopen it (and I can post my answer)!" }, { "ContentLicense"...
[ { "body": "<ul>\n<li>Your code is very spaced out. It doesn't need to be.</li>\n<li>Consider using industry-standard style by using Egyptian braces for control structures like <code>if</code> and <code>foreach</code>.</li>\n<li>Get rid of the <code>$http_host</code> variable; you never use it.</li>\n<li>Conside...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T02:46:58.180", "Id": "56714", "Score": "0", "Tags": [ "php", "url" ], "Title": "Add a set of querystring params to a URL" }
56714
<p>I created a basic desktop calculator using Java. Does anyone have any suggestions as far as coding best practices, readability issues, or just generic coding mistakes I might have missed? Any professional input you could provide would be greatly appreciated.</p> <p>Calculator.java</p> <pre><code>package calc; impo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-08-01T13:00:50.950", "Id": "105587", "Score": "0", "body": "idea is good, code and answers are wrong (excluding invokeLater), use JFormattedTextField (every problems), actioncommand can be used for KeyBindings instead of KeyListener (labe...
[ { "body": "<p>This isn't a full review (yet), but some hopefully helpful comments.</p>\n\n<ul>\n<li><p>You should always start your Swing application by calling <code>SwingUtilities.invokeLater</code>. <a href=\"http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html\">This Oracle/Sun tutorial</...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T04:31:22.977", "Id": "56718", "Score": "8", "Tags": [ "java", "swing", "awt" ], "Title": "Basic Calculator using Java Swing and AWT" }
56718
<h2>Followup to <a href="https://codereview.stackexchange.com/questions/55652">How do I optimize this Java cube root function for BigInteger?</a></h2> <p>So I've tried several implementations of this algorithm. The version using only BigInteger sometimes results in a never-ending cycle of candidates:</p> <pre><code>pub...
[]
[ { "body": "<p>I think your final solution is on the right path.</p>\n\n<p>Just to be clear, I'm assuming you want the integral part of the cube root, i.e. for a given \\$n\\$, <code>cbrt(n)</code> will return the integer \\$m\\$ such that \\$m^3 \\leq n &lt; (m + 1)^3\\$. I'm also assuming you only care about p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T04:41:29.083", "Id": "56719", "Score": "4", "Tags": [ "java", "performance", "algorithm", "mathematics", "fixed-point" ], "Title": "Followup: How do I optimize this Java c...
56719
<p>I am developing a custom grid view with different columns.</p> <p><strong>ViewPossibilities Mockup</strong></p> <p><img src="https://i.stack.imgur.com/tu6LS.jpg" alt="View Possibilities Mockup"></p> <p>Here is the full demo. You can directly use it, with Internet uses permission.</p> <p>This works perfectly but...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T11:10:50.693", "Id": "101048", "Score": "0", "body": "While it is nice to see you incorporating my review in your code, I would like you to refrain from editing parts of the code, that I talked about. We call this answer invalidatio...
[ { "body": "<blockquote>\n<pre><code> arr_string\n .add(\"http://www.bluesodapromo.com/static/DesignCenter/Image/dc_images/clipart/nature/nature_1.png\");\n arr_string\n .add(\"http://www.bluesodapromo.com/static/DesignCenter/Image/dc_images/clipart/nature/nature_1.png\");\n arr_st...
{ "AcceptedAnswerId": "56751", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T05:01:48.943", "Id": "56720", "Score": "10", "Tags": [ "java", "android" ], "Title": "Custom grid view with different columns" }
56720
<p>I have a ZK project in Java 6 (ZK is like ASP.NET but with <code>zul</code> files in stead of <code>aspx</code>). For showing and creating/updating the catalogs I created an abstracted view. This all works with 1 viewmodel at the back. To go to the right catalog I provide a <code>String</code> what is the catalog...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T12:07:58.653", "Id": "101063", "Score": "0", "body": "Are you hand-rolling this code or are you writing a generator?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T13:47:16.550", "Id": "101103", ...
[ { "body": "<p>I have a strong feeling that you are somewhat off track. I had not heard of the ZK framework until I read your post, but a visit to their website confirms that it should be a better way to do a Java website, albeit at a licencing cost. (I am very familiar with Spring MVC and Struts, know a little ...
{ "AcceptedAnswerId": "56736", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T05:17:55.580", "Id": "56722", "Score": "8", "Tags": [ "java", "enum" ], "Title": "Java enum for mapping classes and specific URL" }
56722
<p>I created my first plugin in jQuery and just want some inputs on how I can improve the code and features.</p> <p><a href="http://jsfiddle.net/fruitjs/zpYb4/" rel="nofollow">Here is the fiddle</a></p> <pre><code> $.fn.fruitZoom = function (options) { var defaults = { ele: "p,span", }; var settings = $.exte...
[]
[ { "body": "<h1>Flexibility</h1>\n\n<p>Your plugin relies on very specific markup; an element with an ID of <code>fruitZoom</code> having a first and last child element meant to be used as zoom in and zoom out buttons, respectively.</p>\n\n<p>This is not flexible enough to be generally useful. What if you want m...
{ "AcceptedAnswerId": "56730", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T07:09:22.117", "Id": "56726", "Score": "2", "Tags": [ "javascript", "jquery", "plugin" ], "Title": "Zoom in/zoom out jQuery plugin" }
56726
<p>I tried to implement as many changes suggested as possible as well as expanding the code base according to the suggested link. The original question can be found <a href="https://codereview.stackexchange.com/questions/56558/hints-to-make-sudoku-solver-more-pythonic">here</a>. It does solve 4x4 and 9x9 Sodukus.</p> ...
[]
[ { "body": "<p>Correct idiom for <code>if not cond: raise Exception(message)</code> is <code>assert cond, message</code>.</p>\n\n<p>Also, don't use builtin names for something else. When I look at str.strip, I see unbound method. :-(</p>\n\n<p><code>str[ind] is not '0' and str[ind] is not '.'</code> is <code>str...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T09:42:22.020", "Id": "56734", "Score": "1", "Tags": [ "python", "python-3.x", "numpy", "sudoku" ], "Title": "Hints to make Sudoku solver more Pythonic (II)" }
56734
<p>I have a question regarding whether it is viable or deemed correct if a validation object invoked a query. Essentially, I have some code that looks like this:</p> <pre><code>public interface ICountryCodeValidator { IEnumberable&lt;ValidationError&gt; Validate(string countryCode); } public class CountryCodeVal...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T11:11:29.487", "Id": "101049", "Score": "0", "body": "You could simply set properties in your validator but I must say I question the use; why not just have those validations inside your methods? It's not like you're saving out on c...
[ { "body": "<p>I believe it's ok to use db data inside a validator's body. As long as all you do with database is reading data, and this data is neccesary for validation. But if you're about to change something in database - that's pretty considerable.</p>\n\n<p>Then, if you can do something with this data, like...
{ "AcceptedAnswerId": "56765", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T10:28:36.480", "Id": "56739", "Score": "2", "Tags": [ "c#", ".net", "validation" ], "Title": "Validation invoking queries?" }
56739
<p>I think I can refactor this:</p> <pre><code>if (clicked_id == "contain-word") { $("#specie_filter li.checked").removeClass("checked"); $("#specie_filter li:first").addClass("checked") $("#specie_filter ul").scrollTop(0) $("#cell_filter li.checked").removeClass("checked") $("#cell_filter li...
[]
[ { "body": "<p>This variant came to my mind:</p>\n\n<pre><code>function processFactorFilter() {\n var $factor_filter = $(\"#factor_filter\");\n $(\"li.checked\", $factor_filter).removeClass(\"checked\");\n $(\"li:first\", $factor_filter).addClass (\"checked\");\n $(\"ul\", $factor_filter)...
{ "AcceptedAnswerId": "56752", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T10:43:49.010", "Id": "56741", "Score": "5", "Tags": [ "javascript", "jquery" ], "Title": "Refactoring multiple `else if` code" }
56741
<p>One of the things that has occurred to me more recently is that if you add up all of the bandwidth that is taken up by thousands of users downloading the newlines and tabs used to make HTML source code readable... that's a LOT of wasted bandwidth.</p> <p>So I wanted to add some code that would condense whitespace o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T13:42:12.977", "Id": "101101", "Score": "0", "body": "How about <blockquote> tag?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T13:44:15.790", "Id": "101102", "Score": "0", "body": "@and...
[ { "body": "<ul>\n<li>I don't see much reason to use <code>(*F)</code> instead of the somewhat more understandable <code>(*FAIL)</code>.</li>\n<li>Consider using single-quoted (<code>'</code>) strings for regular expressions to avoid <code>\\\\1</code>.</li>\n<li>There's a big assumption here that the HTML will ...
{ "AcceptedAnswerId": null, "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T10:44:19.990", "Id": "56742", "Score": "3", "Tags": [ "php", "regex" ], "Title": "Automatic condensing of whitespace in HTML" }
56742
<blockquote> <p>For the below query, show that both summation and product are instances of a more general function, called accumulate, with the following signature:</p> <pre><code>def accumulate(combiner, start, n, term): """Return the result of combining the first n terms in a sequence.""" "*** YOUR COD...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T11:26:46.757", "Id": "101053", "Score": "2", "body": "Well for one thing, neither of your `..._using_accumulate` functions *actually use `accumulate`*! Your calls at the end should be inside those functions." }, { "ContentLi...
[ { "body": "<ol>\n<li><p>If a homework problem starts with the words \"Show that\", I would expect the answer to contain a <em>proof</em> (or at least an <em>argument</em>), not just an implementation.</p></li>\n<li><p>You've misunderstood the problem statement. It says that <code>start</code> \"specifies what <...
{ "AcceptedAnswerId": "56755", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T11:12:12.320", "Id": "56744", "Score": "1", "Tags": [ "python" ], "Title": "Higher order functions in Python using reduce technique" }
56744
<p>I'm working on a little project where I have to create sort of an image mask. Overall my code works quite good in all browsers but sporadically the animations "flickr" on Chrome (Windows). So I was wondering if I could increase to performance when repainting my canvas (on mouseover/out).</p> <p><a href="http://jsfi...
[]
[ { "body": "<p>From what I understand, you don't need to draw the image every time the event mouseover/mouseout is triggered. The only thing that changes when the mouse moves is the radius of the colored circle. I mean the following code could be done only once on the initialization process:</p>\n\n<pre><code>_s...
{ "AcceptedAnswerId": "57186", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T11:18:03.887", "Id": "56745", "Score": "4", "Tags": [ "javascript", "performance", "jquery", "canvas" ], "Title": "Increase performance on canvas repainting" }
56745
<p>I have an object, <code>KbArticle</code>, that originally in it's constructor, would try to return null if the SQL query that retrieves the data for its required properties came up with 0 rows. A friend told me that constructors shouldn't return <code>null</code>, and that I should look into the Factory Pattern. I d...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-17T08:09:45.023", "Id": "102312", "Score": "0", "body": "Have you not already caught the exception in `$e`?" } ]
[ { "body": "<h1>My eyes hurt :(</h1>\n<p>I don't think you fully understand OO. Let alone the factory pattern.</p>\n<p>The factory pattern is a pattern that helps us with creating objects. It is best used when creating an object takes a couple of steps or is very hard, for instance a constructors with many vars....
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-09T16:34:18.260", "Id": "56759", "Score": "3", "Tags": [ "design-patterns", "php" ], "Title": "Basic PHP Factory Pattern" }
56759
<p>I'd like to know if I can make this code more efficient in terms of line saving, or any other way:</p> <pre><code>def missingDoor(trapdoor,roomwidth,roomheight,step): safezone = [] hazardflr = givenSteps(roomwidth,step,True) safetiles = [] for i,m in enumerate(hazardflr): safetiles....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T15:09:21.420", "Id": "101124", "Score": "0", "body": "Welcome to CodeReview.SE! It's a bit hard to tell whether things can be done in a more efficient way without telling us what you are trying to achieve. Also, if I were you I'd ke...
[ { "body": "<p>First things first, stop caring about the number of lines. Unless you are trying to make a code golf competition entry, minimizing the number of lines is the last thing you want to optimize for. This code is hard to read and follow because it is deeply nested and there is very little context to de...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T14:53:54.490", "Id": "56762", "Score": "1", "Tags": [ "python", "optimization", "beginner" ], "Title": "Rooms and trapdoors - for-loop and while-loop efficiency" }
56762
<p>I recently created one of my first hover effects using HTML and SASS. Since it is my first hover effect, I'm almost positive that is it horribly inefficient. I'm sure there's a way to do this effect using half the number of lines of code, but I can't figure out any ways to do it. The hover effect in question is f...
[]
[ { "body": "<h1>HTML</h1>\n\n<p>The headline elements (h1-h6) are meant to be used <em>only for headlines</em>. You have 3 of them, 2 of which only contain punctuation. That's a misuse of the element. If you need markup that's purely for styling purposes, use a span.</p>\n\n<pre><code>&lt;h1&gt;&lt;span class...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T14:56:55.737", "Id": "56763", "Score": "1", "Tags": [ "optimization", "html", "css", "sass" ], "Title": "Hover effects using HTML and SASS" }
56763
<p>I'm writing an application for work that requires me to process a list of transactions. The list is small (5 records at the most) and I'm required to display that data in an android <code>ListView</code>. My client has asked that I include the ability to order the list based on the date (I have added ordering it by...
[]
[ { "body": "<h1>Enum</h1>\n<p>First of all, instead of an <code>int orderByType</code>, I would use an <em>enum</em>.</p>\n<pre><code>enum SortOrder {\n NEWER(&quot;date(&quot; + SomeConstant.KEY_DATE + &quot;) desc&quot;),\n OLDER(&quot;date(&quot; + SomeConstant.KEY_DATE + &quot;) asc&quot;),\n ...;\n...
{ "AcceptedAnswerId": "56768", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T14:57:39.567", "Id": "56764", "Score": "6", "Tags": [ "java", "sql", "android", "sqlite" ], "Title": "Using SQL to reorder items in a list view - is this efficient?" }
56764
<p>I'm new to Laravel and trying to figure out how I can reduce/refactor this <code>store()</code> call in my <code>SessionController</code>.</p> <p>Basically, the <code>SessionController</code> is used to authenticate a user against an LDAP server (using <a href="https://github.com/wells/l4-ldap-ntlm" rel="nofollow">...
[]
[ { "body": "<p>Okay, let me get this right (I have no experience working with an LDAP): The <code>Auth</code> class you're first using for <code>$attempt</code> is actually the LDAP library you're implementing?</p>\n\n<p>I don't think I understand the logic in your code. You attempt to log in to the user, and if...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T15:03:08.077", "Id": "56766", "Score": "3", "Tags": [ "php", "authentication", "laravel" ], "Title": "Clean up / refactor this store() method" }
56766
<p>I am constructing a form builder in ASP.NET and I am wanting help with the structure of my POCO classes I have the following so far. I just don't see why I need to add to a list and then process it further again would their be a neater way to return a list of .net controls just to add to <code>Panel</code> using <co...
[]
[ { "body": "<ol>\n<li><p>Your naming conventions are a bit off. Property names (i.e. in <code>FormClass</code>) are commonly <code>PascalCase</code>.</p></li>\n<li><p>If you are not married to the XML file structure (i.e. it's under your control) then you can simplify the de/serialization quite a lot by using th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T15:06:57.843", "Id": "56767", "Score": "2", "Tags": [ "c#", "xml" ], "Title": "FormBuilder code suggestions for POCO" }
56767
<p>I have a piece of code that is used to calculate the cell centers in a rectangular mesh. The mesh size is pretty large (650 columns by 1150 rows). The code runs very slowly. I was wondering if I could employ any tricks to reduce the runtime.</p> <p>In the example below, <code>deltax</code> is a 1D array of column s...
[]
[ { "body": "<p>There are two things I would try to change:</p>\n\n<ul>\n<li><p>Is it necessary, that <code>center_x</code> and <code>center_y</code> are 2-dimensional arrays? In your code, the 2nd dimension holds redundant information and should be avoided.</p></li>\n<li><p>The biggest problem with pure Python (...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T16:06:29.910", "Id": "56772", "Score": "3", "Tags": [ "python", "numpy", "vectorization" ], "Title": "Calculating mesh centers runs very slowly" }
56772
<p>Could you provide feedback for this code? For arrays of length 2, is it more efficient not to use a sorting algorithm? </p> <pre><code>package insertion.sort; import java.util.Arrays; public class InsertionSort { /** * @param args the command line arguments */ public static void main(String[] a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T17:34:02.567", "Id": "101149", "Score": "1", "body": "You could consider finding out about the grammar question on [English Language & Usage](http://english.stackexchange.com/). It doesn't really relate to the code in any way." }...
[ { "body": "<p>As insertion sort is an O(<em>n</em><sup>2</sup>) algorithm, there's not much point to optimizing it. For any input that is large enough for you to care about the performance, you would want to pick a sorting algorithm with better bounds. Quicksort, for example, is usually closer to O(<em>n</em>...
{ "AcceptedAnswerId": "56787", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T17:25:59.567", "Id": "56776", "Score": "4", "Tags": [ "java", "sorting", "insertion-sort" ], "Title": "Can this insertion sort be optimized?" }
56776
<p>I'm writing a small application to score matches of <a href="http://en.wikipedia.org/wiki/First_Tech_Challenge">a game</a>. (There are two "teams" on each "alliance", and two alliances play each other in a match.) I have a "logic" class that handles the values of different scoring elements for each team, and calcul...
[]
[ { "body": "<p>You could put the statuses into a constant array and use the index variable to fetch them out: </p>\n\n<pre><code>void BlockParty::on_comboBox_currentIndexChanged(int index, Score* score)\n{\n static const BlockPartyLogic value_table[] =\n {\n BlockPartyLogic::RAMP_OFF, // Index 0\n ...
{ "AcceptedAnswerId": "56781", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T18:16:34.560", "Id": "56779", "Score": "5", "Tags": [ "c++", "gui", "qt" ], "Title": "Scoring matches of a game - reducing duplicated code" }
56779
<p>This is my simple Perl script implement password dictionary attacking, encryption algorithm SHA1 with different length.</p> <p>It takes 2 arguments as input: first argument is password dictionary file path, the second one is a text file contains line-by-line encrypted text. I used 2 common dictionaries for testing:...
[]
[ { "body": "<h3>Performance</h3>\n\n<p>For each cipher, you re-read and re-encrypt the dictionary again and again. If some of your ciphers have the same length, then this is wasteful. At the minimum, you should load the dictionary only once. If you have a lot of passwords, then you could pre-encrypt all words in...
{ "AcceptedAnswerId": "56790", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T19:50:47.627", "Id": "56786", "Score": "4", "Tags": [ "perl", "cryptography" ], "Title": "Simple password dictionary attack script" }
56786
<p>Simple task, I am just trying to have the data that correlates to a menu item hidden until it is clicked. However, I feel like this can be optimized. There are 2 <code>ng-repeat</code>s, which is a little redundant but I can't think of another way to do it. What do you think?</p> <p>See <a href="http://jsfiddle.net...
[]
[ { "body": "<p>I have made an alternate with only one repeat, though I don't know if it's any better. I'll leave that to you to decide. <a href=\"http://jsfiddle.net/qAFRA/2/\" rel=\"nofollow\">http://jsfiddle.net/qAFRA/2/</a></p>\n\n<pre><code>&lt;script&gt;\n var app = angular.module('app', []);\n app.co...
{ "AcceptedAnswerId": "56793", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T21:55:00.623", "Id": "56792", "Score": "1", "Tags": [ "javascript", "html", "angular.js" ], "Title": "Show <div> on <li> click" }
56792
<p>The following code makes a div tag editable and handles the <kbd>save</kbd> and <kbd>cancel</kbd> buttons. But there is a lot of duplication. How could I remove the duplication on this?</p> <pre><code>var originalTexts = {}; $("div.edit-panel").find("span").click(function() { var panel = $(this).closest('div.si...
[]
[ { "body": "<p>How about using just one declaration and an if block? You remove the top three lines by this for each function - </p>\n\n<p>assuming buttons are <code>&lt;button&gt;</code></p>\n\n<pre><code>var originalTexts = {};\n$(\"div.edit-panel\").find(\"button,span\").click(function(){\n var panel = $(t...
{ "AcceptedAnswerId": "56796", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T22:34:11.327", "Id": "56794", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Making the save and cancel buttons editable" }
56794
<p>An Objective-C category allows extension of an existing class by adding methods to the class. The difference between a category and a sub-class is that with a category, the code that is using the class to which the category is added can use the methods added from the category without changing the variable's class.</...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T23:56:29.273", "Id": "56801", "Score": "0", "Tags": null, "Title": null }
56801
Category is an Objective-C language feature that allows adding methods to an existing class in a different implementation unit without subclassing. They should not be confused with class extensions.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-11T23:56:29.273", "Id": "56802", "Score": "0", "Tags": null, "Title": null }
56802
<pre><code>for (var i = 1; i &lt;= 100; ++i) { var fizzBuzz = "" if i % 3 == 0 { fizzBuzz += "Fizz" } if i % 5 == 0 { fizzBuzz += "Buzz" } if fizzBuzz == "" { fizzBuzz += "\(i)" } println(fizzBuzz) } </code></pre> <p>I don't really like comparing strings with...
[]
[ { "body": "<p>In a <code>for</code> loop in Swift, the parentheses are optional, and from all of Apple's book and sample code, they are usually omitted--you did so yourself on the <code>if</code> statements. Furthermore, Swift has a range operator (two, in fact), so you should use that instead of the manual inc...
{ "AcceptedAnswerId": "56807", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T01:08:59.660", "Id": "56805", "Score": "24", "Tags": [ "beginner", "swift", "fizzbuzz" ], "Title": "Is this FizzBuzz Swift-y?" }
56805
<p>I'd appreciate any help just refining this working code. It has a bit of a weird context, but basically it's for a gallery style site that has hundreds of pages, but needs new navigation buttons. Unfortunately there's no way to add these buttons without adding them for over 300+ pages manually, or using a javascript...
[]
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li><code>oneRoot</code> and <code>twoRoot</code> are only needed in their respective <code>if</code> block, you should move the <code>var</code> statements to those <code>if</code> blocks.</li>\n<li><p>This:</p>\n\n<pre><code>if(twodigit == 10) {\n lastURL = twoR...
{ "AcceptedAnswerId": "57027", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T03:48:35.050", "Id": "56813", "Score": "2", "Tags": [ "javascript", "html", "css" ], "Title": "URL Conditional in JavaScript" }
56813
<p>I don't like the service class below, specifically, the way it exposes the internals of the producer. While it would be possible to combine all three classes into one producer-consumer, I would rather that they stay separated.</p> <p><strong>Service:</strong></p> <pre><code>package net.bounceme.dur.client; impor...
[]
[ { "body": "<p>Yeah, your dependency graph has gotten all tangled up.</p>\n\n<p>In this case, the root problem seems to be that there are a number of different things going on, and you haven't really identified them. So you have your producer/consumer idiom, your queuing, and your threading conflated.</p>\n\n<p...
{ "AcceptedAnswerId": "56816", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T03:50:06.680", "Id": "56814", "Score": "3", "Tags": [ "java", "object-oriented", "design-patterns", "socket", "stream" ], "Title": "Refactoring this producer consumer c...
56814
<p>I have a list of datacenters, which are <code>dc1</code>, <code>dc2</code> and <code>dc3</code>. And each datacenter has six IDs as of now (can be 11 in each datacenter as well or uneven number for each datacenter).</p> <blockquote> <pre><code>dc1 - h1, h2, h3, h4, h5, h6 dc2 - h1, h2, h3, h4, h5, h6 dc3 - h1, h2, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T11:17:16.500", "Id": "101240", "Score": "0", "body": "[Previous question](http://codereview.stackexchange.com/q/56406/9357)" } ]
[ { "body": "<h3>Unit testing</h3>\n\n<p>Your code does the job. But right now there's no good way to verify that. Running the <code>main</code> method with various inputs and reading the output is <em>not a good way</em> to verify. This is relatively easy to fix by converting your manual tests to unit tests that...
{ "AcceptedAnswerId": "56823", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T06:56:23.000", "Id": "56817", "Score": "3", "Tags": [ "java", "optimization", "performance", "algorithm" ], "Title": "Generating a valid number of combinations of datacente...
56817
<p>I am trying to solve <a href="http://www.spoj.com/SPOJ/problems/NGON/" rel="nofollow">NGON</a> problem. I am using bottom up dynamic programming here. Recurrence function is:</p> <p>$$\begin{array}{rl} f(a,b) &amp;= f(a-1,b) + f(a-1,b-1)\,a_i +\frac{f(a-1,b-2)\,a_i(a_i-1)}{2}, a&gt;0,b&gt;0 \\ f(a,0) &amp;=...
[]
[ { "body": "<p>You code is <em>very</em> crushed together; you hardly have any spaces in a single line.</p>\n\n<p>Your code would be a lot more legible if you added spaces.</p>\n\n<p>For example, you could turn this line:</p>\n\n<pre><code>result[a][b]=(result[a-1][b]+result[a-1][b-1]*points[a-1])%MODULO;\n</cod...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T08:56:04.963", "Id": "56818", "Score": "4", "Tags": [ "c", "programming-challenge", "combinatorics", "time-limit-exceeded", "dynamic-programming" ], "Title": "NGON (many p...
56818
<p>I would like to know if this code in .htaccess for forcing SSL and WWW in URL is correct, because with another code I usually get redirect loop, e.g. <code>RewriteCond %{HTTPS} !=on</code> and now it works like a charm (suspiciously). Also, is it possible to write it better/simpler?</p> <pre><code># Force to SSL Re...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T18:56:11.573", "Id": "101322", "Score": "1", "body": "I'm not convinced that this works. Do you have some special setup such that HTTPS requests all have a non-standard `HTTPS: 1` header?" }, { "ContentLicense": "CC BY-SA 3....
[ { "body": "<p>What you're doing with <code>RewriteCond %{HTTP:HTTPS} !1</code> is checking whether the <strong><code>HTTPS</code></strong> header is present in the request and if it is, then the value <em>is not</em> <code>1</code>.</p>\n\n<blockquote>\n <p><code>%{HTTP:header}</code>, where header can be any ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T09:04:54.427", "Id": "56819", "Score": "2", "Tags": [ ".htaccess", "https", "ssl" ], "Title": "Forcing SSL and WWW using .htaccess" }
56819
<p>I wrote this code to list contents of an XPI file and then read the contents in it.</p> <p>I was thinking of these areas of improvement:</p> <ol> <li>I put the <code>zr.open</code> in the <code>try</code> because if the file does not exist it will throw exception, and if zip reader is left open it usually crashes ...
[]
[ { "body": "<blockquote>\n <p>I put the zr.open in the try because if the file does not exist it will throw exception, and if zip reader is left open it usually crashes the add-on.</p>\n</blockquote>\n\n<p>Crash? I wouldn't know about that. But yes, it should be closed. But then again, only <code>.close()</code...
{ "AcceptedAnswerId": "56824", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T09:29:40.680", "Id": "56821", "Score": "5", "Tags": [ "javascript", "error-handling", "io" ], "Title": "Reading the contents of an XPI file" }
56821
<p>I created this demo example for <a href="https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Promise.jsm#Make_user_defined_promise_return_after_multiple_images_finish_loading_%28Promise.all_and_Promise.defer%29" rel="nofollow">MDN documentation to show how to use <code>Promise.all</code> and <co...
[]
[ { "body": "<p>Here's my implementation:</p>\n\n<pre><code>// So we define a function that loads images, and returns a promise for us to listen to\nfunction loadImages(images){\n\n // We can take advantage of `map` which iterates through an array and makes an array\n // out of the returns of each iteration. In...
{ "AcceptedAnswerId": "56895", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T09:35:21.020", "Id": "56822", "Score": "3", "Tags": [ "javascript", "promise" ], "Title": "Promise.jsm demo of Promise.all and Promise.defer" }
56822
<p>A Firefox add-on is a way of adding to or modifying the Firefox web browser. Most commonly, questions in this tag are about Firefox extensions, which add new functionality to the browser, although "add-on" may also refer to themes or browser plug-ins.</p> <ul> <li><a href="https://developer.mozilla.org/en-US/docs/M...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T10:50:46.500", "Id": "56825", "Score": "0", "Tags": null, "Title": null }
56825
A Firefox add-on is a way of adding to or modifying the Firefox web browser. Most commonly, questions in this tag are about Firefox extensions, which add new functionality to the browser, although "add-on" may also refer to themes or plugins.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T10:50:46.500", "Id": "56826", "Score": "0", "Tags": null, "Title": null }
56826
<p><a href="https://developer.mozilla.org/en-US/docs/XPCOM" rel="nofollow">XPCOM (Cross Platform Component Object Model)</a> is a cross-platform component model from Mozilla. It is similar to Microsoft COM and CORBA.</p> <p>It has multiple language bindings, allowing XPCOM components to be used and implemented in Java...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T10:57:23.870", "Id": "56827", "Score": "0", "Tags": null, "Title": null }
56827
XPCOM (Cross Platform Component Object Model) is a cross-platform component model from Mozilla. It is similar to Microsoft COM and CORBA.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T10:57:23.870", "Id": "56828", "Score": "0", "Tags": null, "Title": null }
56828
<p>I decided to take on the FizzBuzz challenge with as twist that I would use Java 8 concepts to make it a bit modular, yet still let it be a short, readable and understandable program.</p> <p>This in contrary to some gem I found on the net: <a href="https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T12:53:25.937", "Id": "101250", "Score": "23", "body": "In my view, any solution to FizzBuzz that doesn't use a simple for loop and System.out.println fails the test." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate"...
[ { "body": "<p>A guideline that I use for deciding on a <code>StringBuilder</code> or not is that it depends on whether I know beforehand how many times it will be used or not. I believe I've come across this recommendation on some MSDN page once but I'm not entirely sure.</p>\n\n<p>In your case, you know that t...
{ "AcceptedAnswerId": "56830", "CommentCount": "14", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T11:28:58.563", "Id": "56829", "Score": "40", "Tags": [ "java", "programming-challenge", "fizzbuzz", "java-8" ], "Title": "The FizzBuzz challenge in Java 8 written in a sho...
56829
<p>I have the below C# code for parsing. Do you think this is most optimized or should I use a generic method in these functions themselves?</p> <pre><code>public static bool GetDBBool(object value) { var result = false; if (value != null &amp;&amp; string.IsNullOrEmpty(value.ToString()) == false) bo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T14:02:18.233", "Id": "101256", "Score": "3", "body": "These methods seem like a pointless abstraction. They don't offer anything over the .NET `TryParse` methods." } ]
[ { "body": "<p><code>== false</code> is not very readable. Use <code>!</code> instead. </p>\n\n<p>If the \"object value\" is already of desired type (e.g. DateTime), it would be slower to convert it to string and then back again. </p>\n\n<p>I would write instead</p>\n\n<pre><code>if (value is DateTime) return (D...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2014-07-12T12:32:57.240", "Id": "56833", "Score": "3", "Tags": [ "c#", "parsing", "datetime" ], "Title": "Optimize parsing more and more" }
56833
<p>This simple console program prompts the users for a number and returns the lowest and highest numbers from their inputs. It is difficult to add more user inputs, though. How can I make this easier to maintain and extend?</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T19:54:47.543", "Id": "101345", "Score": "0", "body": "Your code is broken: The variables `num4` and `num5` are read in but never used (or declared for that matter) in the lowest/highest calculation." } ]
[ { "body": "<p>As a general rule of thumb, you shouldn't nest ternary operators. It quickly (unintentionally) obfuscates the code. I would normally suggest writing separate functions for <code>lowest</code> and <code>highest</code> in this situation. You would then pass your numbers to those functions as an arra...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T13:13:23.727", "Id": "56838", "Score": "6", "Tags": [ "c#", "beginner", "console" ], "Title": "Returning the lowest and highest number based on input" }
56838
<p>There are <a href="https://codereview.stackexchange.com/questions/11489/fizzbuzz-implementation">quite</a> <a href="https://codereview.stackexchange.com/questions/14216/writing-fizzbuzz">a</a> <a href="https://codereview.stackexchange.com/questions/40656/first-scala-fizzbuzz-implementation">large</a> <a href="https:...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-29T04:41:05.520", "Id": "104727", "Score": "1", "body": "This looks familiar. Why does this look familiar? Why do I recognize this language? Found it. [Evolve used KForth](http://silvergravy.com/an-open-source-artificial-intelligence-e...
[ { "body": "<p>Are you using two or three spaces of indentation? Yes.</p>\n\n<p>Are you using two and three spaces of indentation? Yes.</p>\n\n<p>Are you using two <em>xor</em> three spaces of indentation? No.</p>\n\n<p>I don't know the coding conventions of Forth, but I'd personally prefer to see using four spa...
{ "AcceptedAnswerId": "70660", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T13:13:54.000", "Id": "56839", "Score": "24", "Tags": [ "fizzbuzz", "forth" ], "Title": "FizzBuzz in Forth" }
56839
Forth is a stack-based programming language originally developed in the 1970s by Charles H. Moore for controlling radiotelescopes.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T13:48:51.533", "Id": "56841", "Score": "0", "Tags": null, "Title": null }
56841
<p>Using <a href="http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/jdbc.html">Spring's JdbcTemplate</a> to load a specific object by ID if exists, I have this code:</p> <pre><code>Person person = null; try { person = jdbcTemplate.queryForObject(sql, new Object[]{ id }, new PersonMapper()); }...
[]
[ { "body": "<p>If you know what your <code>PersonMapper</code> does and there is no way it could generate a <code>null</code> instance based on a existing row, you could extract this code differently. </p>\n\n<pre><code>private Person execute(String sql, String id) {\n try {\n return jdbcTemplate.query...
{ "AcceptedAnswerId": "56854", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T14:07:49.443", "Id": "56842", "Score": "5", "Tags": [ "java", "spring" ], "Title": "Logging a message and the stack trace of caught exceptions" }
56842
<p>I am looking for a code review for this multipart or single file chunk downloader using threading and queues.</p> <p><strong>downloader.py</strong></p> <pre><code>import argparse import logging import Queue import urllib2 import os import utils as _fdUtils import signal import sys import time import threading DES...
[]
[ { "body": "<p>I'll try it:</p>\n\n<ol>\n<li><p>You are requesting for range queries in parallel, and write them all to the disk: Where are you enforcing the order of chunks? I think you may get an unordered file as a result.</p></li>\n<li><p>I think you loose time instead of saving it, by using thread for <code...
{ "AcceptedAnswerId": "56859", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T14:16:19.003", "Id": "56843", "Score": "-1", "Tags": [ "python", "design-patterns", "multithreading", "unit-testing", "queue" ], "Title": "Command line multipart or sin...
56843
<p>In my quest for learning Objective-C, I have created the common FizzBuzz code in it. This is due to <a href="http://chat.stackexchange.com/transcript/message/16550340#16550340">a suggestion/challenge</a> from <a href="https://codereview.stackexchange.com/users/36366/nhgrif">@nhgrif</a> to re-implement <a href="http...
[]
[ { "body": "<p><strong>You have no curly braces!</strong></p>\n\n<p>You should be sure to include curly braces. For one, it prevents mistakes when you want to go back and add some logic into one of these <code>if</code> statements in the future, and for two, since we're talking about Objective-C and you're almo...
{ "AcceptedAnswerId": "56852", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T14:22:07.097", "Id": "56844", "Score": "8", "Tags": [ "beginner", "objective-c", "fizzbuzz" ], "Title": "FizzBuzz in Objective-C" }
56844
<p>I came across <a href="http://codingbat.com/prob/p199368" rel="nofollow">this problem</a>.</p> <blockquote> <p><strong>Problem Statement:</strong></p> <p>Given an array of <code>int</code>s, is it possible to choose a group of some of the <code>int</code>s, beginning at the start index, such that the group...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T18:12:22.267", "Id": "101309", "Score": "0", "body": "Is nobody interested in this one? lol" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-17T11:42:42.277", "Id": "102338", "Score": "1", "bo...
[ { "body": "<p>This will be a solely style-focused review, because your code (don't take it personal) looks horrible...</p>\n<h2><kbd>SPACE</kbd> to breathe:</h2>\n<p>Your code is cramped, and your poor operators and statments a sqeezed together like sardines in a tin.</p>\n<p><strong>Spaces are free!</strong> U...
{ "AcceptedAnswerId": "57294", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T15:30:21.300", "Id": "56853", "Score": "5", "Tags": [ "java", "recursion", "programming-challenge" ], "Title": "Finding if there is a subset that sums to a target value from an...
56853
<p><strong>Problem Summary</strong>:</p> <blockquote> <p>Given a singly linked list, remove all the nodes which have a greater value on right side.</p> <p>Example: The list 12->15->10->11->5->6->2->3->NULL should be changed to 15->11->6->3->NULL. Note that 12, 10, 5 and 2 have been deleted because there is ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-08-29T06:36:24.657", "Id": "111542", "Score": "0", "body": "I want to downvote the page where you found the problem :-). The problem is not stated very well. (1) linked list don't have right sides (2) the last line of Example \"a\" is wr...
[ { "body": "<p>In <code>appendNode()</code>, you have to provide a pointer to node to <code>sizeof()</code> and typecast its return value to <code>struct node*</code>:</p>\n\n<pre><code>void appendNode (struct node** headRef, int data)\n{\n struct node* newNode = (struct node*)malloc(sizeof(struct node*));\n\...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T17:36:00.113", "Id": "56858", "Score": "2", "Tags": [ "c", "linked-list" ], "Title": "Deleting nodes having greater value on right side" }
56858
<p>I've updated my text-based terrain generator <strong>a lot</strong>. Even though I haven't worked on it all that much. I really just want to know, like usual, is there anything I can improve? How can I shorten the code? What can be made more efficient? Yada yada yada... </p> <pre><code>#!/usr/bin/env python from ra...
[]
[ { "body": "<p>You have two errors here:</p>\n\n<blockquote>\n<pre><code>def generate(world_size):\n system('cls' if name = 'nt' else 'clear')\n for _ in range(world_size):\n print(''.join(choice(tiles) for _ in range(world_size)))\n</code></pre>\n</blockquote>\n\n<p>An unexpected indent and...
{ "AcceptedAnswerId": "56881", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T18:53:30.073", "Id": "56864", "Score": "6", "Tags": [ "python", "python-2.x" ], "Title": "Text-based terrain generator (Part 2)" }
56864
<p>I've just started programming and read a book called <em>Head First Java</em>.</p> <p>I thought it would be fun to make a training project that I can put all the stuff I learn into. Is the code I've written here just really bad or good code written for a beginner?</p> <p>I've got 4 classes:</p> <h3>Main class:</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T23:42:59.523", "Id": "101556", "Score": "1", "body": "Stubbing in support for Easter Eggs already, I see!" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T00:16:05.523", "Id": "101561", "Score"...
[ { "body": "<p>There are a number of things to be improved, but here's a start:</p>\n\n<ol>\n<li><p>Functions should be named according to what they do. This means they should often start with a verb, so rather than <code>Game.OutForAWalk()</code>, it should be <code>Game.goOutForAWalk()</code>. (There are excep...
{ "AcceptedAnswerId": "56922", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T19:15:04.533", "Id": "56866", "Score": "15", "Tags": [ "java", "beginner", "game" ], "Title": "Dog owner simulator" }
56866
<p>Since today is apparently a good day for...unlikely FizzBuzz implementations, I decided to contribute another, this one in C++:</p> <pre><code>#include &lt;iostream&gt; #include &lt;functional&gt; #include &lt;vector&gt; #include "xrange.h" int main() { std::vector&lt;std::function&lt;void(int)&gt; &gt; funcs ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T19:25:22.503", "Id": "101327", "Score": "0", "body": "Did you try extra paranthesis: `funcs[([]...)]`? Note that anything using a lambda in the index brackets is basically obfuscation." }, { "ContentLicense": "CC BY-SA 3.0",...
[ { "body": "<p>I'd be inclined to make a simple fixed array instead of a <code>std::vector</code> for <code>funcs</code>:</p>\n\n<pre><code>const std::function&lt;void(int i)&gt; funcs[] {\n [](int i) { std::cout &lt;&lt; i &lt;&lt; \"\\n\"; },\n [](int ) { std::cout &lt;&lt; \"fizz\\n\"; },\n [](int )...
{ "AcceptedAnswerId": "56874", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T19:15:47.443", "Id": "56867", "Score": "15", "Tags": [ "c++", "c++11", "functional-programming", "fizzbuzz" ], "Title": "Yet another FizzBuzz" }
56867
<p>I have a windows forms application which needs customized dll files to be built and for that I am using an online builder using asp.net. I am in no way a asp.net expert not even near a beginner but this is what I have come up with so far:</p> <p><img src="https://i.stack.imgur.com/s0kA3.png" alt="Project"></p> <p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-07T18:52:56.057", "Id": "101343", "Score": "1", "body": "What exactly are the kind of problems you are having?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-08T08:53:00.530", "Id": "101344", "Scor...
[ { "body": "<p>This looks good to me. A nice use of space, Everything is very clear and easy to read, just a couple of problems:</p>\n\n<p><strong>Magic Numbers / Strings</strong></p>\n\n<p>You have a few of these dotted about, a couple of examples:</p>\n\n<p><code>ctor.Body.Instructions[1].Operand = context.Req...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-06T11:18:08.807", "Id": "56870", "Score": "5", "Tags": [ "c#", "asp.net" ], "Title": "Better approach to online builder" }
56870
<p>First, the struct itself:</p> <pre><code>struct Fraction { var numerator: Int var denominator: Int { didSet (oldDenominator) { if self.denominator == 0 { self.denominator = oldDenominator } } } init() { self.init(numerator: 0, denominator: 1) } i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T12:14:34.760", "Id": "101440", "Score": "1", "body": "I would explore having your `init` function return an optional `Fraction`, with a `nil` value when the denominator is `0`. `Fraction(numerator:1, denominator:0)` should NOT just ...
[ { "body": "<p>I think everything looks quite nice here. It runs well, and you run the necessary checks to make sure that everything is safe. </p>\n\n<p>I did notice that you went to great extent to implement a bunch of operators for your <code>Fraction</code> structure. But you forgot to implement the common...
{ "AcceptedAnswerId": "82080", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T20:08:41.123", "Id": "56872", "Score": "8", "Tags": [ "swift", "rational-numbers" ], "Title": "Fraction (rational number) structure with custom operators" }
56872
<p>Please suggest improvements/refactoring to this game to make it more idiomatic Python.</p> <pre><code>import random import time class Hero: def __init__(self): self.level = 1 self.max_hp = 3 self.hp = self.max_hp self.attack = 5 + self.level self.defense = 5 + self.level...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T20:14:25.127", "Id": "101350", "Score": "0", "body": "Line 183 doesn't work? If so, we cannot help with that here as it's off-topic." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T20:29:00.953", ...
[ { "body": "<p>A few suggestions:</p>\n\n<hr>\n\n<p>Simplify and reduce duplication using inheritance, for example:</p>\n\n<pre><code>class Character(object): # note new-style classes\n\n def __init__(self, name, hp, attack, defence, xp):\n self.name = name\n self.hp = hp\n self.attack = ...
{ "AcceptedAnswerId": "56877", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T20:11:43.277", "Id": "56873", "Score": "5", "Tags": [ "python", "game", "python-2.x", "console" ], "Title": "Text-based adventure game with combat and game-reset functional...
56873
<p>MS SQL Server, no loops. ;)</p> <pre><code>WITH Numbers AS ( SELECT 1 as Number UNION ALL SELECT Number+1 FROM Numbers WHERE Number &lt; 100 ) SELECT CASE WHEN Number % 15 = 0 THEN 'FizzBuzz' WHEN Number % 5 = 0 THEN 'Buzz' WHEN Number % 3 = 0 THEN 'Fizz' ELSE CAST(Number as varchar) EN...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-16T03:05:09.780", "Id": "101984", "Score": "1", "body": "A note about compatibility: this also works as written in SQLite 3. For PostgreSQL compatibility, you need `WITH RECURSIVE` (I believe this is standard), but SQL Server doesn't s...
[ { "body": "<p>Recursive CTEs in SQL Server execute involving a temp table. This is probably why this tiny amount of work even takes a measurable amount of time. This should take &lt;= 1ms.</p>\n\n<p>Use a numbers table. Or, use one of the many tricks to materialize a sequence of numbers without table access suc...
{ "AcceptedAnswerId": "56898", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T20:28:54.153", "Id": "56875", "Score": "19", "Tags": [ "sql", "sql-server", "fizzbuzz" ], "Title": "FizzBuzz in SQL--no loops" }
56875
<p>For this flowchart on finding the minimum of 2 numbers:</p> <p><img src="https://i.stack.imgur.com/TlZ3d.jpg" alt="enter image description here"></p> <p>I've created XML for this flowchart:</p> <pre><code>&lt;start&gt; &lt;InOut&gt; &lt;in&gt; a &lt;/in&gt; &lt;in&gt; b &lt;/in&gt; &lt;out...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T20:43:19.610", "Id": "101358", "Score": "0", "body": "Does it still work properly?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T20:47:20.460", "Id": "101359", "Score": "0", "body": "Wai...
[ { "body": "<p>There are some confusing aspects to your XML, and some practices that you may end up appreciating.....</p>\n<h2>Technical</h2>\n<p>Your XML is valid, but it does not follow best practices. The XML:</p>\n<blockquote>\n<pre><code> &lt;con gurd=&quot;min&gt;b&quot; type=&quot;if&quot;&gt;\n</code>...
{ "AcceptedAnswerId": "56882", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T20:40:29.423", "Id": "56876", "Score": "0", "Tags": [ "xml", "xsd" ], "Title": "Finding the minimum of two numbers" }
56876
<p>Inspired by this question: <a href="https://codereview.stackexchange.com/q/56872/27623"><strong>Fraction (rational number) structure with custom operators</strong></a>, I have written this class for doing some simple work with fractions.</p> <p><strong><code>Fraction.h</code></strong>:</p> <pre><code>#import &lt;F...
[]
[ { "body": "<p>Obj-C is <strong>not</strong> my strong suit, so I thought about putting this in a comment instead. But I guess it's an answer of sorts. It's all about naming, though</p>\n\n<ul>\n<li><p>When saw the name <code>convertToNum</code> I first expected it'd return an <code>NSNumber</code> instance. Bes...
{ "AcceptedAnswerId": "56892", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T22:14:50.517", "Id": "56883", "Score": "7", "Tags": [ "beginner", "object-oriented", "objective-c", "rational-numbers" ], "Title": "Fraction class implemented in Objective-...
56883
<p>Since this problem involves small numbers (particularly with a small loop count of 100), it's possible to ease the modulo operation setup by simply working with 16-bit and 8-bit registers:</p> <p>$$\dfrac{\text{[AX] (16-bit register)}}{\text{[other 8-bit register]}} = \text{[AH] (remainder)}$$</p> <p>My main conce...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T22:59:08.260", "Id": "101380", "Score": "1", "body": "Nice! +1 for the effort writing this is a low level language. May I suggest posting the result set?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-1...
[ { "body": "<p>Since we're doing this in assembly language, it makes sense to do it much more efficiently than is typically done in high level languages. Otherwise, why bother with assembly language? So with that said, there are ways that this can be made much, much more efficient.</p>\n<h2>Avoid division</h2>\...
{ "AcceptedAnswerId": "56896", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T22:39:05.260", "Id": "56884", "Score": "49", "Tags": [ "assembly", "fizzbuzz" ], "Title": "16-bit FizzBuzz in x86 NASM assembly" }
56884
<p>I've decided to write a C++ FizzBuzz with the focus on some new C++11 features, ridiculous optimizations and unit-testability.</p> <p>Are there improvement possibilities in those regards?</p> <pre><code>template &lt;typename T&gt; static void fizzbuzz(std::ostream&amp; out, const T&amp; number, const std::vector&l...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T23:48:43.437", "Id": "101389", "Score": "2", "body": "Which function is called from `main()`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T01:24:26.600", "Id": "101404", "Score": "12", ...
[ { "body": "<h2>Know when to use which feature</h2>\n\n<p>C++11 offers range based for loops so you should use them instead of <code>for_each</code> with lambdas:</p>\n\n<pre><code>for(auto i: values) {\n if (0 == number % i.second) {\n out &lt;&lt; i.first.c_str();\n found = true;\n } ...
{ "AcceptedAnswerId": "57319", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-12T23:31:00.230", "Id": "56886", "Score": "7", "Tags": [ "c++", "c++11", "fizzbuzz" ], "Title": "Enterprise FizzBuzz in C++11" }
56886
<p>I had to jump on the bandwagon for this one. The task does a great job of helping you learn a language you're unfamiliar with.</p> <p>So today I present you with my version of the infamous <a href="http://en.wikipedia.org/wiki/Fizz_buzz" rel="noreferrer">FizzBuzz</a> game in Common Lisp. This is really the first "p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-08-13T15:31:55.607", "Id": "108152", "Score": "1", "body": "Minor note: if a cond clause has only one form, you can simply make it the test form. I.e., instead of `(T (print i))`, you can simply have `((print i))`." }, { "Conten...
[ { "body": "<p>Do not recompute <code>is-multiple</code> repeatedly by either binding the value:</p>\n\n<pre><code>(defun num-action (i)\n (let ((i3 (is-multiple i 3))\n (i5 (is-multiple i 5)))\n (cond ((and i3 i5) (print \"FizzBuzz\"))\n (i3 (print \"Fizz\"))\n (i5 (print \"Buzz\"))...
{ "AcceptedAnswerId": "56911", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T00:47:37.323", "Id": "56890", "Score": "8", "Tags": [ "beginner", "lisp", "common-lisp", "fizzbuzz" ], "Title": "FizzBuzz - officially now in CLISP" }
56890
<blockquote> <p>A node has a next and down pointer. Merge the linked-list such that end result is sorted. Here we have a top level linked-list, followed by a down-list.</p> <p>If { 10 : {20, 30} , 35 { 40, 50 } } is the input data structure, it means that 10 is connected to 35, using the next pointer. 10 ...
[]
[ { "body": "<pre><code>private void addDown(Node head, List&lt;Integer&gt; list) {\n Node prev = null;\n for (Integer item : list) {\n Node node = new Node(item);\n if (prev == null) {\n prev = node; \n head.down = node;\n } else {\n prev.down = node;\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T00:50:29.610", "Id": "56891", "Score": "1", "Tags": [ "java", "linked-list" ], "Title": "Following-up \"given a two dimensional linked list, create a flattened sorted list\"" }
56891
<p>I don't normally write <a href="/questions/tagged/vb.net" class="post-tag" title="show questions tagged &#39;vb.net&#39;" rel="tag">vb.net</a> code, and I would rather maintain a monstruous <a href="/questions/tagged/vb6" class="post-tag" title="show questions tagged &#39;vb6&#39;" rel="tag">vb6</a> project than a s...
[]
[ { "body": "<p>Things I like:</p>\n\n<ul>\n<li><a href=\"https://codereview.stackexchange.com/a/56831/41243\">You defined the requirements correctly.</a></li>\n<li><a href=\"http://msdn.microsoft.com/en-us/library/7825002w(v=vs.90).aspx\" rel=\"nofollow noreferrer\">Module</a> was probably the right call. </li>\...
{ "AcceptedAnswerId": "56902", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T00:55:41.077", "Id": "56893", "Score": "11", "Tags": [ "vb.net", "fizzbuzz" ], "Title": "VBuzz all fizzed up" }
56893
<p>Technically, this is a follow up to these two questions, but I have taken a radically different approach. </p> <ol> <li><a href="https://codereview.stackexchange.com/questions/54769/everyone-loves-fibonacci">Everybody Loves Fibonacci</a></li> <li><a href="https://codereview.stackexchange.com/questions/54894/does-ev...
[]
[ { "body": "<p>A <code>Dictionary</code> is the wrong data structure to use for memoization here. <del>An <code>ArrayList</code></del> A <code>List&lt;int&gt;</code> would be more appropriate. The reason is that the entries are not independent, but rather sequential: it will remember all entries from the 0<sup...
{ "AcceptedAnswerId": "56909", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T02:44:48.850", "Id": "56899", "Score": "12", "Tags": [ "c#", "performance", "algorithm", "cache", "fibonacci-sequence" ], "Title": "I'm not sure if I still love Fibonac...
56899
<p>Recently I submitted some string formatting and printing code (<a href="https://codereview.stackexchange.com/questions/56067/did-i-implement-my-string-formatting-code-correctly">found here</a>) that I wrote as an small exercise. It was implemented naively using string replacement. This time around I wanted to actual...
[]
[ { "body": "<p>There are a few points about this that seem open to improvement (at least to me).</p>\n\n<ol>\n<li><p>Don't compare <code>bool</code>s to <code>true</code> or <code>false</code>, just use their value directly, so </p>\n\n<pre><code>placeholder_mode == false\n</code></pre>\n\n<p>becomes:</p>\n\n<pr...
{ "AcceptedAnswerId": "56905", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T03:06:54.933", "Id": "56900", "Score": "5", "Tags": [ "c++", "strings", "c++11", "formatting", "boost" ], "Title": "Simple parsing for string formatting" }
56900
<p>The <a href="https://codereview.stackexchange.com/a/18898/9357">core problem</a> is simple enough, but I've developed a type system that I'm not sure about. The intention is, if the result is a number, calling <code>num $ fizzBuzz 16</code>, for example, lets me retrieve <code>16</code> as an <code>Int</code>. How...
[]
[ { "body": "<p>In the <a href=\"http://themonadreader.wordpress.com/2014/04/23/issue-23/\" rel=\"nofollow\">issue 23 of The Monad.Reader</a>, there is a nice discussion of FizzBuzz and how to solve it efficiently in Haskell. The efficiency being in terms of future extensions such as \"output Bazz if it's a multi...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T03:10:00.073", "Id": "56901", "Score": "13", "Tags": [ "haskell", "fizzbuzz" ], "Title": "Haskell FizzBuzz with a type system" }
56901
<p>After reviewing autoloader functions on the site, I didn't see anything like this, and I was wonder what may be wrong with this? </p> <pre><code>function findNloader($classFile){ $file = exec("find ./ -name ".$classFile.".php"); if(file_exists($file)){ return require $file; } else { re...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T04:30:19.977", "Id": "101416", "Score": "0", "body": "Is this your own code, and is it working?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T04:30:34.767", "Id": "101417", "Score": "1", ...
[ { "body": "<p>The main problem I see with this is that you are assuming a few things:</p>\n\n<ul>\n<li><strong>I am running Linux</strong> - Are you? The production server might, but are you locally running linux as well? Maybe, but will the next collaborator/developer?</li>\n<li><strong>My Linux distro support...
{ "AcceptedAnswerId": "56977", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T04:29:00.467", "Id": "56903", "Score": "3", "Tags": [ "php", "object-oriented", "mvc", "spl" ], "Title": "Using `exec()` in an autoloader" }
56903
<p>I have written this small little program, to test how my <code>Fraction</code> type behaves when used with and without a custom <code>FractionFormatter</code> - I've implemented two custom formatters:</p> <ul> <li><code>FractionFormatter</code>, which simply puts the numerator at the left of a slash, and the denomi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T13:26:27.857", "Id": "101456", "Score": "2", "body": "How do you handle 0 denominators? I'm not familiar with C# and didn't see anywhere that this was handled." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
[ { "body": "<h2>Immutable structs</h2>\n\n<p>Yay! ✓✓✓</p>\n\n<h2>Format provider</h2>\n\n<p>It seems odd to see a format provider in a constructor, and stranger still to store a format provider for every fraction instance. Think of the memory overhead -- imagine a use case where I perform calculations on million...
{ "AcceptedAnswerId": "56959", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T04:49:10.633", "Id": "56904", "Score": "11", "Tags": [ "c#", "formatting", "rational-numbers" ], "Title": "Formattable Fraction" }
56904
<pre><code>1 REM 2 REM FIZZBUZZ IN COMMODORE BASIC 3 REM 10 FOR I = 1 TO 100 20 IF (I/3)=INT(I/3) THEN PRINT "FIZZ"; 30 IF (I/5)=INT(I/5) THEN PRINT "BUZZ"; 40 IF (I/3)&lt;&gt;INT(I/3) AND (I/5)&lt;&gt;INT(I/5) THEN PRINT I; 50 PRINT 60 NEXT I </code></pre> <ol> <li>I'm not happy with the tests for "multiple of 3" and...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T06:40:38.333", "Id": "101426", "Score": "0", "body": "Commodore BASIC (the real one, anyway) didn't do really integer math at all. It does integer math by converting the integers to floating point, doing the math, and converting the...
[ { "body": "<p>As Jerry explained, all math operations treat numbers as floating point... even numbers stored as integers. This was my first attempt:</p>\n\n<pre><code>1 rem\n2 rem fizzbuzz in commodore basic\n3 rem\n10 t = time\n20 for i = 1 to 100\n30 n = i / 15 :if n = int(n) then print \"fizzbuzz\" :goto 70\...
{ "AcceptedAnswerId": "56914", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T06:33:20.743", "Id": "56910", "Score": "19", "Tags": [ "performance", "fizzbuzz", "basic-lang" ], "Title": "FizzBuzz in Commodore Basic" }
56910
<p>I don't know if it's just me, but I feel like my sign up action method has gotten a bit messy.</p> <p>I think that perhaps instead of setting error messages in a controller, I should set error codes which I can intercept in the View and assign the actual text message to it in there. Because I think it's classified ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T12:14:08.903", "Id": "101439", "Score": "1", "body": "At first glance: It isn't the Controller's responsibility to create the View. The controller should, at most, return the View's name, and have the bootstrap process instantiate i...
[ { "body": "<p>The first thing that jumps out is all the Strings you have which are reused throughout, those need to be removed and ideally put into constants so you only have to change them in one place if you ever need to rename them:</p>\n\n<pre><code>const FIRST_NAME = 'firstname';\nconst LAST_NAME = 'lastna...
{ "AcceptedAnswerId": "56969", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T09:32:18.787", "Id": "56915", "Score": "3", "Tags": [ "php", "optimization", "object-oriented", "controller" ], "Title": "Controller: Sign up action clean up" }
56915
<p>I found a definition of the factory design pattern as:</p> <blockquote> <p>Define an interface for creating an object, but let the subclasses decide which class to instantiate.</p> </blockquote> <p>I understood the first part "defining interface for creation an object", but I am not able to understand the second...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-02-04T21:46:47.213", "Id": "504412", "Score": "0", "body": "Was this code that you wrote or did you find it somewhere?" } ]
[ { "body": "<p>You have implemented is a factory pattern.</p>\n<p>What you describe in the first paragraph is an <a href=\"http://en.wikipedia.org/wiki/Abstract_factory_pattern\" rel=\"noreferrer\">Abstract factory pattern</a>. Slightly different.</p>\n<p>An abstract factory allows you to plug in one of multiple...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T13:45:02.373", "Id": "56924", "Score": "8", "Tags": [ "c++", "design-patterns", "music" ], "Title": "Factory design pattern with music classes" }
56924
<p>I have this implementation of the FizzBuzz challenge in Ruby:</p> <pre><code>(1..100).each do |n| i_3=(n%3==0) i_5=(n%5==0) case when i_3&amp;&amp;i_5 puts 'fizzbuzz' when i_3 puts 'fizz' when i_5 puts 'buzz' else puts n ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T18:40:57.353", "Id": "101734", "Score": "0", "body": "You may be able to learn a thing or two from one of the four Ruby answers to [this question](http://codegolf.stackexchange.com/q/88/18487). Disclaimer: No code on that site follo...
[ { "body": "<ul>\n<li>You've inlined the whole program. It would be beneficial to separate FizzBuzz into it's own method that accepts <code>n</code> as an argument. </li>\n<li>Speaking of <code>n</code>, I discourage the use of one and two letter variable names. <code>number</code> would be better. </li>\n<li>I ...
{ "AcceptedAnswerId": "56929", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T15:40:22.793", "Id": "56927", "Score": "22", "Tags": [ "ruby", "fizzbuzz" ], "Title": "FizzBuzz in Ruby" }
56927
<blockquote> <p>If \$f\$ is a numerical function and \$n\$ is a positive integer, then we can form the \$n\$th repeated application of \$f\$, which is defined to be the function whose value at \$x\$ is \$f(f(...(f(x))...))\$. For example, if \$f\$ adds 1 to its argument, then the \$n\$th repeated application ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T21:09:34.247", "Id": "101524", "Score": "0", "body": "Agreed. +1 for the doc string.. :-)" } ]
[ { "body": "<p>Nice docstring.</p>\n\n<p>Your loop is too complicated, and not idiomatic Python. Use <code>range(n)</code> to repeat <code>n</code> times:</p>\n\n<pre><code>def repeated(f, n):\n \"\"\"Docstring here\"\"\"\n def g(x):\n for _ in range(n):\n x = f(x)\n return x\n ...
{ "AcceptedAnswerId": "56948", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T16:21:50.890", "Id": "56932", "Score": "1", "Tags": [ "python", "programming-challenge", "higher-order-functions" ], "Title": "Application of higher-order function in Python" }
56932
<p>Inspired by this question: <a href="https://codereview.stackexchange.com/questions/56883/fraction-class-implemented-in-objective-c"><strong>Fraction class implemented in Objective-C</strong></a>, I have written what I feel is an improved version of the Fraction class in Objective-C.</p> <p>As per the tips <a href="...
[]
[ { "body": "<p>One big issue I have with your code is that all of of your comparisons are based off of the fraction's double value. This can lead to many bugs down the line that result in questions like <a href=\"https://stackoverflow.com/questions/4732645/iphone-objective-c-comparing-doubles-not-working\">this<...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T17:02:22.577", "Id": "56936", "Score": "10", "Tags": [ "objective-c", "immutability", "rational-numbers", "rags-to-riches" ], "Title": "Immutable Fraction class" }
56936
<p>Here is an <a href="https://crackstation.net/hashing-security.htm">article on password hashing</a>, along with an <a href="https://crackstation.net/hashing-security.htm#javasourcecode">implementation</a>. </p> <ol> <li><p>Is this code secure with number of iterations 10000, key length 256 and salt bytes 32? </p><...
[]
[ { "body": "<p>Okay, be warned, I know a little Java syntax, but I am really unfamiliar with the objects of Java. So if I get something incorrect, I'd appreciate a friendly reminder!</p>\n\n<p>I'll see what I can point out...</p>\n\n<p>So at first I notice you're supplying a static number of iterations. The numb...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T17:24:06.907", "Id": "56939", "Score": "7", "Tags": [ "java", "security", "cryptography", "java-8" ], "Title": "Secure password-hashing in Java" }
56939
<p>I went ahead and implemented a method to calculate Fibonacci numbers using memoization.</p> <pre><code>public class MemoizedFibonacci { private static final List&lt;BigInteger&gt; FIBONACCI_LIST = new ArrayList&lt;&gt;(); static { FIBONACCI_LIST.add(BigInteger.ZERO); FIBONACCI_LIST.add(BigIn...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T20:08:24.437", "Id": "101520", "Score": "0", "body": "The recursive solution is slow, but easy to implement. You have given me an idea to simplify my own though. Thanks for posting this." } ]
[ { "body": "<p>This method is 'off':</p>\n\n<pre><code>private static boolean isInFibonacciList(final int number) {\n return (number &lt;= FIBONACCI_LIST.size() - 1);\n}\n</code></pre>\n\n<p>That should probably be:</p>\n\n<pre><code>private static boolean isInFibonacciList(final int number) {\n return num...
{ "AcceptedAnswerId": "56947", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T17:37:36.863", "Id": "56940", "Score": "6", "Tags": [ "java", "fibonacci-sequence", "memoization" ], "Title": "Memoized Fibonacci" }
56940
<p>I'm trying to enhance the execution speed of my below code. I am using only vanilla JavaScript. I would be willing to bring in additional libraries and plugins as long as they will enhance the overall speed of the code. </p> <p>The goal is to have the <strong>absolute fastest execution time</strong> of the below co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T18:30:47.953", "Id": "101733", "Score": "0", "body": "Is this an exercise? Real people have multi part family names." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T19:29:58.720", "Id": "101749", ...
[ { "body": "<p>The first thing that really jumped out at me is your <code>loadFile</code> method is using <strong>synchronous http requests</strong> (looks accidental as you're using a callback anyway, see <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Synchronous_and_Asynchronous_Requ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T17:40:33.460", "Id": "56941", "Score": "1", "Tags": [ "javascript", "performance", "parsing", "iteration" ], "Title": "Looking for matching names among two text files" }
56941
<p>I tried to look up and suck in most of the information about optimizing this operation and this is what I came up with. As it's pretty much core of the game, I really would like to have it performant as much as I can. I would appreciate if someone can take a look at this and possibly find weak spots.</p> <p><em>Not...
[]
[ { "body": "<p> Do you really need a comment above every line? There are a <em>few</em> good comments like <code># Function to retrieve current timestamp, hopefully using window.performance object</code>, but comments like <code># Indicates if module is running</code> are really not useful. They add no v...
{ "AcceptedAnswerId": "96696", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T18:09:25.207", "Id": "56945", "Score": "5", "Tags": [ "performance", "game", "animation", "coffeescript" ], "Title": "Tick module for the game" }
56945
<p>I found a nice lightbox2-fork, which I tried to improve. After about six hours of work the code passes jslint. I also tried to change variable names for better understanding of what they are for.</p> <p>What else can be improved there? </p> <p><a href="http://jsfiddle.net/f6xyn/" rel="nofollow">jsfiddle</a> (ye...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T23:19:15.207", "Id": "101783", "Score": "0", "body": "Please don't updated the original embedded code based on answers. You may still update the linked code." } ]
[ { "body": "<p>Interesting question,</p>\n\n<p>this code has a serious bit of copy pastage:</p>\n\n<ul>\n<li>Lines 328-365 are identical to 468-504</li>\n<li>Lines 375-412 are identical to 423-459</li>\n</ul>\n\n<p>And, these 2 large blocks of code are very similar to each other ( <code>prevItem</code> &lt;> <co...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T18:21:45.977", "Id": "56946", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Improved lightbox2-fork" }
56946
<pre><code>public class FirstActivity extends Activity { private String userName; private Uri userPhoto; private void onOkButtonPressed() { Intent intent = new Intent(this, SecondActivity.class); intent.putExtra(SecondActivity.Key.USER_NAME, userName); intent.putExtra(SecondActivit...
[]
[ { "body": "<p>One thing that I find is that it is not necessary to wrap your keys inside their own inner class. Putting them inside <code>SecondActivity</code> directly is enough.</p>\n\n<pre><code>public class SecondActivity extends Activity {\n public static class Key {\n public static final String ...
{ "AcceptedAnswerId": "56952", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T18:41:04.323", "Id": "56949", "Score": "7", "Tags": [ "java", "android" ], "Title": "Where to define constants (Bundle Keys) used between 2 Activities?" }
56949
<p>The question is <a href="https://stackoverflow.com/questions/24718193/100-gunmen-in-circle-kill-next-person">here</a>.</p> <blockquote> <p>100 people are standing in a circle with gun in their hands. 1 kills 2, 3 kills 4, 5 kills 6 and so on till we are left with only one person. Who will be the last person alive...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T20:19:01.847", "Id": "101521", "Score": "1", "body": "Rethink your q, pls. Start from the end. 100 is killed by 99. Who kills 99? 98. Who kills 98? If you start with 1 kills 2, who kills 3? The way you stated it, 1 kills ever...
[ { "body": "<h2>Critique</h2>\n\n<p>I think the following code was implied:</p>\n\n<pre><code>public class MyObject {\n private int index;\n\n public MyObject(int i) {\n this.index = i;\n }\n\n public int getIndex() {\n return index;\n }\n\n public static void main(String[] args) ...
{ "AcceptedAnswerId": "56965", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T18:56:41.720", "Id": "56951", "Score": "31", "Tags": [ "java", "programming-challenge" ], "Title": "100 gunmen in circle kill next person" }
56951
<p>I will be adding functionality and most likely additional refactoring, however a stringent review would be welcome before I build it further. I know documentation is probably a bit sparse but, you know how it is. If you feel anything significantly warrants documentation, let me know. I know I understand the code; I...
[]
[ { "body": "<p>I didn't quite get the whole picture of your code without a usage example, but there are a few aspects I can comment on. In order of appearance:</p>\n\n<ul>\n<li><p><code>main()</code> with the extra <code>envp</code> parameter is not standard, though that format is accepted by the main compilers ...
{ "AcceptedAnswerId": "75200", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T18:59:13.123", "Id": "56953", "Score": "6", "Tags": [ "c++", "object-oriented", "c++11", "logging", "wrapper" ], "Title": "Debug log wrapper" }
56953
<p>This basically it sets a shapes default size and radius based on how many characters are in a string that is passed to it, the user gets the option to manually set the Font, otherwise it is automatically set for them. All letters are set to face towards the center of the circle as it wraps around. I do seem to have ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T22:06:30.810", "Id": "101534", "Score": "0", "body": "Welcome to Code Review. Be aware that modifying what your code actually does is not on-topic for this site. While we can review the code you have, correcting the issues that you ...
[ { "body": "<h3>Naming</h3>\n<p>Your class is named <code>circularText</code>, it should be named <code>CircularText</code> as all classes in Java should start with a capital character.</p>\n<hr />\n<h3>Declared fields</h3>\n<p>You have declared two fields as <code>private</code> but what about the rest?</p>\n<p...
{ "AcceptedAnswerId": "57085", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T21:32:58.770", "Id": "56956", "Score": "10", "Tags": [ "java", "javafx" ], "Title": "Circular Wrapping Text, minor adjustments" }
56956
<p>I am using <code>try</code>/<code>catch</code> syntax in combination with a database transaction to (hopefully) prevent partial registrations.</p> <p>I am wondering if I'm on the right track, and what ways, if any, I can improve my code.</p> <p>Please be advised that <code>__construct()</code> is passed an array o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T11:47:26.603", "Id": "101664", "Score": "0", "body": "I see global. And I run away. This code smells ;)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T13:47:35.807", "Id": "101684", "Score": ...
[ { "body": "<p>Your use of <code>try</code> and <code>catch</code> looks good. It is nice to see that you're aware of exceptions and that you want to handle them appropriately. <code>COMMIT</code> is a nice feature here.</p>\n<h2>Database Design</h2>\n<p><strong>Redundant data:</strong> You are saving the IP add...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-13T22:30:44.230", "Id": "56957", "Score": "1", "Tags": [ "php", "error-handling" ], "Title": "Usage of try/catch and database transactions" }
56957
<p>I have created the following code:</p> <pre><code>def LetterCapitalize(str) str = str.split(" ").each {|word| word.capitalize!} str = str.join(" ") return str end </code></pre> <p>This takes in a basic string and capitalizes the first letter of all of the words. It looks kind of awkward to reassign things to...
[]
[ { "body": "<ul>\n<li>Your function name should be in snake_case, not PascalCase. (Thanks @rui.)</li>\n<li>It seems like it would make more sense to use <code>map</code> than <code>each</code> here.</li>\n<li>Ruby doesn't need explicit <code>return</code>.</li>\n<li>You might even want to extend the base string ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T01:30:40.307", "Id": "56961", "Score": "3", "Tags": [ "ruby", "strings" ], "Title": "Capitalize all words in sentence string in Ruby" }
56961
<p>The idea here is to write a function that gives you back a persistent version of a class that you supply. So you if you run</p> <pre><code>PersistentList = make_persistent(list, "PersistentList", ['append', 'extend', 'insert', 'pop', 'remove', 'reverse', 'sort']) </code></pre> <p>You will get back a class that beh...
[]
[ { "body": "<p>No time to do a proper review, but some quick notes:</p>\n\n<ol>\n<li><p>There are no docstrings! How am I supposed to use your code?</p></li>\n<li><p>Doesn't follow the Python style guide (<a href=\"https://www.python.org/dev/peps/pep-0008\" rel=\"nofollow\">PEP8</a>): in particular, line lengths...
{ "AcceptedAnswerId": "56982", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T01:48:53.653", "Id": "56962", "Score": "3", "Tags": [ "python", "meta-programming" ], "Title": "General way to add persistence to a class in Python" }
56962
<p>I am attempting to learn swift by refactoring one of my old games and I need to rewrite my <code>update</code> method which calculates a delta time. This code <em>works</em> but is ugly. How would I go about <em>properly</em> rewriting this?</p> <pre><code>import SpriteKit class GameScene: SKScene { var lastUp...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T23:45:05.150", "Id": "101786", "Score": "0", "body": "I'm not completely certain refactoring old, existing, *working* code into a language that doesn't yet even allow for access modifiers is the best of ideas, particularly not when ...
[ { "body": "<ol>\n<li>You are inconsistent with the optional semicolons. It's optional in Swift, but all the example code I've seen from Apple excludes them. They may be excluding them simply to drive home the point that they're not necessary, but it will probably end up being standard to exclude them. Either...
{ "AcceptedAnswerId": "57143", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T02:47:47.453", "Id": "56966", "Score": "5", "Tags": [ "ios", "swift", "sprite-kit" ], "Title": "Calculating delta in SpriteKit using Swift" }
56966
<p>I'd like this code to be improved.</p> <pre><code>import java.util.Scanner; public class ArrayElementFind { public static void main(String[] args) { // TODO Auto-generated method stub String[] arr= { "A","B","C","D"}; Scanner in=new Scanner(System.in); System.out.println("En...
[]
[ { "body": "<ul>\n<li><p>Since you're not using the <a href=\"http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html\" rel=\"nofollow\"><code>try</code>-with-resources</a> statement with <code>Scanner</code>, you must close it at the end of <code>main()</code> to avoid leaking resource...
{ "AcceptedAnswerId": "57430", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T03:36:25.810", "Id": "56967", "Score": "7", "Tags": [ "java", "beginner", "array", "search" ], "Title": "Program to find the element in an array" }
56967
<p>Following up on <a href="https://codereview.stackexchange.com/q/56904/23788">this post</a>, and including some major <a href="https://codereview.stackexchange.com/a/56959/23788">changes suggested</a>, here's the revised code.</p> <p>Changes include:</p> <ul> <li>No longer keeping an <code>IFormatProvider</code> at...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T04:26:35.760", "Id": "101582", "Score": "0", "body": "That's actually *all of the code*, not just a fraction of it ;)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T04:33:56.100", "Id": "101583",...
[ { "body": "<p>It looks good! Here are some issues I found.</p>\n\n<h2>Readability</h2>\n\n<p>I would recommend <code>0</code> over <code>default(int)</code> for readability.</p>\n\n<h2>Naming</h2>\n\n<p><a href=\"http://en.wikipedia.org/wiki/Greatest_common_divisor\" rel=\"nofollow\">Greatest common divisor</a>...
{ "AcceptedAnswerId": "56994", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T04:23:51.120", "Id": "56968", "Score": "11", "Tags": [ "c#", "formatting", "rational-numbers" ], "Title": "A fraction of the code" }
56968
<p>I'm practicing Swing effects. Everything works but for some reason I get a ton of error messages in the command prompt when the fields are empty, despite my attempt to add some exception handling (this has made me realize I need to practice that a lot more).</p> <pre><code> /* Author: Luigi Vincent Practicing Ja...
[]
[ { "body": "<p>The major problem I can see is this piece of code : </p>\n\n<blockquote>\n<pre><code> try {\n if (num1.getText().length() == 0 || num2.getText().length() == 0) {\n throw new Exception();\n }\n }\n catch (Exception ex...
{ "AcceptedAnswerId": "57020", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T04:59:37.127", "Id": "56970", "Score": "3", "Tags": [ "java", "beginner", "swing", "error-handling", "calculator" ], "Title": "Simple Operations Calculator" }
56970
<p>Currently, the following code runs and produces the expected and desired output. However, I'm sure that there's much wrong with it.</p> <p>This project queries the (flat) database, instantiates each row as an object, adds those objects to a queue, and makes the queue available to clients. Clients may then connect...
[]
[ { "body": "<p>The one thing that is \"glaring\" to me is using the <code>NoSuchElementException</code> as part of the default control flow. Although this is valid and works (considering the multithreaded nature of the program) I believe that in most cases using an exception as the main control for exit of a <co...
{ "AcceptedAnswerId": "57588", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T05:07:05.563", "Id": "56972", "Score": "5", "Tags": [ "java", "object-oriented", "design-patterns", "reinventing-the-wheel", "networking" ], "Title": "Confusing control...
56972
<p><img src="https://i.stack.imgur.com/EOyBN.png" alt="Yii Logo"></p> <p><a href="http://www.yiiframework.com" rel="nofollow noreferrer">Yii</a> is an <a href="/questions/tagged/open-source" class="post-tag" title="show questions tagged &#39;open-source&#39;" rel="tag">open-source</a> <a href="/questions/tagged/php" c...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-14T06:31:13.013", "Id": "56975", "Score": "0", "Tags": null, "Title": null }
56975