body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I wrote a little C++ program for playing Chess:</p>
<p>Now I check the valid moves by filling an 8x8 board with different flags called <code>cBoard</code>.</p>
<ul>
<li><code>fNONE</code> = none type </li>
<li><code>canPASS</code> = the piece can go there</li>
<li><code>cannotPASS</code> = the piece is blocked </l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T20:28:25.553",
"Id": "12344",
"Score": "0",
"body": "oh thx for the edit @Loki Astari, why there was that error? I had it formatted correctly..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T20:29:3... | [
{
"body": "<h3>Main Comments:</h3>\n\n<ul>\n<li><p>I think (by the name of your function) you are missing out on polymorphism (see at bottom)</p></li>\n<li><p>Make sure your code is correctly indented.<br>\nI think you had tabs mixed in with your spaces and the last half was uneven<br>\n(I fixed it so I could r... | {
"AcceptedAnswerId": "7814",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T20:09:04.077",
"Id": "7811",
"Score": "3",
"Tags": [
"c++",
"game"
],
"Title": "Chess game function"
} | 7811 |
<pre><code>import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
/**
* Solution for Quora Classifier question from CodeSprint 2012 This class
* implements a logistic regression classifier trained with Stochastic Gradient
* Desc... | [] | [
{
"body": "<p>Same answer as your other <a href=\"https://codereview.stackexchange.com/questions/7813/general-java-style-suggestions-clustering-question-from-codesprint-2012/7841#7841\">question</a>.</p>\n\n<p>You should have some class to load (and contain) the original data; some Normalizer interface (you mig... | {
"AcceptedAnswerId": "7856",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T20:35:39.077",
"Id": "7812",
"Score": "4",
"Tags": [
"java"
],
"Title": "General Java Style Suggestions - Classification Problem from CodeSprint 2012"
} | 7812 |
<pre><code>import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Patt... | [] | [
{
"body": "<p>A \"General Java Style Suggestion\" is to use class definitions to promote type safety within your system and promote semantically descriptive names. </p>\n\n<p>For example, the statement <code>documents[0][1]</code> means what? The title of the first document in documents. That's not very Java-li... | {
"AcceptedAnswerId": "7841",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T20:42:36.323",
"Id": "7813",
"Score": "5",
"Tags": [
"java"
],
"Title": "General Java Style Suggestions - Clustering Question from CodeSprint 2012"
} | 7813 |
<p>My task was to write a function in C where a string such as <code>{2210090,34566,87234,564676}</code> would be given as input and the function had to find out the count of numbers separated by comma whose average of single digits is greater than or equal to 5.</p>
<p>In the below example, the average of 2210090 is ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T18:04:45.397",
"Id": "12358",
"Score": "4",
"body": "Why is `n` passed into the function if the first thing you do is set it to zero?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T18:05:09.580",
... | [
{
"body": "<p>First, what is the n parameter for, and do you need it?\nSecond, try structuring your code basically like:</p>\n\n<pre><code>function definition\n int n = 0;\n int val = 0;\n int count = 0;\n iterate over the string\n if the character is a numeral\n val += character v... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T18:02:49.693",
"Id": "7818",
"Score": "5",
"Tags": [
"optimization",
"c",
"strings",
"homework"
],
"Title": "String traversal program in C"
} | 7818 |
<p>I'm using django and I wrote this decorator to take away some of the repetitive code I found for ajax views and I want to know your opinion (too basic, bad design, try this instead, etc).</p>
<pre><code>def ajax_only(func):
def _ajax_only(request,*args,**kwargs):
if not request.is_ajax():
re... | [] | [
{
"body": "<ol>\n<li>You should use the functools.wraps function, it makes sure the docstring/name/etc gets passed through</li>\n<li>Instead of \"ajax not supported\" shouldn't it be: \"only ajax supported\"?</li>\n<li>Shouldn't you respond with a Status Code 400 or something if not using ajax when you should b... | {
"AcceptedAnswerId": "7835",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-15T03:58:49.123",
"Id": "7826",
"Score": "4",
"Tags": [
"python",
"django"
],
"Title": "Decorator to take away repetitive code"
} | 7826 |
<p><code>HtmlAgilityPack</code> is being really slow pulling back results. I have seen similar tools that get results a lot faster, but it's taking over a minute just to get the viewcounts on YouTube, and that's just with the first page of results.</p>
<p>Ideally I want to loop through multiple elements, but a nested ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T01:11:58.833",
"Id": "12370",
"Score": "0",
"body": "How long does the `webGet.Load(raw);` take? IO (be it disk, network, etc) will always be the slowest part of your code."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creati... | [
{
"body": "<p>Doing a simple regex on the page result would be most certainly more efficient, though several people will tell you that using an <em>HTML parser</em> to parse <em>HTML</em> is always the best practice.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDa... | {
"AcceptedAnswerId": "7830",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-14T01:05:47.513",
"Id": "7827",
"Score": "5",
"Tags": [
"c#"
],
"Title": "HtmlAgilityPack is being slow"
} | 7827 |
Intel Thread Building Blocks | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-15T04:43:56.843",
"Id": "7833",
"Score": "0",
"Tags": null,
"Title": null
} | 7833 |
<p>I'm interested in the idea of not having my BLL dependent on ASP.NET MVC. This means that I would like to have model binding occur within my service layer. But I want to take advantage of ASP.MVC's model validation as well. So I'm considering returning a custom validation dictionary from my BLL service methods like ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-08-02T15:49:39.297",
"Id": "256205",
"Score": "0",
"body": "Regarding your link, this seems to boil down to: work through a custom validation interface, wrap the ModelStateDictionary, pass it and update in the service; or (your option) re... | [
{
"body": "<p>It feels somewhat awkward to answer a question this old, but there are some things that can be done.</p>\n\n<hr>\n\n<p>First, I want to comment on the naming, simply from the fact that I'm currently building an ASP.NET app which is <em>very</em> large, and I've learned through the process that the... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-15T17:00:28.303",
"Id": "7845",
"Score": "7",
"Tags": [
"c#",
"asp.net-mvc-3"
],
"Title": "Model validation from within the Service Layer"
} | 7845 |
<p>Reading <a href="http://en.wikipedia.org/wiki/Cycle_detection#Tortoise_and_hare" rel="nofollow">the article</a> in Wikipedia about cycle detection I came across a relatively small code snipped of Floyd's cycle-finding algorithm. I'll put it here to keep everything in one place:</p>
<pre><code>def floyd(f, x0):
... | [] | [
{
"body": "<pre><code># -*- coding: utf-8 -*-\n\nfrom __future__ import print_function\nfrom itertools import islice,cycle,chain\n\n\ndef detect_cycle(iterable):\n\n class animal(object):\n</code></pre>\n\n<p>Putting classes inside function is usually not all that helpful. Also, the name doesn't really sugge... | {
"AcceptedAnswerId": "7851",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-15T18:03:03.690",
"Id": "7847",
"Score": "1",
"Tags": [
"python",
"iterator"
],
"Title": "Tortoise and hare cycle detection algorithm using iterators in Python"
} | 7847 |
<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Linq;
using System.Threading;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RestSharp;
namespace ReactiveExtensions
{
class Program
{
static void Main(string[] args)
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-15T23:34:14.827",
"Id": "12422",
"Score": "5",
"body": "Please describe what it does, what is it's purpose, and what features of Rx does it demonstrate."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-16T04... | [
{
"body": "<p>possible improvements :</p>\n\n<ol>\n<li>make CallStackOverflow asynchronous</li>\n<li>use Observavle.Timer instead of thread.sleep</li>\n</ol>\n\n<p>Here is what it would look like</p>\n\n<pre><code>class Program\n{\n static void Main(string[] args)\n {\n\n Observable\n .Timer(T... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-15T18:25:54.797",
"Id": "7849",
"Score": "2",
"Tags": [
"c#",
".net",
"system.reactive"
],
"Title": "Is this a good example of Reactive Extensions? How can I make this better?"
} | 7849 |
<p>I am endeavoring to build my first non-trivial web application and so I'd like to confirm a couple of design decisions.</p>
<p>I have three tiers as follows:</p>
<ol>
<li>UI (my MVC project)</li>
<li>Business Logic (separate project)</li>
<li>Data Access Logic (a simple .dbml that is part of project #2)</li>
</ol>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-23T14:42:11.697",
"Id": "71205",
"Score": "0",
"body": "Have you tried Neos-SDI MVC4 Template? It's a good start for creating a MVC n-tiers web site.\nOnce this template is installed, it will create for you all your layers, use injecti... | [
{
"body": "<p>An accepted design pattern for separation of concerns is the Repository design pattern. There is a pretty good description of using this design pattern in MVC <a href=\"http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-a... | {
"AcceptedAnswerId": "7872",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-16T03:48:18.573",
"Id": "7855",
"Score": "3",
"Tags": [
"c#",
"asp.net-mvc-3"
],
"Title": "nTier architecture for an MVC application"
} | 7855 |
<p>I am doing my homework and i have done this? Is there any other better way to do this?
<br>
<br></p>
<pre><code>def write_log(name, total):
# change user input with shape names
name = name.replace('1', 'triangle')
name = name.replace('2', 'square')
name = name.replace('3', 'rectangle')
name = na... | [] | [
{
"body": "<p><strong>-- One --</strong></p>\n\n<p>You can use a dictionary to hold your translation data:</p>\n\n<pre><code>mydict = {'1':'triangle', '2':'square', '3':'rectangle',\n '4':'pentagon','5':'hexagon', '6':'octagon','7':'circle'}\n</code></pre>\n\n<p>Now your list of replacement lines becom... | {
"AcceptedAnswerId": "7859",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-15T17:26:21.557",
"Id": "7857",
"Score": "4",
"Tags": [
"python",
"homework"
],
"Title": "is there a better way than replace to write this function?"
} | 7857 |
<p>I tried to implement the dispose-finalize pattern on this WCF wrapper.</p>
<p>Do you have any comments about this? Something I missed?</p>
<pre><code>namespace System.ServiceModel
{
public class WCFClientWrapper<TProxy> : IDisposable where TProxy : class
{
private string _endpointAddress;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-09-25T08:26:13.887",
"Id": "116691",
"Score": "0",
"body": "Any final _solution_ with **full source code** sample application ? _IMHO, better samples for minimize learning curve are real \n\napplications with full source code and good pat... | [
{
"body": "<p>Given that much of the code seems to rely on Service being an IClientChannel, and the name of the class implies as such, it may be worth simply adding IClientChannel to your type constraints and remove all the type conversion code.</p>\n\n<p>Building upon that thought, I notice that IClientChannel... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-16T06:55:59.577",
"Id": "7862",
"Score": "3",
"Tags": [
"c#",
"wcf"
],
"Title": "WCF wrapper implementing dispose-finalize pattern"
} | 7862 |
<p>I'm a beginner, currently taking the <a href="http://see.stanford.edu/see/courseinfo.aspx?coll=824a47e1-135f-4508-a5aa-866adcae1111" rel="nofollow">Stanford's free CS106A cours</a>e which teaches Java. The <a href="http://see.stanford.edu/materials/icspmcs106a/19-assignment-3-breakout.pdf" rel="nofollow">second assi... | [] | [
{
"body": "<p>I haven't tried to get into the high level design of your game but here are a few details you might want to fix.</p>\n\n<ul>\n<li><p><code>if (won == true)</code> can be written <code>if (won)</code></p></li>\n<li><p>You can use the ternary operator to use setLabel only once : <code>gameOverLabel.... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-16T15:08:35.563",
"Id": "7865",
"Score": "4",
"Tags": [
"java",
"beginner",
"game"
],
"Title": "Building a Breakout game from scratch"
} | 7865 |
<p>I have the following .net-page. I hope it is ok that it is only an example, describing my problem(s) pretty well.</p>
<pre class="lang-html prettyprint-override"><code><form id="form1" runat="server">
<div>
<asp:TextBox runat="server" ID="textBox1"></asp:TextBox>
<asp:TextBo... | [] | [
{
"body": "<ul>\n<li>I don't see any reason to refactor that code, at least not in its current state.</li>\n<li>Yes, the routine has a single responsibility at this stage, namely to initialise the fields in the form. If you add another responsibility to the method, you can put the initialisation code in a separ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-16T15:37:38.230",
"Id": "7866",
"Score": "2",
"Tags": [
"c#",
"html",
".net",
"datetime"
],
"Title": "Page_Load-routine"
} | 7866 |
<p>Can someone take a look over my bootstrap file and see if you believe it's doing too much or the logic could be better.</p>
<pre><code><?php
/*
* ------------------------------------
* Autoloader for classes/files
* ------------------------------------
*/
function __autoload($class) {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-16T20:02:46.180",
"Id": "12460",
"Score": "1",
"body": "I'd recommend using DIRECTORY_SEPARATOR instead of just assuming that file paths use / as the separator (I'd also recommending aliasing it to something shorter ;) ). Also, I'd re... | [
{
"body": "<p>Generally this is very good code, but I try to be thorough when reviewing so I've listed every minor point that I could think of.</p>\n\n<p>It looks like you write OO code in other places, but you chose to make your bootstrap procedural. Believe it or not <strong>there are benefits to an OO boots... | {
"AcceptedAnswerId": "7918",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-16T15:56:51.480",
"Id": "7867",
"Score": "3",
"Tags": [
"php"
],
"Title": "Bootstrap file - safe and correct"
} | 7867 |
<p>As my <a href="https://codereview.stackexchange.com/q/7684/15094">parallel mergesort implementation</a> was very memory dependent, I wanted to write a parallel quicksort one. Here it comes:</p>
<pre><code>template<class In>
In partition(In b, In e) {
// create uniform distribuiton for random engine
st... | [] | [
{
"body": "<h2>Code</h2>\n\n<p>I would suggest using RAII for your lock.</p>\n\n<p>Instead of:</p>\n\n<pre><code>std::uniform_int_distribution<int> rand_distribution(0, std::distance(b, e - 1));\n\n// call static random engine to get index of random pivot\ntbb::spin_mutex::scoped_lock lock;\nlock.acquire(... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-16T17:56:45.147",
"Id": "7870",
"Score": "12",
"Tags": [
"c++",
"multithreading",
"c++11",
"quick-sort",
"sorting"
],
"Title": "Parallel Quicksort"
} | 7870 |
<p>I'm looking for some assistance with a PHP script I'm writing. It creates a table that is then exported to an Excel file for download.</p>
<p>The issues as I see them are as follows:</p>
<p><code>$students</code> contains 559 items and the <code>$classes</code> has 22 items and <code>$attributes</code> has 6 items... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-17T09:25:57.030",
"Id": "12481",
"Score": "0",
"body": "Depends, where is all that data coming from? Is each of your static class calls a database query?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-17T0... | [
{
"body": "<p>I think what your better off doing is to have a join on your database call, so that the class data and student data is returned in one object.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-17T09:27:4... | {
"AcceptedAnswerId": "7884",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-17T09:23:42.947",
"Id": "7883",
"Score": "3",
"Tags": [
"php",
"mysql"
],
"Title": "Creating a table for use in Excel"
} | 7883 |
<p>I am trying to get my dictionary to iterate seven times after the <code>dateTime</code> is found. I want to iterate through the next week of objects in my dictionary <code>pagesInRange</code>. I figured out how to do it, but I am sure this is not good code. I am wondering if someone could point me in the direction o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-17T04:56:52.513",
"Id": "12485",
"Score": "0",
"body": "`Dictionary<TKey, TValue>` is not appropriate for sorted searches. Something like the .NET 4 `SortedDictionary` would likely be a better fit."
},
{
"ContentLicense": "CC B... | [
{
"body": "<p>You might want to consider using a switch statement since you have so many else if cases. The switch statement I believe can be slightly faster due to the way the compiler uses the test conditions. Though you would have to declare end1 through n as const.</p>\n",
"comments": [
{
... | {
"AcceptedAnswerId": "7887",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-17T04:52:50.143",
"Id": "7885",
"Score": "3",
"Tags": [
"c#",
"homework"
],
"Title": "Iterating through a dictionary in C#"
} | 7885 |
<p>I have about 6 of these, but I'm only posting two. Essentially I have a bunch of options with a "yes" or "no" radio button. If "no" is selected, I want a form to popup.</p>
<pre><code>$('#Option1').live('change', function() {
if ($('input[name=Option1]:checked').val() == "False") {
$('#formDiv').show();... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-17T00:35:52.230",
"Id": "12494",
"Score": "1",
"body": "This belongs on codereview, but when you post it there, please include your HTML. Only by seeing the repeated parts of the HTML can people offer the best way to do the code."
}... | [
{
"body": "<p>This should work:</p>\n\n<pre><code>$('#Option1, #Option2').live('change', function() {\n if ($('input[name=' + $(this).attr('id') + ']:checked').val() == 'False') {\n $('#formDiv').show();\n else {\n $('#formDiv').hide();\n }\n\n });\n</code></pre>\n\n<p>Or, if whatever ... | {
"AcceptedAnswerId": "7891",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-17T00:30:22.933",
"Id": "7890",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"form",
"event-handling"
],
"Title": "Options with a \"yes\" or \"no\" radio button"
} | 7890 |
<p>So i got the grip on the basic MVC patterns in java using Observer / Observable method. Now in interest of keeping it clean and readable i would like some pointers before i move on regarding how to well organize my View as this is where my Classes get most filled up. We been told in school to keep file size per clas... | [] | [
{
"body": "<p>Just a quick note: according to the <a href=\"http://www.oracle.com/technetwork/java/codeconventions-141855.html#3043\" rel=\"nofollow\">Code Conventions for the Java Programming Language, File Organization</a> instance variables should be placed before constructors and methods.</p>\n",
"comme... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-17T21:03:25.273",
"Id": "7896",
"Score": "2",
"Tags": [
"java",
"mvc",
"swing"
],
"Title": "How can i clean and organize up my View (MVC) better"
} | 7896 |
<p>This is a question I have in regards to my implementation of the MVC design paradigm that I came up with. The MVC type I am using is where everything must go through the controller. No communication happens between the model and the View. This is what I saw apple doing when I played with some iPhone stuff so I wante... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-17T21:21:34.213",
"Id": "12523",
"Score": "0",
"body": "If you are flexible, switch to Griffon. It handles the boilerplate of MVC for you and lets you just worry about the meat of the models, views, and controllers. While it's built in... | [
{
"body": "<p>If you are sending everything through the controller, it's not exactly MVC. </p>\n\n<p>The beauty of MVC is that most of your views \"listen\" to changes in the model, which means the controller doesn't need to \"update\" the views for regular data changes. That limits the controller's updating ... | {
"AcceptedAnswerId": "7902",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-17T21:12:53.583",
"Id": "7901",
"Score": "3",
"Tags": [
"java",
"mvc"
],
"Title": "Java: Worries about my implementation of MVC in a GUI Application"
} | 7901 |
<p>I have just 'wrote' a linked list implementation of Disjoint Sets. This is the changed version of <a href="https://stackoverflow.com/a/4522532/675100">Bob Tian's implememnation</a>. Can you take a look and tell me if there is something missing ? For instance memory leaks while destroying <code>nodes</code>. And plea... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-18T02:25:48.710",
"Id": "12536",
"Score": "1",
"body": "Your code does not show any nodes being deleted. Assuming that you do not want to leak them all like this, do you intend to delete them and then continue to have calls to find and... | [
{
"body": "<p>The first thing that meets my eye is all this C-style casting, and in particular you are casting long to pointers and back. Why is the code not typesafe? If you want a pointer use a pointer. If you want a number use a number.</p>\n\n<p>Your node class. Well it's \"struct\" but that just means the ... | {
"AcceptedAnswerId": "7945",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-17T22:48:02.123",
"Id": "7905",
"Score": "3",
"Tags": [
"c++",
"algorithm",
"linked-list",
"union-find"
],
"Title": "Disjoint set implementation as linked list"
} | 7905 |
<p>I have the following code that checks for three different properties. Unfortunately each call can throw up to four exceptions that I all have to catch. Can I some how make the code more readable by reducing the amount of try/catch?</p>
<pre><code>public void retrieveSourceCode() {
try {
fileName... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-09T13:44:45.517",
"Id": "17110",
"Score": "1",
"body": "Someone should of pointed out that ClientProtocolException is an IOException making catching ClientProtocolException pointless in this code."
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>If you upgrade to Java 7, you can use the new Multi-catch syntax. You could change the first block to:</p>\n\n<pre><code> try {\n fileName = RestServices.getInstance().getClassName(getSourceCodeURI()); \n } catch (ClientProtocolException | IOException | RestServicesException e) {\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-18T08:12:00.550",
"Id": "7909",
"Score": "11",
"Tags": [
"java",
"error-handling"
],
"Title": "Retrieving multiple versions of source code for a file"
} | 7909 |
<p>I use the DefaultCodeFormatter of the core Java package to prettify my code. Unfortunately I want to look my code very different from the default settings. That why, I have to explicitly define a lot of values:</p>
<pre><code>public static String makeSourceCodeLookingMoreSexy(String source) {
Map<String,... | [] | [
{
"body": "<p>I'd extract it out to a helper method:</p>\n\n<pre><code>private static Map<String, String> getOptionsMap() {\n final Map<String, String> options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();\n\n options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_6);\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-18T08:15:22.153",
"Id": "7910",
"Score": "3",
"Tags": [
"java",
"formatting"
],
"Title": "Passing many configuration options to Java code formatter"
} | 7910 |
<p>I am relatively new to C and would like some feedback on a function that I have written, if it adheres to C standards or if there are some other things which I could have done better/differently.</p>
<pre><code>/* Function to find DB matches and store them in a glycopeptide structure */
/* Written by Bas Jansen, 18... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-18T16:11:46.220",
"Id": "12566",
"Score": "2",
"body": "That is absolutely the worst commenting I have **ever** seen. Comment your code to describe **what** you are trying to achieve. The code describes **how** you don't need to echo t... | [
{
"body": "<p>I'm not too familiar with C, so just some notes.</p>\n\n<ol>\n<li><p>Comments like these are redundant, so they are unnecessary:</p>\n\n<pre><code>MYSQL_ROW row; /* defines a row structure */\nfree(glycan); /* free the memory allocated for glycan */\n</code></pre></li>\n<li><p>Statements after ... | {
"AcceptedAnswerId": "7914",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-18T09:41:30.673",
"Id": "7912",
"Score": "6",
"Tags": [
"beginner",
"c",
"mysql",
"bioinformatics"
],
"Title": "Finding database matches and storing them in a glycopeptide stru... | 7912 |
<p>I created a function that compares two hashes and returns a report on whether the subtraction of their values is negative or not.</p>
<p>The problem comes down to having a cost hash for a building and a current resources hash like:</p>
<pre><code>cost = {:wood => 300, :stone => 200, :gold => 100}
reqs = {... | [] | [
{
"body": "<p>Here's a version that is a bit more <a href=\"http://en.wikipedia.org/wiki/Don%27t_repeat_yourself\">DRY</a>. It also makes use of ruby's default value for hashes, and I threw in a dummy class in order to make the tests actually run.</p>\n\n<p>This could probably be done even better, but one thing... | {
"AcceptedAnswerId": "7923",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-17T23:45:35.257",
"Id": "7920",
"Score": "5",
"Tags": [
"ruby"
],
"Title": "How do I compare two integer value hashes?"
} | 7920 |
<p>I have a collection (Child Collection) on which I am performing some operation to make another collection (Parent Collection). But that I do in a dirty <code>foreach</code> loop. I want to do it in an elegant way.</p>
<pre><code>GroupInfo grpInfo;
List<GroupInfo> lstGroupInfo = new List<GroupInfo>();
fo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-18T14:11:21.460",
"Id": "12559",
"Score": "0",
"body": "You need to tidy up the code sample, it's very difficult to figure out what some of the variables are.\n\nFor example, what type is lstGroupInfo? or tripAddressInfo?"
},
{
... | [
{
"body": "<p>There's quite a lot of logic in there, so I doubt you will get there completely by using LINQ, and, more importantly, if it would actually be <strong><em>more</em></strong> elegant.</p>\n\n<p>I would rewrite as follows, and be done with it:</p>\n\n<pre><code> foreach (AddressInfo addressInf... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-18T13:19:27.173",
"Id": "7926",
"Score": "2",
"Tags": [
"c#",
"linq"
],
"Title": "Improve grouping in LINQ"
} | 7926 |
<p>I'm building some code with an inheritance heirarchy, and I want to validate the resulting instances. At present I have a method in the base class can override to return a list of the problems (see the code).</p>
<p>My problem here is that this works, provided the inheriting classes remember to get the base results... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T08:41:10.350",
"Id": "12597",
"Score": "0",
"body": "I don't think it is bad that the inheriting classes have to remember to call base.GetValidationIssues(). To help developers out you might want to put a comment on the base impleme... | [
{
"body": "<p>If you don't trust your client classes (maybe they don't call <code>baseClass.GetValidationIssues</code>) you can force it with the <a href=\"http://en.wikipedia.org/wiki/Template_method_pattern\" rel=\"nofollow\">Template method pattern</a>.</p>\n\n<pre><code>public abstract class BaseClass {\n\n... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-18T14:03:22.127",
"Id": "7927",
"Score": "2",
"Tags": [
"c#",
"object-oriented"
],
"Title": "Getting validation from inherited classes"
} | 7927 |
<p>I'm starting to look at Python and its facilities. I've just tried to make one simple program using some base libraries. </p>
<p>I would like to hear some comments about anything you've noticed - style, readability, safety, etc.</p>
<pre><code>#!/usr/bin/python2.6 -u
import urllib2
import simplejson
import zlib
f... | [] | [
{
"body": "<p>I think your naming scheme is good and on first sight its very easy to see what the code does without having to study it too much.</p>\n\n<p>However, if I would pick on something I would say:</p>\n\n<ul>\n<li><p>Remove the unnecessary whitespace, ex. if ( condition ), or self.getUserInfo( userId )... | {
"AcceptedAnswerId": "7970",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-01-18T15:43:16.380",
"Id": "7930",
"Score": "10",
"Tags": [
"python",
"json",
"stackexchange",
"python-2.x"
],
"Title": "Stack Overflow user info fetcher"
} | 7930 |
<p>I've been getting into plugin development for jQuery and my first creation is a tooltip plugin. I've been reading a lot about plugin development especially with the use of JavaScript prototyping. I'm just looking for any tips to further improve my plugin development (only 144 lines of code).</p>
<p>Two questions ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-18T19:56:31.407",
"Id": "12576",
"Score": "2",
"body": "for future reference: [Please include the code in the question, not a link to it](http://codereview.stackexchange.com/faq#questions)"
},
{
"ContentLicense": "CC BY-SA 3.0"... | [
{
"body": "<p><strong>You ask:</strong></p>\n\n<blockquote>\n <ol>\n <li>The tooltip accepts \"settings\" options which I extend the standard jQuery way. Should I be passing only the necessary properties into the \"Tip\" object for each tooltip rather than the whole settings object, which right now I'm just d... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-18T19:05:08.090",
"Id": "7934",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "jQuery tooltip plugin"
} | 7934 |
<p>I'm writing a program to convert integers to Roman numerals (naively -- it doesn't know how to do the subtraction trick yet). What I have is functional, but it is not "Good Ruby". </p>
<pre><code>VALUES = [
["M", 1000],
["D", 500],
["C", 100],
["L", 50],
["X", 10],
["V", 5],
["I", 1],
]
def ro... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-18T21:22:33.530",
"Id": "12578",
"Score": "2",
"body": "With ruby 1.9 hashes are also ordered."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T11:45:28.040",
"Id": "12663",
"Score": "1",
"bod... | [
{
"body": "<p>I don't know what you mean about 'good ruby'. I show you a object-oriented version. \nInstead of </p>\n\n<pre><code>romanize(4)\n</code></pre>\n\n<p>you can call</p>\n\n<pre><code>4.roman\n</code></pre>\n\n<p>My solution is similar to your solution. It is Hash-oriented, so you need ruby 1.9.</p>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-18T20:24:18.563",
"Id": "7937",
"Score": "9",
"Tags": [
"ruby",
"roman-numerals"
],
"Title": "Roman numeral converter"
} | 7937 |
<p>I've updated the previous version to be more object oriented as suggested.</p>
<pre><code>import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
/**
* A class containing a single record. Each record... | [] | [
{
"body": "<p>I just looked briefly but this looks good. I would try to be more expressive with some of your variable names and break the methods up a little more. Also, I think you can get away without using clone.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense"... | {
"AcceptedAnswerId": "8897",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T00:12:45.203",
"Id": "7941",
"Score": "7",
"Tags": [
"java"
],
"Title": "Classification Problem from CodeSprint 2012 (Updated)"
} | 7941 |
<p>This is a solution from the CodeSprint 2012 coding competition. Any suggestions on ways to improve the object orientation or general style would be much appreciated. The code takes several text documents, encodes them into feature vectors using TF-IDF, and then applies k-means clustering to group documents with simi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T05:54:53.633",
"Id": "12589",
"Score": "0",
"body": "possible duplicate of [General Java Style Suggestions - Classification Problem from CodeSprint 2012 (Updated)](http://codereview.stackexchange.com/questions/7941/general-java-styl... | [
{
"body": "<p>Some notes:</p>\n\n<ol>\n<li><p>This comment is unnecessary:</p>\n\n<pre><code>// document title, contents and ID\nprivate final String title;\nprivate final String contents;\nprivate final long id;\n</code></pre>\n\n<p>Since they are inside the <code>Document</code> class, it's obvious that the <... | {
"AcceptedAnswerId": "9065",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T00:29:09.727",
"Id": "7942",
"Score": "6",
"Tags": [
"java",
"object-oriented",
"clustering"
],
"Title": "Document clustering / NLP"
} | 7942 |
<p>I have the follow function:</p>
<pre><code>Download.prototype.fundamentals = function(exchanges, cb){
if (!(exchange = exchanges.pop())) return
var that = this;
this.login(function(err){
if (err) return cb(true, exchange.code)
var path = util.format(that.eoddata.fundamentals['path']... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-18T23:24:01.077",
"Id": "12584",
"Score": "1",
"body": "This might be a better fit on [codereview.se]; I've flagged for moderator attention to migrate, we'll see if they agree you'll do better there. (You can flag too, if you want it h... | [
{
"body": "<p>Firstly, you are missing a <code>var exchange;</code> in your function.</p>\n\n<p>Heavily nested callbacks are no fun for anyone. I would consider using the async library to try to simplify the callbacks.</p>\n\n<p><a href=\"https://github.com/caolan/async#waterfall\" rel=\"nofollow\">https://gith... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-18T23:17:56.483",
"Id": "7943",
"Score": "2",
"Tags": [
"javascript",
"optimization",
"node.js"
],
"Title": "Optimize Node.js function"
} | 7943 |
<p>I have a package called <code>pkg_crypto</code>.</p>
<p>My select looks like this:</p>
<pre><code>SELECT "SEQ", pkg_crypto.decrypt("NAME", 'secret') name, pkg_crypto.decrypt("TEL", 'secret') tel
FROM MYTABLE
ORDER BY "SEQ" DESC
</code></pre>
<p>This takes about 3 seconds for a few thousand records. (Average of 10... | [] | [
{
"body": "<p>have you tried this one?</p>\n\n<pre><code>SELECT MYTABLE_ALIAS.\"SEQ\", MYTABLE_ALIAS.\"NAME\", MYTABLE_ALIAS.\"TEL\"\nFROM (\n SELECT \"SEQ\", pkg_crypto.decrypt(\"NAME\", 'secret') NAME, pkg_crypto.decrypt(\"TEL\", 'secret') TEL\n FROM MYTABLE) MYTABLE_ALIAS\nORDER BY \"SEQ\" DESC\n</code></p... | {
"AcceptedAnswerId": "8291",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T03:49:59.177",
"Id": "7946",
"Score": "3",
"Tags": [
"performance",
"sql",
"oracle",
"plsql"
],
"Title": "Oracle PL/SQL decryption function breaking index?"
} | 7946 |
<p>In a custom Ant task, I have the following constants:</p>
<pre><code>private static final String _REVISION = ".revision";
private static final String _CODEBASE_INFO = ".codebase";
private static final String _DIFF = ".diff";
private static final String _TYPE_GIT = "git";
private static final String _TYPE_SVN = "svn... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T07:56:03.910",
"Id": "12594",
"Score": "1",
"body": "Would you find your code more or less readable if all of these values were inlined? That is, if there were no constants other than the map itself, and you just use the String lit... | [
{
"body": "<p>You should create an <code>ScmCommands</code> interface like this:</p>\n\n<pre><code>public interface ScmCommands {\n public String[] getRevisionCommand();\n\n public List<String[]> getDiffCommand();\n\n public List<String[]> getCodebaseInfoCommand();\n}\n</code></pre>\n\n<p>a... | {
"AcceptedAnswerId": "7958",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T04:14:11.500",
"Id": "7949",
"Score": "6",
"Tags": [
"java",
"object-oriented",
"constants"
],
"Title": "Looking for a better way to define and use constants"
} | 7949 |
<p>I'm newish to obj-c and I have some code that works, but I'm thinking I may be leaking memory as I have two <code>retain</code> statements and no <code>release</code> statements.</p>
<p>In both cases if I remove the <code>retain</code> I get a bad access error on <code>[btPairedDevices count]</code></p>
<p>Am I do... | [] | [
{
"body": "<p>You should definitely be releasing both <code>btMonitoredDevices</code> and <code>btPairedDevices</code> in the <code>dealloc</code>. But it appears that this is your appDelegate so it matters little outside of correctness. I'd do it anyhow.</p>\n\n<p>You shouldn't need the <code>retain</code> on ... | {
"AcceptedAnswerId": "7968",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T08:43:04.947",
"Id": "7952",
"Score": "6",
"Tags": [
"objective-c"
],
"Title": "Is there a memory leak in here?"
} | 7952 |
<p>Given:</p>
<pre><code>k = {'MASTER_HOST': '10.178.226.196', 'MASTER_PORT': 9999}
</code></pre>
<p>I want to flatten into the string:</p>
<pre><code>"MASTER_HOST='10.178.226.196', MASTER_PORT=9999"
</code></pre>
<p>This is the ugly way that I'm achieving this right now:</p>
<pre><code>result = []
for i,j in k.it... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T09:00:09.547",
"Id": "12600",
"Score": "0",
"body": "I don't think it's that bad, unless perhaps you also have Boolean values in your dict, because `isinstance(False, int)` returns `True`, so instead of `flag='False'`, you'd get `fl... | [
{
"body": "<p>For python 3.0+ (as @Serdalis suggested)</p>\n\n<pre><code>', '.join(\"{!s}={!r}\".format(key,val) for (key,val) in k.items())\n</code></pre>\n\n<p>Older versions:</p>\n\n<pre><code>', '.join(\"%s=%r\" % (key,val) for (key,val) in k.iteritems())\n</code></pre>\n",
"comments": [
{
... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T08:47:59.230",
"Id": "7953",
"Score": "20",
"Tags": [
"python",
"strings"
],
"Title": "Flattening a dictionary into a string"
} | 7953 |
<p>Is this a good way to design a class so I can prevent values being changed/ the state must remain as it was when it was intantiated...</p>
<p>This code would be normally instantiated after a call from the database.</p>
<pre><code>public class InstructionWorkflow : IStageWorkflow
{
private readonly int _company... | [] | [
{
"body": "<p>The way you're implementing a read-only object looks fine, except for <code>CurrentStage</code> being mutable. Are you sure you want it that way? It seems counter-intuitive with the rest of the class. Seeing as it is a private member anyway, why not make it <code>readonly</code> just like <code... | {
"AcceptedAnswerId": "7960",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T09:52:28.897",
"Id": "7959",
"Score": "2",
"Tags": [
"c#",
"object-oriented",
"classes"
],
"Title": "Best way to Structure class + Instantiation"
} | 7959 |
<p>I need a bit of help on if I have coded this class correctly.</p>
<p>I want to handle the setting of client cookie/client store.</p>
<pre><code>public class UserSession : IUserSession
{
private readonly IReadOnlySession _repo;
public UserSession(IReadOnlySession repo)
{
_repo = repo;
}
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T13:55:25.117",
"Id": "12620",
"Score": "0",
"body": "The Linq in SetupProfile is very confusing to understand as it is. I would really rather see that written in query syntax. Joins and groups using method syntax never make for read... | [
{
"body": "<p>It's great that you separated the ASP.NET specific implementation from the interface. Two things to watch:</p>\n\n<ol>\n<li>Don't forget to call <code>Session.Abandon();Session.Clear();</code> in the <code>Logout</code> method.</li>\n<li><code>SetupProfile</code> contains a lot of code. This seems... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T11:20:58.317",
"Id": "7961",
"Score": "3",
"Tags": [
"c#",
"asp.net"
],
"Title": "Creating an IUserSession that is used throughout my code"
} | 7961 |
<p>I'm writing some code to perform some simple form validation and I would like to display error messages inside the actual relevant textarea by means of a text fadeout/fadein effect.</p>
<p>To achieve this I am using jQquery UI to do the following:</p>
<ul>
<li>Step 1: Animate the color to match the background colo... | [] | [
{
"body": "<p>Pull it out to a function?</p>\n\n<pre><code>$.fn.textFadeSwap = function(newText, body, customColor) {\n var $this= $(this), \n transparentColor = $this.css('background-color') || 'transparent',\n originalColor = $this.css('color') || '#000',\n customColor = customColor ||... | {
"AcceptedAnswerId": "7966",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T14:07:41.080",
"Id": "7965",
"Score": "10",
"Tags": [
"javascript",
"jquery",
"animation",
"jquery-ui"
],
"Title": "Is there a better way to write this jQuery UI effect anim... | 7965 |
<p>I have inherited the Java function below, and it works the way it should, but you have to look at it for a minute to figure out exactly what is going on. Is there a more succinct or elegant way to encode this logic?</p>
<pre><code>private Float applyFactors(Float originalValue, Float localFactor, Float globalFactor... | [] | [
{
"body": "<p>What I like to do in this sort of complicated conditional situation is to do the comparisons upfront and give them names. This makes it easier to reason about the code, and doesn't have any drawback if the conditional expressions are cheap.</p>\n\n<p>I then go ahead and replace the conditional exp... | {
"AcceptedAnswerId": "7975",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T17:21:45.910",
"Id": "7972",
"Score": "2",
"Tags": [
"java"
],
"Title": "applyFactors refactoring"
} | 7972 |
<p>I was wondering if this was a decent way of handling this function. Please take a look.</p>
<pre><code>// Use Less Mixins from Theme Options to adjust Stylesheets before Parsing Less to CSS
add_filter( 'less_vars', 'wellies_less_vars', 10, 2 );
function wellies_less_vars( $vars, $handle ) {
//Necessary for UpT... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-29T16:27:27.630",
"Id": "13179",
"Score": "0",
"body": "Try to be more specific in your title and question. E.g Efficient how? I do not see any use of caching. Additionally there is a Wordpress stack exchange as well"
}
] | [
{
"body": "<p>No, this can be written a lot easier. There is no need to create variables when you are not going to vary the value. It actually only makes things harder to read. Assuming you are using PHP 5.3+ consider this:</p>\n\n<pre><code>// It is odd that you aren't using $vars in your method.\n// I'll i... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T19:17:55.843",
"Id": "7974",
"Score": "4",
"Tags": [
"performance",
"css",
"php5"
],
"Title": "Repetitive wordpress PHP styling"
} | 7974 |
<p>I have several lists of objects which are stored in different locations, based on what they are and who needs them - the system, or the user, for example. There are times where I am only given an ID and need to find the name, type, or description, but I would like a very succinct, efficient way to do so. Since I'm a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T03:30:51.230",
"Id": "12646",
"Score": "0",
"body": "Off hand, I'd guess that instanceof may provide a more robust solution in the context of derived classes. Can you show the instanceof alternative and also give examples of how you... | [
{
"body": "<p>It just doesn't <a href=\"http://en.wikipedia.org/wiki/Code_smell\" rel=\"nofollow noreferrer\">smell</a> good. Maybe you should post more code. This kind of searches looks weird to me.</p>\n\n<p>Anyway, the <code>User</code> class should have a <code>getProjNameById(final int id)</code> method, t... | {
"AcceptedAnswerId": "7981",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-19T20:46:40.160",
"Id": "7976",
"Score": "4",
"Tags": [
"java",
"object-oriented",
"search"
],
"Title": "Is there a better, more object oriented way to write this Finder method?"
} | 7976 |
<p>I have a method that ascends an inheritance tree and returns the element at the root, progressively yielding the elements if appropriate:</p>
<pre><code># Finds the root of the hierarchy.
def root
element = self
until element.root?
yield element if block_given?
element = element.parent
end
yield ele... | [] | [
{
"body": "<p>One way to only have one <code>yield</code> statement would be to recursion instead of a loop:</p>\n\n<pre><code>def root(&blk)\n yield self if blk\n if root?\n self\n else\n parent.root(&blk)\n end\nend\n</code></pre>\n\n<p>Of course the usual caveats regarding recursion in ruby... | {
"AcceptedAnswerId": "8005",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T04:38:00.367",
"Id": "7982",
"Score": "4",
"Tags": [
"ruby"
],
"Title": "Is there a better way to traverse an inheritance tree?"
} | 7982 |
<p>I am pretty new to JavaScript and learning the intricacies of this language. I wanted a unique collection which will overwrite while adding if an item already exists else add. Rest of the behavior should be just like any other collection. I had written the type and its as below. Instead of using an array internally,... | [] | [
{
"body": "<p>This mostly seems like a layer of sugar coating that just adds overhead and doesn't add any improved functionality over what a javascript object already has. The only new functionality I see is keeping track of a length, but this is a lot of extra overhead just for that. The length could be calc... | {
"AcceptedAnswerId": "7984",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T05:41:40.783",
"Id": "7983",
"Score": "3",
"Tags": [
"javascript",
"beginner",
"collections"
],
"Title": "Implementation of a unique collection"
} | 7983 |
<p>I've been working on this elevator program for quite some time now and finally finished it and made it work and I'm pretty proud of myself, but I'd like to see ways how to optimize my code so I can learn for the future. By optimizing, I mean making the code look better, maybe by using fewer lines of code.</p>
<pre>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T10:06:35.393",
"Id": "12652",
"Score": "1",
"body": "Maybe you could post the complete code of your class."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T10:07:22.460",
"Id": "12653",
"Score"... | [
{
"body": "<pre><code>import java.awt.geom.*;\n\npublic class elevator\n</code></pre>\n\n<p>Class names are typically capitalized</p>\n\n<pre><code>{\n\n static int floor = 0, choice1, person = 0;\n</code></pre>\n\n<p>Prefer local variables to statics like this. Person doesn't appear to be used.</p>\n\n<pre>... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T09:57:51.030",
"Id": "7990",
"Score": "6",
"Tags": [
"java"
],
"Title": "Elevator program"
} | 7990 |
<p>I have the following code with switch case statement:</p>
<pre><code>public string IrregularCouponLabel
{
get
{
switch ((ctrl.IrregularCouponFirst ? 10 : 0) + (ctrl.IrregularCouponLast ? 1 : 0))
{
case 11: return LocalString.Evaluate("label.Both");
case 10: return Loc... | [] | [
{
"body": "<p>I'd write something like this:</p>\n\n<pre><code>string labelName;\nif (ctrl.IrregularCouponFirst && ctrl.IrregularCouponLast) {\n labelName = \"label.Both\"\n} else if (ctrl.IrregularCouponFirst) {\n labelName = \"label.First\";\n} else if (ctrl.IrregularCouponLast) {\n labelName... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T10:23:31.593",
"Id": "7991",
"Score": "17",
"Tags": [
"c#"
],
"Title": "Switch case statement refactoring"
} | 7991 |
<p>A previous developer had an array of strings like so:</p>
<pre><code>public static const PAGE_ONE:String = 'PageOne';
public static const PAGE_TWO:String = 'PageTwo';
public static const PAGE_THREE:String = 'PageThree';
public static const PAGE_FOUR:String = 'PageFour';
public static const PAGE_FIVE:St... | [] | [
{
"body": "<p>It seems to me that what you need is the <a href=\"http://en.wikipedia.org/wiki/State_pattern\" rel=\"nofollow\">State pattern</a>.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T15:45:04.977",
... | {
"AcceptedAnswerId": "8007",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T12:11:04.897",
"Id": "7996",
"Score": "1",
"Tags": [
"actionscript-3"
],
"Title": "Is this possibly confusing code?"
} | 7996 |
<p>I am implementing Unix sort in Clojure. This is my first program, and I would like some feedback regarding any non-idiomatic, harmful code and any other best practices I can include in future versions. I tried my best to follow the coding standards, but went with <code>camelCase</code> instead of <code>hyphen-case</... | [] | [
{
"body": "<p>You should use namespace-qualified keywords instead of strings in the fileKind function:</p>\n\n<pre><code>(defn fileKind [filename]\n (let [f (File. filename)]\n (cond\n (.isFile f) ::file\n (.isDirectory f) ::directory\n (.exists f) ::other \n :else :... | {
"AcceptedAnswerId": "8447",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T14:24:04.640",
"Id": "8000",
"Score": "7",
"Tags": [
"clojure"
],
"Title": "Unix sort in Clojure"
} | 8000 |
Adobe ActionScript 3 is the open source object oriented programming (OOP) language of the Adobe Flash and Air Platforms. AS3 is widely used for RIAs, mobile apps, and desktop applications. (ActionScript 3 is a dialect of ECMAScript.) | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T14:51:54.487",
"Id": "8002",
"Score": "0",
"Tags": null,
"Title": null
} | 8002 |
<p>I have a workflow; within the workflow I can have many stages. I want to open and close a stage based on some business rules. E.g., stage 7 cannot be opened, because stage 5 + 6 need to be closed first; or, check whether key data x is filled out: if so, you can close stage 4.</p>
<p>How can I optimize or improve my... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-22T16:16:17.213",
"Id": "12797",
"Score": "0",
"body": "The ResolveDashboard()-method is almost impossible to read due to heavy overusage of LINQ. I would begin with some refactoring there"
}
] | [
{
"body": "<ul>\n<li>Conceptually you say you open and close stages. Then I'd expect to see open and close methods in a stage class, not in the workflow class.</li>\n<li>Looks like stages are non-trival. I'd expect to see these created w/in some kind of factory pattern</li>\n<li>Wheres the exception handling? S... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T17:01:44.740",
"Id": "8006",
"Score": "3",
"Tags": [
"c#",
"object-oriented",
"classes"
],
"Title": "C#: Simplfy code using Interfaces + business rules / validation"
} | 8006 |
<p>I have a routine that can be potentially reduced.</p>
<pre><code>internal ArrayBufferObject GetAccessorArray()
{
ColladaDocument colladaDocument = GetColladaDocument();
ColladaArray colladaArray = colladaDocument.GetSpecialElement<ColladaArray>(Source);
ArrayBufferObject bufferObject;
if (IsS... | [] | [
{
"body": "<p>Presumably you could pull those sections out into a generic method. </p>\n\n<pre><code>private ArrayBufferObject CreateArrayBuffer<T>(ColladaArray colladaArray)\n{\n uint cursorOffset = Offset;\n\n ArrayBufferObject<T> arrayBufferObject = new ArrayBufferObject<T>(BufferOb... | {
"AcceptedAnswerId": "8043",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T18:46:29.130",
"Id": "8008",
"Score": "6",
"Tags": [
"c#"
],
"Title": "Generics for reducing redundancies"
} | 8008 |
<p>My goal was to make a list dynamically list itself into two columns, no matter the length of the list. I know this is possible by just floating the <code>li</code> nodes, but I wanted to keep the <code>li</code> nodes in the same vertical order. I would really like to hear from people who know more about JavaScript ... | [] | [
{
"body": "<p>the best javascript is no javascript ;-)</p>\n\n<p>you could use css3 columns, see <a href=\"http://jsfiddle.net/bjelline/JWnaz/\" rel=\"nofollow\">http://jsfiddle.net/bjelline/JWnaz/</a> for the result</p>\n\n<pre><code>ul {\n-moz-column-count: 2;\n-moz-column-gap: 20px;\n-webkit-column-count: 2;... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T20:00:33.297",
"Id": "8010",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Is there a better or more concise way to do this?"
} | 8010 |
<p>I am very new to functional programming. I wrote this program where the user can enter an integer and it will print the factorial. If the user enters a negative integer or not an integer at all, it'll give the user a second chance.</p>
<p>This doesn't feel very functional to me. How can I make this code more functi... | [] | [
{
"body": "<p>The line <code>factorial 0 = 1</code> is redundant. The product of the empty list is already 1.</p>\n\n<p>When writing a function that only works with strings (instead of arbitrary lists), I'd prefer to use <code>\"\"</code> instead of <code>[]</code> to denote the empty string. This way it's more... | {
"AcceptedAnswerId": "8019",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T21:13:49.357",
"Id": "8018",
"Score": "8",
"Tags": [
"haskell",
"functional-programming"
],
"Title": "Printing a factorial from an integer"
} | 8018 |
<p>The basic format of a ternary operator is thus:</p>
<pre><code>condition ? first_expression : second_expression;
</code></pre>
<p>A number of languages have a ternary operator consisting of <code>?</code> and <code>:</code>. The proper name for this operator (at least in C and C-like languages) is the "conditional... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T22:06:42.423",
"Id": "8021",
"Score": "0",
"Tags": null,
"Title": null
} | 8021 |
Normally referring to the conditional operator, represented by the characters ? and :, that form a basic conditional expression in several programming languages, also known as inline if. It is used as follows: (condition) ? (value if true) : (value if false). | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T22:06:42.423",
"Id": "8022",
"Score": "0",
"Tags": null,
"Title": null
} | 8022 |
ASP.NET is a web application framework developed by Microsoft to allow programmers to build dynamic web sites and web applications. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T22:11:39.170",
"Id": "8024",
"Score": "0",
"Tags": null,
"Title": null
} | 8024 |
<p>Object-oriented programming is an approach to designing modular, reusable software systems which models the issue first.</p>
<p>Rather than structuring programs as code and data, an object-oriented system integrates the two using the concept of an "object". An object has a state (data) and a behavior (code).</p>
<... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T22:16:43.327",
"Id": "8025",
"Score": "0",
"Tags": null,
"Title": null
} | 8025 |
<blockquote>
<p>Cascading Style Sheets (CSS) is a style sheet language used for
describing the look and formatting of a document written in a markup
language. While most often used to style web pages and interfaces
written in HTML and XHTML, the language can be applied to any kind of
XML document, including p... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T22:17:33.497",
"Id": "8027",
"Score": "0",
"Tags": null,
"Title": null
} | 8027 |
CSS, short for Cascading Style Sheets, is a language used to control the presentation of HTML and XML documents including colors, layout, and fonts. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T22:17:33.497",
"Id": "8028",
"Score": "0",
"Tags": null,
"Title": null
} | 8028 |
<p>A DATABASE is a collection of information organized in such a way that a computer program can quickly select desired pieces of data. You can think of a database as an electronic filing system.</p>
<p>The term <em>database</em> should not be confused with <em>Database Management System</em> (DBMS). A DBMS is the sys... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T22:18:43.090",
"Id": "8029",
"Score": "0",
"Tags": null,
"Title": null
} | 8029 |
<p>A string is a sequence of characters commonly used to represent text; in most languages a string is a data type.</p>
<p>It is also used to represent a sequence of bytes encoding arbitrary binary data.</p>
<p>In the original C representation, a string is an array of characters (which are byte-sized <code>int</code>... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T22:21:07.423",
"Id": "8031",
"Score": "0",
"Tags": null,
"Title": null
} | 8031 |
A string is a sequence of characters. It is commonly used to represent text or a sequence of bytes. Use this tag along with the appropriate programming language being used. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T22:21:07.423",
"Id": "8032",
"Score": "0",
"Tags": null,
"Title": null
} | 8032 |
<h2>Description</h2>
<p>An <a href="http://en.wikipedia.org/wiki/Array_data_type" rel="nofollow noreferrer">array</a> is an ordered data structure consisting of a collection of elements (values or variables), each identified by at least one index, stored in contiguous memory locations. An array is typically stored so ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-01-20T22:22:26.330",
"Id": "8033",
"Score": "0",
"Tags": null,
"Title": null
} | 8033 |
An array is an ordered data structure consisting of a collection of elements (values or variables), each identified by one (single dimensional array, or vector) or multiple indexes. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T22:22:26.330",
"Id": "8034",
"Score": "0",
"Tags": null,
"Title": null
} | 8034 |
<p>Security is important in programming as a single vulnerability can compromise part or the entirety of a system.</p>
<p>Some measures to increase the security of a system include, but are not limited to, access control, awareness training, audit and accountability, risk assessment, penetration testing, vulnerabilit... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-01-20T22:24:01.133",
"Id": "8035",
"Score": "0",
"Tags": null,
"Title": null
} | 8035 |
Computer security is security applied to computing devices such as computers and smartphones, as well as to both private and public computer networks, including the whole Internet. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T22:24:01.133",
"Id": "8036",
"Score": "0",
"Tags": null,
"Title": null
} | 8036 |
<p>Data structures are ubiquitous in software. Hash tables, balanced trees, and dynamic arrays are essential building blocks for large, complicated systems and almost all programmers have encountered them at some point. More complicated structures like binary heaps can speed up complicated systems, while simpler conc... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T22:31:11.993",
"Id": "8037",
"Score": "0",
"Tags": null,
"Title": null
} | 8037 |
A data structure is a way of organizing data in a fashion that allows particular properties of that data to be queried and/or updated efficiently. THIS TAG IS BEING REMOVED, SO USE A SPECIFIC DATA STRUCTURES TAG INSTEAD. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T22:31:11.993",
"Id": "8038",
"Score": "0",
"Tags": null,
"Title": null
} | 8038 |
<p>This is a scraper written in CoffeeScript for NodeJS. It is run in an interval (set to 5 seconds here to dramtically show the leak). Somewhere this code leaks memory. I already tried nulling a few things for manually deleting references. Where is the reference kept that produces the leak?</p>
<pre><code>request = r... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T22:53:52.270",
"Id": "12699",
"Score": "1",
"body": "In coffeescript \\o/. Seriously I can't see a leak in your code which leaves three places jsdom, jQuery and coffeescript"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creat... | [
{
"body": "<p>I got here reading about garbage collection and memory leakage in CS. It's an old post but I 'll give my 2 cents anyway. When emptying an array it's often recommended to avoid using <code>array = []</code>, but use <code>array.length = 0</code>. </p>\n\n<p>Also, in functions that you don't indent ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T22:43:04.190",
"Id": "8039",
"Score": "3",
"Tags": [
"jquery",
"node.js",
"memory-management",
"web-scraping",
"coffeescript"
],
"Title": "Memory leak in a scraper"
} | 8039 |
<p>I'm creating a factory design for math problems. The idea which I have is:</p>
<ul>
<li>When the factory initializes, creates in a list some problems (20 initially)</li>
<li>If the program wants more than 20, the list should grow until reach the requested quantity.</li>
</ul>
<p>For example, if I require 30 proble... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-31T15:11:32.290",
"Id": "13295",
"Score": "0",
"body": "I fail to see the point of `GrowSize`, why don't you just generate problems problems as you need them? It's not like it's going to be faster to generate many problems in a row, ri... | [
{
"body": "<p>I think your list factory shouldn't be responsible for creating the concrete problems. How about separating the list factory from the problem factory? That way you can have <code>timeTableProblems</code> and <code>binaryProblems</code> in the same list. (even though that might not be a requirement... | {
"AcceptedAnswerId": "8277",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-20T23:01:48.327",
"Id": "8041",
"Score": "7",
"Tags": [
"c#",
"factory-method"
],
"Title": "Factory design for math problems"
} | 8041 |
<p>I've been looking at ways to use asserts in programs that must do some kind of cleanup on fatal errors, and have arrived at the following pattern (PROJECT being replaced by the name of the project):</p>
<pre><code>#include <boost/exception/all.hpp>
#include <boost/exception/diagnostic_information.hpp>
#... | [] | [
{
"body": "<p>Note: Personal opinions done matter. Just voicing them.</p>\n\n<p>Personally I don't like (runtime) asserts (checks that disappear in production just asking for trouble and if something goes wrong you can't reproduce it in debug mode now). But OK its better than no checks.</p>\n\n<p>Personally I d... | {
"AcceptedAnswerId": "8167",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T03:29:17.327",
"Id": "8047",
"Score": "6",
"Tags": [
"c++",
"exception-handling"
],
"Title": "Asserting when cleanup is required"
} | 8047 |
<p>I have this method which sends binary data to server. The code works fine, but still, it's structure is kinda stupid: output and input connections are opened like thousands times (depends on data size), closed only once.</p>
<p>I cannot move the code that opens connection outside of the loop because I'm getting str... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T12:39:52.303",
"Id": "12721",
"Score": "1",
"body": "Could you please show `Path` class?"
}
] | [
{
"body": "<p>In my opinion the key way to improve this code is decomposition. Actually, methods with more than 15 java lines are usually <a href=\"http://en.wikipedia.org/wiki/Code_smell\" rel=\"nofollow\">smells</a> for me. So </p>\n\n<pre><code>//There should be other signature depending on what does this me... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T07:59:14.260",
"Id": "8051",
"Score": "3",
"Tags": [
"java"
],
"Title": "Writing to an HttpURLConnection in a loop"
} | 8051 |
<p>There is HTML that triggers the code below I want to disallow executing the script more than once per 24 hours. I wanted this script to store the last visit time in a table against the user ID in a database, then do a time calculation and back them out until the 24 hour expiry time.</p>
<pre><code><?php
//Input ... | [] | [
{
"body": "<p><sub>Note: this is intended to be a Community wiki since it was taken from a deleted answer by <a href=\"https://codereview.stackexchange.com/users/4673/yannis\">yannis</a>; The suggestion to do this was <a href=\"https://codereview.meta.stackexchange.com/a/10625/120114\">here</a></sub></p>\n<hr /... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T11:25:59.237",
"Id": "8053",
"Score": "4",
"Tags": [
"php",
"sql",
"mysql"
],
"Title": "Keeping track of voting"
} | 8053 |
<p>I'm learning functional programming and their concept of <a href="http://en.wikipedia.org/wiki/Monad_%28functional_programming%29">Monads</a>. I've found nothing more effective in learning than writing an implementation in a programming language I have experience with.</p>
<p>I came up with the following implementa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:00:44.690",
"Id": "12725",
"Score": "1",
"body": "Note that without having `return` in your interface (which you can't in Java because interfaces can only specify instance methods), you can't do half the things with your Bindable... | [
{
"body": "<p>As mentioned in the comments, the problem with implementing monads in Java is that in an OO language class methods always work on a single instance. Type classes in Haskell are very different, there you can create values \"out of nowhere\" like in\n</p>\n\n<pre><code>class Monad m where\n retur... | {
"AcceptedAnswerId": null,
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T12:51:34.487",
"Id": "8055",
"Score": "22",
"Tags": [
"java",
"functional-programming",
"monads"
],
"Title": "Java monad implementation"
} | 8055 |
<p>I've wrote this class in PHP for my future projects:</p>
<pre><code><?php
/**
* Auth
* This class is used to securely authenticate and register users on a given website.
* This class uses the crypt() function, and PDO database engine.
*
* @package Class Library
* @author Truth... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-26T21:10:41.133",
"Id": "41347",
"Score": "0",
"body": "Can you descripe or give a sample how you use this class in your page. Maybe with the different pages for login and validate the user against the DB. And use with sessions would b... | [
{
"body": "<pre><code>public function __construct($user = \"\", $pass = \"\") {\n if (empty($user) || empty($pass)) {\n</code></pre>\n\n<p>Don't use <code>empty</code> when the variable is <em>guaranteed</em> to exist. It just makes it harder to catch typos, since it suppresses PHP's error mechanism when the... | {
"AcceptedAnswerId": "8184",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T13:58:36.233",
"Id": "8059",
"Score": "3",
"Tags": [
"php",
"classes",
"security"
],
"Title": "Authentication Class"
} | 8059 |
<p>In object-oriented programming, a constructor (sometimes shortened to ctor) in a class is a special type of subroutine called at the creation of an object. It prepares the new object for use, often accepting parameters which the constructor uses to set any member variables required when the object is first created.<... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:24:34.193",
"Id": "8060",
"Score": "0",
"Tags": null,
"Title": null
} | 8060 |
A special type of subroutine called at the creation of an object. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:24:34.193",
"Id": "8061",
"Score": "0",
"Tags": null,
"Title": null
} | 8061 |
<p>In <a href="http://en.wikipedia.org/wiki/Object-oriented_programming" rel="nofollow">object-oriented programming</a> (see: <a href="/questions/tagged/oop" class="post-tag" title="show questions tagged 'oop'" rel="tag">oop</a>), a class is a construct that is used as a <strong>blueprint</strong> (or <strong>t... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:26:10.757",
"Id": "8062",
"Score": "0",
"Tags": null,
"Title": null
} | 8062 |
Core to Object-Oriented Programming (OOP), a class is a template for creating new objects that describes the common state(s) and behavior(s). | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:26:10.757",
"Id": "8063",
"Score": "0",
"Tags": null,
"Title": null
} | 8063 |
<p>A loop is a sequence of statements which is specified once, but which may be carried out several times in succession. The code inside the loop (the body of the loop) is executed a specified number of times, or once for each of a collection of items, or until some condition is met, or indefinitely.</p>
<p>In <a href... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:27:11.833",
"Id": "8064",
"Score": "0",
"Tags": null,
"Title": null
} | 8064 |
Loops are a type of control flow structure, in which, a series of statements may be executed repeatedly until some condition is met. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:27:11.833",
"Id": "8065",
"Score": "0",
"Tags": null,
"Title": null
} | 8065 |
<p>Functional programming is a paradigm which attempts to solve computational problems by the chained evaluation of functions whose output is determined by their inputs rather than the programme state. In this style of programming, side effects and mutable data are deprecated and usually strictly isolated.</p>
<p>The... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:28:58.133",
"Id": "8066",
"Score": "0",
"Tags": null,
"Title": null
} | 8066 |
Functional programming is a paradigm which attempts to solve computational problems by the chained evaluation of functions whose output is determined by their inputs rather than the program state. In this style of programming, side effects and mutable data are deprecated. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:28:58.133",
"Id": "8067",
"Score": "0",
"Tags": null,
"Title": null
} | 8067 |
<p>There is always the question of whether to work with PHP4 or use PHP5. Unless you're restricted to the earlier version, or you're working with legacy code that would not be compatible, it is <a href="http://stackoverflow.com/questions/716168/php4-vs-php5">always suggested that you work with the latest version</a>.</... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:29:37.007",
"Id": "8068",
"Score": "0",
"Tags": null,
"Title": null
} | 8068 |
The fifth version of the PHP: Hypertext Preprocessor (PHP) scripting language. It features the Zend Engine 2, better object model support, and many other improvements over PHP 4. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:29:37.007",
"Id": "8069",
"Score": "0",
"Tags": null,
"Title": null
} | 8069 |
<p>I have a small library for utility functions for ES5 mainly aimed at OO code organization.</p>
<p>Are there any recommendations for the API or for the code quality / organization? </p>
<ul>
<li><a href="https://github.com/Raynos/pd/blob/master/lib/pd.js" rel="nofollow">github page</a></li>
<li><a href="https://git... | [] | [
{
"body": "<p>There isn't anything majorly wrong, so these will be mostly minor things.</p>\n\n<p><code>getMethods</code> doesn't really get methods, <code>isMethod</code> (or <code>isBindable</code>) is a more descriptive name for it.</p>\n\n<p>You'd also want to check that <code>.call</code> is in fact the <c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:30:00.767",
"Id": "8070",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "ES5 utility functions implementations"
} | 8070 |
<p>Here is a short description of Programming Style from <a href="http://en.wikipedia.org/wiki/Programming_style" rel="nofollow">Wikipedia</a>:</p>
<blockquote>
<p>Programming style is a set of rules or guidelines used when writing the source code for a computer program.</p>
</blockquote>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:30:45.383",
"Id": "8071",
"Score": "0",
"Tags": null,
"Title": null
} | 8071 |
A coding style is a set of conventions and practices used in software, such as naming classes, variables, and files. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:30:45.383",
"Id": "8072",
"Score": "0",
"Tags": null,
"Title": null
} | 8072 |
<p>Developed by <a href="https://www.google.com/" rel="nofollow noreferrer">Google</a> and the <a href="http://www.openhandsetalliance.com/" rel="nofollow noreferrer">Open Handset Alliance</a>.</p>
<ul>
<li><p><a href="http://developer.android.com/" rel="nofollow noreferrer">Android Developers</a> (developer.android.c... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:31:55.647",
"Id": "8073",
"Score": "0",
"Tags": null,
"Title": null
} | 8073 |
Android is Google's software stack for mobile devices. For non-developer questions, see http://android.stackexchange.com | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:31:55.647",
"Id": "8074",
"Score": "0",
"Tags": null,
"Title": null
} | 8074 |
<h3>Description</h3>
<blockquote>
<p>Ideally, each <a href="http://en.wikipedia.org/wiki/Test_case" rel="nofollow noreferrer">test case</a> is independent from the others: substitutes like <a href="http://en.wikipedia.org/wiki/Method_stub" rel="nofollow noreferrer">method stubs</a>, <a href="http://en.wikipedia.org/... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-01-21T14:39:29.160",
"Id": "8076",
"Score": "0",
"Tags": null,
"Title": null
} | 8076 |
Unit testing is a method by which individual units of source code are tested to determine if they are fit for use. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:39:29.160",
"Id": "8077",
"Score": "0",
"Tags": null,
"Title": null
} | 8077 |
<h2>About</h2>
<p>Parsing is the process your compiler or interpreter goes through to extract meaning from your code. It is also how your browser translates the HTML of this page to a DOM, and in turn to graphics on your screen.</p>
<h2>Parser generators</h2>
<p>There are <a href="https://en.wikipedia.org/wiki/Compa... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-01-21T14:43:28.873",
"Id": "8078",
"Score": "0",
"Tags": null,
"Title": null
} | 8078 |
Parsing is the process of analysing a string of symbols, either in natural language or in computer languages, conforming to the rules of a formal grammar. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T14:43:28.873",
"Id": "8079",
"Score": "0",
"Tags": null,
"Title": null
} | 8079 |
<p><a href="http://json.org/" rel="nofollow">JSON</a> (JavaScript Object Notation) is a lightweight data exchange format and is often used with <a href="/questions/tagged/javascript" class="post-tag" title="show questions tagged 'javascript'" rel="tag">javascript</a> and RESTful <a href="/questions/tagged/web-s... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T15:23:34.823",
"Id": "8081",
"Score": "0",
"Tags": null,
"Title": null
} | 8081 |
JSON (JavaScript Object Notation) aka the Fat Free Alternative to XML is a lightweight data exchange format inspired by JavaScript object literals. It is often used with JavaScript, Ajax, and RESTful web services but is completely language independent. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T15:23:34.823",
"Id": "8082",
"Score": "0",
"Tags": null,
"Title": null
} | 8082 |
<h1>Extensible Markup Language</h1>
<p><a href="https://en.wikipedia.org/wiki/XML" rel="nofollow noreferrer">Wikipedia</a> defines XML as follows:</p>
<blockquote>
<p>XML (Extensible Markup Language) is a set of rules for encoding documents in both human-readable and machine-readable form. It is defined in the XML ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-21T15:24:15.337",
"Id": "8083",
"Score": "0",
"Tags": null,
"Title": null
} | 8083 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.