body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I need to add logging functionality for an existing code, based on a result of an operation. I was thinking of creating a class that, when constructed, receives a condition function and a function for execution. Based on the result of the condition, the code will be executed. </p>
<p>Example:</p>
<pre><code>class... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-16T18:20:29.013",
"Id": "57520",
"Score": "1",
"body": "I don't think the type erasure (`std::function`) is necessary, if you use C++11's auto and a function to create the logger. Additionally, the exception handler in the dtor might h... | [
{
"body": "<p>Echoing the comments from the question, the usual design for these sort of things, often called a <a href=\"http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Scope_Guard\" rel=\"nofollow\">scope guard</a>, is to have a function that is called when it no longer needs to be run (frequenlty called <co... | {
"AcceptedAnswerId": "35494",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-16T15:16:33.233",
"Id": "35482",
"Score": "10",
"Tags": [
"c++",
"c++11"
],
"Title": "Automatic function call on scope exit"
} | 35482 |
<p>I wrote a simple utility script to process source code files, extract and pretty print braces. It could be very useful for spotting the ugliest files in a code repository. So, I tidied it up a little bit and open-sourced it <a href="https://github.com/muratdozen/playground/blob/master/scripts/pretty_print_braces/__m... | [] | [
{
"body": "<p>Over all, the code is quite readable, and extensively documented both as docstrings and as command line help. Great!</p>\n\n<p>I found no real problems with the code, but here are a few minor nitpicks:</p>\n\n<ul>\n<li>Your script produces wrong (misleading) results if there are braces inside of s... | {
"AcceptedAnswerId": "35498",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-16T16:55:17.703",
"Id": "35484",
"Score": "2",
"Tags": [
"python",
"file-system"
],
"Title": "Pretty print braces for source code analyzer"
} | 35484 |
<p>So I have this simple code in Java. It <code>enqueue</code> (adds) and element to the end of the queue (implemented by an <code>ArrayList</code>) without changing the original queue.</p>
<pre><code>public class MyQueue<T>{
private List<T> body;
// some constructors and helper functions.
//... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-16T17:28:58.753",
"Id": "57518",
"Score": "4",
"body": "What is the sense of doing so?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-16T19:00:52.170",
"Id": "57525",
"Score": "0",
"body": "`pu... | [
{
"body": "<p>It seems like what you are trying to accomplish here is to make your Queue class <strong>immutable</strong>. That in itself is good, but there are a couple of issues with your approach:</p>\n\n<ul>\n<li>Creating a new class for this is not needed. There already exists classes for that. Use <code>C... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-16T17:00:39.723",
"Id": "35485",
"Score": "3",
"Tags": [
"java",
"optimization",
"array",
"queue"
],
"Title": "A more efficient enqueue algorithm in Java"
} | 35485 |
<p>I have a library that's parsing some expressions, part of which is a CSS selector. More accurately, it's a jQuery-compatible selector. The selector itself is opaque to my library - I don't need to pick it apart, and I don't need to verify that tag and attribute names are valid HTML, or that its pseudo-selectors ex... | [] | [
{
"body": "<p>I can only review the JS part, <a href=\"https://codereview.meta.stackexchange.com/q/1345/14625\">I am not sure that grammar reviews are part of CR</a>.</p>\n\n<p><strong>collapse</strong></p>\n\n<ul>\n<li><code>else</code> branches after a <code>return</code> do not make sense.</li>\n<li>I would ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-16T18:19:06.153",
"Id": "35487",
"Score": "4",
"Tags": [
"javascript",
"css",
"parsing",
"grammar",
"peg.js"
],
"Title": "PEG.js grammar for parsing CSS selectors"
} | 35487 |
<p>This is my first foray into the wild world of jQuery plugin development. The plugin "ajaxifies" forms, which isn't particularly spectacular: </p>
<ul>
<li>It gets the basics (action, method) from the form itself, serializes the form's fields, and sends the request. </li>
<li>Users can provide (via its options) call... | [] | [
{
"body": "<p>Structure and style looks fine, although I have some general notes:</p>\n\n<ul>\n<li>Prefer the strong (in)equality operators (<code>!==</code> and <code>===</code>) whenever possible</li>\n<li>Always use braces, even for one-line \"blocks\". It's nice to save a few keystrokes, but personally I pr... | {
"AcceptedAnswerId": "35508",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-16T18:40:02.790",
"Id": "35488",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"ajax",
"plugin"
],
"Title": "jQuery plugin to ajaxify forms"
} | 35488 |
<p>I've answered <a href="https://stackoverflow.com/questions/20020300/validate-excel-imported-data/20021825#20021825">this</a> question on Stack Overflow. The problem is - there are 30 columns in an Excel sheet and I need to validate each of the fields with different validation logic. The code should avoid a lot of i... | [] | [
{
"body": "<p>First of all, you're not using your generics properly here: </p>\n\n<pre><code>private IValidator validator;\n</code></pre>\n\n<p>I would change this to </p>\n\n<pre><code>private final IValidator<String> validator;\n</code></pre>\n\n<p>Because:</p>\n\n<ol>\n<li><strong>final</strong> becaus... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-16T19:48:07.520",
"Id": "35491",
"Score": "12",
"Tags": [
"java",
"design-patterns"
],
"Title": "Validation class to avoid ugly if-else blocks"
} | 35491 |
<p>I have implemented a solution to <a href="http://projecteuler.net/problem=5" rel="nofollow">Project Euler problem 5</a>:</p>
<blockquote>
<p>2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T00:09:04.780",
"Id": "57552",
"Score": "0",
"body": "The problem with your approach is on the maths side: you are being asked, with other words, what's the least common multiple of range (1..20)"
},
{
"ContentLicense": "CC B... | [
{
"body": "<p>Let me put what @tokland said in another way. In the Zen of Python there is a sentence <code>If the implementation is hard to explain, it's a bad idea.</code>. The same thing that you are doing can be done <strong>much</strong> more efficiently and <strong>clearly</strong> by changing the algorith... | {
"AcceptedAnswerId": "35531",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-16T22:43:49.740",
"Id": "35499",
"Score": "4",
"Tags": [
"python",
"programming-challenge",
"primes"
],
"Title": "Project Euler #5 (LCM of [1, 2, …, 20])"
} | 35499 |
<p>Can you please take a look at the following x86-64 C++ code which should implement a multi consumer/produce lockfree stack? Do you think I have missed anything?</p>
<pre><code>namespace lockfree {
// NOTE: this lock-free stack uses the highest 2 bytes
// of each pointer to store a 'counter' (an "id") to
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T09:39:40.100",
"Id": "57625",
"Score": "0",
"body": "Please note that there's a question related to this one, http://codereview.stackexchange.com/questions/35518/is-throughput-performance-of-lockfree-stack-in-line-with-expectations ... | [
{
"body": "<p>I don't see any problem with the locking, although it is usually quite difficult to see race conditions (which is why you posted it I guess). The code is clearly non-portable (but maybe that is not important), with regard to endian-ness and because <code>unsigned short</code> is not guaranteed to... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T01:49:25.963",
"Id": "35502",
"Score": "4",
"Tags": [
"c++",
"multithreading",
"stack",
"lock-free"
],
"Title": "Multi producer/consumers lockfree stack"
} | 35502 |
<p>I have written a slideshow application and I am looking for some reviews:</p>
<pre><code>import sys
import os
import utils
from PyQt4 import QtGui,QtCore
class SlideShowPics(QtGui.QMainWindow):
""" SlideShowPics class defines the methods for UI and
working logic
"""
def __init__(self, imgLs... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T17:08:51.400",
"Id": "58159",
"Score": "0",
"body": "I am thinking to pass list if valid image paths to the SlideShowPics class at the time of initialization so i do not have to have getAllImages method. any opinion?"
}
] | [
{
"body": "<ul>\n<li>When there are no images to show, you print a message to console and exit without showing the GUI. The problem is that a GUI user probably won't see the console and is left wondering why the program won't start. You could show your window with the text in a label, instead.</li>\n<li>The lis... | {
"AcceptedAnswerId": "35770",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T05:26:35.253",
"Id": "35506",
"Score": "4",
"Tags": [
"python",
"image",
"pyqt"
],
"Title": "Simple PyQt4 image slide show player"
} | 35506 |
<p>I've written C# code for solving a maze problem. It works, but I want to optimize it so that it could give me all paths. To solve the maze, I walk on the zeros and assumed that the final is reaching -3. </p>
<pre><code>const int MAZE_SIZE = 6;
static int[] allowed_move_row = { 0, -1, 0, 1 };
static int[] allo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-08T18:20:32.197",
"Id": "57573",
"Score": "0",
"body": "I would parallelize the algorithm to make it search from both ends of the maze and stop when they meet half way. More of a brute force optimization than anything cleaver."
},
... | [
{
"body": "<p>Walking all zeros is indeed suboptimal. A good first optimization is to preferentially walk on the zeros that bring you closer to the end point.</p>\n<p>To do this, at each step calculate the Pythagorean distance between the x,y coordinates of the array entry you're considering walking to, and the... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-08T18:17:44.813",
"Id": "35509",
"Score": "4",
"Tags": [
"c#",
"optimization",
"recursion",
"pathfinding"
],
"Title": "Optimizing this maze-solver"
} | 35509 |
<p>I made this nice bit of code that I can insert into any of my projects requiring user input. It seems quite long for what it does and I would love some incite as to how I can do this more efficiently i.e. fewer lines of code.</p>
<p>I love to make my code elegant, but I don't see how to do it any better.</p>
<pre>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-08T19:00:30.903",
"Id": "57579",
"Score": "0",
"body": "Fewer lines of code does not mean that your program is more efficient."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-08T19:03:15.833",
"Id": "57... | [
{
"body": "<p>I suggest next way:</p>\n\n<pre><code> String x = (JOptionPane.showInputDialog(\". Each patamater should be separated with a ',' and without spaces. (eg. 1,2,3)\") + \",\");\n String[] split = x.split(\",\");\n Double[] z = new Double[split.length];\n int i = 0;\n for (String s : sp... | {
"AcceptedAnswerId": "35511",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-08T18:53:12.320",
"Id": "35510",
"Score": "1",
"Tags": [
"java"
],
"Title": "Parsing an array of comma-numbers obtained from an input dialog"
} | 35510 |
<p>I've just finished reading <em>Learn You a Haskell</em> and I've started to experiment on my own. I just wanted to create a very simple game system where player A can attack player B.</p>
<p>Now I have 2 questions:</p>
<ol>
<li><p>My <code>autoAttack</code> function was very daunting to write. How could I improve ... | [] | [
{
"body": "<p>First, when you are not using fields in a record, you don't have to use _ to mark that they should be ignored; you only need to include the fields in the pattern that you are actually using.</p>\n\n<p>Second, it is possible to update a couple of fields in a record without respecifying the whole t... | {
"AcceptedAnswerId": "35513",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-09T02:15:26.193",
"Id": "35512",
"Score": "4",
"Tags": [
"haskell"
],
"Title": "How to simplify the record syntax with pattern matching?"
} | 35512 |
PEG.js is a parser generator written in JavaScript for Node.js or the browser. Its parsing expression grammar syntax is more powerful than traditional LL(k) and LR(k) parsers and accommodates expressive error messages and inline JavaScript. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T10:40:23.657",
"Id": "35528",
"Score": "0",
"Tags": null,
"Title": null
} | 35528 |
<p>I was implementing a rolling median solution and was not sure why my Python implementation was around 40 times slower than my C++ implementation.</p>
<p>Here are the complete implementations:</p>
<p><strong>C++</strong></p>
<pre><code>#include <iostream>
#include <vector>
#include <string.h>
usi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T11:51:47.873",
"Id": "57634",
"Score": "1",
"body": "No can do, Python lists are rather slow when you iterate a lot. You could try using the `array` module from the standard library instead. It provide an efficient array class for n... | [
{
"body": "<p>Integer math in tight loops is an area where C++ will definitely run circles around Python. I think your expectations are too high. However, I'd like to point out a couple of things for you, even if they are not enough to reach your goal.</p>\n\n<p>Avoid indexing when you can use direct iteration ... | {
"AcceptedAnswerId": "35636",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T11:38:39.950",
"Id": "35530",
"Score": "10",
"Tags": [
"python",
"c++",
"performance"
],
"Title": "Rolling median solution"
} | 35530 |
<p>i'm wondering is there <strong>any way to optimize this code</strong>?
It must be able to work with big files, <strong>for example, formatting raw 140kb .txt file (12.5k words) takes 2 seconds (measured with Stopwatch class)</strong>.
Text example <a href="http://pastebin.com/2p88v8EN" rel="nofollow">http://pastebi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T12:38:03.683",
"Id": "57638",
"Score": "1",
"body": "Have you tried profiling the code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T12:46:04.127",
"Id": "57639",
"Score": "0",
"body": ... | [
{
"body": "<p>Rewritten code:</p>\n\n<pre><code>class TextManipulations\n{\nprivate const string AlphanumericWords = @\"\\b[\\w']+\\b\";\npublic string[] WordsDist;\n\npublic void TextFormat(string sourcePath, string output)\n{\n var textInput = File.ReadAllText(sourcePath).ToLower();\n var m = Regex.Matc... | {
"AcceptedAnswerId": "35681",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T12:21:24.253",
"Id": "35532",
"Score": "5",
"Tags": [
"c#",
"optimization",
"console"
],
"Title": "How to optimize C# console application"
} | 35532 |
<p>I've got a page on a website that shows a table, and upon clicking on a row in the table, it can dynamically load in more results. I am new to jQuery though.</p>
<p><strong>index.php page:</strong></p>
<pre><code><!DOCTYPE html>
<html>
<head>
<title>Knife kills</title>
... | [] | [
{
"body": "<p>Some basic things (looking only the at the JS)</p>\n\n<ul>\n<li>Don't keep repeating <code>$(clickedRow)</code> - <code>clickedRow</code> is already a jQuery object. There's no need to use <code>$()</code> again.</li>\n<li>Avoid manually tracking a number to figure out whether to hide or show the ... | {
"AcceptedAnswerId": "35568",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T15:10:58.733",
"Id": "35536",
"Score": "3",
"Tags": [
"javascript",
"php",
"jquery",
"beginner",
"mysql"
],
"Title": "Dynamically-loading interactive table"
} | 35536 |
<p>I was given the task of batch process a single-level control break program to produce a lecturer information report by lecturer from a university course file.</p>
<p>I have attempted to create a solution using a OO design in Java. I have run into some problems as I don't think the the modules are cohesive as they a... | [] | [
{
"body": "<p>Variable Names: The name should describe the data that is being stored there. <code>list</code> and <code>aList</code> don't give you any context for what they are being used for. Try to avoid single letter names or abbreviations that might not be clear to other people reading the code.</p>\n\n<p>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T16:22:34.110",
"Id": "35538",
"Score": "5",
"Tags": [
"java",
"object-oriented",
"beginner"
],
"Title": "Batch process as an OO design solution"
} | 35538 |
<p>I am very new to <code>python</code> (probably too new to consider efficiency etc.). But I am bit confused about which method to use while reading a file for <code>post-processing</code>.
Here I am reading it line-by-line. There is other methods also for reading the file(e.g <code>infile.read()</code>), one of them ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T20:00:23.290",
"Id": "57664",
"Score": "0",
"body": "Why would you not use proper coding style and conventions. Code looks too ugly. Also,while handling the IO operations with files, do have check on file size when you loading the c... | [
{
"body": "<p>First, Where are you writing in <code>ofile</code>?</p>\n\n<p>Second, ;) you can use <code>with</code> statement to opening and closing files like below:</p>\n\n<pre><code>pattern=r'species,subl,cmp=\\s{4}(.*)\\s{4}(.*)\\s{4}(.*)\\s{3}s1,torque=(.{12})(.{12})'\ninfile=sys.argv[1]; outfile=sys.argv... | {
"AcceptedAnswerId": "35547",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T16:56:43.657",
"Id": "35540",
"Score": "2",
"Tags": [
"python"
],
"Title": "the better method of I/O from file"
} | 35540 |
<p>I am designing a basic in-memory cache storage with a thin CRUD (actually CRD) interface. The design is inspired by backend solutions such as <a href="https://parse.com/" rel="nofollow">Parse</a> and <a href="https://www.stackmob.com/" rel="nofollow">StackMob</a>.</p>
<p>Main characteristics:</p>
<ul>
<li><p>Cache... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-28T16:03:06.497",
"Id": "59475",
"Score": "0",
"body": "Out of interest why not just use memcached?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-30T14:22:28.300",
"Id": "59661",
"Score": "0",
... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "12",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T17:01:38.663",
"Id": "35541",
"Score": "2",
"Tags": [
"php",
"object-oriented",
"database",
"cache"
],
"Title": "In-memory data cache architecture"
} | 35541 |
<p>My goal is to provide a function with the following functionality:</p>
<pre><code>// Will throw iff a != 42.
check(a == 42) << a << " is not equal to 42!";
</code></pre>
<p>I have the following:</p>
<pre><code>class check
{
public:
check(bool everything_OK = false)
: should_throw{!everyt... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T10:25:28.287",
"Id": "57762",
"Score": "0",
"body": "Added noexcept(false)"
}
] | [
{
"body": "<p>For what you appear to be trying to accomplish, the risk of a call to <code>std::terminate</code> doesn't seem like as horrible a problem as the usual case, for three reasons:</p>\n\n<ul>\n<li>Someone is unlikely to hold on to an instance of <code>CheckStream</code>, so there's a smaller window</l... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T17:32:36.627",
"Id": "35543",
"Score": "2",
"Tags": [
"c++",
"c++11"
],
"Title": "”check” function – OK to throw in destructor?"
} | 35543 |
<p>I've created a simple NAT library, with four essential functions: </p>
<ol>
<li>Find the UNPN device (the router in my case).</li>
<li>Get the external IP address. </li>
<li>Add a port forwarding entry.</li>
<li>Delete a port forwarding entry.</li>
</ol>
<p>Currently, updating an entry in the NAT table will change... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T21:49:30.000",
"Id": "57669",
"Score": "0",
"body": "I'd recommend splitting this code into separate blocks, or only include what's most necessary for review. Excessively-long code could discourage reviewing."
},
{
"Content... | [
{
"body": "<p>My main comment is that you need to concentrate on avoiding duplication of\ncode and on writing smaller functions. 50 lines or so is the sort of max length I use. You also use long names that are often\ntoo long giving the code a very dense appearance and making it difficult ot\nread. Smaller f... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T20:46:57.210",
"Id": "35549",
"Score": "5",
"Tags": [
"c",
"library",
"networking",
"windows"
],
"Title": "A simple NAT library"
} | 35549 |
<p>I've learned PHP following only tutorials on the web and I'm quite sure my style is not at top.</p>
<p>I'd like to understand how this code could be written in a more elegant way:</p>
<pre><code><?
$posts = // array with informations about posts fetched with PHP PDO from DB
$html = "<ul>";
foreach($posts... | [] | [
{
"body": "<p>There is nothing overtly incorrect with your code. </p>\n\n<p>However, one thing that makes PHP nice to work with for web development is it's ability to interpolate variables. When you use double quotes around a string, PHP will interpolate (replace variables with their value). When you do not ... | {
"AcceptedAnswerId": "35559",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T21:52:48.157",
"Id": "35551",
"Score": "4",
"Tags": [
"php"
],
"Title": "Is this a good way to print output?"
} | 35551 |
<p>The whole question is <a href="https://codereview.stackexchange.com/questions/10776/better-implementation-of-a-simplified-regular-expression-engine">Simplified regular expression engine</a>.
I have solved the question, and in turn felt the need to get it reviewed. Any suggestions for clean up and optimization would ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T22:13:45.023",
"Id": "57672",
"Score": "5",
"body": "I think this warrants a [tag:reinventing-the-wheel] tag :)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T22:44:36.270",
"Id": "57676",
"S... | [
{
"body": "<h1>Style</h1>\n\n<ul>\n<li>Use 'final' keyword where you can. It enables the JIT compiler to make better choices when optimizing, and it also ensures that bugs don't creep in to your code. For example, <code>private static int getNonStarIndex(String regex, int starIndex) {...}</code> should be <code... | {
"AcceptedAnswerId": "35561",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T21:57:24.903",
"Id": "35552",
"Score": "5",
"Tags": [
"java",
"optimization",
"parsing",
"regex",
"reinventing-the-wheel"
],
"Title": "Regex parser - request for review... | 35552 |
<p>I am writing an API which gets results from a DynamoDB table and puts the JSON back into the browser.</p>
<p>The code below works and returns the desired results. However, after reading about async and callbacks, it's becoming important for me to know if I should be writing this in another way. Does the following... | [] | [
{
"body": "<p>Can't speak to how it'll scale, but for your 2nd question: Yes, the code above is asynchronous.</p>\n\n<p>When you call <code>db.query()</code> or <code>server.get()</code> you pass a callback as the 2nd argument. That's the asynchronous stuff, as you don't know when that callback will be invoked.... | {
"AcceptedAnswerId": "35557",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T22:18:02.777",
"Id": "35554",
"Score": "1",
"Tags": [
"javascript",
"json",
"api",
"asynchronous",
"callback"
],
"Title": "Node.js DynamoDB callback"
} | 35554 |
<p>I've made this simple function for reading <strong>N</strong> bits from an <code>unsigned char*</code> (with a possible offset) and I'm willing to share it here, get a review, suggestions for improving it, etc...</p>
<pre><code>typedef struct bits_t {
unsigned char *data;
unsigned int len;
} bits_t;
bits_... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T23:55:00.343",
"Id": "57687",
"Score": "0",
"body": "1. Your function is never called. 2. Have a look at [this other question](http://stackoverflow.com/questions/7863499/conversion-of-char-to-binary-in-c) (or other similar questi... | [
{
"body": "<ol>\n<li>Consider checking <code>src[currentByte]</code> for <code>'\\0'</code> and abort when it's true (apparently the passed in string wasn't long enough). Depends on your usage though.</li>\n<li>Alternatively to the previous point you could add a <code>source_length</code> parameter to let the c... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T22:45:29.110",
"Id": "35555",
"Score": "3",
"Tags": [
"c",
"bitwise"
],
"Title": "Function for reading bits"
} | 35555 |
<p>I've just finished a program for a 2-way carousel. Meaning, if I click left or right, you are able to go up and down, depending on where you are. This is suppose to work for iPad or tablet only.</p>
<p>I would like to know how to make the code better or if there are any suggestions. I would appreciate it. I am ne... | [] | [
{
"body": "<p>There's <em>a lot</em> of code there, so allow me to generalize a bit rather than go line by line.</p>\n\n<p>I see some overall issues with your code:</p>\n\n<ol>\n<li>There's a lot of repetition, redundancy, and hard-coded values</li>\n<li>You're mixing jQuery and raw DOM pretty randomly instead ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-17T22:59:10.227",
"Id": "35556",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"beginner"
],
"Title": "2-way carousel for iPad and tablet"
} | 35556 |
<p>As mentioned in @rolfl comment. What this program does is that it "resequences the cards using a fixed system and count the number of times the resequencing happens before the output is the same as the input."</p>
<p>I was wondering how I could make this program faster or perhaps use less memory. I thought about u... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T02:22:21.383",
"Id": "57706",
"Score": "0",
"body": "Is this 'shuffle' code? It appears to resequence the cards using a fixed system and count the number of times the resequencing happens before the output is the same as the input..... | [
{
"body": "<p>Here is a good opportunity to break out a couple of tools from the standard library.</p>\n\n<p><code>collections.deque</code> offers fast appends and pops on both ends and is thus perfect to represent your deck of cards, when you take cards from the top and put some back to the bottom.</p>\n\n<p><... | {
"AcceptedAnswerId": "35726",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T02:16:21.660",
"Id": "35564",
"Score": "1",
"Tags": [
"python",
"optimization",
"combinatorics",
"performance",
"shuffle"
],
"Title": "Increase efficiency of card-order... | 35564 |
<p>The first function, <code>sqlPull()</code>, connects to a local MySQL database and pulls the last 20 rows from the database every 5 seconds. The data coming in is a list of tuples, where <code>MAC</code>, <code>RSSI</code> and <code>TimeStamp</code> are the 3 elements in each tuple. The data is entering the databa... | [] | [
{
"body": "<p>You need rate-limit the amount of records you receive. You'll have to determine what the best rate is by yourself, as that is specific to your scenario.</p>\n\n<h2>High Priority:</h2>\n\n<ul>\n<li><p>Keep the list of \"synced\" entries in the database. Something like an <code>IsSentToAnalytics</co... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T03:24:47.420",
"Id": "35566",
"Score": "4",
"Tags": [
"python",
"mysql"
],
"Title": "Data-pulling fuctions"
} | 35566 |
<p><em>I originally asked this <a href="https://stackoverflow.com/questions/20039172/seeking-the-right-ways-to-convert-these-two-python-functions-to-go">question</a> on StackOverflow. Reproduced here by recommendation.</em></p>
<p>I've got a number of Python scripts that I'm considering converting to Go. I'm seeking c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T08:07:39.937",
"Id": "57744",
"Score": "3",
"body": "`rldsPat, `adsPat1`, `adsPat2` - `wtfPat`? Plse dnt try to sve lttrs n vribl nms :)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T06:55:31.543",
... | [
{
"body": "<p>Early return is better than nesting. For example:</p>\n\n<pre><code>var adsPat1 = regexp.MustCompile(`\\.txt$`)\nvar adsPat2 = regexp.MustCompile(`_[0-9]{8}\\.txt$`)\nfunc addDateSuffix(target string, suffix string) error {\n fis, e := ioutil.ReadDir(target)\n if e != nil {\n return e... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T04:29:46.137",
"Id": "35567",
"Score": "3",
"Tags": [
"python",
"go"
],
"Title": "Am I writing good Go here? Python functions converted to Go"
} | 35567 |
<p>I put the readable version into the gist file -> <a href="https://gist.github.com/poc7667/7523230" rel="nofollow">link</a></p>
<p>Please ignore the <code>print</code> and <code>comment</code> in the following code.</p>
<p>I often have to write this sort of logic: init the conditions, and deep into loop condition, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T08:02:06.190",
"Id": "57742",
"Score": "2",
"body": "Isn't `while True and somecondition` same as `while somecondition`? Am I missing something obvious here?"
}
] | [
{
"body": "<p>I'm having trouble figuring out exactly what your code is doing. It's called <code>get_exception_region</code> but it appears to do a lot of printing. Is that just for debugging purposes? I'm going to assume that's the case, and thus that <code>get_exception_region</code> returns the row (line num... | {
"AcceptedAnswerId": "35624",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T06:06:51.983",
"Id": "35574",
"Score": "1",
"Tags": [
"python"
],
"Title": "How to refract a while loop with a necessary initial setting?"
} | 35574 |
<p>I had an half an hour interview with Microsoft for an intern position. I was asked to generate a list of alternatively positioned odd and even number out of an array of unsorted integers. I guess it was below the interviewer expectations since I did not get the offer. Can any one give me some hints on improving m... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T08:26:58.353",
"Id": "57746",
"Score": "0",
"body": "in your min(int, int) method, what if n = m? Then neither is the min."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T13:06:29.527",
"Id": "577... | [
{
"body": "<ol>\n<li><p>You probably should have used <a href=\"http://docs.oracle.com/javase/6/docs/api/java/lang/Math.html\" rel=\"nofollow\"><code>Math.min()</code></a>. Even if it was requested by the interviewer to not use anything else besides <code>ArrayList</code>, <code>min</code> can be written much m... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T06:42:41.170",
"Id": "35576",
"Score": "8",
"Tags": [
"java",
"array",
"interview-questions"
],
"Title": "Generating a list of alternatively positioned odd and even number out of ... | 35576 |
<p>I have a bit of code that I use to update my blog. Basically, I send an email to a particular address, and every x minutes the daemon fetches the emails, creates the files, executes middleman and then synchronizes it all to S3.</p>
<p>The thing is that I'm using lots of different apps to do it all, be it system com... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-14T20:42:17.420",
"Id": "57725",
"Score": "0",
"body": "Thanks for the tip. I should have looked better. I see no way to move my own question though."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-14T21:22... | [
{
"body": "<p>Well, I tend to agree on at least one count - this one is an eye-sore! Here are my 2 cents on what you need to do:</p>\n\n<p>Break your code into following files:</p>\n\n<ul>\n<li><strong>config.rb</strong>: If you spend some time looking at open-source projects out there, you'd notice that almost... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-14T20:28:49.480",
"Id": "35577",
"Score": "1",
"Tags": [
"ruby",
"beginner"
],
"Title": "Daemon code for updating blog"
} | 35577 |
<p>I write the following version of an if-statement very often. And every time, I hate the way that I make it, but I don't know how to improve it.</p>
<p>For example, I have two <code>ArrayList</code>'s. If one of them is not empty, then I convert it to a <code>StringBuilder</code> and send it per mail. The problem is... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T15:21:25.723",
"Id": "57791",
"Score": "3",
"body": "`array1string` and `array2string` will never be equal to `null`; you're giving them each a value near the start of the code segment. They might result in empty strings, but they'r... | [
{
"body": "<p>Your code can be shortened to:</p>\n\n<pre><code>if(!array1.isEmpty() || !array2.isEmpty()) {\n mail.sendMail(\"Array1: \" + getContent(array1) + \", Array2: \" + getContent(array2));\n}\n</code></pre>\n\n<p>When you have:</p>\n\n<pre><code>String getContent(ArrayList<String> list) {\n ... | {
"AcceptedAnswerId": "35585",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T08:22:50.947",
"Id": "35584",
"Score": "11",
"Tags": [
"java"
],
"Title": "Improve my if-statement to prevent double checks"
} | 35584 |
<p>I am developing a bean class which has multi face properties (name has first name, last name and middle name). The object is going to be used to create an xml file. Please compare my two methods to incorporate the same in my application.</p>
<p>Method 1:</p>
<pre><code>public class SampleVO {
String firstName;
Str... | [] | [
{
"body": "<p>From a performance perspective both approaches are comparable. Yes, method 2 will use some additional memory and require a few more instructions for instantiating your <code>NameVO</code>, but unless you're dealing with millions of objects, I would not worry too much about that. </p>\n\n<p>From a ... | {
"AcceptedAnswerId": "35597",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T10:21:47.197",
"Id": "35591",
"Score": "3",
"Tags": [
"java"
],
"Title": "Java beans performance with object inside object"
} | 35591 |
<p>I have this basic JavaScript that, using a constructor, validates the form where the login fields can't be empty. All this WITHOUT using any JS libraries.</p>
<pre><code>function Validator(txtbox) {
this.txtbox = txtbox;
}
var validator = new Validator([ "username", "password"]);
Validator.prototype.validate ... | [] | [
{
"body": "<p>Your Validator(txtbox) function needs to change it's parameter name. It reads like it takes a single element, but in your case you are sending an array of elements. </p>\n\n<p>All your validation does is just making sure there is something in the textbox, but i could still send a whitespace string... | {
"AcceptedAnswerId": "35599",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T11:19:50.827",
"Id": "35592",
"Score": "3",
"Tags": [
"javascript",
"constructor"
],
"Title": "Login field validator"
} | 35592 |
<p>I was searching for a way to put a <code>Tuple<List></code> into a <code>Tuple<IEnumerable></code>, and I found that Tuple has no covariance.</p>
<ol>
<li><a href="https://stackoverflow.com/questions/2872867/is-c-sharp-4-0-tuple-covariant">Is C# 4.0 Tuple covariant</a></li>
<li><a href="https://stackove... | [] | [
{
"body": "<ol>\n<li><p>I think that non-interface types shouldn't be called <code>ISomething</code>. You could just call the static class <code>Tuple</code> and differentiate it from <code>System.Tuple</code> by using a different namespace. Or you could call the class something like <code>TupleEx</code>, thoug... | {
"AcceptedAnswerId": "35605",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T15:01:06.363",
"Id": "35601",
"Score": "10",
"Tags": [
"c#",
".net",
"covariance"
],
"Title": "A Covariant Tuple"
} | 35601 |
<p>I would like some comments on my code and implementation for this simple piece of jQuery. </p>
<p>Basically it is 2 div boxes #side1 and #side2, in a container div called #frontimage, where #side2 can be swung out by dragging from right to left along #frontimage. </p>
<p>My jQuery code below continuously updates t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T17:39:51.473",
"Id": "57813",
"Score": "1",
"body": "As per the FAQ, please embed the code you'd like reviewed."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T17:44:50.900",
"Id": "57814",
"S... | [
{
"body": "<p><strong>Edit:</strong>\nSomething else that I now noticed while I was reviewing this answer, your if statements could be written differently, it looks like it should be an if/else statement rather than two separate if statements. </p>\n\n<p>We know that if <code>yDegrees</code> is less than <cod... | {
"AcceptedAnswerId": "35621",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T17:39:06.923",
"Id": "35609",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"css",
"beginner",
"jquery-ui"
],
"Title": "Simple jQuery drag event"
} | 35609 |
<p>This is a template for one of our data injection tokens. </p>
<p>When I first looked at the template, it was worse than it is now. I would like some input on this because I think that it can be cleaned up even better.</p>
<p><em>Side note: this is code that we've received from a vendor to use in conjunction with ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T22:28:39.180",
"Id": "57875",
"Score": "0",
"body": "http://programmers.stackexchange.com/questions/27798/what-should-be-the-maximum-length-of-function"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T... | [
{
"body": "<pre><code>string MachineName = System.Environment.MachineName;\n</code></pre>\n\n<p>Why do you have this in a field? When you need to know the machine name, just access the <code>Environment.MachineName</code> property.</p>\n\n<pre><code>string conSource;\n</code></pre>\n\n<p>I don't see any reason ... | {
"AcceptedAnswerId": "35629",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T17:41:23.353",
"Id": "35610",
"Score": "4",
"Tags": [
"c#",
"sql",
"sql-server"
],
"Title": "Injecting data into XML using a dll"
} | 35610 |
<p>I've just completed the WordWrap Kata in the Ruby Kata gem and I'd love some feedback. Thanks!</p>
<p>Here's the Kata:</p>
<pre><code>$kata take word_wrap.rb
WordWrap Kata
Create a "WordWrap" class that is initialized with an integer parameter
- detail: The parameter is the wrap column
- example: Wo... | [] | [
{
"body": "<p>Here are some things you can improve:</p>\n\n<ol>\n<li>Ruby has a method <a href=\"http://ruby-doc.org/core-2.0.0/Enumerable.html#method-i-each_cons\" rel=\"nofollow\"><code>each_cons(n)</code></a>. In your code, you can write <code>word_array.each_cons(2) do |current_word, next_word|</code>.</li>... | {
"AcceptedAnswerId": "35817",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T18:12:14.273",
"Id": "35614",
"Score": "1",
"Tags": [
"ruby",
"rspec"
],
"Title": "Ruby Kata Gem: WordWrap"
} | 35614 |
<p>I am creating a <a href="http://en.wikipedia.org/wiki/Frogger" rel="nofollow">Frogger game</a> in Flash AS3 and just wanted to see if anyone can help me improve it without breaking the game.</p>
<p>The reason I ask for it because I don't have any errors, but I do get over 50 of these:</p>
<blockquote>
<p>Warning... | [] | [
{
"body": "<p>It is just a warning. The source of the warnings is that you redeclare the same variable <code>newTruck:Truck</code> numerous times in your startGame function as well as <code>newLog:LogWood</code>.</p>\n\n<p>It's just a warning, because it is ok to do so. The reason it warns you is that it might ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T19:11:35.400",
"Id": "35622",
"Score": "5",
"Tags": [
"game",
"actionscript-3",
"actionscript"
],
"Title": "Frogger game in Actionscript 3"
} | 35622 |
<p>I had to write my own iterator implementation for my structure which has <code>ArrayList<Vector></code> field. An iterator is supposed to iterate over mentioned <code>List</code>. Any suggestions on improving it, or anything else?</p>
<pre><code>public class ExamplesIterator implements Iterator<Vector> ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T19:32:41.833",
"Id": "57852",
"Score": "3",
"body": "In Java it is illegal to call `remove()` twice in a row, or without calling `next()` first. See this code I have written here for some ideas: https://github.com/hunterhacker/jdom/... | [
{
"body": "<p>I think your implementation is overall very good, two small comments:</p>\n\n<ul>\n<li>Improving readability for return statement in <code>hasNext</code> to <code>return examples.size() != index;</code></li>\n<li>Making the <code>examples</code> field <strong>final</strong>: <code>private final Li... | {
"AcceptedAnswerId": "35627",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T19:25:15.557",
"Id": "35626",
"Score": "7",
"Tags": [
"java",
"iterator"
],
"Title": "Iterator Implementation"
} | 35626 |
<p>I made a simple app that fetches the favourite programming language of a Github user, by simply inserting their username. The full code is uploaded on Github, please feel free to fork it from <a href="https://github.com/elmargasimov/lovelanguage" rel="nofollow">https://github.com/elmargasimov/lovelanguage.</a></p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T18:44:51.487",
"Id": "57978",
"Score": "0",
"body": "Wouldn't `this.$el` be undefined? Shouldn't it be `this.el`?"
}
] | [
{
"body": "<p>Can't say much about the javascript in general as I don't use it but:</p>\n\n<p>Please do not comment every line of code. This means you write your program twice: once in the comments and once in code. They are bound to drift apart and get out of sync and all of a sudden you have code which does t... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T19:37:11.977",
"Id": "35628",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"backbone.js",
"underscore.js"
],
"Title": "Need review and best practice tips for a Backbone pro... | 35628 |
<p>The code below is used to download a JSON data from the web and use the data to fill a spinner. I would like to know if there is better way. Is it wise to move everything from <code>onGetPriceType</code> to the <code>AsyncTask</code>?</p>
<p><strong>Interface</strong></p>
<pre><code>public interface GetBuildTypeIn... | [] | [
{
"body": "<p>I see a very big advantage of your current approach rather than moving the implementation of <code>onGetPriceType</code> to the <code>GetBuildType</code> class <em>(May I suggest changing the name to <code>GetBuildTypeTask</code>?)</em></p>\n\n<ul>\n<li><strong><a href=\"http://en.wikipedia.org/wi... | {
"AcceptedAnswerId": "35642",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T22:16:28.890",
"Id": "35639",
"Score": "2",
"Tags": [
"java",
"android"
],
"Title": "Filling a spinner from JSON web data"
} | 35639 |
<p>This is a trade script for an online virtual currency exchange I have been developing. We have a team of 3, and we all work in our own trees. Since we're all young and not very experienced, we would like some feedback and advice prior to hiring penetration testing.</p>
<pre><code>if (isUserLoggedIn())
{
//get bal... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T02:01:13.017",
"Id": "58235",
"Score": "4",
"body": "[**Don't use `mysql_*` functions in new code!**](http://stackoverflow.com/q/12859942/1667018)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T02:09... | [
{
"body": "<p>There's quite a few things you can fix here. If it is not already in version control, do that <em>first</em>, and then do a commit for every improvement; that way, if anything goes wrong, you can roll back easily. Git is good, but use whatever you know.</p>\n\n<p>Firstly, the business logic and th... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T23:47:58.713",
"Id": "35645",
"Score": "1",
"Tags": [
"php",
"mysql",
"security",
"finance"
],
"Title": "Online virtual currency exchange"
} | 35645 |
<p>This code section is from the main method of my Annual Fuel Use class. The program projects my annual fuel usage based on at least three fill ups of my car.
Here, I am calculating the max and min for distance (which is miles traveled), MPG, and price per gallon. I'd like a general review.</p>
<pre><code>//initiali... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T01:11:21.047",
"Id": "57894",
"Score": "0",
"body": "You forgot to change some of your `>` to `<`. As per [your StackOverflow question](http://stackoverflow.com/questions/20060321/java-erromax-and-min-of-array-object-data/20060373#2... | [
{
"body": "<p>The code violates <a href=\"http://pragprog.com/articles/tell-dont-ask\" rel=\"nofollow\">Tell, Don't Ask</a>:</p>\n\n<blockquote>\n <p>Procedural code gets information then makes decisions. Object-oriented code tells objects to do things.\n ~Alec Sharp</p>\n</blockquote>\n\n<p>Before we get to ... | {
"AcceptedAnswerId": "35652",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T00:13:28.310",
"Id": "35647",
"Score": "7",
"Tags": [
"java",
"object-oriented"
],
"Title": "Calculating min and max with if-statements within a for-loop"
} | 35647 |
<p>My homework is to make a program that calculates the total value of products sold. It works, but I use the <code>if</code> statement because it was asking for the quantity on the output before ending the loop. And for the same reason, I couldn't make the program ask the user again to enter a number from 1 to 5.</p>... | [] | [
{
"body": "<ul>\n<li><p>Prefer not to use single characters as variable names (except for simple loop counters). Saving a few keystrokes is not worth it if your readers cannot understand your code.</p>\n\n<p>Based on the context, it looks like <code>n</code> and <code>q</code> should respectively be named <cod... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T00:43:28.103",
"Id": "35649",
"Score": "2",
"Tags": [
"java",
"homework"
],
"Title": "Calculating a total price by using switch statement and sentinel controlled loop"
} | 35649 |
<p>Below is my implementation for an interview question of printing a binary tree level by level. I've also included some methods for creating a binary tree from a vector in my solution. Please review my solution.</p>
<pre><code>#include <iostream>
#include <unordered_map>
#include <vector>
#include... | [] | [
{
"body": "<ol>\n<li><p>You should only use single letter variable names for loop variables. Parameters and other local variables should have more descriptive names. For example when I first quickly glanced over the code I saw this <code>printBinaryTree (n, m, 0);</code> and thought <em>"Strange, why is he... | {
"AcceptedAnswerId": "35685",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T02:09:59.637",
"Id": "35656",
"Score": "7",
"Tags": [
"c++",
"c++11",
"interview-questions",
"tree"
],
"Title": "Printing out a binary tree level by level"
} | 35656 |
<p>I've written a program all by myself, but I just want to make sure I did it right and if anybody has any suggestions on improving it in any way.</p>
<ol>
<li><p>Define and implement the <code>Die</code> class depicted by the following UML diagram to create an ADT for one die (singular of dice) with faces showing va... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T05:54:49.600",
"Id": "57908",
"Score": "0",
"body": "Where do you call `srand()`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T15:19:50.283",
"Id": "57943",
"Score": "1",
"body": "Prefe... | [
{
"body": "<p>That's not composition. That was inheritance, done poorly. The difference is, would you say that…</p>\n\n<ul>\n<li>A <code>pairOfDice</code> has two dice, but is not a die <em>(composition)</em>, or</li>\n<li>A <code>pairOfDice</code> is a loaded die <em>(inheritance)</em>?</li>\n</ul>\n\n<p>Sin... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T05:40:08.170",
"Id": "35663",
"Score": "1",
"Tags": [
"c++",
"object-oriented",
"random",
"dice"
],
"Title": "Modeling a pair of dice using composition in C++"
} | 35663 |
<p>I've attempted to write a program to find the largest palindrome in a sentence. Spaces are included and characters are case-sensitive. Can you suggest better ways of doing this?</p>
<pre><code>//public static void main(String args[])--
String source = "my malayalam is beautiful";
//Find the the largest palindrom ... | [] | [
{
"body": "<p>There are two things that can be criticized here: Your coding style and your algorithm.</p>\n\n<h3>Code Style</h3>\n\n<ul>\n<li><p>There are unnecessary spaces inside some parens: <code>new StringBuilder( source)</code>, <code>for (…; start++ ){</code>. Make a conscious decision to follow <em>one<... | {
"AcceptedAnswerId": "35710",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T05:55:48.193",
"Id": "35664",
"Score": "2",
"Tags": [
"java",
"strings",
"palindrome"
],
"Title": "Finding largest string palindrome"
} | 35664 |
<p>Please review my <code>FindMovie</code> and <code>AddMovie</code> methods.</p>
<pre><code>public static boolean FindMovie(String movietofind, String[] ArrayMovie) {
movie Movieobject = new movie();
for (String ArrayMovie1 : ArrayMovie) {
if (ArrayMovie1.equals(movietofind)) {
return tru... | [] | [
{
"body": "<p>Quick pointers:</p>\n\n<ol>\n<li>What is the point of <code>movie Movieobject = new movie();</code> ?</li>\n<li>According to Java naming conventions, your use of camel cases is inverted. Variable and method names should start with a lower case, and classes (e.g. <code>movie</code>) should start wi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T06:25:38.213",
"Id": "35665",
"Score": "3",
"Tags": [
"java",
"array"
],
"Title": "A menu option that receives input from users and then performs actions"
} | 35665 |
<p>Here's my code:</p>
<pre><code>let rem x y =
let rec aux acc i n =
if i=n then acc else
if acc+1=y then aux 0 (i+1) n else
aux (acc+1) (i+1) n in
aux 0 0 x;;
</code></pre>
<p>I'm just learning OCaml and I wonder:</p>
<ol>
<li>Is this tail recursive? </li>
<li>Is there a more efficient algorithm, i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T08:27:55.263",
"Id": "57915",
"Score": "0",
"body": "I do not clearly understand what are you trying to achieve. If you want to implement `mod` function using sequence of additions your solution can be cheaper for when `x div y` is ... | [
{
"body": "<p>I don't know OCaml, but I know enough similar languages that I think I can read that well enough to answer. Still, take this with a grain of salt. </p>\n\n<p>That is tail recursive. You either return a value, or return the result of a recursive call that depends only on its input parameters tha... | {
"AcceptedAnswerId": "35672",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T23:39:19.763",
"Id": "35666",
"Score": "6",
"Tags": [
"recursion",
"ocaml"
],
"Title": "I've written remainder(x,y) in OCaml. Is there more efficient than O(n)?"
} | 35666 |
<p>I've created a module that implements a basic "Document at a time" algorithm for inverted index querying (<a href="http://fontoura.org/papers/vldb2011.pdf">more background here</a>). There are many algorithm improvements possible, but I'm now interested in feedback on the structure of the Erlang code, specifically:<... | [] | [
{
"body": "<p>I'm not sure writing explicit type specifications is idiomatic Erlang. In all programming languages that support inference, type specifications are used in specific cases, eg. when you want to restrict the possibles types, but not by default. Even if the <a href=\"http://www.erlang.org/doc/referen... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T08:18:43.417",
"Id": "35679",
"Score": "7",
"Tags": [
"erlang"
],
"Title": "Improving clarity and style of this \"Document at a time\" algorithm"
} | 35679 |
<p>I am relatively new to Java, but have been reading up on how to improve the quality of my code.</p>
<p>I am writing a system where I take in a series of points from a file with x and y co-ordinates and by checking slopes relative to each other, am calculating and drawing a line if there is four or more co-linear po... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T16:46:21.823",
"Id": "57955",
"Score": "1",
"body": "You should give your question a more descriptive title - even simply that it looks for lines in a set of points."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate"... | [
{
"body": "<p>Several comments</p>\n\n<p>1) according to java coding conventions we write <code>{</code> at the same line where operator is, i.e.</p>\n\n<pre><code>if () {\n}\n</code></pre>\n\n<p>and not </p>\n\n<pre><code>if () \n{\n{\n</code></pre>\n\n<p>2) If you do not have special reason to use primitive w... | {
"AcceptedAnswerId": "35702",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T16:36:57.283",
"Id": "35693",
"Score": "3",
"Tags": [
"java",
"beginner",
"computational-geometry"
],
"Title": "Refactor code to find four co-linear points"
} | 35693 |
<p>I have a tree of objects.</p>
<pre><code>Object id:0 Object type:0
Object id:1 Object type:0
Object id:3 Object type:0
Object id:2 Object type:0
Object id:4 Object type:0
Object id:5 Object type:0
</code></pre>
<p>For each object I have a method that returns its "index" in the tree down to the root... | [] | [
{
"body": "<p>I came up with a cleaner looking solution:</p>\n\n<pre><code>bool isVisibleTo(Node * accessor) {\n Node * node = accessor;\n while (node) {\n if (node == this) return true;\n if (node->_parent) {\n uint i = node->_parent->_children.indexOf(node);\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T16:37:16.573",
"Id": "35694",
"Score": "1",
"Tags": [
"c++",
"algorithm",
"scope"
],
"Title": "Order and visibility tracking algorithm (e.g. scope visibility)"
} | 35694 |
<p>This method finds the smallest positive number that is evenly divisible by all numbers from 1 to 20.</p>
<p>I am wondering if there is a better way to test if all iterations of a <code>for</code> loop completed successfully. When I put the found boolean outside the <code>for</code> loop, it was terminating my <code... | [] | [
{
"body": "<p>There are two parts to my initial assessment of your code.</p>\n\n<p>Firstly, often the 'best' way to solve a problem where you are tempted to have a <code>found = true</code> type situation is to call a seperate method for that part of the work, and to simply 'return value' when you find the valu... | {
"AcceptedAnswerId": "35705",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T17:15:33.967",
"Id": "35699",
"Score": "2",
"Tags": [
"java",
"interval"
],
"Title": "Finding the smallest positive number evenly divisible by a range of numbers"
} | 35699 |
<p>This tag should not be confused with <a href="/questions/tagged/template-meta-programming" class="post-tag" title="show questions tagged 'template-meta-programming'" rel="tag">template-meta-programming</a>.</p>
<p>Templates are pieces of code that are written with the intention of being used over and over a... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T19:14:26.150",
"Id": "35712",
"Score": "0",
"Tags": null,
"Title": null
} | 35712 |
a design structure for creating several things that are almost identical but need different values. Not template-meta-programming. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T19:14:26.150",
"Id": "35713",
"Score": "0",
"Tags": null,
"Title": null
} | 35713 |
<p>I've written this simple JavaScript application for a homework assignment and I've received feedback saying it could be written better.</p>
<p>Can I get some feedback on how to write this differently? It works for me and returns the results I need, but I would like some more specific feedback. It was meant to be s... | [] | [
{
"body": "<p>Looks good to me. You could cache the ul:</p>\n\n<pre><code>var repoList = $(\"<ul>\").appendTo('#results');\n</code></pre>\n\n<p>So you don´t have to query the dom again when appending the list items.\nAlso it is better to build the list items in memory and only append the complete list to ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T19:26:09.760",
"Id": "35714",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"json",
"dom"
],
"Title": "JavaScript app to search GitHub using JSON API"
} | 35714 |
<p>I'm creating a chess engine and I'm currently in the stage of adding validation. I'm starting off with the major validationrule: checking if a piece can move to the given target destination.</p>
<p>I have setup a system that allows me to very fluently define how a piece can move and validation is done on these rule... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T22:25:07.380",
"Id": "58022",
"Score": "0",
"body": "I have restructured the code a little. Since the horizontal and diagonal moves will not be influenced by black or white I have moved them outside the loop. The code is already eas... | [
{
"body": "<p>There are 33 if statements in your validation, all highly nested. There are lots of ways you could deal with that; what immediately comes to mind are helper functions. Don't be afraid to use helper functions, especially if you can give them a good, descriptive name. </p>\n\n<p>For instance, you... | {
"AcceptedAnswerId": "35728",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T20:45:09.633",
"Id": "35718",
"Score": "4",
"Tags": [
"c#"
],
"Title": "Rewriting an extensive validation method with duplication of code in different circumstances"
} | 35718 |
<p>I am having an issue with the following query returning results a bit too slow and I suspect I am missing something basic. My initial guess is the 'CASE' statement is taking too long to process its result on the underlying data. But it could be something in the derived tables as well. </p>
<p>The question is, ho... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T21:11:09.967",
"Id": "58008",
"Score": "0",
"body": "Have you indexed your tables properly?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T21:11:52.710",
"Id": "58010",
"Score": "2",
"bod... | [
{
"body": "<p>You need to pull some stuff out of your nested queries.</p>\n\n<p>You have aggregate functions inside of a Nested Select Statement for Join Tables. \nThat should be a temp table or a table variable, at the least.</p>\n\n<pre><code>select\n order_no,\n SUM(ext_price_calc) as ext_price_calc\nf... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T21:02:53.973",
"Id": "35721",
"Score": "2",
"Tags": [
"optimization",
"sql",
"sql-server",
"t-sql"
],
"Title": "Query too slow - Optimization"
} | 35721 |
<p>I'm working on implementing the stochastic gradient descent algorithm for recommender systems (see Funk) using sparse matrices with Scipy.</p>
<p>This is how a first basic implementation looks like:</p>
<pre><code>N = self.model.shape[0] #no of users
M = self.model.shape[1] #no of items
self.p = np.random.rand(N, ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2018-11-15T19:52:46.583",
"Id": "401038",
"Score": "0",
"body": "Which matrix is the scipy sparse matrix?"
}
] | [
{
"body": "<p>There may be other optimizations available, but this one alone should go a long way...</p>\n\n<p>When you do <code>e = self.model - np.dot(self.p,self.q.T)</code>, the resulting <code>e</code> is a dense matrix the same size as your <code>model</code>. You later only use <code>e[u, i]</code> in yo... | {
"AcceptedAnswerId": "35731",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T22:32:22.200",
"Id": "35727",
"Score": "4",
"Tags": [
"python",
"performance",
"matrix"
],
"Title": "Optimize Scipy Sparse Matrix Factorization code for SGD"
} | 35727 |
<p>I am trying to design an exception hierarchy for logging errors.<br>
These logs will be used only by developers and not by users.<br>
This is a base class that I came up with. </p>
<pre><code>#ifndef TSTRING_TYPEDEF
#define TSTRING_TYPEDEF
typedef std::basic_string <TCHAR> tstring ;
#endif
struct BaseEx... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T00:01:14.703",
"Id": "58035",
"Score": "1",
"body": "Read this: http://programmers.stackexchange.com/a/118187/12917"
}
] | [
{
"body": "<blockquote>\n <p>1) I've been searching online for exception class design, and haven't found anything like this. This worries me. Is there something wrong with designing exceptions this way?</p>\n</blockquote>\n\n<p>Here is my opinion: <a href=\"https://softwareengineering.stackexchange.com/a/11818... | {
"AcceptedAnswerId": "35732",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T23:42:39.300",
"Id": "35730",
"Score": "3",
"Tags": [
"c++",
"exception-handling",
"windows"
],
"Title": "Exception Handling Design"
} | 35730 |
<p>Basically, find x and y given the product = xy and sum = x + y. I would like review on optimization, clean code, and complexity. It looks like O(1), but the <code>while</code> loop makes me wonder if it's something different.</p>
<pre><code>/**
* x will always be less than or equal to y.
*/
final class Variable... | [] | [
{
"body": "<p>Before we start guessing, lets solve the equations properly. We can substitute the equations so that we get <code>product = x · (sum - x) = -x² + sum·x ⇔ 0 = x² - sum·x + product</code>, with <code>y = sum - x</code>.</p>\n\n<p>The equation can be solved by <code>x = sum/2 ± √(sum²/4 - product)</c... | {
"AcceptedAnswerId": "35749",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T06:25:57.410",
"Id": "35744",
"Score": "5",
"Tags": [
"java",
"optimization",
"algorithm",
"mathematics"
],
"Title": "Given sum and product, find the two variables"
} | 35744 |
<p><a href="http://lesscss.org/" rel="nofollow">LESS</a> is a dynamic stylesheet language that extends <a href="/questions/tagged/css" class="post-tag" title="show questions tagged 'css'" rel="tag">css</a> with dynamic behavior such as variables, mixins, operations and functions.</p>
<p>LESS runs on both the s... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T08:53:37.660",
"Id": "35747",
"Score": "0",
"Tags": null,
"Title": null
} | 35747 |
LESS is a dynamic stylesheet language that extends CSS with dynamic behavior such as variables, mixins, operations and functions. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T08:53:37.660",
"Id": "35748",
"Score": "0",
"Tags": null,
"Title": null
} | 35748 |
<p>I just wrote the code to evaluate a postfix expression and would like it if someone reviews it for me, it works perfectly fine but I'm having trouble adding the character "=" at the end.</p>
<pre><code> public static int evalPostfix(String exp) {
int res = 0;
myStack list = new myStack();
int n1; ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T12:54:15.223",
"Id": "58100",
"Score": "1",
"body": "We are not here to *fix* your code. And it is also very unclear what you mean by \"adding the character `=` at the end\"."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Crea... | [
{
"body": "<p><strong>Conventions</strong></p>\n\n<p>According to coding conventions, Java class names should start with an uppercase letter. <code>myStack</code> should be <code>MyStack</code>.</p>\n\n<p><strong>Variable names</strong></p>\n\n<p>Whenever you have a comment after declaring a variable, <em>renam... | {
"AcceptedAnswerId": "35752",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T12:41:26.203",
"Id": "35750",
"Score": "2",
"Tags": [
"java",
"stack",
"math-expression-eval"
],
"Title": "Postfix evaluation using a stack"
} | 35750 |
<p>I have created a state diagram to show the different transitions and states. I could not find many examples of the state pattern in C, so I have taken an example from a Java state pattern and tried to convert it to C.</p>
<p>Is there a way to create the state pattern in C? I'd like some tips or tricks in doing thi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T10:55:29.287",
"Id": "58108",
"Score": "1",
"body": "OO design patterns in C? Of course you *can* do it, but ick!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-04-23T03:55:04.557",
"Id": "158598",
... | [
{
"body": "<p>Looking at the <a href=\"http://en.wikipedia.org/wiki/State_pattern\">State Pattern on Wikipedia</a> I'd say it's more normal to replace the entire function table at once, rather than write individual function pointers.</p>\n\n<p>To this end, I would do this:</p>\n\n<pre><code>struct watch_state {... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T05:20:24.880",
"Id": "35754",
"Score": "10",
"Tags": [
"c",
"design-patterns",
"state"
],
"Title": "Developing a better state pattern in C"
} | 35754 |
<p>I am slowly learning to master JavaScript and particularly the art of self-executing/invoking functions. I have developed a simple JavaScript plugin and I think I have followed the correct standards.</p>
<p>It is pretty basic in what it does, it is to store information on a oData BATCH request, which provides funct... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T14:28:28.857",
"Id": "58133",
"Score": "1",
"body": "your aside question should be posted on [StackOverflow.com](http://stackoverflow.com). the rest of the question seems to be on topic"
}
] | [
{
"body": "<blockquote>\n <p>Is there anything I'm doing stupidly bad here?</p>\n</blockquote>\n\n<p>Nothing I can see. It works and it seems well written. However, you don't appear to be using BatchCacheRequest?</p>\n\n<blockquote>\n <p>how would I reference functions in b, inside a separate function in b?</... | {
"AcceptedAnswerId": "35767",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T14:23:07.660",
"Id": "35756",
"Score": "4",
"Tags": [
"javascript",
"library"
],
"Title": "Developing a JavaScript library"
} | 35756 |
<p>The method <code>foo</code> gets a <strong>sorted list with different numbers</strong> as a parameter and returns the count of all the occurrences such that: <code>i == list[i]</code> (where <code>i</code> is the index <code>0 <= i <= len(list)</code>). </p>
<pre><code>def foo_helper(lst, start, end):
i... | [] | [
{
"body": "<p>I don't know enough Python to comment on your code, but returning a count of where <code>array[index] == index</code>, should be O(n). And as I said, I dunno Python, but it looks like you are making this a lot more complicated than it is. It could be as simple as</p>\n\n<pre><code>function foo(arr... | {
"AcceptedAnswerId": "35812",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T15:05:04.517",
"Id": "35760",
"Score": "3",
"Tags": [
"python",
"array",
"recursion",
"binary-search",
"complexity"
],
"Title": "count all array[index] == index occurre... | 35760 |
<p>What I'm basically wondering is if there's anything that is possible to improve in this C++ code:</p>
<pre><code>#include <cstddef>
#include <string>
bool is_palindromic(std::string s)
{
std::size_t i = 0;
std::size_t j = s.length() - 1;
while (i < j) {
if (s[i++] != s[j--]) {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T17:08:57.570",
"Id": "58160",
"Score": "2",
"body": "Yep. Try a for loop. Learn how to use references. Consider accidental mutation."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T22:13:17.967",
... | [
{
"body": "<p>First of all, you should pass the <code>std::string</code> by const reference and not by value, therefore, replace <code>std::string s</code> by <code>const std::string& s</code>, otherwise you will make a whole copy of the string everytime you invoke the function.</p>\n\n<p>Also, you program ... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T17:02:20.787",
"Id": "35764",
"Score": "12",
"Tags": [
"c++",
"c++11",
"palindrome"
],
"Title": "Checking for a palindrome"
} | 35764 |
<p>I created this module, and I'm wondering if I did a good job. How would an experienced JavaScript developer improve this simple slider module further? Like, let's say that you want to use this module on 3 sliders on the same page.</p>
<p><a href="http://jsfiddle.net/W9rEu" rel="nofollow">Here</a> is a jsFiddle.</p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T18:08:53.740",
"Id": "58170",
"Score": "2",
"body": "your comments and white space are very distracting."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T18:52:41.083",
"Id": "58176",
"Score": ... | [
{
"body": "<h1><code>document.querySelector</code></h1>\n<p>While it is a great function to use, you are using in the wrong situations.</p>\n<p>For every time you use it, you are getting an array of elements with a class that you passed in to the function. Why not just use <code>document.getElementsByClassName<... | {
"AcceptedAnswerId": "84436",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T17:10:52.397",
"Id": "35768",
"Score": "4",
"Tags": [
"javascript",
"modules"
],
"Title": "Slider module and extending it further"
} | 35768 |
<p>My question is to find the longest DNA sub-sequence that appears at least twice. The input is only one DNA string, NOT TWO strings as other LCS programs.</p>
<p>I have done my 4th program and it seems to be working and efficient (computes 10k strings in 4 seconds). But I don't know if this is 100 % correct. This is... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T20:19:07.020",
"Id": "58183",
"Score": "1",
"body": "What is the expected bahaviour with overlaps... i.e. is the longest sequence in this string `ababa` the value `aba` or just `ab` or `ba` ?"
},
{
"ContentLicense": "CC BY-S... | [
{
"body": "<p>There are a number of items which concern me in your code.</p>\n\n<p>First up, when I pull your code in to eclipse, it immediately gives me lots of warnings.... which are easy to fix, but make the code cumbersome. Also there's a couple of other items:</p>\n\n<ol>\n<li><code>Scanner sc ....</code> ... | {
"AcceptedAnswerId": "35780",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T20:06:15.287",
"Id": "35776",
"Score": "2",
"Tags": [
"java",
"strings",
"bioinformatics"
],
"Title": "Longest DNA sequence that appears at least twice (only one DNA string as ... | 35776 |
<p>I have written some example code to test object inheritance, but I'm not sure if it's really the best way for an object to inherit another's functions (like Java's <code>extends</code>).</p>
<pre><code>function Class() {
console.log("Created class"); // The base class
}
Class.prototype.test = function() {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T21:07:42.267",
"Id": "58186",
"Score": "0",
"body": "Not to take away from the question at hand, but more of an aside: [MooTools](http://mootools.net/) ([Wikipedia Entry](http://en.wikipedia.org/wiki/MooTools)) facilitates OOP javas... | [
{
"body": "<p>my first impression is that this is a good design and it functions well. I don't know much about the way that Java does Extension, but your code looks well planned and looks like you know the basics of Extension. when you put this into practice on something bigger you should post it as an additio... | {
"AcceptedAnswerId": "36511",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T20:07:03.883",
"Id": "35777",
"Score": "6",
"Tags": [
"javascript",
"object-oriented",
"inheritance",
"extension-methods"
],
"Title": "Object inheritance"
} | 35777 |
<p>I have an image upload form with which I call multiple functions before uploading the file such as checking the size and dimensions, and that it is in a valid image. The code works, but calling the functions and dealing with the results seems quite cumbersome and complex.</p>
<p>Is there a tidier way of structuring... | [] | [
{
"body": "<p>Yes, there's room for a lot of improvement here!</p>\n\n<p>First of all, you can \"break early\" to avoid excessive indentation. Since <code>die</code> terminates the script, you can check if the file is <strong>not</strong> valid.</p>\n\n<p>Secondly, instead of <code>echo</code>ing first and <cod... | {
"AcceptedAnswerId": "35787",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T21:58:40.830",
"Id": "35782",
"Score": "2",
"Tags": [
"php"
],
"Title": "Calling multiple functions in image upload form"
} | 35782 |
<p>I have this jQuery function I wrote up to set the size of an input based off of its data. In this case I have already figured out the widths for each character based off of a 12px font size for Helvetica.</p>
<p>It's not super flexible or anything, but I would like to know if there is any good way to take what I ha... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T22:15:42.277",
"Id": "58201",
"Score": "1",
"body": "I'd suggest an array of widths so you can just get the charcode of the character and look it's width up in the array. This would be a lot faster and more elegant than the giant `... | [
{
"body": "<p>Here's how you could use a table array for the widths. I didn't fill in all the character widths (I just did lowercase) because it's tedious to build, but you can extend it to contain all the typeable characters that you want to support. I also made it a jQuery method that you can call like this... | {
"AcceptedAnswerId": "35792",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T22:13:14.183",
"Id": "35784",
"Score": "5",
"Tags": [
"javascript",
"jquery"
],
"Title": "Input text sizing function"
} | 35784 |
<p>I'm fairly new to Python and am going to be parsing hundreds of thousands of names eventually. What I wanted to do was take individual CSV files, and create new CSV files with only the info I wanted. Then to take the whole lot and combine it into one big file.</p>
<p>This code does that, but I feel I have typed w... | [] | [
{
"body": "<p>What is the purpose of those intermediate \"output\" csv files with a single column of name?</p>\n\n<p>I don't see the purpose of it. So I removed it:</p>\n\n<pre><code>import csv\n\nFILES = [\n 'dictionary/first_names.csv',\n 'dictionary/last_names.csv',\n 'dictionary/last_name_prefixes.... | {
"AcceptedAnswerId": "35794",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-20T22:47:48.260",
"Id": "35789",
"Score": "1",
"Tags": [
"python",
"optimization",
"design-patterns",
"csv"
],
"Title": "CSV file cleanup"
} | 35789 |
<pre><code>public static StringBuffer infixToPostfix(StringBuffer infix) throws InvalidCharacterException
{
StringBuffer postfix = new StringBuffer("");
Stack<String> myStack = new Stack<String>();
myStack.push("(");
infix.append(')');
for(int i = 0; i ... | [] | [
{
"body": "<p>When doing String comparisons, *<em>DO NOT USE <code>==</code> *</em></p>\n\n<p>Change your lines:</p>\n\n<pre><code>if(poppedOp == \"+\") {\n postfix.append(\"+ \");\n}\n.....\n</code></pre>\n\n<p>to be</p>\n\n<pre><code>if(\"+\".equals(poppedOp)) {\n postfix.append(\"+ \");\n}\n.....\n</... | {
"AcceptedAnswerId": "35801",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T03:31:55.240",
"Id": "35798",
"Score": "-6",
"Tags": [
"java",
"strings",
"stack",
"converting"
],
"Title": "Code review: infix to postfix converter"
} | 35798 |
<p>Here is a simple webpage that I wrote to test HTML code in real time as typed, what are some ways that I can Improve my code? part of the code is reused from a previous project, I believe that it may now be causing problems. I am still learning about CCS and in places i used both the HTML width tag and the CCS prope... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T04:17:54.680",
"Id": "58263",
"Score": "0",
"body": "I have retracted my close vote, and upvoted - I'm no javascript writer but this looks like pretty trivial code, I'm sure you'll get answers pretty soon. Good luck!"
},
{
"... | [
{
"body": "<p>Try rewriting your script with an addEventListener instead of an onChange method.</p>\n\n<p>However, keep in mind that an addEventListener is not compatible with IE lower then IE9. So don't use this yet in live sites.</p>\n\n<ul>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Even... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T03:33:58.230",
"Id": "35799",
"Score": "4",
"Tags": [
"javascript",
"html",
"css"
],
"Title": "Real time HTML tester"
} | 35799 |
<p>I've recently been learning about design patterns. Now I decided that I know enough to be able to refactor my inventory code. The question solely exist so I could show my fellow programmers the kind of destructive and lame mindset you'd get out of OOP, SOLID etc. <code>Adder.Add<CoolAdd>(new CoolAddArgs(1, 2, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T09:59:32.550",
"Id": "58303",
"Score": "0",
"body": "Since you acknowledged that you are not sure about **D**, you should '?' in the comparison table."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T1... | [
{
"body": "<p>I think I came up with a way to halve dependencies, and reduce the amount of code required to add items to just:</p>\n\n<pre><code>AddItems(new NormalAdd(1, 2, 3, etc));\n</code></pre>\n\n<p>I don't know how I missed this, but the key is to leave the <code>Implement</code> method abstract in the b... | {
"AcceptedAnswerId": "36149",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T06:40:02.030",
"Id": "35807",
"Score": "8",
"Tags": [
"c#",
"design-patterns",
"comparative-review"
],
"Title": "Comparison between two design battle approaches"
} | 35807 |
<p>I've written a small function for solving simple quadratic equations:</p>
<pre><code>class EquationSolver
def solve(x, *args)
args.reverse.map.with_index { |coefficient, index| coefficient * x ** index }.reduce { |result, element| result + element }
end
end
</code></pre>
<p>To calculate <code>f(3)</code> ... | [] | [
{
"body": "<p>Yes, there is a more elegant version. Here it is:</p>\n\n<pre><code>class EquationSolver\n def solve(x, *args)\n args.reverse.each_with_index.reduce(0) { |result, (coefficient, index)| result + coefficient * x ** index }\n end\nend\n</code></pre>\n\n<p>It's possible to do this because iterato... | {
"AcceptedAnswerId": "35825",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T07:47:25.183",
"Id": "35810",
"Score": "3",
"Tags": [
"ruby",
"mathematics"
],
"Title": "Polynomial equation solver in Ruby"
} | 35810 |
<p>I'm learning Python, and found a fun little video on YouTube called "Learn Python through public data hacking". In essence it uses the CTA unofficial API to do some parsing of XML data. In taking things further than inline code, I'm chunking behaviors into modules and classes to further understand how Python works... | [] | [
{
"body": "<p>Makes sense to me. A couple small things:</p>\n\n<p><code>lambda f: float(f)</code> should be equivalent to just <code>float</code> if I'm not mistaken. You can simplify the loop a bit too since you're not actually using the dictionary keys.</p>\n\n<pre><code>types = [\n (r'(regex)', float),\n (... | {
"AcceptedAnswerId": "35814",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T07:57:42.127",
"Id": "35813",
"Score": "3",
"Tags": [
"python",
"regex",
"casting"
],
"Title": "Limited typecasting with regex"
} | 35813 |
<p>Is there a way to make this smarter?</p>
<p>Here is the complete code <a href="http://jsbin.com/uzuJUSE/5/edit?html,js,output" rel="nofollow" title="jsbin link">jsbin link</a></p>
<p>the code needs to filter the table,
and show in the parameters list, only the filters that remain in the table,
and with the number ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T11:48:24.067",
"Id": "58561",
"Score": "1",
"body": "Already quite smarter than a lot of JS I see these days, if you ask me :) A lead for improvement would be to separate more clearly presentation from business logic (too much data ... | [
{
"body": "<p>Overall I think it works pretty well. There are just a few minor issues with the existing implementation that I could highlight : </p>\n\n<p><strong>Ensuring State \"Safety\"</strong></p>\n\n<p>On first render filter items have a <code>data-count</code> value of <code>0</code>, which only gets up... | {
"AcceptedAnswerId": "36290",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T09:11:08.477",
"Id": "35818",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "code review: filter table with filter parameters"
} | 35818 |
<p>I have a fairly ugly controller method I would like to refactor / extract. I can only test this in an integration-type test which kind of signals a code smell.</p>
<p>The method processes the form and needs to do one of 5 things, depending on which button was pressed</p>
<ol>
<li>if submitted and valid (button 1) ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T04:49:39.930",
"Id": "58525",
"Score": "0",
"body": "This question appears to be off-topic because it seems like you are asking us how to write code for you, or how to do something other than increase readability, performance, speed... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T10:34:09.603",
"Id": "35824",
"Score": "1",
"Tags": [
"php",
"mvc",
"symfony2"
],
"Title": "Form-processing controller action"
} | 35824 |
<p>The class takes an input of a game-id from the ESPN soccer website. The code then has to grab the commentary, process that and also grab the player names/ids and create a small dictionary of those.</p>
<p>I understand the premise of OOP when shown in basic examples but I cannot get my head around using it in actual... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T13:36:45.793",
"Id": "58321",
"Score": "0",
"body": "It would help to fix the indentation on the code sample. Paste the code, highlight it all, and hit the \"Code Sample\" button."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<ul>\n<li>There are no docstrings, so a user of your class is left wondering which methods could be useful to call. In fact, after studying the code, it looks like all the methods are meant to be called by <code>__init__</code>, in a specific order. Makes me wonder if this should be a class at all.</... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T13:05:43.640",
"Id": "35830",
"Score": "3",
"Tags": [
"python",
"scrapy",
"xpath"
],
"Title": "Using Scrapy/Xpath to scrape ESPN for football (soccer) commentaries"
} | 35830 |
<p>I am just trying to convert each list of values to String by index one by one. My Code is running fine. But I am thinking that I can write better code than this. I Need your good coding possibilities here to convert from list to String.</p>
<p>I am using the code below to convert:</p>
<pre><code>CarComment[] list ... | [] | [
{
"body": "<p>I have modified the loop. Here is the code --</p>\n\n<pre><code>for (CarComment carComment : list) {\n String text = carComment.getText();\n if (isEmpty(text)) { continue; }\n\n JSONArray commObj = new JSONArray();\n commObj.put(text.replaceAll(\"<\", \"&lt;\"));\n\n comments.put(commO... | {
"AcceptedAnswerId": "35838",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T14:23:16.433",
"Id": "35835",
"Score": "2",
"Tags": [
"java",
"strings",
"collections"
],
"Title": "Assigning list index values to String"
} | 35835 |
<p>I've a requirement to find sum of an attribute of each JSON row and then add another attribute to show percentage of corresponding attribute.
The JSON is as follows -</p>
<pre><code>[
{"value":150, ...},
{"value":125, ...},
{"value":100, ...},
{"value":60, ...},
{"value":30, ...}
]
</code></pre>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T06:48:40.213",
"Id": "58348",
"Score": "0",
"body": "Since you need totalValue to compute the label, it seems like it might be hard to stick one loops."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T... | [
{
"body": "<p>No, <code>totatVal</code> won't be a <code>totalVal</code> until you loop through all the rows to find it.\nIt might be solved by a single loop with some fancy standard functions but at the end it will come down to 2 loops. </p>\n\n<p>It's pure math - you need to count your total value first in or... | {
"AcceptedAnswerId": "35843",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T06:44:44.183",
"Id": "35842",
"Score": "4",
"Tags": [
"javascript",
"jquery"
],
"Title": "Can only one loop be used to calculate percentage?"
} | 35842 |
<p>Can someone help me make this code more professional? I'm trying my best to find something similar, but I wasn't successful.</p>
<p>I want to avoid the repeat of the code for every single value and also I can't find a solution to avoid select. I only get it run when I repeat the code and count <code>rng</code>, <c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T15:24:37.400",
"Id": "58359",
"Score": "3",
"body": "sounds like you need to create a function or two."
}
] | [
{
"body": "<p>Doing <kbd>Copy</kbd>+<kbd>Paste</kbd> in your IDE should raise a big red flag and then there should be a neural inhibitor that prevents your left hand from doing it, causing your right hand to move your mouse further down the module and then start typing <code>Private Function...</code></p>\n\n<p... | {
"AcceptedAnswerId": "35847",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T15:15:38.243",
"Id": "35844",
"Score": "14",
"Tags": [
"vba",
"excel"
],
"Title": "Avoiding repeated code in worksheet"
} | 35844 |
<p>I'm fetching some values from the memory. I would like to create some custom events that I can listen to for each value. Since there are no existing events regarding memory changes, I've decided to go with a polling solution. I'm restarting the timer below manually just to make certain the work is finished.</p>
<p>... | [] | [
{
"body": "<ol>\n<li><p>Having a private property is quite unusual. It's especially weird since you only use it once in <code>TimerElapsed</code>. I would probably just use the field directly and call <code>RaisePropertyChanged()</code> manually when necessary.</p></li>\n<li><p>Why is the initial value passed i... | {
"AcceptedAnswerId": "35869",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T15:23:57.287",
"Id": "35845",
"Score": "5",
"Tags": [
"c#",
"multithreading",
"timer"
],
"Title": "Listening for values changed by the memory"
} | 35845 |
<p>Here's some code of mine that I don't like (this was my very first attempt at DI/IoC!). It's a small C# application that runs scheduled on one of our servers and is responsible for fetching the latest version of a VB6 codebase, compiling it and packaging an installer for it.</p>
<p>There's an <code>Execute</code> m... | [] | [
{
"body": "<p>I would create a helper method for returning the value you want to give to <code>OnExecutedCompleted</code>, and also store the value of <code>Properties.Settings.Default</code> in a variable.</p>\n\n<pre><code>bool TodoRenameMeToWhatYouThinkSuitsYou()\n{\n SomeType settings = Properties.Settin... | {
"AcceptedAnswerId": "35863",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T15:53:27.107",
"Id": "35849",
"Score": "10",
"Tags": [
"c#"
],
"Title": "Multiple return statements smells like what?"
} | 35849 |
<p>Timers can be used in a variety of ways.</p>
<p>Software timers as described on <a href="http://en.wikipedia.org/wiki/Timer#Software_timers" rel="nofollow">Wikipedia</a>:</p>
<blockquote>
<p>As the number of hardware timers in a computer system or processor is
finite and limited, operating systems and embedded... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T16:22:59.840",
"Id": "35850",
"Score": "0",
"Tags": null,
"Title": null
} | 35850 |
This tag is for questions about using timers in code to make things happen in a certain order or for gathering amount of time elapsed. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T16:22:59.840",
"Id": "35851",
"Score": "0",
"Tags": null,
"Title": null
} | 35851 |
<p>This is a stored procedure that takes 5-30+ minutes to run depending on the parameter they select.</p>
<p>It also has a nasty side effect of clogging down our SQL Server.</p>
<pre><code>SET NOCOUNT ON;
DECLARE @clients TABLE (customer varchar(200))
IF (NULLIF(@startdate, '') IS NULL)
set @startda... | [] | [
{
"body": "<p>performance review of SQL code without knowing the cardinality of the data, and the indexes used, is a real challenge, but, I would recommend that you try two things:</p>\n\n<p>first, try make <code>@customer</code> table a top-level item in the Join:</p>\n\n<pre><code>from @customer csub\ninner j... | {
"AcceptedAnswerId": "35862",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T17:21:51.867",
"Id": "35858",
"Score": "1",
"Tags": [
"sql",
"sql-server",
"time-limit-exceeded"
],
"Title": "Stored procedure to run a credit-card debt query"
} | 35858 |
<blockquote>
<p>“There are only two hard things in Computer Science: cache
invalidation and naming things.” -- Phil Karlton</p>
</blockquote>
<p>That being said, I created this SimpleCache class which I intend to use to cache database queries and results over a relatively short period of time. </p>
<p>I'm just as... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T18:14:26.217",
"Id": "58429",
"Score": "4",
"body": "Use the built in [MemoryCache](http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache%28v=vs.110%29.aspx) class!"
}
] | [
{
"body": "<ol>\n<li>You have a static dictionary as backing store which means that all cache instances share it. Not saying that this is wrong and it might be intended but you should be aware of it.</li>\n<li>Your cache apparently is not thread-safe. You need to protect access to the dictionary with locks or i... | {
"AcceptedAnswerId": "35871",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T18:10:18.663",
"Id": "35864",
"Score": "7",
"Tags": [
"c#",
"database",
"cache"
],
"Title": "A Simple Cache class"
} | 35864 |
<p>For code that aims to solve problems in all branches of mathematics. Related tags include:</p>
<ul>
<li><a href="/questions/tagged/algorithm" class="post-tag" title="show questions tagged 'algorithm'" rel="tag">algorithm</a></li>
<li><a href="/questions/tagged/primes" class="post-tag" title="show questions... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T18:23:13.783",
"Id": "35867",
"Score": "0",
"Tags": null,
"Title": null
} | 35867 |
For code that aims to solve problems in all branches of mathematics. (Please do NOT use this tag for incidental trivial use of arithmetic. A simple test to apply is: would an amateur or professional mathematician take an interest in the question?) | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T18:23:13.783",
"Id": "35868",
"Score": "0",
"Tags": null,
"Title": null
} | 35868 |
<p>In most computer languages, the implementation of floating-point arithmetic is based on the <a href="http://en.wikipedia.org/wiki/IEEE_floating_point" rel="nofollow">IEEE 754 standard</a>. The standard specifies four formats, with the 32-bit ("single precision") and 64-bit ("double precision") formats being most co... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T19:05:32.050",
"Id": "35873",
"Score": "0",
"Tags": null,
"Title": null
} | 35873 |
For questions with concerns specifically related to the usage of floating point, such as accuracy and precision of calculations, handling of 0, infinity, and over/underflow, input/output, and binary representation. Not for code that casually happens to use floating point. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T19:05:32.050",
"Id": "35874",
"Score": "0",
"Tags": null,
"Title": null
} | 35874 |
<p><strong>Background</strong></p>
<p>Today at work, I had to bring a component that used to load CSV data into MySQL, and perform calculations as result of SQL queries. I was tasked with replicating that in a programming language.</p>
<p>The general example is like:</p>
<p>There's a 2D array (a table) with columns ... | [] | [
{
"body": "<p>Consider loading the 2D list into an in-memory SQLite database (aka. <code>sqlite3</code> package) created on-the-fly. Given that there is an existing codebase of well-defined SQL queries, you can reuse the query expressions in your python code with the in-memory SQLite database. And for sufficien... | {
"AcceptedAnswerId": "35910",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T20:40:20.263",
"Id": "35875",
"Score": "4",
"Tags": [
"python"
],
"Title": "Basic querying on Python 2D arrays"
} | 35875 |
<p>I think I have fixed the issues which caused this program to not be functional.</p>
<p>Now I believe the design of my code is somewhat bad and may be causing problems with the number of processes that are created (I would think 10 processes would be created when 20 are?). I am unsure what may be causing this, but ... | [] | [
{
"body": "<p>This question appears to be off topic for Code Review, because the code does not work.\n<hr>\n<em>(Regarding <a href=\"https://codereview.stackexchange.com/revisions/35876/1\">original revision</a>:)</em><br>\nBut anyway, I don't think using <code>psutils</code> to suspend a subprocess is a good i... | {
"AcceptedAnswerId": "35906",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T21:03:45.710",
"Id": "35876",
"Score": "2",
"Tags": [
"python",
"multithreading",
"gui"
],
"Title": "Pausing and Manipulating Data in a Process with a GUI"
} | 35876 |
<p>I have a select case that checks against a string variable. It's starting to get large and I am wondering if there is a better way of doing this?</p>
<p>Here is a sample of the <code>Select Case</code> statement:</p>
<pre><code>Select Case Param.ToLower
Case "dashboard_home_vm"
Return _Locator.Dashboa... | [] | [
{
"body": "<p>A classic solution to this problem is to use a data table - in your case probably in form of a dictionary. It depends of what type your values are - I assume they are some sort of view models? I'm also going to assume they have a common base class:</p>\n\n<p>One time setup:</p>\n\n<pre><code>Dim d... | {
"AcceptedAnswerId": "35882",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T21:07:56.920",
"Id": "35877",
"Score": "4",
"Tags": [
".net",
"strings",
"vb.net"
],
"Title": "Select case string comparison"
} | 35877 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.