body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I've written a backup script to make a backup of the latest modified files in 12 hours. Basically, it searches two directories for modified files (statically coded) then the <code>find</code> command is used to find the related files. A log file is then created to keep a list of the files. Later on, they are used to... | [] | [
{
"body": "<p>A general suggestion which might yield a performance boost: if you can somehow determine that the directories in the <code>source</code> lists are on different harddisks, you could execute the main loop (which spends most of the time in the <code>find</code> invocation, I guess) in parallel.</p>\n... | {
"AcceptedAnswerId": "1881",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-13T18:30:45.843",
"Id": "1866",
"Score": "8",
"Tags": [
"python",
"linux"
],
"Title": "Linux backup script in Python"
} | 1866 |
<p>I present you my first ever module to learn some Erlang awaiting your scrutiny . It does a word frequency count using map/reduce . I'm an Erlang noob, so I would very much like feedback about:</p>
<p>Unneeded verbosity / code</p>
<p>Erlang 'style' mistakes</p>
<p>Things that can be done more elegantly</p>
<pre><... | [] | [
{
"body": "<p>A few initial points:</p>\n\n<ul>\n<li>Your mapping phase is all done on one process, so you're not getting any parallelism. You should fire off <code>M</code> mappers to do the mapping for you, and give them bits of the data to map over. They can pass this on to one of <code>R</code> reducers who... | {
"AcceptedAnswerId": "1905",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-13T22:55:30.887",
"Id": "1869",
"Score": "6",
"Tags": [
"erlang"
],
"Title": "Newbie Map/Reduce word frequency counter"
} | 1869 |
<p>I have a method that gets an RSS feed using LINQ to XML and returns a collection of an object that grabs only the data I need. There's really only one other method in the class I'm concerned about that you'll see in the sample -- RemoveUrlNoise.</p>
<p>How do I test a method like this or change it to be more testab... | [] | [
{
"body": "<p>Separate the concerns of fetching the feed XML from parsing it by extracting a class (e.g. FeedReader) to do the reading. Your IFeedReader would be generically reusable and look something like:</p>\n\n<pre><code>public interface IFeedReader\n{\n XElement Load(string url);\n}\n</code></pre>\n\n<... | {
"AcceptedAnswerId": "1871",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-14T02:07:10.930",
"Id": "1870",
"Score": "2",
"Tags": [
"c#",
"linq",
"unit-testing"
],
"Title": "How would I unit test a method that gets data from an RSS feed?"
} | 1870 |
<p><img src="https://i.stack.imgur.com/npc8B.gif" alt="queens"></p>
<blockquote>
<p>Figure 2.8: A solution to the
eight-queens puzzle. The
``eight-queens puzzle'' asks how to
place eight queens on a chessboard so
that no queen is in check from any
other (i.e., no two queens are in the
same row, column, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-14T10:53:16.287",
"Id": "62807",
"Score": "0",
"body": "Begin with `(define empty-board null)`."
}
] | [
{
"body": "<p>I do not know scheme that much that I be able to read this code, but I have idea how to avoid counting rotations and reflections (if you have not implement it yourself)</p>\n\n<ol>\n<li>Place 1st queen on A1 to A4</li>\n<li>Queen placed on H column should have row number higher that column number ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-14T05:35:31.547",
"Id": "1872",
"Score": "6",
"Tags": [
"lisp",
"scheme",
"sicp",
"n-queens"
],
"Title": "Eight-queens puzzle"
} | 1872 |
<p>Here's an interesting scenario that I encountered the other day. I did eventually reach a solution on my own. However, I'd welcome any comments and better approaches.</p>
<p><strong>The requirements</strong></p>
<p>I want to generate JAXB objects based on a collection of XSDs using XJC as part of a Maven build. I'... | [] | [
{
"body": "<p>The <code><jaxb:javaType /></code> tag generates a new <code>org.w3._2001.xmlschema.AdapterN</code> class for each new javaType definition. So a better approach would be:</p>\n\n<ul>\n<li>Create a class extending <a href=\"http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/annotation/ad... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-14T09:32:02.847",
"Id": "1877",
"Score": "29",
"Tags": [
"java",
"xml",
"jodatime",
"maven",
"jaxb"
],
"Title": "JAXB XJC code generation - adding @XmlRootElement and Joda Da... | 1877 |
<p>It seems to play up sometimes and I'm not sure if this is due to the class itself or the way I'm using it. Can someone confirm that this is a 'good' implementation of a <code>VertexArrayObject</code> class?</p>
<pre><code>//The following code is public domain
public class VertexArray : GraphicsResource
{
prote... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2017-07-30T08:51:27.070",
"Id": "325040",
"Score": "0",
"body": "I found many similarities with my code: https://github.com/luca-piccioni/OpenGL.Net.Objects/blob/master/OpenGL.Net.Objects/VertexArrays.cs"
}
] | [
{
"body": "<p>I know nothing of OpenGL and what a correct implementation of a VertexArrayObject should look like, but I do have a couple of observations:</p>\n\n<ul>\n<li>I like that the <code>ID</code> private field is <code>readonly</code>, ...but its naming breaks the naming convention for private fields, wh... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-14T12:27:41.573",
"Id": "1880",
"Score": "5",
"Tags": [
"c#",
"object-oriented",
"opengl"
],
"Title": "OpenGL VertexArrayObject class"
} | 1880 |
<p>I am quite new to Java and was trying to improve my skills a little by doing a binary file reader. The choosen one was the <a href="http://en.wikipedia.org/wiki/Type-length-value" rel="nofollow">TLV</a> format. I've chosen that one for being reasonably simple, but not so simple. Also I had some concrete examples wit... | [] | [
{
"body": "<p>Of course the constructor is too long, but you need to be careful when you factor out some parts into separate private methods, especially with error handling. Right now error handling isn't correct: <code>dis.close();</code> will never be called in case of an file error etc, leaving the stream op... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-06T16:32:26.190",
"Id": "1885",
"Score": "1",
"Tags": [
"java",
"beginner"
],
"Title": "How to make this TLV Reader class look nicer and work smoother?"
} | 1885 |
<pre><code>var studentRepo = new StudentRepository();
int gradeParaleloId = Convert.ToInt32(cmbGradeParalelo.SelectedValue);
var students = studentRepo.FindAllStudentsFromGradeParalelo(gradeParaleloId);
int year = DateTime.Now.Year;
int month = Convert.ToInt32(cmbMes.SelectedIndex) + 1;
AttendanceRepository attendance... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-15T05:12:54.613",
"Id": "3188",
"Score": "1",
"body": "40*30=1200, not 120"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-15T12:28:08.467",
"Id": "3192",
"Score": "0",
"body": "I thought I type... | [
{
"body": "<p>First of all, minor beef. I'd reccommend that you change your index names to be more descriptive, particularly the inner one. For instance you could make your repo query</p>\n\n<pre><code>DateTime date = new DateTime(year, month, **day**);\n</code></pre>\n\n<p>Much more readable. When an index has... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-15T00:37:04.003",
"Id": "1890",
"Score": "5",
"Tags": [
"c#",
"entity-framework"
],
"Title": "Small method for saving student attendance"
} | 1890 |
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-15.html" rel="nofollow">SICP 2.2.4</a>:</p>
<p>The textbook has already defined a function (right-split ...) as follows:</p>
<blockquote>
<pre><code>(define (right-split painter n)
(if (= n 0)
painter
(let ((smaller (right-split paint... | [] | [
{
"body": "<p>In order to test it, you need to have definitions for things like beside and below. There's something strange in the text book code because the painter \"smaller\" is not actually scaled in the code, or is it indicated that \"below\" and \"beside\" scale their arguments? Anyway, you can just defin... | {
"AcceptedAnswerId": "1898",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-15T02:37:44.667",
"Id": "1895",
"Score": "3",
"Tags": [
"lisp",
"scheme",
"sicp"
],
"Title": "Writing a general purpose \"split\" function (for SICP's imaginary language)"
} | 1895 |
<blockquote>
<p><strong>Exercise 2.46.</strong></p>
<p>A two-dimensional
vector v running from the origin to a
point can be represented as a pair
consisting of an x-coordinate and a
y-coordinate. Implement a data
abstraction for vectors by giving a
constructor make-vect and
corresponding selectors ... | [] | [
{
"body": "<p>No.</p>\n\n<p>If this would be production code, you would be better off by</p>\n\n<pre><code> (define (sub-vect v1 v2) (add-vect v1 (scale-vect v2 -1)))\n</code></pre>\n\n<p>However, this is not what the exercise asks for, as everything should be written \"in terms of constructors and selectors\"... | {
"AcceptedAnswerId": "1897",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-15T03:01:40.737",
"Id": "1896",
"Score": "2",
"Tags": [
"lisp",
"scheme",
"sicp"
],
"Title": "Adding, subtracting, and multiplying a vector by a scalar"
} | 1896 |
<p>I have a class which is responsible for checking whether a website is up or down. I've made it to run asynchronously, but I would like critique if this is a good/bad way or if there is another better way to do it.</p>
<pre><code>class UrlChecker {
private readonly IValidationCondition _condition;
private re... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T11:44:46.563",
"Id": "24241",
"Score": "0",
"body": "@Kiquenet Unfortunately not at the moment. I'll see if I can extract it from my project."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T19:56:40.8... | [
{
"body": "<p>I don't see how this runs asynchronously. <code>callback(_status);</code> will still only be called after all processing is finished, parallel or not. In this case this makes the callback rather redundant, as it does the same as a simple return value.</p>\n\n<p>If you want to make it asynchronous ... | {
"AcceptedAnswerId": "1904",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-15T11:10:27.720",
"Id": "1903",
"Score": "4",
"Tags": [
"c#",
"asynchronous"
],
"Title": "Asynchronous website monitor"
} | 1903 |
<p>I have been reviewing the code of a new co-worker and, although in general I think it's OK, there's a thing that causes me mixed feelings:</p>
<pre><code> private void Method(...)
{
Thread t = new Thread(() =>
{
// Some ~50 lines of code here
});
t.Start();
}
</code></... | [] | [
{
"body": "<p>I think it should be a separate method rather than a lambda expression. If the method is as large as 50 lines then you should seriously think about breaking it up anyway, being an anonymous method only compounds the issue. It may be better to extract portions of the method instead, but that is a d... | {
"AcceptedAnswerId": "1933",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-15T16:04:18.557",
"Id": "1911",
"Score": "16",
"Tags": [
"c#",
"lambda"
],
"Title": "Long function as a lambda, right or wrong?"
} | 1911 |
<p>The script is fully working, but I ask is there a better way I can do this rather than name all of the query variables, <code>$q</code>, <code>$q1</code> etc, and then use <code>if</code> <code>else</code> statements to execute the code.</p>
<pre><code><?php
// open the mysql connection
require_once('mysqli.ph... | [] | [
{
"body": "<p>Appears you are storing cleartext passwords and doing a 1:1 comparison. <strong>This is bad</strong>. </p>\n\n<p>You can clean the code up by doing the following and executing <strong>1</strong> query to MySQL:</p>\n\n<pre><code>require_once('mysqli.php'); \n// successful login variables \n$q ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-15T11:47:00.597",
"Id": "1915",
"Score": "5",
"Tags": [
"php",
"mysql"
],
"Title": "Simple activation script"
} | 1915 |
<p>I've been using the following the code to store temporal error messages in <code>TempData</code>, to be displayed from my master page on production sites without any problems, but is this a good way of doing it?</p>
<h2>The controller helper code:</h2>
<pre><code>namespace System.Web.Mvc
{
public static class ... | [] | [
{
"body": "<p>On the whole the approach is fine, but do <em>not</em> use <code>TempData</code> unless you're looking to populate this information across redirects. <code>TempData</code> comes with a host of issues, and its behaviour isn't quite what you think.</p>\n\n<p><code>ViewData</code>, on the other hand,... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-16T15:50:01.877",
"Id": "1926",
"Score": "5",
"Tags": [
"c#",
"asp.net-mvc-2"
],
"Title": "Storing Temporal Message Lists in ASP.NET MVC TempData"
} | 1926 |
<p>I am making a simple transposition cipher. I am testing the program with the word "computer" with the secret key "5,2,8,3,7,1,4,6", where the encrypt method will put the 5th letter 'u' in the first position, 2nd letter 'o' in 2nd position, 8th letter 'r' in 3rd position...</p>
<p>So the output would be:<br>
origin... | [] | [
{
"body": "<p>If you can assume that every index in the encrypted message is included in the key, You can loop over the key and encrypted message together, placing each letter into the correct decrypted message slot directly:</p>\n\n<pre><code>public static char[] decrypt(char[] encrypted, int[] key)\n{\n ch... | {
"AcceptedAnswerId": "1928",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-16T18:16:07.340",
"Id": "1927",
"Score": "5",
"Tags": [
"java",
"algorithm"
],
"Title": "How can I make my decrypt method more efficient?"
} | 1927 |
<p>I have this version comparison function in java. </p>
<p>Any cleaner way to write this without all the nested 'if' statements? </p>
<p>Note that the suggestions must be in Java code only.</p>
<pre><code>@Override
public int compareTo(Version o)
{
int result = this.major.compareTo(o.major);
if (result == 0... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-18T11:46:14.610",
"Id": "3255",
"Score": "2",
"body": "The nesting pretty much reflects the cascading structure of the data - why do you want to get rid of it? PHP-Coder shows an legitimate solution but I wouldn't necessarily prefer it... | [
{
"body": "<p>In the apache.common package (very usefull by the way) </p>\n\n<p>There is a <code>CompareToBuilder</code>. Works like a charm (like the <code>ToStringBuilder</code>)</p>\n\n<p><a href=\"http://commons.apache.org/lang/api-2.6/org/apache/commons/lang/builder/CompareToBuilder.html\">http://commons.a... | {
"AcceptedAnswerId": "1945",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-17T20:31:43.300",
"Id": "1934",
"Score": "11",
"Tags": [
"java"
],
"Title": "Version comparison function"
} | 1934 |
<p>I am trying to learn how to write good, clean, and efficient JavaScript. I consider myself a novice, at best, in JavaScript. Any comments are appreciated.</p>
<p>In an effort to become a better JavaScript programmer, I am trying to write a simple JavaScript animation using HTML5's new canvas element. Functionally s... | [] | [
{
"body": "<p>I think that pattern is fine. It has the advantage that you have \"named arguments\", which is very readable and can be useful if you call the some function/constructor with different sets of arguments. </p>\n\n<p>The only thing I'd suggest is to use another name for the parameter, because capital... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-18T04:12:47.170",
"Id": "1940",
"Score": "8",
"Tags": [
"javascript",
"beginner",
"animation",
"collision"
],
"Title": "Canvas Drawing/Animation"
} | 1940 |
<p>I'm working on interfacing some older positioning equipment with an arduino, but having done the majority of my work with higher level language I'm having trouble adjusting to the limitations of AVR-GCC.</p>
<p>I basically have two questions: Is this a good way to parse out the strings? What can I do to optimize th... | [] | [
{
"body": "<p>IMHO string parsing is not a good idea for embedded applications. If you really care for speed, it would be better to use some binary format w/o dynamic length numbers etc.</p>\n\n<p>I suggest you cannot change protocol due to legacy code/hardware. Then you could try turning your parser into finit... | {
"AcceptedAnswerId": "1992",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-18T06:02:04.393",
"Id": "1942",
"Score": "3",
"Tags": [
"c++"
],
"Title": "String parsing with AVR-GCC"
} | 1942 |
<p>I have a form that submits to a servlet that has optional parameters. If they are empty they are just ignored. This is the template I am using:</p>
<pre><code>if (!(param = (String)params.get("httpParam")).equals("")) {
// Handle parameter
}
</code></pre>
<p>It doesn't quite feel right. It <em>works</em>, but I... | [] | [
{
"body": "<p>I suggest extract code for getting parameter to separate method (see <a href=\"http://sourcemaking.com/refactoring/extract-method\" rel=\"nofollow\">extract method</a> refactoring's tehnique):</p>\n\n<pre><code>param = getOptionalParameter(\"httpParam\");\nif (! param.isEmpty()) {\n // Handle p... | {
"AcceptedAnswerId": "1948",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-18T13:54:19.507",
"Id": "1947",
"Score": "7",
"Tags": [
"java",
"null",
"servlets"
],
"Title": "Handling optional parameters in a servlet"
} | 1947 |
<p>I have decided to go PDO and have started implementing it on one of my webprojects. I have limited programing skills but can usually pull it off with some tutorials and forums.</p>
<p>Here is my code this far and it works fine but how is the code correct regarding the picking up errors, syntax, order and begintrans... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-18T14:12:03.700",
"Id": "3256",
"Score": "0",
"body": "I don't see any need for transactions. You only have 1 insert. Do you plan to add more write queries? Note that by beginning a transaction you don't issue any implicit locks on the... | [
{
"body": "<p>Instead of checking for a UID collision before an insert, I would put a unique key on that column, and then write fallback code for the case (very very unlikely) when two collide. That way you can simplify your logic and reduce the number of queries to one instead of two. You also don't need a tra... | {
"AcceptedAnswerId": "1950",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-18T14:08:16.753",
"Id": "1949",
"Score": "4",
"Tags": [
"php",
"mysql",
"pdo"
],
"Title": "Implementing PDO, code correct so far?"
} | 1949 |
<p>I just wrote this small inch <-> cm conversion program. It works just fine, although I know that I've done some things in a rather stupid manner and that it could be improved.</p>
<pre><code>def conversion():
try: amount = int(raw_input("Please enter the value: "))
except ValueError:
print "Pleas... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-24T16:49:42.230",
"Id": "110541",
"Score": "1",
"body": "where are cm and inch?"
}
] | [
{
"body": "<p>The first point would be the separation of concerns: every entity (function, class …) should only be responsible for <em>one</em> task (except, ironically, printing the result).</p>\n\n<p>In your code, one function (<code>conversion</code>) is responsible for everything. Try separating the differe... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-18T14:57:51.360",
"Id": "1952",
"Score": "5",
"Tags": [
"python",
"converting"
],
"Title": "Inch <-> cm conversion program"
} | 1952 |
<p>Below I have some jQuery code that handles footnotes. My question is actually about the formatting and indentation of the code, so I won't bother trying to explain what the code does beyond that.</p>
<p>I'd like to know what patterns of indentation are considered the most maintainable and readable when chaining jQu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-03-15T15:30:19.810",
"Id": "36941",
"Score": "0",
"body": "@jonnysooter: my question was specifically about the indentation and formatting. why would you change the indentation and formatting of the code in the question? rolling back to ... | [
{
"body": "<p>My suggestion:</p>\n\n<pre><code>$('.footnote[id^=\"ret_\"]')\n .removeAttr('title')\n .removeAttr('alt')\n .mouseenter(function(e) {\n var footnote = $('#footnote_cont_' + this.id.substring(4)).html(); \n $footnoteTooltip.stop(true, false);\n\n //only completely hide and cha... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-18T19:48:45.480",
"Id": "1957",
"Score": "9",
"Tags": [
"javascript",
"jquery"
],
"Title": "Indentation and formatting for chained jQuery methods"
} | 1957 |
<p>I need to get the total milliseconds to the next mid-day (12:00:00) to signal a timer that will run once a day. </p>
<p>Assuming the application can be shut down and started anytime, is this code to get the milliseconds left to midday (used to set the timer) correct? (It doesn't need to be exact; it can be off by ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-19T12:57:08.847",
"Id": "3292",
"Score": "0",
"body": "If it can be off by a few seconds, why are you worried about millisecond resolution?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-19T12:59:57.410",
... | [
{
"body": "<pre><code>if (r > 0) // It's before noon\n ;\nelse // It's after noon\n r = TimeSpan.FromTicks(TimeSpan.TicksPerDay).TotalMilliseconds + r; \n</code></pre>\n\n<p>Change to:</p>\n\n<pre><code>if (r <= 0) // It's after noon\n r = TimeSpan.FromTicks(TimeSpan.TicksPerDay).TotalMilliseconds +... | {
"AcceptedAnswerId": "1963",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-18T20:30:09.077",
"Id": "1959",
"Score": "10",
"Tags": [
"c#",
"datetime"
],
"Title": "Getting the miliseconds from now to the next midday"
} | 1959 |
<p><a href="http://www.djangoproject.com/" rel="nofollow">Django</a>, "the web framework for perfectionists with deadlines", is a Python-based framework for creating web applications.</p>
<p>With a powerful object-based database mapper, a clean syntax for mapping URLs to views, a simple template language and a conveni... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-19T05:27:39.047",
"Id": "1965",
"Score": "0",
"Tags": null,
"Title": null
} | 1965 |
Django is a Python-based framework for creating web applications. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-19T05:27:39.047",
"Id": "1966",
"Score": "0",
"Tags": null,
"Title": null
} | 1966 |
<p>I want to join strings together, but when doing this it often happens that there is a comma too many, and therefore I need to remove that comma. In this code, I use the <code>substring</code> to delete the two last characters.</p>
<p>How can this become more elegant?</p>
<pre><code>List<String> paramList = n... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-19T20:01:39.063",
"Id": "3926",
"Score": "8",
"body": "How about instead of adding comma and then removing it just not add comma to the last item? using the index based approach would have been fine.\n\nfor (int i = 0; i < paramList.si... | [
{
"body": "<pre><code>for ( String p : paramList )\n{\n if (result.length() > 0) result.append( \", \" );\n result.append( p );\n}\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-19T12:44:29.457",
"Id": "3291",
"Score":... | {
"AcceptedAnswerId": "1975",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-19T09:36:47.943",
"Id": "1973",
"Score": "164",
"Tags": [
"java",
"strings"
],
"Title": "Remove Last Comma"
} | 1973 |
<p>Could someone review an <a href="https://stackoverflow.com/questions/5644093/returning-first-result-where-case-result-x/5680184#5680184">accepted answered</a> I gave on Stack Overflow?</p>
<p>The use-case is as follows:</p>
<blockquote>
<p>Given a messaging system where a user
can receive a message from a sing... | [] | [
{
"body": "<p>My solution has a similar complexity to yours (14 steps in <code>EXPLAIN</code>), assuming MySQL's query optimizer is smart enough. However, in my opinion, this formulation will be much easier to understand.</p>\n\n<pre><code>SELECT IF(recipientid,\n CONCAT('Message To: ', recipient.us... | {
"AcceptedAnswerId": "29833",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-19T14:24:10.287",
"Id": "1981",
"Score": "6",
"Tags": [
"sql",
"mysql"
],
"Title": "Retrieving the most recent communication from a user"
} | 1981 |
<p>I needed to write code in WPF for a client. The application is done with prism (not my decision, they already had people working on it), so I got a sparkling clean new module to work in. Since this was my first time writing WPF code going to production, I wanted to handle the code in a good manner. I decided to go M... | [] | [
{
"body": "<p>ViewModel generally looks good though I would still propose some changes: </p>\n\n<ol>\n<li><p>I do not see why do you need <code>collectionView</code> field. You're moving it's <code>CurrentItem</code> but neither it nor the entire view is exposed anywhere. </p></li>\n<li><p><code>public IComma... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-19T15:00:48.820",
"Id": "1983",
"Score": "7",
"Tags": [
"c#",
"wpf",
"mvvm",
"xaml"
],
"Title": "View Model Base"
} | 1983 |
<p><a href="http://www.ruby-lang.org/" rel="nofollow">Ruby</a> is an open-source, dynamic, object-oriented, interpreted language that combines the good bits from Perl, Smalltalk, and Lisp. Its primary purpose is to "help every programmer in the world to be productive, and to enjoy programming, and to be happy." Ruby fo... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-19T18:30:15.843",
"Id": "1986",
"Score": "0",
"Tags": null,
"Title": null
} | 1986 |
Ruby is a multi-platform, open-source, dynamic, object-oriented, interpreted language created by Yukihiro Matsumoto (Matz) in 1993. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-19T18:30:15.843",
"Id": "1987",
"Score": "0",
"Tags": null,
"Title": null
} | 1987 |
<p><strong>Ruby on Rails</strong> is an open-source web framework that's optimized for programmer happiness and sustainable productivity. It lets you write beautiful code by favouring convention over configuration.</p>
<ul>
<li><a href="http://rubyonrails.org/" rel="nofollow">Ruby on Rails website</a></li>
<li><a href... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-19T18:34:49.847",
"Id": "1988",
"Score": "0",
"Tags": null,
"Title": null
} | 1988 |
Ruby on Rails is an open-source web development framework written in Ruby. If your question code is written in Ruby on Rails, tag with Ruby as the language tag. Many things are defined by convention, freeing you from having to re-invent things to stay productive. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-19T18:34:49.847",
"Id": "1989",
"Score": "0",
"Tags": null,
"Title": null
} | 1989 |
<p><a href="https://www.python.org/" rel="nofollow noreferrer">Python</a> is a <a href="https://wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language" rel="nofollow noreferrer">dynamic and strongly typed</a> programming language that is used for <a href="https://... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2011-04-20T00:57:25.853",
"Id": "1994",
"Score": "0",
"Tags": null,
"Title": null
} | 1994 |
Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability. Use the python tag for all Python related questions. If you believe your question may be even more specific, you can include a version specific tag such as python-3.x. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2011-04-20T00:57:25.853",
"Id": "1995",
"Score": "0",
"Tags": null,
"Title": null
} | 1995 |
<blockquote>
<p><strong>Exercise 2.54</strong></p>
<p>Two lists are said to
be <code>equal?</code> if they contain equal
elements arranged in the same order.</p>
<p>For example,</p>
<pre><code>(equal? '(this is a list) '(this is a list))
</code></pre>
<p>is true, but</p>
<pre><code>(equal? '(this... | [] | [
{
"body": "<p>Since the <code>and</code> operation is associative, one could write:</p>\n\n<pre><code>(and (and (symbol? a) (symbol? b)) (eq? a b))\n</code></pre>\n\n<p>as:</p>\n\n<pre><code>(and (symbol? a) (symbol? b) (eq? a b))\n</code></pre>\n\n<p>Similarly:</p>\n\n<pre><code>(and (and (and (not (null? a)) ... | {
"AcceptedAnswerId": "2000",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-20T03:54:39.923",
"Id": "1996",
"Score": "3",
"Tags": [
"lisp",
"scheme",
"sicp"
],
"Title": "equal? predicate for lists"
} | 1996 |
<blockquote>
<p><strong>Exercise 2.56.</strong></p>
<p>Show how to extend the
basic differentiator to handle more
kinds of expressions. For instance,
implement the differentiation rule</p>
<p>$$ \frac{d(u^n)}{dr} = nu^{n-1}(\frac{du}{dr})$$</p>
<p>by adding a new clause to the deriv
program and... | [] | [
{
"body": "<p>Your definitions are correct except for one minor detail. The <code>cond</code> clause:</p>\n\n<pre><code>((= m2 1) m1)\n</code></pre>\n\n<p>should be:</p>\n\n<pre><code>((=number? m2 1) m1)\n</code></pre>\n\n<p>since one needs to test first whether <code>m2</code> is a number.</p>\n\n<p>Stylisti... | {
"AcceptedAnswerId": "2001",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-20T05:38:26.970",
"Id": "1997",
"Score": "1",
"Tags": [
"lisp",
"scheme",
"sicp",
"symbolic-math"
],
"Title": "Extending basic differentiator to handle more kinds of expression... | 1997 |
<blockquote>
<p>Exercise 2.57. Extend the
differentiation program to handle sums
and products of arbitrary numbers of
(two or more) terms. Then the last
example above could be expressed as</p>
<p><code>(deriv '(* x y (+ x 3)) 'x)</code></p>
<p>Try to do this by changing only the
representation fo... | [] | [
{
"body": "<p>Your have the right ideas for implementing <code>make-sum</code> and <code>make-product</code>. You may improve upon them in the following ways, in my opinion.</p>\n\n<p>Within the two functions, you employ an inner function <code>iter</code> to partition numeric and non-numeric terms. Tradition... | {
"AcceptedAnswerId": "2061",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-20T06:57:20.540",
"Id": "1998",
"Score": "5",
"Tags": [
"lisp",
"scheme",
"sicp"
],
"Title": "Extend sums and products functions"
} | 1998 |
<p>I am making a website using the MVP pattern. It is a simple website, so for the repository I use Linq2SQL. My architecture is basically:</p>
<p>(View - Presenter) - Service Layer - Domain Models.</p>
<p>The View consists of 10 dropdownlists, and a submit button.</p>
<p>Between the (View - Presenter) and the Servi... | [] | [
{
"body": "<p>Best practice is to let the presenter handle the formatting. If you are, for example, dealing with multiple views, the code will be much easier to maintain and also be parsed/formatted from just the one location.</p>\n\n<p>By the look of your code, i'd suggest you use a simple POCO-class for the d... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-20T14:38:57.080",
"Id": "2002",
"Score": "3",
"Tags": [
"c#"
],
"Title": "MVP presenter code in C# - possible troubles with DTO's"
} | 2002 |
<p><strong>Background</strong>:<br>
This began with <a href="http://jcoglan.com/">James Colgan</a>'s <a href="https://github.com/jcoglan/lisp-dojo">Lisp-Dojo</a> for Ruby. My implementation can be found <a href="https://github.com/antarestrader/lisp-dojo">here</a>. I then moved on to <a href="http://en.wikibooks.org/w... | [] | [
{
"body": "<p>When I went through the WYAS48 I made the same decision of breaking the bits of <code>eval</code> off into smaller functions. I found this made testing easier since I could focus on just one function at a time.</p>\n\n<p>I find that having a function be one massive bunch of logic is not helpful. I... | {
"AcceptedAnswerId": "49256",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-20T15:53:33.260",
"Id": "2003",
"Score": "11",
"Tags": [
"lisp",
"scheme",
"haskell"
],
"Title": "On Implementing a Lisp"
} | 2003 |
<p>I just started learning how to code PHP as well as HTML and as a challenge for myself I put together a questionnaire with what I have learnt so far which isn't as much as I would like to know e.g. sessions, databases, etc. Anyhoo, I would like to get the review of peers and would appreciate any constructive suggesti... | [] | [
{
"body": "<p>I think you may improve your code by using <a href=\"http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller\" rel=\"nofollow\">MVC pattern</a>. In your case, for example, I had recommend:</p>\n\n<ul>\n<li>extract all logic to class (don't print any message or use $_POST directly from i... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-20T16:33:20.010",
"Id": "2004",
"Score": "3",
"Tags": [
"php",
"form"
],
"Title": "PHP Questionnaire Code Peer Review"
} | 2004 |
<p>How can I make this sort faster and better?</p>
<pre><code>function OrderBy(a,b) {
if (a < b) return -1;
if (a > b) return 1;
return 0;
}
SortBy = function($th) {
var $tbody = $th.closest('tbody');
var $table = $tbody.parent();
$tbody.detach();
$('#Processing').show('fast',functio... | [] | [
{
"body": "<p>You could read the cell texts before sorting, so that it doesn't have to happen repeatedly in the order function:</p>\n\n<pre><code> var rowsWithText = $tbody.find('tr').map(function() {\n return {\n row: this, \n text: $(this).children('td').eq(column).text()\n };\n ... | {
"AcceptedAnswerId": "2022",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-20T18:14:47.777",
"Id": "2006",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Ordering cell rows and columns"
} | 2006 |
<pre><code>if params[:package]
city_ids = []
city = params[:package].delete 'city'
city_ids << city if city.to_i > 0
cities = params[:package].delete 'cities'
city_ids += cities if cities.class == Array && cities.length > 0
params[:package][:cities] = city_ids.map{ |c| City.get(c) }... | [] | [
{
"body": "<p>This code looks pretty clean to me. Here are a few thoughts:</p>\n\n<p>I'm not sure what your ORM is (or even that <code>City</code> is database backed), but most have a way to fetch more then one record at a time. Making a single call will save time and Database resources.</p>\n\n<p>Another thoug... | {
"AcceptedAnswerId": "2027",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-20T22:15:56.337",
"Id": "2007",
"Score": "4",
"Tags": [
"ruby"
],
"Title": "Nicer way to work params"
} | 2007 |
<p>I had some difficulty with this problem, so I'm sure there is a better way. Here is the question from <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-16.html" rel="nofollow">SICP</a>:</p>
<blockquote>
<p><strong>Exercise 2.58</strong></p>
<p>Suppose we want to
modify the differentiation prog... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-21T01:31:57.973",
"Id": "2009",
"Score": "5",
"Tags": [
"lisp",
"scheme",
"sicp",
"math-expression-eval"
],
"Title": "Standard Algebraic Derivative Calculator"
} | 2009 |
<p>For web-uploading of Cyrillic-named images, I've written the script below:</p>
<pre><code>#!/usr/bin/python
# coding=utf-8
import os
import argparse
import shutil
class Error: pass
class FolderError(Error): pass
def copytranstree (src, dst):
names = os.listdir( src )
try:
os.makedirs( dst )
exce... | [] | [
{
"body": "<ol>\n<li>All exceptions in python should\ninherit from an Exception class.</li>\n<li>WindowsError only works on Windows, its better to use the more general OSError</li>\n<li>You twice have a very long line to transliterate a string. Put it in a function and call it</li>\n<li>You should put any code ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-21T01:54:43.660",
"Id": "2011",
"Score": "8",
"Tags": [
"python",
"beginner",
"file-system",
"i18n"
],
"Title": "Web-uploading of Cyrillic-named images"
} | 2011 |
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-16.html" rel="nofollow">SICP</a>:</p>
<blockquote>
<p>Exercise 2.60. We specified that a
set would be represented as a list
with no duplicates. Now suppose we
allow duplicates. For instance, the
set {1,2,3} could be represented as
the l... | [] | [
{
"body": "<p>Just as <code>adjoin-set</code> simply became <code>cons</code>, <code>union-set</code> can be defined as:</p>\n\n<pre><code>(define union-set append)\n</code></pre>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": ... | {
"AcceptedAnswerId": "2063",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-21T02:01:44.567",
"Id": "2012",
"Score": "4",
"Tags": [
"lisp",
"scheme",
"sicp"
],
"Title": "Set representation allowing duplicates"
} | 2012 |
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-16.html" rel="nofollow">SICP</a>:</p>
<blockquote>
<p><strong>Exercise 2.61</strong></p>
<p>Give an implementation
of adjoin-set using the ordered
representation. By analogy with
element-of-set? show how to take
advantage of the order... | [] | [
{
"body": "<p>Calling <code>element-of-set?</code> from <code>adjoin-set</code> introduces unnecessary redundancy. One may incorporate this test within the adjoin-set function (in your case, <code>rec</code> should be the main body of your function, with an <code>=</code> test added):</p>\n\n<pre><code>(define... | {
"AcceptedAnswerId": "2064",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-21T02:15:44.297",
"Id": "2013",
"Score": "2",
"Tags": [
"lisp",
"scheme",
"sicp"
],
"Title": "Adjoin-set for an ordered set representation"
} | 2013 |
<p>I've just finished the Ruby Koans and one of the last projects was creating a Proxy class that sends methods to another class. I was wondering whether you would change anything about my solution (if there's something wrong or a better way to do it). I'm still a beginner and I want to get better.</p>
<pre><code>requ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-29T12:58:00.283",
"Id": "3505",
"Score": "0",
"body": "I'm also experimenting with Ruby, and am looking for examples/a tutorial/exercises which discuss the more advanced ruby features. I finished the chapter in 7 languages in 7 weeks, ... | [
{
"body": "<pre><code>@methods_to_pass, @messages = [], []\n@object = target_object\n@object.class.instance_methods(true).each { |method_name| @methods_to_pass << method_name; method_name }\n</code></pre>\n\n<p>Couple of things to note here:</p>\n\n<p>First of all the <code>; method_name</code> bit is com... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-21T02:38:11.667",
"Id": "2015",
"Score": "11",
"Tags": [
"ruby",
"beginner",
"proxy"
],
"Title": "Ruby Koans Proxy Project"
} | 2015 |
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-16.html" rel="nofollow">SICP</a>:</p>
<blockquote>
<p><strong>Exercise 2.65</strong></p>
<p>Use the results of
exercises 2.63 and 2.64 to give (n)
implementations of union-set and
intersection-set for sets implemented
as (balanced) b... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-21T07:15:41.693",
"Id": "2018",
"Score": "2",
"Tags": [
"tree",
"lisp",
"scheme",
"sicp"
],
"Title": "Union-set intersection-set for a binary-tree implementation of sets"
} | 2018 |
<p>I'm writing a function with the following signature:</p>
<pre><code>(Ord a) => [a] -> [Int]
</code></pre>
<p>It's semantics is to find an order-preserving mapping from list of objects to list of <code>Int</code>s.</p>
<p>The version of mine:</p>
<pre><code>import Data.List
import Data.Map (Map, (!))
import... | [] | [
{
"body": "<p>I think a sorting-based approach would be simpler than using a map. The basic idea is that we sort the list, assign each item a value based on its position in the list, then undo the sorting and take the value assigned to each item. In order to undo the sorting we have to remember the position eac... | {
"AcceptedAnswerId": "2026",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-21T07:45:08.597",
"Id": "2019",
"Score": "4",
"Tags": [
"functional-programming",
"haskell"
],
"Title": "Most elegant approach to writing list renumbering function"
} | 2019 |
<p>I have ext_scaffold (<code>question.js</code>). When I row click I get answers on this question, so</p>
<pre><code>'rowselect': function(sm, row, rec) {
store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: '/answers/index_all_for_question_id/' + rec.data.id + '?format=ext_json',
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-12-09T21:53:16.003",
"Id": "10403",
"Score": "0",
"body": "How about something as simple as putting your duplicated values in a variable that you access from both files?"
}
] | [
{
"body": "<p>The trouble with your question is that the code resembles more config than coding and there is nothing wrong with it except that it is not DRY between those 2 files.</p>\n\n<p>It seems that Ext JS supports <code>require</code> as of version 4, so you simply need to extract the common logic/config ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-21T12:24:26.637",
"Id": "2021",
"Score": "4",
"Tags": [
"javascript",
"ext.js"
],
"Title": "Ext JS: Avoid duplication"
} | 2021 |
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-16.html" rel="nofollow">SICP</a>:</p>
<blockquote>
<p>Exercise 2.66. Implement the lookup
procedure for the case where the set
of records is structured as a binary
tree, ordered by the numerical values
of the keys.</p>
</blockquote>
<p>I... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-21T13:41:09.663",
"Id": "2024",
"Score": "4",
"Tags": [
"lisp",
"scheme",
"sicp",
"lookup"
],
"Title": "Search on a binary tree"
} | 2024 |
<p>The <code>ConcurrentDictionary<T,V></code> in .NET 4.0 is thread safe but not all methods are atomic.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/dd997369.aspx">This</a> points out that:</p>
<blockquote>
<p>... not all methods are atomic, specifically <code>GetOrAdd</code> and <code>AddOrUpdate... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-01-10T18:57:45.713",
"Id": "12000",
"Score": "0",
"body": "So does this mean that if the dictionary was exposed by a third party and was not defined as a <T,Lazy<V>>, you would not be able to do it?"
},
{
"ContentLicense": "CC BY-... | [
{
"body": "<ul>\n<li><p>Allowing the caller to provide the type argument <code>U</code> implies that they are allowed to use a subclass of <code>Lazy<V></code>, but this will not work as your implementations always creates a new <code>List<V></code> and cast it to <code>U</code>. Since this means <c... | {
"AcceptedAnswerId": "2040",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-21T14:27:47.290",
"Id": "2025",
"Score": "35",
"Tags": [
"c#",
"thread-safety"
],
"Title": "Extension methods to make ConcurrentDictionary GetOrAdd and AddOrUpdate thread safe when usi... | 2025 |
<p>I have two elements on my page:</p>
<pre><code><ul id="VerticalMenu></ul>
<ul id="AccordionMenu"></ul>
</code></pre>
<p>I'm calling some JSON with jQuery and loading elements in the <code>div</code>s. I'm curious if there are things I can be doing more efficiently, and better ways to use se... | [] | [
{
"body": "<p>Two small nickpicks at the start: </p>\n\n<ul>\n<li>Empty HTML lists (<code>ul</code>, <code>ol</code>) are strictly spoken invalid. They should contain at least one list item. That said, I believe there is no browser limitation or other technical reason an empty list shouldn't work.</li>\n<li>It ... | {
"AcceptedAnswerId": "2033",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-21T17:19:17.943",
"Id": "2028",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"json"
],
"Title": "Getting JSON with jQuery and creating lists with click events calling more jQuer... | 2028 |
<p>This journey started with a quest to <a href="https://stackoverflow.com/questions/1297020/creating-the-shortest-possible-case-insensitive-verification-number">create the shortest possible case-insensitive verification number</a>. Based on the answers there, I worked out a <a href="https://stackoverflow.com/questions... | [] | [
{
"body": "<p>If you really want to chase those milliseconds then I would try following: </p>\n\n<p>1) I consider division operations as slow so I would avoid using two divisions if it can be replaced with one division and some easier operation: </p>\n\n<pre><code>Function ToBase32(ByVal lInput)\n Dim lMo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-21T19:04:18.143",
"Id": "2029",
"Score": "8",
"Tags": [
"algorithm",
"optimization",
"vbscript",
"asp-classic"
],
"Title": "Is there a more efficient way to do Base 32 encoding/d... | 2029 |
<p>I don't have any questions about this piece of code; it compiles just fine in Visual Studio 2010. I just wanted to post it to see if anyone has any good ideas on how to simplify it, or pointing out any bad practices I have have done.</p>
<pre><code>// Tic Tac Toe Game
#include <iostream>
#include <iomanip... | [] | [
{
"body": "<p>Well for one, you've got some unreachable code:</p>\n\n<pre><code>if(Board[row][col] == 0)\n{\n return true;\n}\nelse if (Board[row][col] != 0)\n{\n cout <<\"Can go there, Dude!\\n\\n\";\n return false;\n}\nelse\n{\n // The cell is neither 0 nor non-0!!!\n // cout << \"W... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-22T01:37:41.303",
"Id": "2032",
"Score": "12",
"Tags": [
"c++",
"game",
"tic-tac-toe"
],
"Title": "Tic Tac Toe game"
} | 2032 |
<p>I've found this implementation on the web:</p>
<blockquote>
<pre><code>void insertSort(int a[], int length)
{
int i, j, value;
int k=0;
for(i = 1; i < length; i++)
{
value = a[i];
for (j = i - 1; j >= 0 && a[j] > value; j--)
{
a[j + 1] = ... | [] | [
{
"body": "<p>First of all, what you implemented is not insertion sort:</p>\n\n<p>Insertion sort uses one loop to iterate over the array, and for each element uses another loop to move the element to its desired location. This makes its running time \\$O(n^2)\\$.</p>\n\n<p>Your algorithm iterates over each pair... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-22T10:05:53.340",
"Id": "2034",
"Score": "9",
"Tags": [
"c",
"sorting",
"insertion-sort"
],
"Title": "Insertion sort implementation adapted from the web"
} | 2034 |
<p>I want to split my helpers in different modules (and files), but I found some problems which I got around with the following solution:</p>
<pre><code># app/helpers/application_helper.rb
module ApplicationHelper
include ApplicationContainer
# ...
end
# app/helpers/partials/application_container.rb
module Applic... | [] | [
{
"body": "<p>Your current solution is fine, in my opinion. The underscore naming-convention used on view-partials doesn't apply for modules, that's why you got the uninitialized constant-error. If you name it <code>ApplicationHelper::ApplicationContainer</code> it has to be in a file named <code>application_co... | {
"AcceptedAnswerId": "2082",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-22T21:25:20.913",
"Id": "2037",
"Score": "6",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "How and where to define a partial helper module"
} | 2037 |
<p>This example comes from <a href="https://stackoverflow.com/questions/5761117/testing-if-colors-equal">a code snippet posted on Stack Overflow</a>:</p>
<pre><code>private double brickVal(Color c) {
if (c == Color.RED) {
return 10.0;
} else if (c == Color.ORANGE) {
return 8.0;
} else if (c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-23T11:11:08.600",
"Id": "3350",
"Score": "1",
"body": "I wouldn't use both in the same function! In what context is this function being used?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-05T07:57:13.170"... | [
{
"body": "<p>No, it's not correct (and thus of course also not best practice). For example the condition <code>c == Color.GREEN</code> will be true if the method is called as <code>brickVal(Color.GREEN)</code>, but false if it is called as <code>brickVal(new Color(0, 255, 0))</code>. Since <code>Color.GREEN</c... | {
"AcceptedAnswerId": "2045",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-23T00:56:02.470",
"Id": "2039",
"Score": "7",
"Tags": [
"java"
],
"Title": "Comparing Color objects with =="
} | 2039 |
<pre><code>string s = Clipboard.GetText().Replace("\r", " ");
string[] lines = s.Split('\n');
int row = dgView.CurrentCell.RowIndex;
int col = dgView.CurrentCell.ColumnIndex;
int linesCount = lines.Count();
if ((row + linesCount) - dgView.RowCount > 0) dgView.Rows.Add((row + linesCount) - dgView.RowCount);
asyncSql... | [] | [
{
"body": "<p>I wasn't convinced that the code <em>per se</em>, besides what could be done to improve it, would take this long under 'normal' circumstances. I thought I'd actually test this myself before bed and so threw something together, here's what I did...</p>\n\n<p>I created a WinForms application with th... | {
"AcceptedAnswerId": "2058",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-23T04:46:12.440",
"Id": "2042",
"Score": "6",
"Tags": [
"c#",
".net",
"winforms"
],
"Title": "Why is this code to paste into a DataGridView so slow?"
} | 2042 |
<p>From the text:</p>
<blockquote>
<p>Exercise 2.68. The encode procedure
takes as arguments a message and a
tree and produces the list of bits
that gives the encoded message.</p>
</blockquote>
<pre><code>(define (encode message tree)
(if (null? message)
'()
(append (encode-symbol (car message)... | [] | [
{
"body": "<p>Wouldn't it be easier to unpack the tree into a dictionary mapping each symbol to its corresponding bit string? Then you could simply look up each symbol in the input to generate the corresponding output bits.</p>\n\n<p>EDIT:\nAs suggested by <code>syb0rg</code>, here is an implementation (C#, I'... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-23T09:17:31.977",
"Id": "2043",
"Score": "3",
"Tags": [
"lisp",
"scheme",
"sicp"
],
"Title": "Encode-symbol for Huffman tree"
} | 2043 |
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-16.html#%_thm_2.69" rel="nofollow">SICP</a>:</p>
<blockquote>
<p>Exercise 2.69. The following
procedure takes as its argument a list
of symbol-frequency pairs (where no
symbol appears in more than one pair)
and generates a Huffman encodin... | [] | [
{
"body": "<p>It's been a while since I've done any Lisp/Scheme, but I'll make one style point and one algorithmic point.</p>\n\n<p>Style point: it's usually more readable if you define structure projection functions with meaningful names rather than using <code>car</code>, <code>cdr</code>, etc.</p>\n\n<p>Algo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-23T14:18:05.923",
"Id": "2046",
"Score": "3",
"Tags": [
"lisp",
"scheme",
"sicp",
"compression"
],
"Title": "Huffman encoding successive-merge function"
} | 2046 |
<p>What would be a prettier/faster way to do handling of multiple errors in Ruby? Here is the code I am working with:</p>
<pre><code>begin
response = session.get url
rescue Patron::HostResolutionError
puts "Error resolving remote host."
exit 1
rescue Patron::PartialFileError
puts "File size mismatch. (Host rep... | [] | [
{
"body": "<p>Your begin/rescue code does look repetitive, but on the hand it would be easy to extend in the future. If you are certain you will always have this structure (rescue with an error message + exit), you can abstract it, for example:</p>\n\n<pre><code>exceptions = {\n Patron::HostResolutionError =&g... | {
"AcceptedAnswerId": "2057",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-23T21:26:23.647",
"Id": "2049",
"Score": "13",
"Tags": [
"ruby",
"error-handling",
"networking",
"curl"
],
"Title": "Handling many networking exceptions in Ruby"
} | 2049 |
<p>The <a href="http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm" rel="noreferrer">TEA</a> is a very simple encryption algorithm requiring little time and space - perfect for embedded systems. There are extensions to it, and every version has its flaws (WEP was based on it), but for casual protection it's perfec... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-20T22:53:42.670",
"Id": "28307",
"Score": "0",
"body": "Would you mind explaining the following: 1. \"pointer to 8 bit data array\" means? does that mean the data is read by 8-bits once? 2. In your implementations shows 4 fixed keys, b... | [
{
"body": "<p>I'm not familiar with your algorithm, but in glancing over your code, it looks like sum and delta are magic numbers. Since delta is shared between encrypt and decrypt, it might be a good idea to #define them at the top of the file.</p>\n\n<p>edit: I just looked at the Wikipedia article and the mag... | {
"AcceptedAnswerId": "2053",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2008-09-06T22:17:14.337",
"Id": "2050",
"Score": "32",
"Tags": [
"c",
"algorithm",
"cryptography"
],
"Title": "Tiny Encryption Algorithm (TEA) for arbitrary sized data"
} | 2050 |
<p>5 years ago, when i was in love with <code>VB</code>, I created this simple program to detect if a file is virus or not.</p>
<p>What I'd like is to see if you can help me optimize it, speed-wise.</p>
<p>I open an executable file in a rich textbox control and use the <code>Instr</code> method to search for occurren... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-24T12:55:55.703",
"Id": "3364",
"Score": "0",
"body": "Firstly, are you using .NET or not?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-24T12:57:55.957",
"Id": "3365",
"Score": "0",
"body": "... | [
{
"body": "<p>In VB2010 the instr out performed indexof</p>\n\n<pre><code> Dim ipsum As String = \"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-24T03:00:13.323",
"Id": "2059",
"Score": "5",
"Tags": [
"vb6",
"performance"
],
"Title": "VB6: String Searching Performance "
} | 2059 |
<p>In my nested <code>for</code> loops below, it is sometimes necessary to exit the outer loop and then continue program execution. Since loop labels and other goto-like constructions are heavily discouraged, I'm a bit afraid of raptors. Is this usage OK? Is there a better way to structure the program?</p>
<pre><code>... | [] | [
{
"body": "<p>In general, the code is OK, i.e. I don't think it must be changed. However, to increase clarity, I would do a couple of things differently:</p>\n\n<p>It's probably better to write an <code>is_valid()</code> method for your objects, so that whole inner loop is a single function call. Then, you can ... | {
"AcceptedAnswerId": "2714",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-24T08:13:15.613",
"Id": "2060",
"Score": "3",
"Tags": [
"perl"
],
"Title": "Can I jump like this?"
} | 2060 |
<p>I am new to Rails and have a system that needs to process transactions.</p>
<p>A user can enter a transaction to which one or more users are tied. These users owe some amount of money to the person making the transaction. For example, Bill might buy lunch for 4 friends and the bill is $125. They decide to split ... | [] | [
{
"body": "<p>I think it's a bad practice to use transactions in Controllers.\nYou should add a method on the <code>Tran</code> model instead (for example, <code>save_and_update_user_balances</code>):</p>\n\n<pre><code>def create\n @title = \"Create Transaction\"\n\n # Add the transaction from the client\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-24T22:17:48.597",
"Id": "2073",
"Score": "5",
"Tags": [
"beginner",
"ruby",
"ruby-on-rails",
"finance",
"locking"
],
"Title": "Transactions and locking in Rails 3"
} | 2073 |
<p>My friend does a bunch of Java work (commandline, still toying around) and I notice a bunch of try/catch blocks like this:</p>
<pre><code> try {
double a = Double.parseDouble(secondInput);
}
catch(NumberFormatException nFE) {
System.out.println("The input was not an integer.");
try {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-25T02:01:26.653",
"Id": "3376",
"Score": "1",
"body": "There are a number of problems with this code. What element in particular are you asking about - the nested try/catch blocks, like Vicente mentions?"
},
{
"ContentLicense":... | [
{
"body": "<p>You hit infamous checked exceptions feature in Java. Here is <a href=\"http://www.mindview.net/Etc/Discussions/CheckedExceptions\" rel=\"nofollow\">one of the basic articles on this</a>, by Bruce Eckel but you can find more by googling \"checked exceptions in Java\".</p>\n\n<p>In most cases it's h... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-25T01:58:51.080",
"Id": "2076",
"Score": "8",
"Tags": [
"java",
"error-handling",
"floating-point"
],
"Title": "Aborting a program for invalid floating-point input"
} | 2076 |
<p>I have a simple quantity display function that runs for every product displayed in our catalog. The <code>MaxQtyDisplay</code> value is set in our web.config file. Part of me thinks the function is as streamlined as possible and part of me thinks it can be improved upon somewhere. Because this function is called ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-11T14:19:25.520",
"Id": "392527",
"Score": "0",
"body": "Are the values involved really doubles? Using Integers would help."
}
] | [
{
"body": "<p>I'm sure there will be elements of your application that are of much more concern, performance-wise, than this, but it could certainly be a little more clear, or maybe a little less superfluous...</p>\n\n<ul>\n<li>Evaluation of and work within conditions is only required if <code>q > 0</code></... | {
"AcceptedAnswerId": "2094",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-25T17:35:49.197",
"Id": "2093",
"Score": "4",
"Tags": [
"asp.net",
"vb.net"
],
"Title": "Display catalog product quantity"
} | 2093 |
<p>This is a jQuery plug-in I've created that relies on jQuery UI's tabs plug-in. It adds some framework specific logic when setting up tabs:</p>
<ol>
<li>Fixes a bug in jQuery that appears when an id/class contains a "."</li>
<li>Manages the tab state using a framework specific cookie API (does not use the jQuery coo... | [] | [
{
"body": "<p>These are probably more comments, but I'll post them as an \"answer\", because it's easier.</p>\n\n<ul>\n<li><p>Could you point out a source or an example for the bug with ids/classes containing <code>.</code> and <code>:</code>, because in a quick test they seem to work fine: <a href=\"http://jsf... | {
"AcceptedAnswerId": "2103",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-25T19:51:01.093",
"Id": "2096",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "jQuery Plugin Review - wrapper for jQuery UI's tabs"
} | 2096 |
<p>I am new to the world of coding as well as XHTML and PHP. As a way to gain more experience as well as to put theory into practice including a way to challenge myself, I put together the following code that calculates values a user enters into a form. </p>
<p>This was to test my knowledge regarding PHP's own functio... | [] | [
{
"body": "<p>This is going to have a lot of extensibility concerns. What if I want to add exponentials or scientific notation? What if I want to chain operations? What if I want to ensure someone doesn't put unsafe code that could bork my webserver in the POST variable?</p>\n\n<p><a href=\"https://stackoverflo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-26T02:31:42.647",
"Id": "2097",
"Score": "3",
"Tags": [
"php"
],
"Title": "PHP and Custom Functions"
} | 2097 |
<p><strong>Edit:</strong></p>
<p>The purpose of this method is to search a specific directory for a given file type, ex. (*.txt, *.pdb, *.exe") then move the file(s) to a given destination directory and delete the original file from the source directory.</p>
<p>Is there a better way to write the following code?:</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-26T11:02:44.037",
"Id": "3401",
"Score": "0",
"body": "Your code does something else than the title indicates?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-26T11:29:54.710",
"Id": "3402",
"Score"... | [
{
"body": "<p>From msdn:</p>\n\n<pre><code>string sourceFile = @\"C:\\Users\\Public\\public\\test.txt\";\nstring destinationFile = @\"C:\\Users\\Public\\private\\test.txt\";\n\n// To move a file or folder to a new location:\nSystem.IO.File.Move(sourceFile, destinationFile);\n\n// To move an entire directory. To... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-26T09:23:03.153",
"Id": "2101",
"Score": "7",
"Tags": [
"c#",
".net"
],
"Title": "Is there a better way to search directories for a file or files?"
} | 2101 |
<p>In a controller (PHP, CodeIgniter) I'm adding scripts & css to variables to be used in the view output. My initial coding looked like this:</p>
<pre><code>private function _add_script($path, $where = self::ADD_LAST) {
$html = "<script src='$path'></script>\n";
switch($where) {
case s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-27T00:39:36.580",
"Id": "3449",
"Score": "0",
"body": "Your rewrite would be good if you were adding many different tags. I.E. more than just the two (script and link)"
}
] | [
{
"body": "<p>I think what you did was a good thing. I also think you could combine the first 2 functions as well. </p>\n\n<p>Something like this: </p>\n\n<pre><code>private function _add_item($path, $type, $where = self::ADD_LAST) {\n $script = \"<script src='$path'></script>\\n\";\n $css = \... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-26T14:58:45.077",
"Id": "2112",
"Score": "1",
"Tags": [
"php"
],
"Title": "Have I gone too far in factoring out repeated code in this example?"
} | 2112 |
<p>I'm currently using an Open Source FTP library in all my projects as I've never managed to code a decent <strong>FTP Helper Library</strong> based on the C# 4.0 API.</p>
<p>What do you think about this approach? I'm not quite versed in TDD but ideally I'd like to make this class as testable as possible.</p>
<pre><... | [] | [
{
"body": "<p>Unit testing means that automated tests can run in isolation from any dependencies (such as other classes, but also the environment).</p>\n\n<p>The DownloadFile method has a hard-coded dependency on WebClient and thus on the environment. It can't be used without using the network and (presumably) ... | {
"AcceptedAnswerId": "2124",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-26T19:31:02.883",
"Id": "2114",
"Score": "10",
"Tags": [
"c#",
"unit-testing"
],
"Title": "FTP Download Helper Method"
} | 2114 |
<p>I am a newbie to Python and have started object-oriented programming recently. I have implemented a "Rock Paper Scissors" application in OOP. I would like for you to evaluate my code, and tell me where can I improve my code and how I can better organize the functionality.</p>
<pre><code>import random
class RockPap... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-26T19:53:17.463",
"Id": "3441",
"Score": "0",
"body": "In the future please avoid cross-posting. The moderators will migrate the post to the new site. It helps keep noise across the SE sites down."
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>All in all, you're looking good!</p>\n\n<p>Here are a few things that stand out to me:</p>\n\n<ul>\n<li>You're using double-underscore name\nmangling, when you probably don't\nneed to. It's not the best habit to\nget into. Single-underscore says \"I\nam private\" without doing the\nhorrendous name... | {
"AcceptedAnswerId": "2139",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-26T19:34:37.407",
"Id": "2116",
"Score": "11",
"Tags": [
"python",
"beginner",
"object-oriented",
"game",
"rock-paper-scissors"
],
"Title": "Rock Papers Scissors in Python"... | 2116 |
<p>This essentially reads a specially-structured file from the scanner and then parses random phrases and prints them:</p>
<pre><code>{
<start>
<greeting> <object>
}
{
<greeting>
hello
bonjour
aloha
}
{
<object>
world
universe
multiverse
}
</code></pre>
<p>Possible random phrases could... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-27T04:29:40.683",
"Id": "3454",
"Score": "0",
"body": "If you ask performance questions, you should mention a) what machine you're running on, b) how fast it is now and how fast it has to be. c) What is the sample size? Solutions which... | [
{
"body": "<p>I'm no expert in performance optimization or even threads, so my code review will mostly be some style suggestions, but I do have suggestions how I would implement the the phrase building to be faster - purely from my gut :-)</p>\n\n<ul>\n<li><p>A nitpick at the beginning: You should try and clean... | {
"AcceptedAnswerId": "2125",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-27T00:21:20.530",
"Id": "2123",
"Score": "4",
"Tags": [
"java",
"optimization",
"parsing",
"random",
"file"
],
"Title": "Parsing random phrases from a file"
} | 2123 |
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-18.html" rel="nofollow">SICP</a>:</p>
<blockquote>
<p><strong>Exercise 2.82</strong></p>
<p>Show how to generalize
apply-generic to handle coercion in
the general case of multiple
arguments. One strategy is to attempt
to coerce all th... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-27T12:07:22.740",
"Id": "2126",
"Score": "2",
"Tags": [
"lisp",
"scheme",
"sicp"
],
"Title": "Coercion with multiple arguments"
} | 2126 |
<p>I've been rolling around several ideas or approaches in my head, and none seem any more useful or "right" than another. I'm sure this is extremely objective but I'm looking for a close-to-definitive answer on the object oriented approach to large block string storage and output in PHP. Given the following example, h... | [] | [
{
"body": "<p>Well, I think the most convenient way is to use templates. Your HTML block with variables is actually a template. You can use some template engine like <a href=\"http://www.twig-project.org\" rel=\"nofollow\">Twig</a> or <a href=\"http://www.smarty.net/\" rel=\"nofollow\">Smarty</a> to build your ... | {
"AcceptedAnswerId": "2141",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-27T16:27:47.673",
"Id": "2128",
"Score": "3",
"Tags": [
"php",
"html",
"object-oriented"
],
"Title": "PHP Output Block Defining and Best Practices"
} | 2128 |
<p>I have the following construction in the program:</p>
<pre><code> while(true) {
<...>
try {
JobManager.markJobCompleted(unitOfWork.getSqlFactory(), jobId, dataOut);
} catch (DbLogicException e) {
logger.error(JobManager.CANNOT_MARK_JOB_COMPLETED + jobId, e);
try {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-27T17:33:35.203",
"Id": "3462",
"Score": "2",
"body": "You could move the `continue` statement up into the second `try` clause, right after the `rollback()`. Not much of a change, but maybe you like it better?"
},
{
"ContentLi... | [
{
"body": "<p>Yes.</p>\n\n<ol>\n<li>Throw specialized exceptions like <code>CannotMarkJobCompletedException</code> and <code>CannotRollbackTransactionException</code>...</li>\n<li>Make your <code>toString()</code> method on exceptions to return something you want what your logger to log</li>\n<li>Instead of doi... | {
"AcceptedAnswerId": "2131",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-27T16:59:26.090",
"Id": "2129",
"Score": "4",
"Tags": [
"java",
"error-handling",
"database",
"exception"
],
"Title": "Making a job completed, rolling back on error"
} | 2129 |
<p>I finished the Ruby chapter in <a href="http://pragprog.com/titles/btlang/seven-languages-in-seven-weeks" rel="nofollow"><em>Seven Languages in Seven Weeks</em></a>. It tries to make you familiar with the core concepts of several languages rather quickly. Dutifully I did all exercises, but most likely they can be im... | [] | [
{
"body": "<p>A couple of minor things:</p>\n\n<p>First of all the convention in the ruby world is to use 2 spaces for indentation, not 4. It doesn't really matter much, but it's generally easier to use the style conventions that everyone uses unless you have a reason not to.</p>\n\n<pre><code>range = (0..10)\n... | {
"AcceptedAnswerId": "2136",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-27T20:55:54.257",
"Id": "2134",
"Score": "7",
"Tags": [
"ruby",
"game"
],
"Title": "Higher lower game in Ruby"
} | 2134 |
<p>As an exercise, I've implemented a simple reader macro in Common Lisp (using SBCL). It converts Octal (unsigned integers only) into numbers.</p>
<p>Usage:</p>
<pre><code>* #z1234
668
</code></pre>
<p>The code:</p>
<pre><code>(defun oct-string-to-number
(string)
"Converts an octal string to a number. Only... | [] | [
{
"body": "<p>First of all a note about variables: You're using <code>setq</code> on previously undefined and undeclared variables. This is actually undefined behavior and in most implementations will create global dynamic/special variables. To create local variables (which you presumably intended) use <code>le... | {
"AcceptedAnswerId": "2137",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-27T22:44:04.573",
"Id": "2135",
"Score": "2",
"Tags": [
"common-lisp"
],
"Title": "Simple octal reader macro in Common Lisp"
} | 2135 |
<p>In <a href="https://stackoverflow.com/questions/5801586/idiomatic-haskell-for-database-abstraction">this</a> post I asked about what would be idiomatic haskell database abstraction. I had been thinking for it a while, and the first answer was similar to what I had in mind, and I wrote a proof-of-concept of it. Disca... | [] | [
{
"body": "<p>First of all, I spotted a bug: since HDBC implicitly runs queries in a transaction, and since you never <a href=\"http://hackage.haskell.org/packages/archive/HDBC/latest/doc/html/Database-HDBC.html#v%3acommit\" rel=\"noreferrer\">commit</a>, none of your changes are actually applied to the databas... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-28T09:33:06.600",
"Id": "2140",
"Score": "8",
"Tags": [
"sql",
"haskell"
],
"Title": "Idiomatic haskell database connectivity"
} | 2140 |
<p>I finished the Ruby chapter in <a href="http://pragprog.com/titles/btlang/seven-languages-in-seven-weeks" rel="nofollow noreferrer">Seven Languages in Seven Weeks</a>. It tries to make you familiar with the core concepts of several languages rather quickly. Dutifully I did all exercises, but most likely they can be ... | [] | [
{
"body": "<pre><code>File.open( 'grepFile.txt', 'r' ) do |file|\n lines = []\n line_number = 1\n file.readlines.each do |line|\n lines[line_number] = line\n line_number += 1\n end\n lines.each_index do |i| \n line = lines[i]\n puts \"line #{i.to_s}: #{line}\" if line =~ /bleh/\n end\nend\n</... | {
"AcceptedAnswerId": "2143",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-28T12:40:11.277",
"Id": "2142",
"Score": "8",
"Tags": [
"ruby"
],
"Title": "Custom grep in Ruby"
} | 2142 |
<p>I finished the Ruby chapter in <a href="http://pragprog.com/titles/btlang/seven-languages-in-seven-weeks" rel="nofollow noreferrer">Seven Languages in Seven Weeks</a>. It tries to make you familiar with the core concepts of several languages rather quickly. Dutifully I did all exercises, but most likely they can be ... | [] | [
{
"body": "<pre><code>def method_missing( name, *args )\n @row_hash[ name.to_s ]\nend\n</code></pre>\n\n<p>Doing it like this means that if the user calls a row method with arguments, the arguments will silently be ignored. Also if the user calls any method which does not exist and for which no row exists eith... | {
"AcceptedAnswerId": "2145",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-28T14:37:12.323",
"Id": "2144",
"Score": "5",
"Tags": [
"ruby",
"csv"
],
"Title": "CSV module in Ruby"
} | 2144 |
<p>I have been working with C# for quite some time but relatively new to the concepts of lambdas and Linq. I was working with a Linq To SQL example and trying to write a generic solution for executing a search against a collection of entities (eg. list of <code>Customer</code> objects) where the search parameter will b... | [] | [
{
"body": "<p>How much did <a href=\"http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx\" rel=\"nofollow\">you look into LINQ to SQL</a>? Unless you have a reason not to expose the <code>DataContext</code>, you can just perform queries on it without using the 'search object'.</p>\n\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-29T05:39:21.990",
"Id": "2154",
"Score": "7",
"Tags": [
"c#",
"linq",
"performance"
],
"Title": "Performance optimization for Linq To SQL"
} | 2154 |
<p>Both functions look fairly similar to each other, but they are different in the type of string. I have 6 functions like this and all differ only in the "string cmd". Any ideas on how I can put it all into one?</p>
<pre><code>public void getFrmSingProgTbl(int flg)
{
if (flg == 1)
{
ob... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-29T23:53:20.563",
"Id": "3506",
"Score": "0",
"body": "How much control do you have over the structure of the td object's type?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-05-04T17:34:07.617",
"Id": "1... | [
{
"body": "<p>Quick thoughts off the top of my head.</p>\n\n<ol>\n<li>Use the standard .Net naming convention and don't abbreviate</li>\n<li>Don't change the whole processing of a method by a flag</li>\n<li>If you control td.CheckOk(...) why does it return an array when it isn't used that way? Also, it should r... | {
"AcceptedAnswerId": "2158",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-29T15:11:29.057",
"Id": "2156",
"Score": "7",
"Tags": [
"c#",
"strings"
],
"Title": "Managing part types and counts"
} | 2156 |
<p>I have small Class which handles user's information. (name, surname, login, hash of password). Also this class can activate, register and login the user. This means I should connect to DB. Is it normal? I'm using Pear MDB2 to connect to DB. </p>
<p>Does it mean that every instance of User will have MDB2 object init... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-02T17:58:32.460",
"Id": "3544",
"Score": "0",
"body": "What is MDB2.php doing?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-02T19:16:40.847",
"Id": "3546",
"Score": "0",
"body": "MDB2.php is ... | [
{
"body": "<blockquote>\n<p>Also this class can activate, register and login the user. This means I should connect to DB. Is it normal?</p>\n</blockquote>\n<p>It's up to you and your requirements. Personally I am trying to make all domain specific objects simple as possible and use it only as <a href=\"http://e... | {
"AcceptedAnswerId": "2206",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-29T15:46:52.153",
"Id": "2157",
"Score": "4",
"Tags": [
"php",
"object-oriented",
"database"
],
"Title": "User php class. Should I connect to DB in this class?"
} | 2157 |
<p>I'm giving a lecture on basic programming to first-year mathematics students. The programming language is Java (defined by curriculum).</p>
<p>Last week I gave the following task:</p>
<blockquote>
<p>Write a program, that reads in the date of birth of the user separated into year, month and day and subsequently ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-03T11:21:30.010",
"Id": "3563",
"Score": "0",
"body": "Do they know loops?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-04T12:17:04.463",
"Id": "3577",
"Score": "0",
"body": "@HosamAly: Yes, ... | [
{
"body": "<p>Wow, arrays would be really nice for this, but I suppose you can give a \"rewrite that first problem using arrays\" once they learn them. :)</p>\n\n<p>What happens if they enter zero or negative values?</p>\n\n<p>Anyone born in February is automatically invalid:</p>\n\n<pre><code>case 2: //februar... | {
"AcceptedAnswerId": "2167",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-29T22:46:27.720",
"Id": "2161",
"Score": "3",
"Tags": [
"java",
"datetime"
],
"Title": "Days of life calculator for first-year mathematics students"
} | 2161 |
<blockquote>
<p>I remember once going to see [Srinivasa Ramanujan] when he was ill at Putney. I had ridden in taxi cab number 1729 and remarked that the number seemed to me rather a dull one, and that I hoped it was not an unfavorable omen. "No," he replied, "it is a very interesting number; it is the smallest number... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-19T14:21:53.743",
"Id": "7333",
"Score": "0",
"body": "give more examples on the topic"
}
] | [
{
"body": "<p>Your code looks mostly fine, I see a few very minor things to comment on:</p>\n\n<ul>\n<li><p>There's no need to define <code>cube</code> and <code>cube-root</code> at the innermost scope,</p></li>\n<li><p>Using <code>define</code> for internal functions makes it look a little clearer,</p></li>\n<... | {
"AcceptedAnswerId": "2169",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-29T23:55:04.117",
"Id": "2162",
"Score": "8",
"Tags": [
"scheme"
],
"Title": "Find the Hardy–Ramanujan number using R5RS scheme"
} | 2162 |
<p>The objective was the following to be solved in Python:</p>
<blockquote>
<p>Given a string, def a function that
returns another string with the vowels
(upper or lowercase) replaced by
0,1,2,3,4 respectively.</p>
<hr>
<p>Example input:</p>
<pre><code>"bB nN aei ou AEIOU"
</code></pre>
<p>Desi... | [] | [
{
"body": "<p>The calls to append, index, join, str are just noise.</p>\n\n<p>Here's the same idea but with a map and a generator expression:</p>\n\n<pre><code>def crypt(s):\n m = {\"A\": \"0\", \"E\": \"1\", \"I\": \"2\", \"O\": \"3\", \"U\": \"4\"}\n return \"\".join(m[c.upper()] if c.upper() in m else ... | {
"AcceptedAnswerId": "2168",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-30T00:24:30.360",
"Id": "2164",
"Score": "11",
"Tags": [
"python",
"strings"
],
"Title": "Change upper or lowercase vowels to [0,1,2,3,4] respectively and leave the rest the same"
} | 2164 |
<p>I have been using the following function (in the kohana html class in a table) to generate tables.</p>
<pre><code>function table($columns,$reverse=false,$fill=false,array $attr=null){
$c = '';
//ugly hack, looking for fix
$max=sizeof(max($columns));
for($i=0;$i<sizeof($columns);$i++){
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-31T00:06:42.447",
"Id": "4230",
"Score": "0",
"body": "There's also [PEAR's HTML_Table](http://pear.php.net/package/HTML_Table) package, if you're into that sort of thing. :-)"
}
] | [
{
"body": "<ul>\n<li>Some of the variable names could benefit from being slightly less terse.</li>\n<li>Aren't you passing in an array of rows? Each element in the array is then an array of columns.</li>\n<li>What is max? Is it trying to find the row with the most columns? Either rename to something more self-d... | {
"AcceptedAnswerId": "2288",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-30T02:44:51.897",
"Id": "2171",
"Score": "6",
"Tags": [
"php",
"php5"
],
"Title": "PHP Table generation"
} | 2171 |
<p>In the situation where I am looping through a collection looking for an item, is it better practice to <code>break</code> before I <code>return</code> or should I <code>break</code> and then <code>return</code>?</p>
<p>Return during loop:</p>
<pre><code>foreach(string item in items)
{
string[] split = item.Spl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-29T19:58:25.763",
"Id": "3515",
"Score": "3",
"body": "`return (from split in items.Select(item => item.Split('|')) where split[0] == searchFor select split[1]).FirstOrDefault();`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cr... | [
{
"body": "<p>If you break, you need to introduce an additional variable. In my opinion, it's more clear to return as soon as possible from any function.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-29T19:57:52.540",
"Id": "3518",
... | {
"AcceptedAnswerId": "2173",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-29T19:54:07.993",
"Id": "2172",
"Score": "14",
"Tags": [
"c#",
"strings"
],
"Title": "Looping through a collection"
} | 2172 |
<p>I managed to get something up and running, but I've no idea whether there are better ways to do this. I've spent all morning trying to figure out the best way to use parameters (allowing objects from the pipeline, or to be passed in, allowing overriding the <code>modelName</code>, etc.) and trying to understand diff... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-30T11:54:51.267",
"Id": "2180",
"Score": "18",
"Tags": [
"shell",
"powershell",
"razor"
],
"Title": "PowerShell module for formatting objects using Razor"
} | 2180 |
<p>I've never been satisfied with any of the possible <code>sprintf()</code>-like functions in C++:</p>
<ul>
<li><code>sprintf()</code> is a C function and it's very unsafe and dangerous to use (undefined behavior all over the place)</li>
<li><code>boost::format</code> is too slow and awkward to use (think of the <cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-30T14:26:32.517",
"Id": "3526",
"Score": "0",
"body": "PS: comments in the code talk about alignment, the {0,10} syntax, which is not implemented yet. Also I wrote my examples (but not the unit tests) without trying to run them first."... | [
{
"body": "<p>In my opinion:</p>\n\n<ul>\n<li>Use fullscope names (like <code>std::vector</code>, <code>boost::shared_ptr</code>)</li>\n<li>Don't use <code>const &</code> for simple types (for example <code>int</code> or <code>double</code>)</li>\n<li>Write <code>const</code> after the type: <code>std::stri... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-30T14:11:00.527",
"Id": "2182",
"Score": "12",
"Tags": [
"c++",
"reinventing-the-wheel",
"formatting"
],
"Title": "My own C++ Format function"
} | 2182 |
<p>I am writing a wrapper for dynamic behavior in C#. If I use <code>GetMethod()</code>, then an exception is thrown when there is more than one method (overloads). I figure it will become apparent at runtime that if there is an argument mismatch anyway. Is this a good way to solve the problem?</p>
<pre><code>public... | [] | [
{
"body": "<p>The order the method infos are returned in dose not appear to be a defined one, I would suggest filtering on argument types to avoid the risk of it all crumbling to dust when the order changes.</p>\n\n<p>Also you may want to consider the case when a method is defined on both the base class and the... | {
"AcceptedAnswerId": "2186",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-04-30T17:18:28.257",
"Id": "2184",
"Score": "4",
"Tags": [
"c#"
],
"Title": "Wrapper for dynamic behavior"
} | 2184 |
<p>I am seeing it more and more.</p>
<p>Which do you think works best and why?</p>
<p>This:</p>
<pre><code>$config = array(
'param1'=>'abc'
'param2'=>'dfg'
);
new Class($config);
</code></pre>
<p>Or:</p>
<pre><code>new Class('abc','dfg');
</code></pre>
| [] | [
{
"body": "<p>I'd always use the second version, since one could use type-hinting. The array style is less transparent.</p>\n\n<p>At least the array style should read like this:</p>\n\n<pre><code>$config = array(\n Class::PARAM_1_INFO =>'abc'\n Class::PARAM_1_SOMETHING =>'dfg'\n);\n</code></pre>\n\n<p>Thi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-01T17:00:32.253",
"Id": "2189",
"Score": "4",
"Tags": [
"php"
],
"Title": "single array or many single argument to call a constructor with params?"
} | 2189 |
<p><a href="http://en.wikipedia.org/wiki/Trie" rel="noreferrer">http://en.wikipedia.org/wiki/Trie</a></p>
<p>The basic idea is to support fast searches via prefix matching. In my implementation, I allow each node to store all of the words that match its given prefix, and then if the word length exceeds the length of t... | [] | [
{
"body": "<p>Instead of returning a collection, why not return an IEnumerable? Then you would perform no list copying, and it would be low cost to return an Enumerable that actually recurses through all the children lists.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"Cr... | {
"AcceptedAnswerId": "2202",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-02T18:13:02.800",
"Id": "2195",
"Score": "5",
"Tags": [
"c#",
"search"
],
"Title": "Is this a reasonable Trie implementation?"
} | 2195 |
<p>I have this python code that compares merge sort and selection sort, but it is taking "forever."</p>
<pre><code>import time
import random
# Selection Sort Code #
def maxIndex(J):
return J.index(max(J))
def swap(LCopy, i, j):
temp = LCopy[i]
LCopy[i] = LCopy[j]
LCopy[j] = temp
# Implementation of ... | [] | [
{
"body": "<p>The first reason that your code is slow is because you are implementing a selection sort which will be slow in any implementation. It has to scan through a large list looking for the values for each iteration. That's gonna be slow.</p>\n\n<p>The second problem is that you freely create new lists. ... | {
"AcceptedAnswerId": "2200",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-02T20:41:38.680",
"Id": "2199",
"Score": "7",
"Tags": [
"python",
"performance",
"sorting",
"mergesort"
],
"Title": "Merge sort and selection sort comparison taking too long"
} | 2199 |
<p>In order to avoid the user having to explicitly prefix a script with <code>sudo</code> or <code>su --command</code>, I wrote the following:</p>
<pre><code>import sys
import os
if os.getuid():
root = "/usr/bin/sudo"
if not os.path.exists("/usr/bin/sudo"):
root = "/bin/su --command"
command = "{}... | [] | [
{
"body": "<p>The last time I checked (which admittedly has been a while) all major Linux distributions except Ubuntu have a default setup in which sudo is installed, but not configured to be able to start arbitrary applications. So on those your script will fail.</p>\n\n<p>Apart from that I think it's a bad id... | {
"AcceptedAnswerId": "2205",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-03T01:18:16.187",
"Id": "2203",
"Score": "7",
"Tags": [
"python"
],
"Title": "Becoming root from Python"
} | 2203 |
<p>Just for the heck of it, I wrote a simple little interpreter that takes in inputs in the form of Polish Notation.</p>
<p>The user will input something like</p>
<blockquote>
<p><code>+ 5 6</code></p>
</blockquote>
<p>And it will then output</p>
<blockquote>
<p><code>11</code></p>
</blockquote>
<p>Here's anot... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-26T20:50:20.423",
"Id": "67422",
"Score": "1",
"body": "You've described [Polish notation](http://en.wikipedia.org/wiki/Polish_notation), not [Reverse Polish notation](http://en.wikipedia.org/wiki/Reverse_Polish_notation)."
}
] | [
{
"body": "<p>If you look at the similarity of your various perform_xxx functions, it suggests there is duplication that could be removed. One way to do this would be to extract Operator classes, one for each operation, where the common behavior of extracting left and right values from the stream was expressed... | {
"AcceptedAnswerId": "2216",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-03T17:30:11.730",
"Id": "2211",
"Score": "6",
"Tags": [
"c++",
"calculator",
"math-expression-eval"
],
"Title": "Polish notation interpreter/calculator"
} | 2211 |
<p>Is it good or bad practice (or, when is it appropriate) to use shorthand methods?</p>
<p>Lets pretend we're using jQuery here, because it has a lot of them.:</p>
<pre><code>jQuery.ajax()
jQuery.get()
jQuery.getJSON()
jQuery.getScript()
.load()
jQuery.post()
</code></pre>
<p>These are all really just shorthand for... | [] | [
{
"body": "<p>Hm, good question. I guess I would say that the number one rule of programming is DRY: Don't Repeat Yourself. You could argue that any function is \"just shorthand for\" whatever it does. But whenever you find yourself typing the same thing over and over and over, even if that thing is only two or... | {
"AcceptedAnswerId": "2245",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-03T19:02:08.923",
"Id": "2214",
"Score": "5",
"Tags": [
"javascript",
"jquery"
],
"Title": "shorthand methods"
} | 2214 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.