body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I'm trying to implement search over two models. In this example <code>Book</code> and <code>Article</code>. Here are the attributes from both of these :</p>
<pre><code>Article(id: integer, magazine: string, title: string, body: text, created_at: datetime, updated_at: datetime)
Book(id: integer, publisher: string, a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T01:34:11.030",
"Id": "58507",
"Score": "1",
"body": "The most elegant and scalable way is to use a search engine like [Sunspot](http://github.com/outoftime/sunspot/tree/master/sunspot_rails) or [Sphinx](http://pat.github.io/thinking... | [
{
"body": "<p>you want a separate model for search, i.e.</p>\n\n<pre><code>class SearchResult < AR::Base\n #columns: content, title, user\n belongs_to :searchable, polymorphic: true\nend\n\nclass Book < AR::Base\n has_one :searchable, polymorphic: true, class_name: 'SearchResult'\n belongs_to :user\n\... | {
"AcceptedAnswerId": "36169",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T21:08:03.517",
"Id": "35878",
"Score": "4",
"Tags": [
"ruby",
"object-oriented",
"ruby-on-rails"
],
"Title": "Searching over more models rails"
} | 35878 |
<p>I have a fairly ugly controller method I would like to refactor / extract. I can only test this in a 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-21T08:41:13.543",
"Id": "58482",
"Score": "0",
"body": "In every case, controller has a large number of dependencies for unit testing(request, routing, templates, forms, db, etc). But it is not difficult to understand that he do and yo... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-18T18:17:51.783",
"Id": "35887",
"Score": "2",
"Tags": [
"php",
"unit-testing"
],
"Title": "Symfony2: Extract method from controller, form events, remove conditional"
} | 35887 |
<p>From <a href="https://www.codeeval.com/browse/115/" rel="nofollow">https://www.codeeval.com/browse/115/</a>:</p>
<blockquote>
<p>You have a string of words and digits divided by comma. Write a program which separates words with digits. You shouldn't change the order elements. </p>
</blockquote>
<p>I tried to do ... | [] | [
{
"body": "<p>I think you've overcomplicated the problem because you're approaching it the way you would in an imperative language. I'll describe the way I would approach the problem. <em>Notice that I do a lot of my \"thinking\" in GHCi!</em></p>\n\n<p>Your code reads the file and splits it up into lines just ... | {
"AcceptedAnswerId": "35940",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-21T23:15:22.710",
"Id": "35890",
"Score": "3",
"Tags": [
"haskell"
],
"Title": "Rearrange content string"
} | 35890 |
<p>Contains 3 options. Given an input array </p>
<ol>
<li>Unsorted and consecutive range, and array is 1 element short. eg: range is 6-9, and <code>array = [7, 8, 9]</code> output should be 6. </li>
<li>All conditions same as previous except 2 numbers are missing.</li>
<li>Input is sorted, numbers are consecutive, arr... | [] | [
{
"body": "<ol>\n<li>I'd suggest some naming improvements for your variables:\n<ul>\n<li><code>a1</code> -> <code>numbers</code> or <code>sequence</code></li>\n<li><code>sum1</code>/<code>squareSum1</code> -> <code>sumRange</code>/<code>squareSumRange</code></li>\n<li><code>sum2</code>/<code>squareSum2</code> -... | {
"AcceptedAnswerId": "35908",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T07:01:38.523",
"Id": "35902",
"Score": "2",
"Tags": [
"java",
"algorithm",
"array"
],
"Title": "Find a missing numbers, single missing number and two missing numbers, from cons... | 35902 |
<p>I have created a module to draw text tables. The relevant parts are below and here's the full code for <a href="https://github.com/atomgomba/txtable/blob/master/txtable/__init__.py" rel="nofollow">txtable</a>).</p>
<pre><code>class Row(Txtable):
[...]
def format(self, col_widths):
"""Return the row ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T16:55:57.423",
"Id": "58615",
"Score": "1",
"body": "This code doesn't run: you must post *working* code for us to review."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-24T18:24:06.590",
"Id": "587... | [
{
"body": "<p>The nested loop under <code># render cells and measure column widths</code> computes maximum cell width of each column. Using <code>itertools.zip_longest</code> to turn columns into rows lets you use <code>max</code> on them:</p>\n\n<pre><code>cell_widths = [[len(row.format_cell(x)) for x in range... | {
"AcceptedAnswerId": "36533",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T09:05:33.643",
"Id": "35909",
"Score": "2",
"Tags": [
"python",
"performance",
"python-3.x",
"formatting"
],
"Title": "Drawing a table in Python3"
} | 35909 |
<p>I am working on a <em>SimCity</em> clone, and I am noticing a drop in frame rate as I add more objects to my map, now this is expected, but, when I fill the whole screen, the game maintains about 300 FPS.</p>
<p>Will it hold this as I add a lot more objects, or will it continue to drop?</p>
<pre><code>import pygam... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T18:11:11.010",
"Id": "58637",
"Score": "4",
"body": "You ask: `Will it hold this as I add a lot more objects? Or will it continue to drop?` ... well, have you tried that and observed what happens?"
},
{
"ContentLicense": "CC... | [
{
"body": "<p>As you asked in your question, I'm going to <em>try</em> and address your performance issues here. Some of this will be a style review though, so bear with me.</p>\n\n<hr>\n\n<h1>Style</h1>\n\n<ul>\n<li><p>First off, no offense, but this code looks, not so great. You have many major style issues, ... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T12:28:07.130",
"Id": "35914",
"Score": "11",
"Tags": [
"python",
"performance",
"game",
"pygame"
],
"Title": "SimCity clone performance"
} | 35914 |
<p>How can I improve the speed of this LINQ query?</p>
<pre><code>using (var txn = new TransactionScope(TransactionScopeOption.Required,
new TransactionOptions { IsolationLevel = IsolationLevel.ReadUncommitted }))
{
var myAlertsList = (from alerts in _db.Alerts.AsNoTracking()
wher... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T14:02:19.540",
"Id": "58583",
"Score": "1",
"body": "you have 3 `OrderByDescending`s followed by takes of which you can remove all but the last"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T15:01:52... | [
{
"body": "<p>First lets split up the query so we can read it:</p>\n\n<pre><code>var alertList = from alerts in _db.Alerts.AsNoTracking()\n where alerts.AlertID >= Id.AlertID && alerts.DataWystapienia >Id.DataWystapienia\n select new MyAlerts { AlertID = alerts.AlertI... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T13:53:16.910",
"Id": "35919",
"Score": "2",
"Tags": [
"c#",
"sql",
"linq",
"performance"
],
"Title": "Improve speed of LINQ query"
} | 35919 |
<p>I have the following algorithm which retrieves information in a <code>List</code> of <code>KeyValuePair</code> (prices) and write them in a <code>DataRow</code>. I was wondering if I could achieve the same result without <code>j</code>. </p>
<pre><code>if (prices != null)
{
for (int i = 8, j=0; j <... | [] | [
{
"body": "<p>I would approach this first by flattening the prices dictionary into a sequence of values eg <code>{ Key, Value, Key, Value, Key, Value }</code>.</p>\n\n<pre><code>// This method is returning object for now since I'm not clear what types are in your data row..\nIEnumerable<object> Flatten<... | {
"AcceptedAnswerId": "35932",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T15:38:57.963",
"Id": "35924",
"Score": "4",
"Tags": [
"c#"
],
"Title": "Writing information from a List of KeyValuePairs into a DataRow"
} | 35924 |
<p>I would like feedback on things I can improve. If you want to see the full example in action, here is the <a href="http://labs.lesevades.com/recipe-book" rel="nofollow">link</a>.</p>
<pre><code>$(document).ready(function() {
var all = $("#slider-view");
var winWidth = window.innerWidth;
var winHeight ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T16:16:23.453",
"Id": "58604",
"Score": "0",
"body": "Continuously numbered variables (css classes, IDs, etc) are always a code smell."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T16:17:53.397",
... | [
{
"body": "<p>I took a look at your chat with Tomalak and it seems you got some good advice, so big tip-o'-the-hat to Tomalak.</p>\n\n<p>These are just some thoughts on the overall approach to some of this stuff. I'm not so much looking at your current code, but the things I touch on should be applicable regard... | {
"AcceptedAnswerId": "35943",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T15:40:46.750",
"Id": "35925",
"Score": "4",
"Tags": [
"javascript",
"jquery"
],
"Title": "jQuery carousel code"
} | 35925 |
<p>I thinking of a way to start a new transaction inside a single EJB bean. Typical use case would be to process every item from a list in a separate transaction.</p>
<p>One way to do it would be to use <code>UserTransaction</code>:</p>
<pre><code>@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
publ... | [] | [
{
"body": "<h1>Variable Names:</h1>\n<p>Your variable names are very generic. The <code>List<Object></code> you pass in is just called <code>list</code>. This might be fine at coding-time, but as soon as you have to analyze the code weeks or maybe even months later, you will probably wonder, what purpose ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T15:44:07.197",
"Id": "35926",
"Score": "6",
"Tags": [
"java"
],
"Title": "Starting a new transaction inside a single bean"
} | 35926 |
<p>I'm not very good with templates, so any general tips would be appreciated. </p>
<p>Basically this class parses a CSV file with a very specific format.<br>
My original idea for this was that I wanted this to be useful in MFC desktop applications and non-MFC applications such as Windows services. Basically, I wante... | [] | [
{
"body": "<p>I've long since wanted to explore doing this sort of thing myself. In different code bases, different string classes are so much more prevalent, and thus more appropriate to keep using. Your approach isn't quite the right way to go, as it scales on the wrong axis. I can totally see removing the te... | {
"AcceptedAnswerId": "35963",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T16:07:31.897",
"Id": "35931",
"Score": "8",
"Tags": [
"c++",
"parsing",
"csv",
"template"
],
"Title": "Parsing a CSV file with a very specific format"
} | 35931 |
<p>I am using <a href="https://stackoverflow.com/questions/12260493/how-to-connect-to-ms-sql-server-using-innosetup">this code</a> to run my sql scripts in inno setup. However ADO gives an error if the script contains GO syntax within it. I added my own code to overcome this problem.</p>
<p>My code below splits the sc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T17:28:27.880",
"Id": "58625",
"Score": "0",
"body": "what language is this?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T17:29:36.753",
"Id": "58627",
"Score": "0",
"body": "@Malachi, i... | [
{
"body": "<p><em><strong>1. Function block</em></strong></p>\n\n<p>Standalone action like loading a script from file and splitting it into SQL commands by the <code>GO</code> command, I would move into a separate function. That function might have the following prototype:</p>\n\n<pre><code>function LoadScriptF... | {
"AcceptedAnswerId": "35948",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T16:50:18.240",
"Id": "35934",
"Score": "3",
"Tags": [
"pascal-script"
],
"Title": "Using ADO to run sql script (with GO syntax) in inno setup"
} | 35934 |
Pascal Script is a free scripting engine that allows you to use most of the Object Pascal language within your Delphi or Free Pascal projects at runtime. Written completely in Delphi, it is composed of a set of units that can be compiled into your executable, eliminating the need to distribute any external files. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T17:32:08.163",
"Id": "35936",
"Score": "0",
"Tags": null,
"Title": null
} | 35936 |
<p>I am looking for tips on improving my short program. I am using <code>system("PAUSE")</code> because this was for an assignment. </p>
<p><img src="https://i.stack.imgur.com/AfMgr.png" alt="enter image description here"></p>
<p>Code:</p>
<pre><code>#include <iostream>
#include <string>
#include <io... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T19:27:58.087",
"Id": "58644",
"Score": "4",
"body": "You can also use `getchar()`..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T23:19:59.390",
"Id": "58656",
"Score": "0",
"body": "@t... | [
{
"body": "<ul>\n<li><p>I assume you'll have no more than 10 names/hours/percents, but you could use an <a href=\"http://en.cppreference.com/w/cpp/container/vector\"><code>std::vector</code></a> in place of these arrays. This will allow you any number of inputs without fear of exceeding the allotted 10. If yo... | {
"AcceptedAnswerId": "35945",
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T19:19:43.097",
"Id": "35941",
"Score": "6",
"Tags": [
"c++",
"homework"
],
"Title": "Hour averaging program"
} | 35941 |
<p>I have a method that generates a 10 digit random number where each digit occurs only once.</p>
<p>eg:</p>
<pre><code>0123456789
3645720918
</code></pre>
<p>Is there any way this method could be optimized/improved?</p>
<pre><code> private static String randomize(){
Random r = new Random();
List... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T05:54:08.483",
"Id": "58678",
"Score": "0",
"body": "If performance is truly a concern, you can actually do this with a single call to `Random.nextInt()`. [Example](http://stackoverflow.com/questions/7918806)"
},
{
"Content... | [
{
"body": "<p>Short answer: Speed optimized? Perhaps. Memory optimized? Not that I am aware of. Improved flexibility? Yes.</p>\n\n<ul>\n<li>The number <code>10</code> is a <strong>magic number</strong> in your code. If you change it on one place, you need to change it everywhere else. This number should be put ... | {
"AcceptedAnswerId": "35953",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T23:48:46.173",
"Id": "35950",
"Score": "12",
"Tags": [
"java",
"optimization",
"random"
],
"Title": "Optimize random number generator"
} | 35950 |
<p>I created this out of curiosity and it has some code duplication issues and the fact that sticking <code>.yield()</code> on the end of a call to a unit converter is pretty strange.</p>
<p><strong>How would you improve it?</strong></p>
<pre><code>/**
* A very special velocity converter
* Designed mainly for a ver... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T02:41:02.143",
"Id": "58667",
"Score": "0",
"body": "Just curious why there's differing spellings of yield scattered about.."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T02:43:58.370",
"Id": "5... | [
{
"body": "<p>You can override <code>valueOf</code> to perform the same function as <code>yield</code> in your code. Then, you could override <code>toString</code> to get the quantitative part and append the unit name. For the purposes of outputting your measures to text, and for debugging with e.g. Firebug, ... | {
"AcceptedAnswerId": "35958",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T01:46:16.717",
"Id": "35955",
"Score": "3",
"Tags": [
"javascript",
"design-patterns"
],
"Title": "Javascript velocity converter, fully chainable"
} | 35955 |
<p>The kinds of control flow statements supported by different languages vary, but can be categorized by their effect:</p>
<ul>
<li>continuation at a different statement (unconditional branch or jump),</li>
<li>executing a set of statements only if some condition is met (choice - i.e., conditional branch),</li>
<li>ex... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T03:43:23.727",
"Id": "35960",
"Score": "0",
"Tags": null,
"Title": null
} | 35960 |
Within an imperative programming language, a control flow statement is a statement whose execution results in a choice being made as to which of two or more paths should be followed. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T03:43:23.727",
"Id": "35961",
"Score": "0",
"Tags": null,
"Title": null
} | 35961 |
<p>I have finished my first Android App, but I am getting lots of skipped frame messages from Choreographer. So, I started reading and got the impression that I should put as less calculations/works as possible in main thread, rather should use AsyncTask.</p>
<p>To understand the thumb rule, can anybody please validat... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T22:42:55.780",
"Id": "58749",
"Score": "0",
"body": "Possibly related: http://stackoverflow.com/questions/15963969/choreographer639-skipped-50-frames . Are you running on an emulator or a real device? If you are running on a real de... | [
{
"body": "<p>Both the methods <code>editSave()</code> and <code>populateData()</code> require access to a database to function. They both should be modified to use <code>AsyncTask</code> in order to reduce the footprint that your code has on the 'main thread'.</p>\n\n<p>I presume the database is local to the d... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T05:49:48.613",
"Id": "35965",
"Score": "1",
"Tags": [
"java",
"optimization",
"android"
],
"Title": "Android code optimization - AsyncTask"
} | 35965 |
<p>MongoDB does not provide means to lock a document (like <code>SELECT FOR UPDATE</code> in RDBMS).</p>
<p>There is a recommended approach to <a href="http://docs.mongodb.org/manual/tutorial/isolate-sequence-of-operations/" rel="nofollow">Isolate Sequence of Operations</a>, which is sometimes called <em>optimistic lo... | [] | [
{
"body": "<ol>\n<li><p>The above code will fail with multiple worker nodes (or processes).</p></li>\n<li><p>To achieve atomic find-and-update, mongodb provides native solution (findOneAndUpdate, findAndModify, updateOne, updateMany).</p></li>\n</ol>\n",
"comments": [],
"meta_data": {
"CommentCoun... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T09:06:08.383",
"Id": "35968",
"Score": "2",
"Tags": [
"python",
"multithreading",
"locking",
"mongodb"
],
"Title": "Python app-level document/record locking (eg. for MongoDB)"... | 35968 |
<p>I create series of objects out of Student Class and store them in a vector. I write each object in to a .ser file once it created. Then I read them back. My code is working perfectly. What I want to know is, I do this in a correct optimized way or are there any easy and optimized ways to get this done?? And also how... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T14:32:46.867",
"Id": "58691",
"Score": "1",
"body": "your very last question is off topic, we won't tell you how to write a block of code."
}
] | [
{
"body": "<p>Why didn't you provide a constructor for <code>Student</code> class? Was that on purpose? However...</p>\n\n<ul>\n<li><p>Use <a href=\"https://stackoverflow.com/questions/285793/what-is-a-serialversionuid-and-why-should-i-use-it\"><code>serialVersionUID</code></a>.</p></li>\n<li><p>In Java it's re... | {
"AcceptedAnswerId": "35975",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T12:33:48.463",
"Id": "35974",
"Score": "3",
"Tags": [
"java",
"vectors",
"serialization"
],
"Title": "best way to write series of objects to a .ser file using ObjectOutputStrea... | 35974 |
<p>I create class level static ArrayList by the following line.</p>
<pre><code>static ArrayList<Student> studentList = null;
</code></pre>
<p>Then I create and fill ArrayList with some objects inside a function.</p>
<pre><code>studentList = new ArrayList<Student>();
Write(student);
</code></pre>
<p>late... | [] | [
{
"body": "<p>First of all, speaking of good practice, I would not have the variable as <code>static</code>. Using <code>static</code> variables is like using Singletons. There can be only one. You might regret this strategy later. Instead, if possible, I would declare the <code>List</code> <em>in another objec... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T15:52:04.837",
"Id": "35977",
"Score": "3",
"Tags": [
"java",
"object-oriented",
"array",
"memory-management"
],
"Title": "Clear ArrayList"
} | 35977 |
<p>Is there a simpler and optimized way to calculate <code>listAdminCorePriveleges</code> and <code>privileges</code> ?</p>
<pre><code>public string[] GetPrivilegesForUserByPersonEntityId(int personEntityId)
{
var listPrivileges = new List<string>();
var listAdminCorePriveleges = (_accountRep... | [] | [
{
"body": "<p>To know for sure what exactly is inefficient you'd need to hook up a profiler.</p>\n\n<p>Code wise you should be able to do it all in one query if I'm not mistaken:</p>\n\n<pre><code>return _accountRepository.AsQueryable()\n .Where(acc => acc.PersonEntityId == personEntityId)\n ... | {
"AcceptedAnswerId": "35995",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T17:39:29.107",
"Id": "35984",
"Score": "2",
"Tags": [
"c#",
"linq",
"entity-framework",
"ienumerable"
],
"Title": "Nested select Linq"
} | 35984 |
<p>I currently have this bit of code, but I need to repeat it for red green and blue. Is there a way I can do it without copying and pasting the code 3 times?</p>
<pre><code>yellow.setOnClickListener(new View.OnClickListener() {
public void onClick (View v) {
switch (buttonCount) {
case ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T20:17:54.370",
"Id": "58743",
"Score": "2",
"body": "Have you tried writing a function and then pass your arguments(Colour.RED, Color.BLUE and Color.GREEN). Remember that these are constants. Try it out and then post here what have ... | [
{
"body": "<p>If you look at your naming schema, you have <code>emptyX</code> and <code>guessX</code>, where <code>X</code> is an index. This is an indicator that you should be using an array or a list:</p>\n\n<pre><code>EmptyType empties[5] = { empty1, empty2, ... };\nGuessType guesses[5] = { guess1, guess2, .... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T19:57:07.507",
"Id": "35986",
"Score": "4",
"Tags": [
"java",
"android"
],
"Title": "Best way to get rid of code repetition?"
} | 35986 |
<p>I recently gutted and redid my game code to be object oriented (before it was just functions and a mass of global variables.</p>
<p>Before I go an make more functionality happen, I would like to take one last step backwards to make sure I have the best foundation I can before proceeding.</p>
<p>Note: the point of ... | [] | [
{
"body": "<h1>Use prototypes</h1>\n\n<p>I notice you do this:</p>\n\n<pre><code>function _player() {\n ...\n this.isDead = function() {\n if (this.hp <= 0) return true;\n else return false;\n }\n</code></pre>\n\n<p>One issue with this one is that for every instance of <code>_player</c... | {
"AcceptedAnswerId": "36008",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-23T22:23:53.677",
"Id": "35989",
"Score": "9",
"Tags": [
"javascript",
"html",
"game",
"dom"
],
"Title": "JavaScript Game Engine Design"
} | 35989 |
<p>this tag should be used for questions pertaining to the <a href="http://php.net/manual/en/book.spl.php" rel="nofollow">Standard PHP Library</a></p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-24T00:38:08.520",
"Id": "35993",
"Score": "0",
"Tags": null,
"Title": null
} | 35993 |
Code Focused around the use of the Standard PHP Library | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-24T00:38:08.520",
"Id": "35994",
"Score": "0",
"Tags": null,
"Title": null
} | 35994 |
<p>I want to implement something like C# Linq in C++</p>
<p>Currently only <code>select</code> and <code>where</code> is implemented, but others should be fairly easy if I can make a good structure.</p>
<p>The main concerns I have is I am not sure when to pass reference and when to pass value. Also how it works with ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T04:21:53.220",
"Id": "58842",
"Score": "0",
"body": "This is great. I don't know enough C++ to really answer your questions though (I'm much more of a C and C# guy!)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate"... | [
{
"body": "<p>I am not sure this is a good idea (nor do I think the cpplinq in @MichaelUrman's post is a good idea - though it's definitely workable).</p>\n\n<p>Basically you are writing a fully templated hierarchy of classes, to replace (existing, stable and presumably tested) functionality in std algorithm:</... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-24T04:10:10.053",
"Id": "35997",
"Score": "11",
"Tags": [
"c++",
"linq",
"c++11",
"reinventing-the-wheel"
],
"Title": "C++ linq-like library"
} | 35997 |
<p>The <a href="http://vanilla-js.com/" rel="nofollow">Vanilla.js framework</a> isn't actually a framework, but a joke about JavaScript frameworks. Using Vanilla.js means you're <em>not</em> using a framework.</p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-24T06:59:42.323",
"Id": "36000",
"Score": "0",
"Tags": null,
"Title": null
} | 36000 |
For "vanilla" JavaScript. I.e. JavaScript written without using a framework or library. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-24T06:59:42.323",
"Id": "36001",
"Score": "0",
"Tags": null,
"Title": null
} | 36001 |
<p>I'm reading <a href="http://rads.stackoverflow.com/amzn/click/1118185463" rel="nofollow"><em>Professional Node.js: Building Javascript Based Scalable Software</em></a> by Pedro Teixeira and created a web page responding with <a href="http://www.google.de" rel="nofollow">www.google.de</a>. Could you take a look at my... | [] | [
{
"body": "<p>Here are my suggestions:</p>\n\n<ul>\n<li>Get rid of the anonymous functions. They are notoriously difficult to test. I am hoping that you have written the test cases. If not, now would be a good time to try writing these tests.</li>\n<li>There is either a documentation or implementation bug where... | {
"AcceptedAnswerId": "36007",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-24T08:17:56.910",
"Id": "36003",
"Score": "1",
"Tags": [
"javascript",
"node.js",
"http",
"server",
"timeout"
],
"Title": "Node.JS HTTP server displaying Google"
} | 36003 |
<p>I have attemped to define a function which scan an int value in a specified range and returns that value. The lower bound is the lower of the two parameters, the upper bound is the larger of the two parameters.After invalid input, the function displays a message and repeats input (and message, if necessary ) until a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-24T16:53:47.420",
"Id": "58783",
"Score": "0",
"body": "Could you add the `checkDate` method as well?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-24T18:29:07.153",
"Id": "58790",
"Score": "0",
... | [
{
"body": "<p>When it comes to user-input, efficiency really is not the point.... what does it matter if it takes 4 milliseconds to validate some data, or 4 nanoseconds? The user component of time dwarfs the rest.... Obvioulsy, if the code was taking more than 10 milliseconds I would be concerned, but I doubt t... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-24T16:36:32.930",
"Id": "36011",
"Score": "1",
"Tags": [
"java"
],
"Title": "Scanning an int variable"
} | 36011 |
<p>I am doing my best to keep this code clean and fast, but as I add more to the game, it seems to get harder to maintain a frame-rate higher than 200! I believe that the culprit is a somewhat large <code>for</code> loop inside of the main loop. It performs all of the actions for the tiles inside of the world, and as m... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-24T21:45:35.170",
"Id": "58810",
"Score": "1",
"body": "When the framerate is at 200 (I presume 200 frames per second), and the human eye is more than satisfied at the movies with a framerate of < 30 fps, I have to wonder whether you a... | [
{
"body": "<p>I believe comparing images isn't of the greatest efficiency, replace the spr with a enum type value, then you don't need to swap over the image, or at least not compare them.</p>\n\n<p>also you keep changing the alpha on the images, duplicate the image and keep both versions, one with alpha 100 an... | {
"AcceptedAnswerId": "36020",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-24T20:36:47.200",
"Id": "36015",
"Score": "3",
"Tags": [
"python",
"performance",
"game",
"pygame"
],
"Title": "SimCity clone with PyGame"
} | 36015 |
<p>The class supplies a simple thread pool that uses the thread class from C++11.</p>
<p>When I schedule the job, I pass two <code>std::function<void()></code> objects that the pool will execute: the first function is the real job, the second is executed to send some sort of notification that the job has been do... | [] | [
{
"body": "<p>A few thoughts:</p>\n\n<ul>\n<li><p>If I understand this correctly, if one of your job functions throws an exception, it ends processing for your entire thread pool; Threads that are running (but did not throw an exception) will keep running, but the ThreadPool object may be deleted as part of sta... | {
"AcceptedAnswerId": "36142",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-24T22:51:04.810",
"Id": "36018",
"Score": "16",
"Tags": [
"c++",
"multithreading",
"c++11"
],
"Title": "Thread pool on C++11"
} | 36018 |
COBOL (COmmon Business Oriented Language) was the product of a US Department of Defense initiative to develop a standard and portable programming language for business applications. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T00:36:04.773",
"Id": "36023",
"Score": "0",
"Tags": null,
"Title": null
} | 36023 |
<p>I have this CSS selector:</p>
<pre><code>.img + *{
}
</code></pre>
<p>Which, from my understanding, will make the browser look for all the elements and then select only those which follow an element with the class <code>img</code>. Is there a better way of writing this selection to improve performance?</p>
<p>Rel... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T23:10:28.817",
"Id": "59163",
"Score": "1",
"body": "Your understanding that it selects \"only \\[elements\\] which are being followed by an element with the class `img`\" is incorrect. It selects only elements which _follow_ an ele... | [
{
"body": "<p>Here is something that you could do in your HTML, you could get rid of the <code><div class=\"img></code> </p>\n\n<p>this looks like it would be extra code for you to write, anything that you can style on a <code>div</code> you should be able to style on the <code><img></code> tag as ... | {
"AcceptedAnswerId": "36162",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T01:01:58.210",
"Id": "36026",
"Score": "5",
"Tags": [
"performance",
"css"
],
"Title": "CSS selector for image captions"
} | 36026 |
<p>I've implemented a working version of Array#uniq in Ruby to answer the question here: <a href="http://www.rubeque.com/problems/like-a-snowflake" rel="nofollow">http://www.rubeque.com/problems/like-a-snowflake</a>, but I'd like to see if there's ways to clean up my code or some better practices I should follow? This... | [] | [
{
"body": "<p>For one, I'd use the <code><<</code> operator rather than <code>push</code> just out of convention.</p>\n\n<p>Second, you still have other Array/Enumerable methods at your disposal. So there's no need to create a new array and add unique items to it. Try filtering the array instead.</p>\n\n<... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T01:05:38.973",
"Id": "36027",
"Score": "4",
"Tags": [
"ruby",
"array"
],
"Title": "Implementing Array#uniq in Ruby"
} | 36027 |
<p>Looking for reviewers to suggest optimization and improvements, and to evaluate coding practices.</p>
<pre><code>final class Variables {
private final int x;
private final int y;
Variables(int x2, int y2) {
this.x = x2;
this.y = y2;
}
public int getX() {
return x;
}... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T03:45:29.377",
"Id": "58836",
"Score": "0",
"body": "I am not convinced that this code works.... `low` is initialized to an index in the array, but then it is compared to a value in the array `if (a1[i] != low)`. This makes no sense... | [
{
"body": "<p>You say the problem is to find missing values from a 'Range', but your method only takes a start value, not an end value.... is this intentional? The method comment says:</p>\n\n<blockquote>\n <p>Takes an input a sorted array with two variables that repeat in the range. and returns two variables ... | {
"AcceptedAnswerId": "36032",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T03:07:29.733",
"Id": "36031",
"Score": "4",
"Tags": [
"java",
"algorithm",
"array"
],
"Title": "Find two missing elements from a sorted array in given range"
} | 36031 |
<p>I want a git repository, accessible over ssh, to be read-only when used with certain keys. With other keys access to the full system is okay.</p>
<p>Here is my solution.</p>
<p>git-readonlyshell:</p>
<pre><code>if echo "$2" | egrep -q ^git-upload-pack; then
sh -c "$2"
else
echo Error: read only access 1>&a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T04:29:13.060",
"Id": "58845",
"Score": "2",
"body": "Why not just have a user that is read-only for the repository and use one user for full-access, and the other for read-only?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"C... | [
{
"body": "<p>Should be</p>\n\n<pre><code>printf \"%s\\n\" \"$2\" | grep -E \"^git-upload-pack\" && sh -c \"$2\"\n</code></pre>\n\n<p>Notes:</p>\n\n<ul>\n<li><code>sh</code> not <code>bash</code> for portability</li>\n<li>The <code>printf</code> instead of <code>echo</code> is for safety. What happens ... | {
"AcceptedAnswerId": "36036",
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T04:24:29.950",
"Id": "36034",
"Score": "3",
"Tags": [
"shell",
"git"
],
"Title": "Make a git repository read-only over ssh depending on the key used"
} | 36034 |
<p>This is a school project that I am turning in late. The prof suggested that i somehow prove myself by improving upon the basic code. This is really tough to do for someone who is just starting to learn to code. </p>
<p>Is there something I can do to: </p>
<ol>
<li>add onto the code (have it do or ask something dif... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T04:34:42.613",
"Id": "58851",
"Score": "3",
"body": "Adding code or functionality is off-topic for this site. Improving existing code is within scope. I've tagged this as [tag:homework] to indicate that answers should provide hints ... | [
{
"body": "<p>If you've learned object-oriented programming, you might see how the residential and business functions could share code by becoming classes (or more likely a class and a subclass)</p>\n\n<p>If you haven't looked at OO, think about refactoring the way 'business' and 'residential' work to avoid hav... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T04:26:03.980",
"Id": "36035",
"Score": "1",
"Tags": [
"python",
"beginner"
],
"Title": "Computing cable bills using F(x)'s"
} | 36035 |
<p>Probably the hardest part of learning lisp has been to think in the "lisp way" which is elegant and impressive, but not always easy. I know that recursion is used to solve a lot of problems, and I am working through a book that instead uses <code>apply</code> to solve a lot of problems, which I understand is not as ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T09:55:10.227",
"Id": "58877",
"Score": "0",
"body": "why do you think using apply is a bad style? I saw several similar opinions, but didn't get any arguments for that."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDa... | [
{
"body": "<h1>Lisp is a multiparadigm language.</h1>\n\n<p><a href=\"http://www.lispworks.com/documentation/HyperSpec/Body/f_apply.htm\" rel=\"nofollow\"><code>apply</code></a> is just as lispy as recursion, and, in a way, much more so (think in HOFs)!</p>\n\n<h1>Style</h1>\n\n<ol>\n<li><p>Please fix indentati... | {
"AcceptedAnswerId": "36050",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T08:58:32.067",
"Id": "36042",
"Score": "2",
"Tags": [
"recursion",
"lisp",
"common-lisp"
],
"Title": "Rewrite apply function to use recursion instead"
} | 36042 |
<p>I have written some code to search a for a pattern in a list of tuples. </p>
<p>It works, but I am sure that it can be improved. Any feedback or ideas would be greatly appreciated.</p>
<p>The list of tuples I am searching in looks like this:</p>
<blockquote>
<p>x = [('A', True), ('B', True), ('C', False), ('D',... | [] | [
{
"body": "<p>If I understand correctly, your problem can be defined as:</p>\n\n<ul>\n<li>take the longest uninterrupted chain of True elements ending in X</li>\n<li>take X regardless of value </li>\n<li>take all True elements after X until the first False one</li>\n</ul>\n\n<p>So the actual position of X is no... | {
"AcceptedAnswerId": "36048",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T10:36:32.900",
"Id": "36045",
"Score": "2",
"Tags": [
"python"
],
"Title": "Searching for a pattern in a list of tuples"
} | 36045 |
<p>I have a series of text boxes in a table to gather input as below:</p>
<p><img src="https://i.stack.imgur.com/v1fNL.jpg" alt="enter image description here"></p>
<p>The user will input a target and actual value for each measurement point they require. I would then like to validate the actual values against the targ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T17:11:40.627",
"Id": "58922",
"Score": "0",
"body": "Do you have a separate `lblTest` for each check, or are you reusing the same field? Are you only checking 1 at a time?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creatio... | [
{
"body": "<p>I would write it like this</p>\n\n<pre><code>Dim m1 As TolerenceHelper\nDim flag As Boolean = True\n\nm1 = New TolerenceHelper\n\nflag = m1.IsInTolerence(Integer.Parse(txtT1.Text), Integer.Parse(txtA1.Text), Integer.Parse(txtTolerance.Text))\n\nIf flag = False Then\n lblTest.Text = \"Out of tol... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T12:34:37.910",
"Id": "36047",
"Score": "5",
"Tags": [
"asp.net",
"vb.net",
"validation"
],
"Title": "Most efficient way to validate multiple textboxes against a tolerance value"
} | 36047 |
<p>Allow for stuff like:</p>
<ul>
<li>API/ExampleObjects</li>
<li>API/ExampleObjects/SOME_INTEGER_ID/Children</li>
<li>...</li>
</ul>
<p>with children knowing their owners (aka parents).</p>
<p><a href="https://github.com/Evan-R/RESTfulPHP" rel="nofollow">Full repo here</a></p>
<ul>
<li>Please be brutally honest if... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T17:10:06.447",
"Id": "58920",
"Score": "1",
"body": "This is just a front controller. There is nothing inherently RESTful about it."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T06:30:15.990",
"... | [
{
"body": "<h1>Good</h1>\n<ul>\n<li>Private attributes for storing state in the class (<code>id</code>, <code>owner</code>).</li>\n<li>Getter and setter methods are simple.</li>\n</ul>\n<hr />\n<h1>Bad</h1>\n<h2>Not a RestApi</h2>\n<ul>\n<li>REST is an architectural style it can't be represented by an object. ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T13:57:08.547",
"Id": "36049",
"Score": "4",
"Tags": [
"php",
"api"
],
"Title": "RESTfulPHP / controller / structure"
} | 36049 |
<p>I'm about to release this application as a hobby and I'm wondering how would I improve the speed of the calculations and overall responsiveness of the class?</p>
<p>I have covered a module briefly in data structures and algorithms so I'm thinking a big factor would be reducing the amount of loops I'm using.Can some... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T15:28:34.947",
"Id": "58900",
"Score": "2",
"body": "The code you posted doesn't have any loops. As an additional comment, the repeated code in `onClick()` should be extracted into a single method that is called 3 times."
}
] | [
{
"body": "<p>Looking through this code I feel that there must be something missing? Does it work? Does it even compile?</p>\n\n<p>For example the onClick() method all the places I have marked are 'dead' variables... variables you declare inside a block and are not visible outside the block:</p>\n\n<pre><code>... | {
"AcceptedAnswerId": "36060",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T14:57:25.747",
"Id": "36052",
"Score": "-3",
"Tags": [
"java",
"performance",
"android"
],
"Title": "How would I improve this class in terms of responsiveness and performance?"... | 36052 |
<p>I'm writing an AI for an italian Card game scopa <a href="http://en.wikipedia.org/wiki/Scopa" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Scopa</a> And as part of it i need to generate all moves available to the user.</p>
<p>A move consists of finding cards in the centerboard that sum to a card in the pl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T16:40:10.890",
"Id": "58911",
"Score": "0",
"body": "Have you implemented `hashCode` and `equals` properly in your `Move` class and your `Card` class?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T1... | [
{
"body": "<p>In your recursive generateMoves method, you can reduce a huge amount of the duplicates by limiting where in the <code>centerCards</code> list you operate in.</p>\n\n<p>My suggestion would be to pass that list through the recursion with a pointer to your current position in the array.... for exampl... | {
"AcceptedAnswerId": "36057",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T16:15:44.517",
"Id": "36055",
"Score": "5",
"Tags": [
"java",
"algorithm",
"performance"
],
"Title": "Performance/Optimization of Knapsack(ish) algorithm for move generation fo... | 36055 |
<p>I just started working with ASP.NET MVC a few weeks ago, and I'm finding that it can be very easy to write spaghetti code in the controllers. For my first project, I created a very simple view with a few controls. At first, all of my code was in the <code>Index()</code> action result. That worked okay for a while... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T17:17:15.730",
"Id": "58923",
"Score": "1",
"body": "It's easy to write spaghetti code in *any language*, using *any framework* :)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T00:40:31.757",
"I... | [
{
"body": "<p>It sounds like you need to add a service layer where you can include all your business logic. This way your controller classes do not become bloated with business logic and they are only dealing with the handling of requests and the population of view-models.</p>\n\n<p>Using thin controllers like ... | {
"AcceptedAnswerId": "36062",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T17:08:27.720",
"Id": "36061",
"Score": "7",
"Tags": [
"c#",
"asp.net-mvc-4"
],
"Title": "ASP.NET MVC to produce a repair invoice"
} | 36061 |
<p>My project for my class is to create a Java-based game where the user must enter a number between 1-20 and a number between 250 and 300. The computer randomly chooses a number between those 2 numbers. Then the user has 10 guesses to correctly guess what number the computer is "thinking of."</p>
<p>There is a catch,... | [] | [
{
"body": "<p>I'm guessing you're not allowed to use any kind of loop, because then you could just use a for-loop.</p>\n\n<p>Anyhow, I would suggest you encapsulate more of your code in methods. Think about what kind of operations you use repeatedly.</p>\n\n<p>Also, you don't need multiple guessing variables (g... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T20:23:43.777",
"Id": "36074",
"Score": "10",
"Tags": [
"java",
"game",
"homework",
"random",
"number-guessing-game"
],
"Title": "Guess a random number between a selected i... | 36074 |
<p>I am struggling with commenting and variable naming. My teacher says my comments need to be more explanatory and explicit. He says my variable names are also sometimes confusing. I was just wondering whether you could go through my code, see whether you are able to understand the comments and whether the variables n... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T21:44:31.630",
"Id": "58952",
"Score": "1",
"body": "Your variable names look mostly fine to me, and the comments look _more_ explicit than they should be. As for improvements, you could try using docstrings and function annotations... | [
{
"body": "<p>You'll find that there are many attitudes, but the type of commenting you've shown here is largely only helpful as a language learner. When I look at the code, already familiar with the language, the comments are way <em>too</em> explicit. You've essentially got comments repeating what every line ... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T21:31:11.250",
"Id": "36078",
"Score": "23",
"Tags": [
"python",
"homework",
"caesar-cipher"
],
"Title": "Reading and writing data for Caesar cipher"
} | 36078 |
Comments are non-executable remarks embedded in source code that are directed at programmers or that are for documentation. Use this tag to indicate that the comments in the code are a concern (verbosity, helpfulness, or formatting). | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T21:55:23.433",
"Id": "36080",
"Score": "0",
"Tags": null,
"Title": null
} | 36080 |
<p>I'm debating which version would be more suitable in parameters of code length, readability and maintenance. This is a portion of a set of functions which together parse a Gif file.</p>
<p><strong>Version 1:</strong></p>
<pre><code>if ((errno = GifLoadHeaders(g, &bufTemp)) != GIF_SUCCESS) {
GifDispose(g);
... | [] | [
{
"body": "<p>Without knowing the context, I'd write it as:</p>\n\n<pre><code>if( (errno = GifLoad( g, &bufTemp )) == GIF_SUCCESS ) {\n // Process the correctly loaded image as necessary.\n GifProcess( g );\n}\n\n// Release memory once processing is complete.\nGifDispose( g );\n*gPtr = NULL;\n\n// Single ... | {
"AcceptedAnswerId": "36135",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T22:44:44.443",
"Id": "36083",
"Score": "6",
"Tags": [
"c",
"image",
"comparative-review",
"error-handling"
],
"Title": "Error handling for function calls to parse a GIF fil... | 36083 |
<p>I can't seem to get the formatting right, so here is the pastebin if needed:
<a href="http://pastebin.com/g6VmdYbM" rel="nofollow">http://pastebin.com/g6VmdYbM</a></p>
<pre><code>public class Hangman {
///////////////////////////////////
// Global Variables
///////////////////////////////////
private static String... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T22:52:14.083",
"Id": "58966",
"Score": "5",
"body": "what you mean by efficient?"
}
] | [
{
"body": "<p>So, going through your code I am struck by a few things....</p>\n\n<ul>\n<li>static variables are seldom the 'right' way to do things in Object Oriented languages like Java. Other than for constants, it is a red flag that something is wrong.</li>\n<li>you have a problem with generating random numb... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T22:44:48.210",
"Id": "36084",
"Score": "3",
"Tags": [
"java",
"optimization",
"game",
"hangman"
],
"Title": "Hanging men efficiently"
} | 36084 |
<p>Coming from Java and Android development and Objective-C still is a bit strange to me, but I just went in head first and started writing code. Before I started getting really far into it, I just want to throw some basic code here for suggestions about correct syntax, etc. I just want to make sure that my variable an... | [] | [
{
"body": "<p>There are a lot of takes on how to structure things in Objective-C, largely based on the age of the language. It used to require you to use <em>x</em>, but now it lets you use <em>y</em>, kind of things. I like to go with the minimalist/OOAD-purist approach.</p>\n\n<p><strong>Your Header File</s... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T23:44:11.850",
"Id": "36088",
"Score": "4",
"Tags": [
"objective-c",
"ios"
],
"Title": "Calculator ViewController"
} | 36088 |
<p>PostgreSQL (often called "Postgres") is a powerful, object-relational database system (ORDBMS).</p>
<p>Open source since 1996, it has a proven architecture that has earned it a strong reputation for reliability, data integrity, and correctness. Standards compliance is a major focus of the development team. Postgre... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T23:56:11.103",
"Id": "36089",
"Score": "0",
"Tags": null,
"Title": null
} | 36089 |
PostgreSQL is an open-source, Relational Database Management System (RDBMS) available for many platforms including Linux, UNIX, MS Windows and Mac OS X. Please mention your PostgreSQL version when asking questions. Always include the "sql" tag and possibly the "plpgsql" tag if applicable. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-25T23:56:11.103",
"Id": "36090",
"Score": "0",
"Tags": null,
"Title": null
} | 36090 |
<p>I have become interested in reflection and I wrote a class to wrap an Object so that I can access its private instance fields. The code works great. I do not need to wory about the exceptions in the <code>get()</code> and <code>set()</code> methods because I cast the values appropriately through my wrappers accessor... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T12:50:07.147",
"Id": "59043",
"Score": "2",
"body": "This question appears to be off-topic because the code to be reviewed is not 'actual code from a project' and but is 'pseudo-code or example code'. It belongs to programmers SE."
... | [
{
"body": "<p>Essentially you are after the answer to:</p>\n\n<blockquote>\n <p>Does this mean that anyone can just wrap another persons class, unless it is immutable, and inject data?</p>\n</blockquote>\n\n<p>And you are not really interested in a review of your code... right? (By the way, your code looks nea... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T01:46:34.813",
"Id": "36093",
"Score": "0",
"Tags": [
"java",
"optimization",
"generics",
"reflection",
"type-safety"
],
"Title": "Java reflection: Inject data generically... | 36093 |
<p>I am trying to implement the F1 score <a href="http://www.kaggle.com/c/facebook-recruiting-iii-keyword-extraction/details/evaluation" rel="nofollow">shown here</a> in Python.</p>
<p>The inputs for my function are a list of predictions and a list of actual correct values. I thought that the most efficient way of ca... | [] | [
{
"body": "<p>To compute the length of a set difference, you only need to subtract the length of the intersection from the length of the set.\nYou could make use of the intersection when computing the differences. Subtracting the intersection gives the same result but processes fewer elements.</p>\n\n<pre><code... | {
"AcceptedAnswerId": "36118",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T01:59:16.680",
"Id": "36096",
"Score": "2",
"Tags": [
"python"
],
"Title": "Implementing F1 score"
} | 36096 |
<p>I'm making this little game for programming class. Not as an assignment, but as a small side project. Just wanted to point out I do not know a lot about Python, so please don't be harsh, but I can take constructive criticism. </p>
<pre><code>from scene import *
from random import random
import console
import canvas... | [] | [
{
"body": "<p>The biggest thing you can do to improve the code is to find ways to make the relationship between the game flow, the data, and the code more concise.</p>\n\n<p>Right now the whole game is a series of if statements, and you're using variable names as the equivalent of old-fashioned GOTOs to jump ar... | {
"AcceptedAnswerId": "36112",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T02:51:24.003",
"Id": "36101",
"Score": "1",
"Tags": [
"python",
"game",
"adventure-game"
],
"Title": "Better way to code this game?"
} | 36101 |
<p>I recently received a <strong>'good, but not good enough'</strong> rating on a coding exercise I was asked to perform. It was to validate that if "Product complaint" option was selected that Product name, Product size, Use-by date and Batch code fields all needed to have values. <strong>What can I do to improve the ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T03:42:49.200",
"Id": "58986",
"Score": "0",
"body": "were you given the html as-is, or were you asked to create those fields as well?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T03:49:23.467",
... | [
{
"body": "<p>Searching for all the labels is a waste of time/resources. You only ever need a label if the validation fails on an entry, and only then should you locate the matching label for the failed validation.</p>\n\n<p>That way, when all the fields validate, then no labels need to be searched at all.</p>\... | {
"AcceptedAnswerId": "36106",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T03:16:14.430",
"Id": "36102",
"Score": "3",
"Tags": [
"javascript",
"form",
"validation"
],
"Title": "JavaScript form validation: improve on 'good, but not good enough'"
} | 36102 |
<p>I've written a simple function for building a prefix tree (and searching):</p>
<pre><code>import qualified Data.List as L
import qualified Data.Map as M
data Tree a = Empty | Node a [Tree a] deriving (Show, Eq)
partitionBy f = map snd . M.toList . M.fromListWith (++) . map (\x -> (f x, [x]))
buildTree value dt =... | [] | [
{
"body": "<p>At first glance, here are some suggestions-</p>\n\n<ol>\n<li><p>(\\x -> head x) can be written as just \"head\".</p></li>\n<li><p>(\\x -> 0 < length x) can be written as \"(0 <) . length (this is point free notation, which I prefer, although some people may prefer your way.</p></li>\n<li><p>... | {
"AcceptedAnswerId": "36157",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T04:14:00.590",
"Id": "36107",
"Score": "5",
"Tags": [
"haskell",
"beginner",
"tree"
],
"Title": "Simple prefix tree"
} | 36107 |
<p>So I'm writing some code to perform a quite specific task given a large numpy array with N rows and 3 columns representing points in 3D. The 3D points are to be binned along one of the dimensions between specified bin edges. For each of these bins, there is a set fraction by which I must reduce the number of points ... | [] | [
{
"body": "<p>You could use <a href=\"http://docs.scipy.org/doc/numpy/reference/generated/numpy.digitize.html#numpy.digitize\" rel=\"nofollow\"><code>numpy.digitize</code></a> to determine which bin each point belongs in, allowing for a simpler expression inside <code>where</code>.</p>\n",
"comments": [],
... | {
"AcceptedAnswerId": "36116",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T05:43:21.907",
"Id": "36110",
"Score": "1",
"Tags": [
"python",
"numpy",
"statistics"
],
"Title": "Downsampling n-dimensional data from bins in one dimension"
} | 36110 |
<p>I have created a Drupal 6 module that sends messages through PubNub when the user updates information about a Node. I have a separate app that, when launched, calls my Drupal site and receives a JSON array containing a lot of information about some nodes. I then update the info in my other app by PubNub->publish fro... | [] | [
{
"body": "<p>If you are receiving the data you expect, I think you are 99% there. </p>\n\n<p>Alternatively, you could include the PubNub JS client into your Drupal app (vs. the PHP client), then you can publish asynchronously, or even completely after page load.</p>\n\n<p><a href=\"http://www.pubnub.com/docs/j... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T05:59:16.993",
"Id": "36111",
"Score": "4",
"Tags": [
"php",
"json",
"drupal",
"pubnub"
],
"Title": "Module for sending messages through PubNub"
} | 36111 |
<p>Suggestions for cleanup and optimization request. </p>
<p><strong>This question is a follow-up question on <a href="https://codereview.stackexchange.com/questions/35902/find-a-missing-numbers-single-missing-number-and-two-missing-numbers-from-cons">this post</a></strong>. </p>
<p>Lets assume the range of </p>
<bl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T18:31:13.610",
"Id": "59123",
"Score": "0",
"body": "@JavaDeveloper Please see [this meta question](http://meta.codereview.stackexchange.com/questions/1065/how-to-deal-with-follow-up-questions/) about follow-up questions. You would ... | [
{
"body": "<p>Firstly there are 2 classes so don't show them as a single code when showing your code. Place a heading with the class name then your code then second class name then your second class's code. That makes it easier to copy paste it into Eclipse when seeing the code.</p>\n\n<p>Why have you named the... | {
"AcceptedAnswerId": "36229",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T09:34:47.267",
"Id": "36117",
"Score": "4",
"Tags": [
"java",
"optimization",
"array",
"sorting"
],
"Title": "Find missing numbers in a range, with duplicate numbers in a s... | 36117 |
<p>This is my forked branch attempting to make the code better, This is an application for having a slide show of photographs in current directory or supplied as argument.</p>
<p>Use keyboard controls[left to go backward and Right key to go forward and spacebar to toggle play/pause] only.</p>
<p><strong>File 1. utils... | [] | [
{
"body": "<p>Two general observations:</p>\n\n<p>1) Use more lookups and fewer if-else checks. For example: </p>\n\n<pre><code>def isExtensionSupported(filename):\n \"\"\" Supported extensions viewable in SlideShow\n \"\"\"\n if filename.endswith('.PNG') or filename.endswith('.png') or\\\n filename... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T09:57:44.243",
"Id": "36119",
"Score": "0",
"Tags": [
"python",
"design-patterns",
"unit-testing"
],
"Title": "Feedback on logic implementation and testing"
} | 36119 |
<p>Suppose I am listening for network changes with the following listener:</p>
<pre><code>interface NetListener {
void onNetworkAvailable(boolean isWifi);
void onNetworkUnavailable();
}
</code></pre>
<p>I want to have an object, accessible from anywhere within the app, holding the registered <code>NetListen... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T10:59:03.923",
"Id": "59031",
"Score": "0",
"body": "Can a listener trigger a change in the network availability and therefore re-trigger the event while it is being processed?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cr... | [
{
"body": "<p>In general this is a good solution, but there are a few points you should consider:</p>\n\n<ul>\n<li>General style: Make the class <code>final</code>. There is no reason for anyone to subclass it, and the private Constructor shows that intent, but making the class itself final is a good thing.</li... | {
"AcceptedAnswerId": "36127",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T10:03:56.037",
"Id": "36120",
"Score": "3",
"Tags": [
"java",
"performance",
"android"
],
"Title": "Singleton holding and notifying registered listeners"
} | 36120 |
<p>I have something like that:</p>
<ol>
<li><p>My custom exception class:</p>
<pre><code>public class SolvableException extends RuntimeException {
protected boolean solved = false;
public SolvableException(String message) {
super(message);
}
public void setSolved() {
this.solved = t... | [] | [
{
"body": "<p>Especially if you expect these exceptions to occur (relatively) often, I think that using exceptions is a bad idea here. <a href=\"https://stackoverflow.com/questions/729379/why-not-use-exceptions-as-regular-flow-of-control\">Exceptions should not be used for regular flow of control</a>, this appl... | {
"AcceptedAnswerId": "36128",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T11:03:05.613",
"Id": "36125",
"Score": "5",
"Tags": [
"java",
"exception-handling",
"exception"
],
"Title": "Rethrowing exception just as an information"
} | 36125 |
<p>I am looking to make a generic config file using variables such as:
$PLACEHOLDER_USER</p>
<p>Then after moving the file into the correct position I want to replace every instance of *$PLACEHOLDER_VARIABLE* into the value of <em>$VARIABLE</em> from my settings.sh file. </p>
<p>In the example below *"$PLACEHOLDER_US... | [] | [
{
"body": "<p>First up, the shell variable <code>USER</code> is already defined in bash, and is the log-in name of the current user.... so, if you log in as 'rolfl' then <code>echo $USER</code> will print <code>rolfl</code>. There are a number of programs and other systems that may be confused if you change the... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T12:46:22.503",
"Id": "36130",
"Score": "2",
"Tags": [
"bash",
"linux",
"shell"
],
"Title": "Bash to find all placeholder variables in a file and replace will real variables"
} | 36130 |
<p>I'm dealing with huge amount of data. I've written following code into a function to find out similar questions. It's working perfectly but it is taking too much time in execution. Can anyone help me to optimize the function code so that the execution time will be less?</p>
<pre><code><?php
class QuestionMatc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T14:09:52.427",
"Id": "59059",
"Score": "1",
"body": "sql injection alert"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T18:23:03.813",
"Id": "59118",
"Score": "0",
"body": "How does `simi... | [
{
"body": "<p>Unfortunately there's not much you can do here. Unless you try the difficult but efficient approach at the end of my answer, your for loops won't go away and you will need to understand what takes you time inside those loops to get small wins.</p>\n\n<h2>Micro-optimizations</h2>\n\n<p>You need to ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T13:24:37.743",
"Id": "36134",
"Score": "2",
"Tags": [
"php",
"optimization",
"php5"
],
"Title": "How to optimize the following code in order to decrease the execution time?"
} | 36134 |
<p>I'm trying to solve a programming challenge for fun. The programming challenge is <a href="http://uva.onlinejudge.org/external/100/10029.html" rel="nofollow">here</a> and my solution for the same can be found here.</p>
<p>It currently causes an exceeded time limit.</p>
<pre><code>#include <iostream>
#include... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T14:58:05.723",
"Id": "59070",
"Score": "0",
"body": "don't use std::strings if you want performance"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T15:03:03.773",
"Id": "59072",
"Score": "0",
... | [
{
"body": "<p>when you generate the map you immediately throw it away, this will likely be your biggest slowdown</p>\n\n<p>because the map doesn't change in the <code>for</code> you can cache it:</p>\n\n<pre><code>l = all.size();\nmap<string, bool> edits = generate(s);\nfor ( int i = 0; i < l-1; i++ ) ... | {
"AcceptedAnswerId": null,
"CommentCount": "13",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T14:27:55.527",
"Id": "36137",
"Score": "4",
"Tags": [
"c++",
"algorithm",
"performance",
"stl",
"edit-distance"
],
"Title": "\"Edit distance\" UVA programming challenge"
... | 36137 |
<p>I attempt to create a reusable and scalable Cron Wrapper in PHP.</p>
<p>I'm at the begining of the project and I wanted have some tips/ critics / improvments to make before going too far.</p>
<p>The final objective is to have a complete cron wrapper which allows to lauch :</p>
<ul>
<li>'one-shot' task (like huge ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T15:27:48.300",
"Id": "59075",
"Score": "0",
"body": "What's up with the `static` explosion?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T13:57:09.823",
"Id": "59254",
"Score": "2",
"bod... | [
{
"body": "<p>Going to try to answer my own question. So I should use :</p>\n\n<ul>\n<li>Less <code>static</code>s, and implement an interface to deal with config parameters, and just keep the most useful in attributs (<code>logging</code>, <code>profilling</code>)</li>\n<li>Move the mailing functionnality to h... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T15:10:09.757",
"Id": "36140",
"Score": "5",
"Tags": [
"php",
"object-oriented"
],
"Title": "PHP Cron wrapper"
} | 36140 |
<p>I'm working on an application which has a defined and immutable (for our purposes) communication protocol. One of the features is that users on the controlling terminal can enter text commands that in many ways mimic interacting with a commandline application.</p>
<p>The structure of these commands (wrapped within ... | [] | [
{
"body": "<blockquote>\n <p><strong>Nested Switch</strong></p>\n</blockquote>\n\n<p>Nasty smell, but not such a bad idea - if it <em>gets it done</em>, then it could easily be refactored into a much better-looking and less error-prone form. There are already tons of posts here and on StackOverflow about refac... | {
"AcceptedAnswerId": "36159",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T16:17:34.767",
"Id": "36144",
"Score": "5",
"Tags": [
"c#",
"parsing"
],
"Title": "Nested switches vs domain specific parser"
} | 36144 |
<p>I'm working on a path planning algorithm that will be converted to RobotC. I'm trying to optimize it so that it uses the least amount of memory, as the robot it will be implemented on has supposedly as little as 15k available memory.</p>
<p>It may just be the nature of the algorithm used, but it is apparent that it... | [] | [
{
"body": "<p>The pathological hunting in the left region of your test case is an unfortunate consequence of using a naïve greedy algorithm. It really is at least as good locally to move up rather than left, and that's true whether you use Manhattan distances or Euclidean distances. If you want to avoid patho... | {
"AcceptedAnswerId": "36151",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T16:20:25.250",
"Id": "36145",
"Score": "4",
"Tags": [
"javascript",
"performance",
"algorithm",
"pathfinding"
],
"Title": "Path Planning - Greedy Best First Search"
} | 36145 |
<p>I have written about 180 lines of code that implements an Event system.</p>
<p>I would like a general review about the code and I'd love comments about the usability of it. (Is the code useful? Would you like to use it or a similar system like it?)</p>
<h3>Summary of the parts involved</h3>
<ul>
<li><code>IEvent<... | [] | [
{
"body": "<p>Being particularly pedantic, but I have the following observations:</p>\n\n<h1>Annotation @Event</h1>\n\n<p>You go to great lengths to document <code>@Event</code> but not to document the <code>priority()</code> setting .... just saying... The priority is the sort of thing that needs documentation... | {
"AcceptedAnswerId": "36158",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T19:53:47.340",
"Id": "36153",
"Score": "14",
"Tags": [
"java",
"event-handling"
],
"Title": "My Event-handling system"
} | 36153 |
<p>The code works just fine, but recently performace has taken a hit and it has SQL Timeouts far too often. I have it set up so I can run 50 different version of the application two for each different <code>m.qlevel</code>.</p>
<p>This allows it to run fairly fast, but the SQL timeouts are requiring to much babysitti... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T22:35:14.483",
"Id": "59151",
"Score": "0",
"body": "Have you done an execution plan on the SQL statements inside your code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T22:44:27.290",
"Id": "5... | [
{
"body": "<p>Try this Query</p>\n\n<pre><code>const string Sql = @\"select top 1 d.UID, d.CreatedDate, d.Location, m.number from master m with (NOLOCK)\n inner join documentation_attachments da with (NOLOCK)\n on m.number = da.accountid\n inner jo... | {
"AcceptedAnswerId": "36164",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T22:10:34.057",
"Id": "36161",
"Score": "4",
"Tags": [
"c#",
"sql",
"sql-server"
],
"Title": "Speed up application and avoid SQL Timeouts"
} | 36161 |
<p>I would like advice on making my code more elegant and straightforward. The code works great, but it lacks these things.</p>
<pre><code><?php
if(isset($_POST['retrieve_posts'])) {
$post_ret = $_POST['retrieve_posts'];
}
if(isset($_POST['retrieve_images'])) {
$image_ret = $_POST['retrieve_images'];
} els... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-20T21:48:14.980",
"Id": "66571",
"Score": "0",
"body": "Please do not remove your code after receiving answers."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-21T06:41:43.763",
"Id": "66627",
"Scor... | [
{
"body": "<p>It's not too bad.</p>\n\n<ul>\n<li>First, make sure your indentation is always correct, eg. in your last <code>if</code> and your last <code>foreach</code>.</li>\n<li>Second, never store passwords in your main source file! They should go in a file that is not version-controlled and only contains t... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T22:20:44.793",
"Id": "36163",
"Score": "6",
"Tags": [
"php",
"json",
"api"
],
"Title": "Retrieving information and images for rental properties using an API"
} | 36163 |
<p>I was tasked with refactoring our existing <code>IniReader</code> class, which is Windows only compatible, to be cross-platform ( specifically UNIX compatible ). We decided that <code>boost::property_tree</code> was a good fit for this and a quick play with property_tree confirms this.</p>
<p>The original class had... | [] | [
{
"body": "<p>I wouldn't worry too much about temporaries (shouldn't they be optimized away?), but I think you're focusing on the smaller problem. You fundamentally have the following options:</p>\n\n<ul>\n<li>Disambiguate by disallowing certain combinations, like you say you've currently done (<code>readValue&... | {
"AcceptedAnswerId": "36176",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T23:13:24.347",
"Id": "36166",
"Score": "3",
"Tags": [
"c++",
"template"
],
"Title": "IniReader template overrides become ambiguous"
} | 36166 |
<p>As a school project in my navigator 12 class, I've decided to try and learn Java. I thought that I'd try and make the Game of Life, because it would be a good way to start learning Java (watched a bunch of Java tutorials).</p>
<p>Could I get your feedback on this program I wrote? I would like input on if everything... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-03T03:54:14.637",
"Id": "68662",
"Score": "2",
"body": "I thought first programs are like System.out.println(\"Hello World\"); When did first programs become games? People must be getting smarter!"
}
] | [
{
"body": "<p>So there's a lot to go though in here. I think that as a beginner project you can be proud of your code... there are a number of things I would change, but, on the whole, it is systematic, logical, and well-formatted. In my opinion this is far more preferable than 'clever' code that is hard to rea... | {
"AcceptedAnswerId": "36175",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T01:28:30.433",
"Id": "36172",
"Score": "8",
"Tags": [
"java",
"beginner",
"game-of-life"
],
"Title": "First Java program critique (Game of Life)"
} | 36172 |
<p>As shameful as it is to say I wanted to see what all the fuss about was with Tinder, but after downloading it I found I was more interested with its animation effects and started wondering how they did them!</p>
<p>I decided I wanted to see if I could replicate some of them using jQuery so they can be used on web a... | [] | [
{
"body": "<p><em>Disclaimer: I don't know what Tinder is yet.</em><br>\nShorter version:</p>\n\n<pre><code>$(document).ready(function () {\n function addCircle() {\n var $circle = $('<div class=\"circle\"></div>');\n $circle.animate({\n 'width': '300px',\n 'he... | {
"AcceptedAnswerId": "36177",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T03:42:44.917",
"Id": "36174",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"animation"
],
"Title": "Tinder-esque location pulse animation effect"
} | 36174 |
<p>I have an assignment as follows:</p>
<blockquote>
<p>Write a program which reads from the keyboard two integers n and m,
and a character c from the keyboard. This program should define and
call a function:
print rectangle(n, m, c) which prints a rectangle of
size n x m consisting of the character c</p>
</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T08:12:10.847",
"Id": "59204",
"Score": "2",
"body": "\"[...] and a character c from the keyboard\". c should also be input from the user, just like n and m."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-1... | [
{
"body": "<pre><code>def print_rect(n, m, c):\n l = (n * c for a in range(m))\n print '\\n'.join(l)\n</code></pre>\n\n<p>I believe this would be slightly faster. I did a test on my computer:) <em>(I'm using Python 2.7.5 so the code is slightly different with Python3)</em></p>\n\n<pre><code>import timeit\... | {
"AcceptedAnswerId": "36203",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T07:58:15.090",
"Id": "36182",
"Score": "2",
"Tags": [
"python",
"homework",
"python-3.x",
"console"
],
"Title": "Printing a rectangle"
} | 36182 |
<p>Here is a small library which manages writing into and reading out a byte array. It uses TValue arrays to get and put data, its my first time using them. Its crudely written, and poorly optimized but I tried to make the best solution in the 3 hrs I was given to build and debug it. Right now it only supports Integer,... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-28T08:53:14.283",
"Id": "59411",
"Score": "0",
"body": "Why do you have all of those commented lines? Is this by convention? Because it's ugly!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-28T09:00:31.03... | [
{
"body": "<p>I'm not a Delphi programmer, but here are a two comments based on what I understood.</p>\n\n<p>Use an enumeration type instead of characters ('n', 't'...) to determine the type.</p>\n\n<p>It seems that TArray is a <a href=\"http://en.wikipedia.org/wiki/Dynamic_array\" rel=\"nofollow\">dynamic arra... | {
"AcceptedAnswerId": "36288",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T09:57:31.853",
"Id": "36195",
"Score": "2",
"Tags": [
"performance",
"delphi",
"object-pascal"
],
"Title": "Thoughts on my byte array library"
} | 36195 |
<p>I found myself writing code of the form...</p>
<pre><code>val foo : Foo = ???
val step1 : Foo = {
if ( someCharacteristic( foo ) )
someTransformation( foo )
else
foo
}
val step2 : Foo = {
if ( otherCharacteristic( foo ) )
otherTransformation( foo )
else
foo
}
val result = step2;
</code></p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T12:50:24.863",
"Id": "59251",
"Score": "0",
"body": "Umm... I think you could easily solve the problem above with a `Map` (or even just a sequence of tuples) and two basic operations: `filter` and `foldLeft`. :) Although it doesn't ... | [
{
"body": "<p>What you are describing are simply functions.</p>\n\n<p>To take a related example from mathematics, </p>\n\n<pre><code> / x, if x >= 0\nabs(x) = |\n \\ -x, otherwise\n</code></pre>\n\n<p>And you are just composing functions: <code>f(g(x))</code>.</p>\n\n<p>You can somewhat... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T10:13:07.407",
"Id": "36197",
"Score": "1",
"Tags": [
"scala",
"monads"
],
"Title": "Is this a reasonable Scala monad?"
} | 36197 |
<p>We have a large directed acyclic graph and a requirement to filter it by allowing a user to select certain nodes and then we remove all nodes that are not selected nodes, ancestors of those nodes, or descendants of those nodes.</p>
<p><img src="https://i.stack.imgur.com/Ec8Fg.png" alt="graph removal"></p>
<p>As yo... | [] | [
{
"body": "<p>Since your nodes are double-linked (i.e. each has a list of all parents and children), creating the list of closures for all children of a certain node (especially the root node) seems like an overkill, especially if you're doing that whenever you start to filter. If you have a doubly linked graph... | {
"AcceptedAnswerId": "36234",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T10:40:21.270",
"Id": "36198",
"Score": "6",
"Tags": [
"c#",
"algorithm",
"performance",
"graph"
],
"Title": "How to improve this algorithm for building a graphs closures"
} | 36198 |
<p>I have this code which will store user session credentials:</p>
<pre><code>import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class SessionCache
{
/**
* Default Constructor
*/
public SessionCache()
{
}
/**
* Map which... | [] | [
{
"body": "<ol>\n<li>First you should rename your instance members in ActiveConnections class - having methods and variables named getOne(), getTwo(), etc, are horrible because at first you'd expect them to return the int value of one, two, three (e.g., returning 1, 2, 3) but in reality they most likely won't.<... | {
"AcceptedAnswerId": "36206",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T11:35:57.617",
"Id": "36200",
"Score": "3",
"Tags": [
"java",
"search",
"cache"
],
"Title": "How to improve this session cache to search faster"
} | 36200 |
<p>just wanted to check with you could this be done better:</p>
<pre><code>awk -F"\t" '{
for (i = 1; i <= NF; i++) {
if ($i != "NULL") {
printf("%s%s", $i, FS);
}
}
printf("\n");
}' file1
</code></pre>
<p>The goal is to print only non-<code>NULL</code> fields. For example:<... | [] | [
{
"body": "<p>The same behaviour can be achieved using <code>sed</code> as follows:</p>\n\n<pre><code>echo -e 'TestRecord001\\tNULL\\tNULL\\tAge\\t29\\tNULL\\tNULL\\tName\\tJohn' | sed '\ns/$/\\t/;\ns/\\(\\tNULL\\)\\+\\t/\\t/g;\ns/^NULL\\t//';\n</code></pre>\n\n<p>Explanation:</p>\n\n<p><code>sed s/SearchPatter... | {
"AcceptedAnswerId": "36205",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T11:49:47.723",
"Id": "36201",
"Score": "4",
"Tags": [
"shell",
"null",
"unix",
"awk"
],
"Title": "Removing NULL / empty fields"
} | 36201 |
<p>I have implemented several lock-free algorithms to maximise throughput but have always baulked when performing a spin-lock. I can usually convince myself that this is the only way but it still nags at me that a spin-lock is a terribly bad idea.</p>
<p>I recently came across a <a href="http://docs.oracle.com/javase/... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T14:34:27.900",
"Id": "59262",
"Score": "0",
"body": "Note - I have tinkered with it a bit since first post so if you have taken a copy to test, please recopy."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013... | [
{
"body": "<p>I believe there's race conditions in your code, Specifically, if you call <code>wakeup()</code> asymettrically (more times than you call <code>sleep()</code>) then you run the risk of a few things:</p>\n\n<ol>\n<li>you could have multiple running threads (i.e. there's not just one thread using the... | {
"AcceptedAnswerId": "36228",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T12:44:56.233",
"Id": "36204",
"Score": "5",
"Tags": [
"java",
"lock-free"
],
"Title": "Block a thread - spin-lock replacement"
} | 36204 |
<p>I'd like to have this code looked over because I feel my approach might be very novice and there has to be a more elegant or at least less "grunt-work" way of doing it.</p>
<p>I have to write a small TCP client in my application which can send an object to a server for it to be stored in a Database. Before I send t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T15:07:39.600",
"Id": "59279",
"Score": "1",
"body": "are you worried about thread safety or not because currently it's not thread safe"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T15:10:26.000",
... | [
{
"body": "<p>I find whenever I <em>feel the need</em> to use a <code>#region</code>, there's something fishy going on with my code; I see the same in your <code>SendPlejeFamilieObjekt</code> method: all those <code>WriteLine</code>/<code>Flush</code> calls look very suspicious. Why do you flush at every single... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T14:20:11.197",
"Id": "36207",
"Score": "4",
"Tags": [
"c#",
"tcp",
"client"
],
"Title": "Objects sending TCP Client"
} | 36207 |
<p>I am trying to implement a function below:</p>
<blockquote>
<p>Given a target sum, populate all subsets, whose sum is equal to the target sum, from an <code>int</code> array.</p>
</blockquote>
<p>For example:</p>
<p>Target sum is 15.</p>
<p>An <code>int</code> array is <code>{ 1, 3, 4, 5, 6, 15 }</code>.</p>
... | [] | [
{
"body": "<p>There are three reasonable responses here:</p>\n\n<ul>\n<li>yes, your recursion code can be improved for performance.</li>\n<li>yes, part of that improvement can come from sorting the data.</li>\n<li>yes, there's a way to refactor the code to not use recursion, and it may even be faster.</li>\n</u... | {
"AcceptedAnswerId": "36247",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T15:04:51.970",
"Id": "36214",
"Score": "30",
"Tags": [
"java",
"array",
"recursion",
"mathematics",
"combinatorics"
],
"Title": "Find all subsets of an int array whose ... | 36214 |
<p>I have an assignment as follows:</p>
<blockquote>
<p>Write a program where you can enter from the keyboard up to 10
integers. If the number entered is equal to -99, stop reading numbers
from the keyboard and compute the average and sum of all values
(excluding -99). Print the average on the screen. Make sur... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T16:30:03.500",
"Id": "59309",
"Score": "1",
"body": "have you read the assignment? `excluding -99`. Also you are displaying results after every input."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-05T1... | [
{
"body": "<p>A few things:</p>\n\n<p>The application should do 2 things.</p>\n\n<blockquote>\n <ol>\n <li><p>Collect up to 10 different integers, or until the entered value is -99</p></li>\n <li><p>Sum and Average the values</p></li>\n </ol>\n</blockquote>\n\n<pre><code># so lets start by creating a list a... | {
"AcceptedAnswerId": "36219",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T15:19:23.240",
"Id": "36216",
"Score": "1",
"Tags": [
"python",
"python-3.x",
"mathematics"
],
"Title": "Taking the sum and average of the keyboard inputs"
} | 36216 |
<p>I am developing a GUI using Swing, but before my project gets too complex. I would like to have a good design structure. I have a few ideas and will use a simple example to illustrate. Some feedback on whether or not this is a good approach would be great. </p>
<p>This is what my GUI looks like:</p>
<p><img src=... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T15:51:19.030",
"Id": "59299",
"Score": "1",
"body": "I haven't done Java in years, but both panels seem to have a lot in common. Perhaps you can reduce duplicate code by putting all of the common features into a base class that exte... | [
{
"body": "<ul>\n<li><p>Variable names. Imagine yourself a couple of months from now on, when you look back at the code. Will you remember without looking at the variable declaration what <code>gnb</code> is short for? I suggest you use longer variable names so that you even won't have to try to remember it. <c... | {
"AcceptedAnswerId": "36225",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T15:43:27.193",
"Id": "36220",
"Score": "5",
"Tags": [
"java",
"swing",
"gui"
],
"Title": "GUI design in Java Swing"
} | 36220 |
<p>I have written a method that uses binary search to insert a value into an array.</p>
<p>It is working, but i would like to get a second opinion to see if i didn't write too much code for it. aka doing same thing twice for example.</p>
<p>The code looks for the right index for insertion and is called by an insert m... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T16:05:51.693",
"Id": "59303",
"Score": "0",
"body": "Can you also post the other variables that aren't mentioned in this function? It will help with the code review :) `nElems`, data type of `curIn`, declaration of `a[]` and whateve... | [
{
"body": "<p>Here is my version of your code.</p>\n\n<ol>\n<li>You never use \"max\" so I used it by throwing an exception if you are trying to insert too many elements.</li>\n<li>You should make everything that shouldn't be public; private. </li>\n<li>In your <code>binaryInsert()</code> you should move your ... | {
"AcceptedAnswerId": "36233",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T16:01:28.400",
"Id": "36221",
"Score": "9",
"Tags": [
"java",
"array",
"binary-search",
"reinventing-the-wheel"
],
"Title": "Binary search for inserting in array"
} | 36221 |
<p>I have a <code>List</code> of objects, <code>List<myObject> objectList</code>, and each object contains a <code>List</code> of strings like so:</p>
<pre><code>myObject: StringList( "A_1", "B_1", "C_1", "D_1", "E_1", "F_1" )
myObject: StringList( "A_2", "B_2", "C_1", "D_2", "E_2", "F_1" )
myObject: StringL... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T16:28:38.343",
"Id": "59311",
"Score": "1",
"body": "Did you try SelectMany?"
}
] | [
{
"body": "<p>Just get rid of the outer <code>foreach</code> as well:</p>\n\n<pre><code>dict = objectList.SelectMany(x => x.StringList)\n .Select(x => x.Split('_'))\n .GroupBy(x => x[0])\n .ToDictionary(x => x.Key, x => x.Select(g => g[1]).Distinct().ToList());\n</code></pre>... | {
"AcceptedAnswerId": "36224",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T16:25:26.127",
"Id": "36223",
"Score": "7",
"Tags": [
"c#",
"strings",
"linq",
"hash-map"
],
"Title": "Creating a dictionary of strings and list of strings"
} | 36223 |
<p>Whenever I create a Javascript "class" I do something like this:</p>
<pre><code>// Definition
function MyObject() {
this.id = 0;
this.legs = 2;
}
MyObject.prototype = {
walk: function() {
// Do stepping
},
stop: function() {
// Stop stepping
}
};
// Instanciation
var TestMyObject = ne... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T18:11:15.313",
"Id": "59342",
"Score": "0",
"body": "Welcome! Yes, it certainly looks like you have come to the right place!"
}
] | [
{
"body": "<p>Correct, the lifetime of <code>objectSettings</code> is only for the <code>MyObject</code> function, so you don't need the assignment to <code>null</code> at the end.</p>\n\n<p>Passing in an object to the constructor is a common pattern to set its properties, and if you don't want to add specific ... | {
"AcceptedAnswerId": "36237",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T18:02:37.120",
"Id": "36231",
"Score": "5",
"Tags": [
"javascript",
"object-oriented"
],
"Title": "Object construction differences"
} | 36231 |
<p>Should I leave the Default Route in if it's not adding any benefit?</p>
<p>I have a RouteConfig.cs file that looks like this:</p>
<pre><code>public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Dashboard",
url... | [] | [
{
"body": "<p>I am thinking that you would want to keep that default route in there in the case that something happens to the other routes, then there is something to route to if your custom routes get hosed up for some reason.</p>\n\n<p>Defaults are there for a reason, don't get rid of them</p>\n",
"commen... | {
"AcceptedAnswerId": "36313",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T18:41:18.497",
"Id": "36236",
"Score": "5",
"Tags": [
"c#",
"asp.net-mvc-4",
"url-routing"
],
"Title": "MVC4 Routes, using Default"
} | 36236 |
<p>I need to build the following XML document</p>
<pre class="lang-xml prettyprint-override"><code><?xml version="1.0"?>
<SFDocument>
<TableID>5415</TableID>
<PageSize>1</PageSize>
<PageIndex>1</PageIndex>
<MultiCompany>No</MultiCompany>
&... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T21:25:16.630",
"Id": "59365",
"Score": "2",
"body": "Recently i have started using serializable classes for these kinds of things, the advantage being that i can easily read the XML document back into the same structure, by deserial... | [
{
"body": "<p>Back when using .NET 2.0, I wrote a <code>Tag</code> class which inherited from <code>XmlElement</code>, and a <code>XmlBuilder</code> which inherited from <code>XmlDocument</code>. For legacy reasons we still use it, but I'm pretty sure it could be rewritten in half the code as a few extension m... | {
"AcceptedAnswerId": "36312",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T18:58:55.747",
"Id": "36238",
"Score": "5",
"Tags": [
"c#",
"linq",
"xml"
],
"Title": "Proper and elegant way of Building a XML Document"
} | 36238 |
<p>How can I rewrite this code to make it more readable and, if possible, more efficient? The conditions are entirely necessary in this problem, but how could I rewrite those <code>if(a != 1)</code> and such?</p>
<pre><code>celula ** verificaNo(celula ** matriz, int linhas, int colunas){
celula ** aux = matriz;
int i,... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-28T15:06:49.943",
"Id": "59460",
"Score": "1",
"body": "As to discuss the readability, would you explain a little bit more about its function? So no one has to guess."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": ... | [
{
"body": "<p>This would become instantly more understandable if you gave a description (a comment at the start of the function) of what it was supposed to do. You could also give the structure <code>celula</code>, which I'm assuming is at least:</p>\n\n<pre><code>struct celula\n{\n int no; // number... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T20:07:58.693",
"Id": "36241",
"Score": "1",
"Tags": [
"optimization",
"c",
"matrix"
],
"Title": "How can I make this code more readable and efficient?"
} | 36241 |
<p>This code basically connects to a database, sets login success and failure pages, queries the database for user details, checks if user is active, sets session value and redirects accordingly.</p>
<p>Can you have a look? What do you think of it? Any suggestions?</p>
<pre><code><?php
session_start();
// Connec... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T20:29:36.433",
"Id": "59359",
"Score": "1",
"body": "You mean *improve* a piece of code right? Or you're a code jazzman?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T20:40:53.577",
"Id": "59361... | [
{
"body": "<p>Just few quick things come to my mind:</p>\n\n<ul>\n<li><p>The way try/catch is used is to exit on error, which would happen anyway. Maybe you need to send some info to the user here instead.</p></li>\n<li><p>Are you passing raw user input to the database, without validation? This would be clear s... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T20:17:43.077",
"Id": "36242",
"Score": "1",
"Tags": [
"php",
"mysql",
"session"
],
"Title": "Login and User Information Requests"
} | 36242 |
<blockquote>
<p>Open-source programming language and integrated development environment (IDE) built for the electronic arts, new media art, and visual design communities with the purpose of teaching the fundamentals of computer programming in a visual context, and to serve as the foundation for electronic sketchbooks... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-11-27T20:19:28.280",
"Id": "36243",
"Score": "0",
"Tags": null,
"Title": null
} | 36243 |
Open-source programming language and IDE built to teach the fundamentals of computer programming in a visual context, and to serve as the foundation for electronic sketchbooks. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-11-27T20:19:28.280",
"Id": "36244",
"Score": "0",
"Tags": null,
"Title": null
} | 36244 |
<p>A Session refers to all the requests that a single client makes to a server.</p>
<p>From <a href="http://en.wikipedia.org/wiki/Session_%28computer_science%29" rel="nofollow">Wikipedia</a>: </p>
<p>A session is a semi-permanent interactive information interchange, also known as a dialogue, a conversation or a meeti... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T20:38:37.470",
"Id": "36248",
"Score": "0",
"Tags": null,
"Title": null
} | 36248 |
<p>I am trying to simplify the below <code>if</code> <code>else</code> statement, and I think it can be done.</p>
<p>Algorithm is like this - </p>
<blockquote>
<p>If <code>user_ptr</code> exists, then <code>lock attrmap</code>, find <code>user_ptr</code>. And if it
is a <code>batch</code>, then don't ping. And el... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T21:09:49.403",
"Id": "59364",
"Score": "0",
"body": "You *could* technically simplify it by expressing results in values and run the values through a 'switch' block."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate"... | [
{
"body": "<p>What you have is essentially:</p>\n\n<pre><code>if (a) {\n if (b) c();\n d();\n}\nelse if (b) e();\n</code></pre>\n\n<p>Where:</p>\n\n<pre><code>a = user_ptr\nb = batchOrTimestamp != \"batch\"\nc = user_ptr->ping();\nd = 2 lines, starting with `AttributeMap::GuardSPtr guard = user_ptr->m... | {
"AcceptedAnswerId": "36257",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-27T21:07:35.360",
"Id": "36250",
"Score": "2",
"Tags": [
"c++"
],
"Title": "Simplifying the if else statement"
} | 36250 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.