body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I have been writing PHP programs in the MVC pattern for quite some time. But I am not sure if I am doing it right.</p> <p>For instance, I have this PHP file that prints results in XML, and I put this file in 'model':</p> <pre><code>header("Content-Type: text/xml"); echo '&lt;?xml version="1.0" encoding="utf-8" sta...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T17:13:13.307", "Id": "49454", "Score": "1", "body": "http://php.net/manual/en/book.simplexml.php - Avoid coding your own XML documents by hand: use an API." } ]
[ { "body": "<p>Ok, this might come across as blunt and hurtful, but it's meant to be helpful (code-review IMO should be harsh, <a href=\"https://codereview.meta.stackexchange.com/questions/810/guidelines-for-new-users-proposal-tag\">here's why</a>):</p>\n\n<p><em>\"I have been writing PHP programs in the MVC pat...
{ "AcceptedAnswerId": "31085", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T04:51:21.587", "Id": "31035", "Score": "2", "Tags": [ "php", "object-oriented", "mvc", "xml", "php5" ], "Title": "Printing results in XML" }
31035
<p>I want to optimize the following code:</p> <pre><code>#ifdef USE_SSE #define STRING_PREFETCH_TBL(ptr) \ _mm_prefetch(ptr, _MM_HINT_T0); \ _mm_prefetch(ptr+64, _MM_HINT_T0); \ _mm_prefetch(ptr+128, _MM_HINT_T0); \ _mm_prefetch(ptr+192, _MM_HINT_T0) #else #define STRIN...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T09:59:13.683", "Id": "49408", "Score": "3", "body": "Note that your `StrToLowerCase` function is not Unicode-enabled, and it only handles English letters." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-...
[ { "body": "<p>This is what Visual Studio 2012 with <code>/O2</code> generated for me without SSE support:</p>\n\n<pre><code>_StrToLowerCase:\n 00000000: 8B 54 24 04 mov edx,dword ptr [esp+4]\n 00000004: 8B 44 24 08 mov eax,dword ptr [esp+8]\n 00000008: 8A 0A mov ...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T06:49:16.977", "Id": "31036", "Score": "4", "Tags": [ "optimization", "c", "performance", "strings" ], "Title": "Fastest StringToLowerCase()" }
31036
<p>I need a valid and semantic HTML structure for the user-account (user-panel) section of the overall layout of my web application. </p> <p>What I saw in other web apps include:</p> <ol> <li>User title (or email, or username)</li> <li>A thumbnail (on which you can click to change your picture)</li> <li>A notificatio...
[]
[ { "body": "<p>\"Saeed Neamati\" should probably be the heading (<code>h1</code>) of the section (instead of <code>span</code>).</p>\n\n<p>Don’t forget the <code>alt</code> attribute for the <code>img</code>.</p>\n\n<p>The <code>.notifications</code> should be a sectioning element, probably <code>section</code>,...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T07:23:17.830", "Id": "31038", "Score": "3", "Tags": [ "html", "html5" ], "Title": "Optimizations for this user-account HTML structure?" }
31038
<p>What this should do is wait for <code>dataBlockSize</code> bytes to be ready and then continue, but wait for 10ms if they are not ready yet to not block the CPU, but not the first time as I do not want to wait once even if the bytes are ready.</p> <p>Is there a better way of doing this?</p> <pre><code>while (!canc...
[]
[ { "body": "<p>I think it is just a matter of taste. Here is one approach:</p>\n\n<pre><code>do\n{\n var ftdiStatus = FtdiDevice.FtdiDevice.Instance.GetRxBytesWaiting(ref rxBytes);\n\n if (ftdiStatus != FTDI.FT_STATUS.FT_OK)\n return null;\n\n if(rxBytes &gt;= dataBlockSize)\n break;\n\n ...
{ "AcceptedAnswerId": "31046", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T09:21:14.607", "Id": "31040", "Score": "4", "Tags": [ "c#", "multithreading" ], "Title": "Waiting for bytes to be ready" }
31040
<pre><code>int count; int gcdCount; int testCase = 5; while (testCase &gt; 0) { int n = 5; count = 0; gcdCount = 0; // to get two random numbers a and b a&lt;=n and b&lt;=n //get probablity of gcd(a,b) ==b for (int i = 1; i &lt;= n; i++) { for (int j = 1; j &lt;= n; j++) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T11:17:30.517", "Id": "49416", "Score": "1", "body": "Can you fix the formatting of the code?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T12:27:11.887", "Id": "49427", "Score": "1", "bo...
[ { "body": "<p>You do not need to increment \"count\" variable in every loop. The value of it depends on \"n\".</p>\n\n<p>Here you can find some ways to optimize a loop:\n<a href=\"http://en.wikipedia.org/wiki/Loop_optimization\" rel=\"nofollow\">http://en.wikipedia.org/wiki/Loop_optimization</a></p>\n\n<p>What ...
{ "AcceptedAnswerId": "31053", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T10:48:30.543", "Id": "31044", "Score": "2", "Tags": [ "java", "optimization", "algorithm", "performance" ], "Title": "How can I optimize this code that finds the GCD?" }
31044
<p>Can I create a method to do work with these five sections? I'm doing binding operations so many times. Do you have an idea on how to make this code prettier? </p> <ul> <li><code>ddlModelValue</code> -> ASP.NET <code>DropDownList</code></li> </ul> <p></p> <pre><code>var dtModel = Session[SystemConstant.ModelSes...
[]
[ { "body": "<p>This would be a start:</p>\n\n<pre><code>Sub bindTableToControl(table as DataTable, _\n control, _\n Optional textField As String = \"Name\", _\n Optional valueField As String = \"Name\")\n\n control.DataSource = table;\n control.Da...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T11:49:10.277", "Id": "31050", "Score": "0", "Tags": [ "c#", "asp.net" ], "Title": "Generalising the data binding operation" }
31050
<p>Can someone give me suggestions on how to improve this program?</p> <p>The <a href="http://projecteuler.net/problem=1" rel="nofollow">objective</a> is to find the sum of all the multiples of 3 or 5 below 1000.</p> <pre><code>#include &lt;stdio.h&gt; main() { int S, s3,s2,S1; int a=333,b=3,c=999, i=5,j=995...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T11:56:46.653", "Id": "49420", "Score": "1", "body": "provide a link to the problem, or describe the problem. Some of us don't know what project Euler is." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-1...
[ { "body": "<p>You certainly got the point of the problem. You applied Inclusion-Exclusion principle. Your code works well too. Most of the operations you use are constant time operations and can't be optimized further. The only problem is code formatting. Every coder develops a coding style that suites him or h...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T11:52:37.997", "Id": "31051", "Score": "5", "Tags": [ "c", "project-euler" ], "Title": "Please review my solution to Project Euler program 1" }
31051
<p>Please explain the relationship between pointers and arrays. In this <a href="http://www.cprogrammingexpert.com/C/Tutorial/functions/pass_by_reference.aspx" rel="nofollow">tutorial</a>, they change <code>int c</code> by changing <code>*r</code> in the function. How is that possible?</p> <p>Also, please review my ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T14:38:12.877", "Id": "49447", "Score": "0", "body": "You should be aware that your code requires C99, but that's fine for now." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T18:47:13.763", "Id": ...
[ { "body": "<p>No, I've compiled your code with C90 and it doesn't reverse the given string.</p>\n\n<ul>\n<li><code>int main(int argc, char *argv[])</code> If you're not compiling from the command line with arguments to be used by the program, then <code>int main()</code> suffices.</li>\n<li>Passing argument by ...
{ "AcceptedAnswerId": "31077", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T14:29:27.320", "Id": "31056", "Score": "4", "Tags": [ "c", "strings", "beginner", "pointers" ], "Title": "Modifying a string by passing a pointer to a void function" }
31056
<p>I have a situation in which a program, communicating over the network, can timeout or otherwise fail to establish a connection through no fault of my application or its user. If and when this happens, an exception is thrown. The solution is obvious; simply try again a couple more times, and if multiple tries don't w...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T17:19:17.593", "Id": "49456", "Score": "4", "body": "Personally, I don't think that `while (true)` is a code smell." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T23:41:40.960", "Id": "49475", ...
[ { "body": "<p>Yeah, I'd probably redo it with an actual condition. That way, intent looks clear and is not dependent on internal code to <code>break</code>, <code>continue</code>, etc.</p>\n\n<pre><code>const int NumberOfRetries = 3;\nvar retryCount = NumberOfRetries;\nvar success = false;\nwhile(!success &amp;...
{ "AcceptedAnswerId": "31060", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T16:05:46.277", "Id": "31059", "Score": "19", "Tags": [ "c#", "error-handling" ], "Title": "Attempt to reconnect, with timeout" }
31059
<p>After learning a lot about programming, I've decided to write some code pertaining to scripting and use of different functions. I've come to a point where I'd like others to verify my code for correctness. Is there anything I can do better, different, or easier, to make my code more efficient?</p> <p>My main goal...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T08:30:04.313", "Id": "49496", "Score": "0", "body": "In your `WHERE` clause you're using `&&`, while it _should_ be [`AND`](http://lists.mysql.com/mysql/216549). It may work on `MySQL`, but it's definitly not standard (there is not ...
[ { "body": "<p>From a quick glance of your code it looks like you are doing a lot in your PHP that you should be doing on the database with SQL.</p>\n\n<p>I recommend that you look into Stored Procedures for MySQL, I think that a lot of what you are doing can be done using Stored Procedures on your database, the...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T17:09:31.340", "Id": "31061", "Score": "2", "Tags": [ "php", "optimization", "performance", "mysql", "sql" ], "Title": "Correct use of my JOIN and arrays to fetch the data...
31061
<p>It seems like <a href="https://stackoverflow.com/questions/18685039/how-to-portably-use-system-or-popen-but-with-array-of-arguments">there's no good library function</a> I can use for popen with array of arguments instead of single shell-interpreted shell. So I implemented my own one: <a href="https://github.com/vi/...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T20:52:18.047", "Id": "49466", "Score": "1", "body": "From what I read, you are not asking how to improve it, you are asking how to make it a library." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T21...
[ { "body": "<p>The function <code>popen_arr</code> would resemble <code>popen</code> more closely if it\ntook a 'mode' parameter in the same way, instead of your <code>pipe_into_program</code>:</p>\n\n<pre><code>FILE* popen_arr(const char* program,\n const char* const argv[], \n con...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T17:36:48.540", "Id": "31063", "Score": "4", "Tags": [ "c", "linux" ], "Title": "popen with array of arguments" }
31063
<p>In my small application, I need to use a variety of visual themes.</p> <p>The simplified structure of this class:</p> <blockquote> <pre class="lang-none prettyprint-override"><code>Theme | .__ menu | | | .__ screenBackground | .__ itemsColor | .__ getRandomItemAnimation() | .__ ga...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T22:06:10.453", "Id": "49552", "Score": "1", "body": "You might find the cons in the first answer relevant: http://programmers.stackexchange.com/questions/190955/using-public-final-rather-than-private-getters" } ]
[ { "body": "<blockquote>\n <p>I want to write code like this: <code>setBackground(theme.game.screenBackground)</code> instead of <code>setBackground(theme.game().screenBackground())</code>.</p>\n</blockquote>\n\n<p>Why would you sacrifice encapsulation (<a href=\"http://www.netobjectives.com/files/Encapsulation...
{ "AcceptedAnswerId": "31074", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T19:01:13.143", "Id": "31065", "Score": "2", "Tags": [ "java", "animation" ], "Title": "Using visual themes in a game" }
31065
<p>I'd appreciate some feedback on my latest PHP script. It is supposed to work like this:</p> <ol> <li>When obtained, it checks whether the cache is still up-to-date</li> <li>IF YES, return the cache; IF NOT, reset the cache</li> <li>Get all JS scripts in the parent directory</li> <li>Minimize the code</li> <li>Add i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T16:33:22.380", "Id": "49534", "Score": "2", "body": "If you are able to use a more recent version of PHP, try refactoring this as OOP, and try functions like `glob` instead of `scandir`, they're cleaner." }, { "ContentLicens...
[ { "body": "<p>This snippet at the end...</p>\n\n<pre><code>if (compilingRequired())\n{\n if (file_exists($cache_path)){\n unlink($cache_path); \n unlink($index_path);\n }\n\n $scripts_in_directory = getScriptsInDirectory();\n $file_handler = fopen($cache_path, 'w+');\n $cache_han...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T19:13:00.277", "Id": "31068", "Score": "2", "Tags": [ "php", "php5", "cache" ], "Title": "Combine and minimize all .js files in parent folder" }
31068
<p>I made a small web application with a search box. I wanted to highlight the words found in the search.</p> <pre><code>foreach my $article (@{$search_articles}) { my @result; foreach my $word (split(' ', $article-&gt;{content})) { if ( $word =~ params-&gt;{search} ) { push(@result, ...
[]
[ { "body": "<p>Assuming that your search input is plain characters (i.e., no <code>&lt;</code>, <code>&gt;</code>, and likes), this is still problematic as can ruin your HTML code. Let's say I search for \"border\" in a page that contains <code>&lt;table border=\"1\"&gt;</code>, or \"class\" in virtually any pag...
{ "AcceptedAnswerId": "31073", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T19:13:27.420", "Id": "31069", "Score": "1", "Tags": [ "perl", "search" ], "Title": "Highlight a pattern found" }
31069
<p>This is not, strictly speaking, code review, but I think my question can be asked here.</p> <p>This is a request to find out what seems to be the cleanest. This project is a blog engine that uses the file system. There are still many things to do to improve the code (it's not great). I have such a class article a...
[]
[ { "body": "<p>The CHI uses many caching backends and you did not said which one you are using. Fastest is perl's internal arrays, then hashes and then any other implementations. CHI may use persistent files to caching, like Berkeley DB backend or one of mmap implementation to reduce memory usage. When you are u...
{ "AcceptedAnswerId": "31122", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T19:41:56.270", "Id": "31071", "Score": "0", "Tags": [ "perl" ], "Title": "Complex structure vs object" }
31071
<p>I have the following code. It's purpose is to add up and sort another columns Data. I tweaked it to fulfil my purpose, but I'm sure it can be cleaned up. </p> <p>The only problem I have with its function is it leaves a trailing zero if the last item in the referenced list is text.</p> <p>Can this be changed withou...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T22:37:23.820", "Id": "49473", "Score": "0", "body": "At first glance this looks very repetitive; I'll take a deeper look a bit later, but for now I'm pretty sure you can write a function that starts with `current_row = 45` and ends ...
[ { "body": "<p>There are many iterative structures in VBA, but I think the one that would be most useful here is <code>For...Next...Step</code>; in your case, looks like <code>Step</code> should be 4, looping from 7 to 87. </p>\n\n<p>All of your code blocks look very, very similar. I would only keep a single blo...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-10T20:48:36.130", "Id": "31075", "Score": "6", "Tags": [ "vba", "excel" ], "Title": "Add up & sort a spreadsheet column" }
31075
<p>I'm trying to brush up on my Dynamic Programming by doing some example problems. I've got the following...</p> <p>Given an array of integers, print the longest decreasing segment.</p> <p>For example <code>{4,3,2,1,5,6,7,6,5,4,3,2,1}</code> would print <code>"7, 6, 5, 4, 3, 2, 1"</code></p> <p>The following is my ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T04:16:52.050", "Id": "49489", "Score": "2", "body": "Having an extra array doesn't imply a space complexity of O(n^2). Your space complexity is still O(n)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09...
[ { "body": "<p>As said above adding an extra Array does not change the space complexity to n^2. </p>\n\n<ul>\n<li>Another thing is you do not need that extra Array also. All you need is 3 or 4 variables. </li>\n<li>You can store the previous beginIndex and length of and the currentBeginIndex and length and if it...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T03:42:36.407", "Id": "31078", "Score": "1", "Tags": [ "java", "algorithm" ], "Title": "Print Longest Decreasing Segment" }
31078
<p>The program is behaving like expected, but I think something better can be done since I'm a novice C programmer. I suspect that the interrupt handler can use some other way of calling the hardware instead of direct memory. Can you look and tell me what can be improved?</p> <pre><code>#include &lt;stdio.h&gt; #incl...
[]
[ { "body": "<p>The interrupt handler looks a little verbose. There are too many comments, most of which are 'noise' (they contribute little, also true elsewhere) and there are many empty sections (key-up detection). Here is a simplified version if the ISR:</p>\n\n<pre><code>void irq_handler_keys(void *context,...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T06:51:12.240", "Id": "31080", "Score": "1", "Tags": [ "c", "beginner", "fpga" ], "Title": "Hardware interrupts for Nios 2" }
31080
<p>I am trying to use IXMLDOMDocument for XML reading/writing. I am not good COM, and I am not aware that I am doing things right or wrong. I am very unsure that there could be some problems with COM initialization and relase. Here is my code below and let me know If there are any possibles bugs / memory leaks here due...
[]
[ { "body": "<p>MSDN documentation for this is a mess and for the most part, inadequate (it's better than MSDN's C++ ADO documentation though). </p>\n\n<p>If you have access to <a href=\"http://msdn.microsoft.com/en-us/library/ms757018%28v=vs.85%29.aspx\" rel=\"noreferrer\">MSXML</a>, then you can use smart poin...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T08:38:13.453", "Id": "31084", "Score": "4", "Tags": [ "c++", "memory-management", "dom", "com" ], "Title": "Proper way of using IXMLDOMDocument" }
31084
<p>I'm relatively new to PHP and have recently created a small website for friends and family to upload and share photos, protected by a very simple login system.</p> <p>While I'm aware what I'm doing isn't best practice and you'd never use this in a "published" site, I'd like to use this as learning experience to imp...
[]
[ { "body": "<p>I'd like to think security as a thing that at first refuses everything, and after that permits something specific. Your code does the opposite at the moment. It checks that if the user is NOT logged in, and if the condition does not pass, the user is permitted to view the page.</p>\n\n<p>I'd do th...
{ "AcceptedAnswerId": "31096", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T09:10:28.000", "Id": "31087", "Score": "4", "Tags": [ "php", "security" ], "Title": "Very simple login script review" }
31087
<p>I'm try to implement the <a href="https://ece.uwaterloo.ca/~z70wang/research/ssim/" rel="nofollow">SSIM</a> method. This method has already been implemented in Python (<a href="http://isit.u-clermont1.fr/~anvacava/code.html" rel="nofollow">source code</a>), but my goal is implement it with using only Python and NumP...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2018-10-08T18:37:12.853", "Id": "395687", "Score": "0", "body": "Can this be updated to Python 3?" } ]
[ { "body": "<p>In your strided <code>filter2</code>, <code>x1</code> is <code>(1014, 1014, 11, 11)</code>. You are iterating over the 1st 2 dimensions in order to sum on on the last 2. Let <code>sum</code> do all the work for you, <code>res = x1.sum((2,3))</code></p>\n\n<pre><code>def filter2(window, x):\n ...
{ "AcceptedAnswerId": "31840", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T09:34:55.793", "Id": "31089", "Score": "6", "Tags": [ "python", "numpy" ], "Title": "Using the SSIM method for large images" }
31089
<p>The idea is to write a function that reads string of unknown size from <code>stdin</code>, keep it in dynamically allocated array of unknown size and return a copy of that array.</p> <p>Is this the right approach? Could I be more clear? Would reading the input char-by-char be better than getting bigger chunks at on...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T12:06:22.790", "Id": "49511", "Score": "2", "body": "I edited your code to make it more readable. Also, note that `sizeof(char)` is 1 by definition, so multiplying by it is redundant." } ]
[ { "body": "<p>It would be wise to check if the reallocation of the memory worked.</p>\n\n<p>Also, this:</p>\n\n<pre><code>copy=malloc(strlen(output)+1); /* allocate memory for copy of output +1 for \\0 char */\nif(copy==NULL)\n return NULL;\nstrcpy(copy, output); /* strcpy output to copy */\nfree(output); /* ...
{ "AcceptedAnswerId": "31098", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T11:18:59.947", "Id": "31095", "Score": "4", "Tags": [ "c", "strings", "memory-management", "beginner" ], "Title": "Reading unlimited input strings in C" }
31095
<p>This is my solution for an exercise from a book. It's a simple <code>Golf</code> class with member variables <code>fullname</code> and <code>handicap</code>. The constructor sets the variables to the provided name and handicap using values passed as arguments. The <code>setgolf()</code> function solicits name and h...
[]
[ { "body": "<ul>\n<li>Lose the <code>private</code>, <code>class</code> members are private by default.</li>\n<li><p><code>setGolf()</code>: Instead of returning 1 or 0, you can apply <em>exceptions management</em> here. Also, you're doing double jobs by <code>*this = Golf(name, hc);</code>. You call a construct...
{ "AcceptedAnswerId": "31109", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T13:49:22.167", "Id": "31100", "Score": "3", "Tags": [ "c++", "algorithm", "classes" ], "Title": "Simple class exercise using the \"this\" pointer" }
31100
<p>I'm working in my project with the following script:</p> <pre><code>;(function($, doc, win) { "use strict"; // cache the window object var jQuerywindow = $(window); $('section[data-type="background"]').each(function(){ // declare the variable to affect the defined data-type var jQueryscroll = $(this); ...
[]
[ { "body": "<p>First of all, your code looks quite good. You've encapsulated the plugin well, and cached all your jQuery instances, which are, in my experience, the most common pitfalls. </p>\n\n<p>One thing I noticed is that you create a <code>scroll</code> event handler for every <code>section[data-type=\"back...
{ "AcceptedAnswerId": "31114", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T14:18:15.663", "Id": "31102", "Score": "1", "Tags": [ "javascript", "optimization", "jquery", "parallax" ], "Title": "jQuery parallax plugin" }
31102
<p>I'm learning F# and I'm trying the following exercise (exercise 4.10 of <a href="http://rads.stackoverflow.com/amzn/click/1107684064" rel="nofollow">Functional Programming Using F#</a>).</p> <blockquote> <p>Declare an F# function <code>prefix</code>: <code>'a list -&gt; 'a list -&gt; bool when a:equality</code>. ...
[]
[ { "body": "<p>You can use the <code>match … with …</code> syntax:</p>\n\n<pre><code>let rec prefix a b =\n match (a, b) with\n | ([], _) -&gt; true\n | (_, []) -&gt; false\n | (x0::xst,y0::yst) -&gt; x0 = y0 &amp;&amp; prefix xst yst\n</code></pre>\n", "comments": [], "meta_data": { "C...
{ "AcceptedAnswerId": "31115", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T16:12:18.787", "Id": "31112", "Score": "2", "Tags": [ "f#" ], "Title": "How to use pattern matching within curried function" }
31112
<p>Is there a more reliable way of getting the content elements for each SVG element?</p> <pre><code>#----------------------------------------------------------------------- # Get Element content from SVG specification from: # http://www.w3.org/TR/2011/REC-SVG11-20110816/single-page.html # Philip R Brenan at gmail dot...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T22:47:13.620", "Id": "49554", "Score": "0", "body": "Isn't this exactly the kind of problem that [`XML::XPath`](http://search.cpan.org/~msergeant/XML-XPath-1.13/) solves?" }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[ { "body": "<p>First a general code review, not specific to your “is there a more reliable way”. Later, I will show a superiour solution. But first, a lengthy rant.</p>\n\n<p>I see you have a very unique coding style. This is not good: Every piece of code has two audiences: The computer, and a maintainer. Everyb...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T18:21:46.120", "Id": "31118", "Score": "0", "Tags": [ "perl", "svg" ], "Title": "Perl hash mapping SVG elements to content elements" }
31118
<p>Is there a more reliable way of building a hash of the attributes associated with each SVG element?</p> <pre><code> #----------------------------------------------------------------------- # Hash of SVG elements, attributes,animation from: # http://www.w3.org/TR/2011/REC-SVG11-20110816/attindex.html # Philip...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T20:03:41.777", "Id": "49547", "Score": "1", "body": "Why do you want to parse SVG (XML) in Perl? Also: http://search.cpan.org/~msergeant/XML-Parser-2.36/Parser.pm" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
[ { "body": "<p>Houston, we have a problem. I'm going to be blunt, not because I enjoy saying mean things to fellow programmers, but because there really isn't any way to sugar-coat it. This is unintentionally obfuscated Perl, the kind that gives the language a bad reputation.</p>\n\n<p>Before continuing, I'd lik...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T18:49:14.617", "Id": "31120", "Score": "0", "Tags": [ "perl", "svg" ], "Title": "Perl Hash mapping SVG elements to their attributes" }
31120
<p>I'm just getting started with XNA and game development in general. I followed <a href="http://msdn.microsoft.com/en-us/library/bb203893.aspx" rel="nofollow">these instructions</a> to create a basic game, then <a href="http://www.berecursive.com/2008/c/sprite-sheets-in-xna-the-basics" rel="nofollow">this article</a> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T04:42:18.180", "Id": "49570", "Score": "2", "body": "Hm, you should consider moving to an other technology because [XNA is dead](http://www.gamasutra.com/view/news/185894/Its_official_XNA_is_dead.php). I think MonoGame is the new op...
[ { "body": "<ol>\n<li><p>I would move the inner loop which loads the texture into the <code>SpriteGroup</code> class as well as moving the texture loading for the single sprite into the <code>Sprite</code> class:</p>\n\n<pre><code>public class Sprite\n{\n ....\n public void LoadTexture()\n {\n T...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-11T21:26:42.350", "Id": "31124", "Score": "7", "Tags": [ "c#", "object-oriented", "design-patterns", "animation", "xna" ], "Title": "Sprite animation for a game" }
31124
<p>Below is the code for my templated callback implementation. Currently it works for a single parameter. One thing I was going to try and do next was increase the argument to the function from 1..N arguments. Ideally this would be as simple as adding Args... everywhere using variadic templates. I don't have a lot of e...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T05:48:09.850", "Id": "49574", "Score": "0", "body": "Sure. But why would I use this?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T07:56:05.867", "Id": "49695", "Score": "0", "body": "So...
[ { "body": "<p>The functionality you are trying to create already exists in <code>std::function&lt;&gt;</code> using <code>std::bind&lt;&gt;</code> to help.</p>\n\n<h3>Comments on the rest of the code:</h3>\n\n<p>Here you use emplace back:</p>\n\n<pre><code> void attach ( CbType cb )\n {\n callbacks_.emplac...
{ "AcceptedAnswerId": "31307", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T03:02:12.180", "Id": "31128", "Score": "4", "Tags": [ "c++", "template", "callback" ], "Title": "Fast templated call back implementation" }
31128
<p>I was trying to write code which does a validation for the below wildcards:</p> <blockquote> <ul> <li><p>'?' ------> The question mark indicates there is zero or one of the preceding element. For example, colou?r matches both "color" and "colour".</p></li> <li><p>'*' ------> The asterisk indicates there...
[]
[ { "body": "<p>Right away, I see two bugs:</p>\n\n<p>First, it is not valid to say</p>\n\n<pre><code>if (text.equals(EMPTY_STRING) || pattern.equals(EMPTY_STRING)) {\n return false;\n}\n</code></pre>\n\n<p>… because a non-empty pattern can certainly match an empty string.</p>\n\n<p>Second, it takes a state ma...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T03:14:36.470", "Id": "31129", "Score": "1", "Tags": [ "java", "strings", "regex" ], "Title": "Wildcard pattern-matching algorithm" }
31129
<p>There is an e-commerce site that I'm working on that has thousands of pages in it (mostly product pages). I've got some jQuery that I'm running on about 1300 of these products. Only specific products need the code to run so what I've done is set up the product codes (which display in the URL of the product) in a JSO...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-14T06:03:36.340", "Id": "52241", "Score": "2", "body": "Your code makes no sense. You are just concatenating strings together, `location_var` will never equal `-1`. Please provide a better explanation of what you are trying to achieve ...
[ { "body": "<p>What exactly do you have in the javascript (json) file? Can you get the product code from anywhere other than the the path?</p>\n\n<p>Here is what I suggest:</p>\n\n<ol>\n<li><p>Just include the javascript file. Don't bother pulling it via JSON. Doing so just adds overhead you don't need since ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T03:53:16.813", "Id": "31130", "Score": "0", "Tags": [ "javascript", "jquery", "json" ], "Title": "More Efficient Javascript indexOf query" }
31130
<p>Question 1: functionxxx_as_string() is used below. How else could it be more elegantly named?</p> <p>Question 2: Is the static char* array method adopted below the only solution? Best solution? Any suggestions?</p> <p>Generally, I have this issue where my list of enums will be from 3 - say 50 items, mostly less...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T10:35:46.843", "Id": "49583", "Score": "0", "body": "In general, the values of an enum are not required to be unique, e.g. `enum light { red, yellow, green, stop = 0, go = 2 };`. That makes the name for a given value plural." }, ...
[ { "body": "<p>You should use one of the preprocessor macro-based solutions proposed in <a href=\"https://stackoverflow.com/questions/147267\">StackOverflow Question 147267</a>. For example, here is a solution using X() macros. I've also rewritten your <code>get_state_as_string()</code> as a stringifier for iost...
{ "AcceptedAnswerId": "31216", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T09:52:09.890", "Id": "31136", "Score": "6", "Tags": [ "c++", "enum" ], "Title": "Converting enum values to strings in C++" }
31136
<p>Can the below <code>foreach</code> loop be improved? Since I use the same method twice, maybe use <code>continue</code> or <code>break</code>?</p> <pre><code>int? index = null; int count = 0; foreach (Break b in breaks) { if (index.HasValue) { if (index == count) b.Remove(); } e...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T17:06:43.263", "Id": "49615", "Score": "6", "body": "`index` is always `null`, so why not simply remove it? `int count = 0; foreach(Break b in breaks { b.Remove(); count++ }`? What value does having `index` serve?" }, { "C...
[ { "body": "<p>How about removing the loop at all like:</p>\n\n<pre><code>if (!index.HasValue)\n{\n breaks.Clear();\n}\nelse\n{\n breaks.RemoveAt((int)index);\n}\n</code></pre>\n\n<p>if you want/need to keep the loop, i would change your second way like:</p>\n\n<pre><code>foreach (Break b in breaks)\n{\n...
{ "AcceptedAnswerId": "31140", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T12:19:41.473", "Id": "31139", "Score": "4", "Tags": [ "c#" ], "Title": "Can this foreach loop be improved?" }
31139
<p>I am creating a performant C# socket server. I'd like it to be able to accept as many simultaneous connections as possible. I've tested with 100 clients and all clients are fine. With 1000 however, clients begin to stop connecting. Is it possible to improve something to increase the number of simultaneous connection...
[]
[ { "body": "<p>You are holding on to some <code>IDisposable</code> resources that you shouldn't be, which will impact scalability, GC pressure and likely performance. Here's the augmented <code>Listener</code> class:</p>\n\n<pre><code>internal sealed class Listener : IDisposable\n{\n private readonly int port...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T13:42:44.243", "Id": "31143", "Score": "7", "Tags": [ "c#", "socket", "tcp", "server", "client" ], "Title": "Performant C# Socket server" }
31143
<p>Here's my version of singly linked list. Any constructive criticism is highly appreciated.<br> First header file "sll.h":</p> <pre><code>#ifndef _SLL_H_ #define _SLL_H_ #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; /* declaration of node in Singly linked list */ typedef struct node{ int value; struct node...
[]
[ { "body": "<p>Some minor comments.</p>\n\n<p><code>add_at_order</code> is missing a return value. Also the comment to the function\nseems wrong and the function name is awkward. </p>\n\n<p><code>create_sll</code> is named <code>create_list</code> in the header file. Either way it seems\nto be misnamed as it ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T13:47:51.527", "Id": "31144", "Score": "4", "Tags": [ "c", "linked-list", "beginner" ], "Title": "Singly linked list in C" }
31144
<p>I am writing an open-source application for real-time messaging in web. In my application clients from browser can subscribe on channels. But every channel belongs to a certain namespace which determines channel's settings:</p> <pre><code>client.subscribe('/football/news', function(message) { // message from ch...
[]
[ { "body": "<p>An opinion question, always tough to answer.</p>\n\n<p>I like the first way better, 1 less parameter and it is easier to grok for me. </p>\n\n<p>Incidentally, ABAP uses forward slashes for namespaces as well.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "Crea...
{ "AcceptedAnswerId": "31157", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T14:12:13.183", "Id": "31145", "Score": "1", "Tags": [ "javascript", "api", "interface" ], "Title": "Client's method for channel subscribing" }
31145
<p>I was wondering what would be the most appealing way of achieving this goal.</p> <p>I have a blackbox. I give it a <code>supported type</code> and it returns a random value base off of the type.</p> <p>For my supported types, I have an <code>enum</code> defined as follows:</p> <pre><code>public enum Types { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T21:02:39.210", "Id": "49643", "Score": "1", "body": "See the Command pattern to avoid countless if-else-if statements: http://stackoverflow.com/a/4480360/59087" } ]
[ { "body": "<p>1) I don't think you need to define an enum since you can use Boolean.class, Integer.class, etc.</p>\n\n<p>2) </p>\n\n<pre><code>public static &lt;T&gt; T getRandom(Class&lt;T&gt; classs) {\n if (classs.equals(Boolean.class)) {\n return (T) randomBool();\n } else if (classs.equals(Integer.c...
{ "AcceptedAnswerId": "31151", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T14:46:19.387", "Id": "31146", "Score": "3", "Tags": [ "java", "design-patterns" ], "Title": "Method Of Retrieving Random Value Depending on Type" }
31146
<p>How to improve this kind of redundancy?</p> <pre><code>$nid = isset( $_GET['nid'] ) ? $_GET['nid'] : 0; </code></pre> <p>I want to avoid to repeat $_GET['nid']</p> <p>Example of useful use case:</p> <pre><code>$nid = isset( $node-&gt;field_mymodule_extended_nid['und'][0]['target_id'] ) ? $node-&gt;field_mymodule...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T09:12:05.067", "Id": "49702", "Score": "1", "body": "Couldn't you just create a helper function for that?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T11:38:49.383", "Id": "49707", "Score":...
[ { "body": "<p>By <a href=\"http://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary\" rel=\"nofollow noreferrer\">reading the manual</a>:</p>\n\n<blockquote>\n <p>Since PHP 5.3, it is possible to leave out the middle part of the ternary operator. Expression expr1 ?: ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T14:53:31.547", "Id": "31148", "Score": "2", "Tags": [ "php" ], "Title": "PHP test isset and instantiate in one shot. Possible in PHP?" }
31148
<p>This program calculates the min and the max value and the average of the items of a vector. It's an exercise from a book so I can't change the header file. </p> <p>Is this code proper? </p> <p>sales.h</p> <pre><code>#include &lt;vector&gt; class Sales { private: std::vector&lt;double&gt; sales; ...
[]
[ { "body": "<ul>\n<li><p>The program won't compile with the default <code>Sales s2</code>. This is because you're calling the default constructor, which you no longer have as it's been overloaded.</p>\n\n<p>Add this to the header:</p>\n\n<pre><code>Sales();\n</code></pre>\n\n<p></p>\n\n<p>Add this to the implem...
{ "AcceptedAnswerId": "31156", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T16:18:50.483", "Id": "31152", "Score": "3", "Tags": [ "c++", "classes", "vectors" ], "Title": "Simple class exercise - min, max, and average of vector items" }
31152
<p>i have an <code>vector&lt;tuple&lt;A,b&gt; &gt; v</code> and want to make a <code>map&lt;A,B&gt;</code> from it i came up with 3 variants:</p> <pre><code>std::transform(v.begin(),v.end(), std::inserter(map,map.begin()),[](std::tuple&lt;int,char&gt; t){ return std::make_pair(std::get&lt;0&gt;(t),std::get&lt;1&gt...
[]
[ { "body": "<p>I would use the last as the simplest, yes. I'd probably write a <code>pair_from_tuple</code> helper function to not have to write out the <code>std::get</code> explicitly.</p>\n\n<p>The first and second both require you to write out the tuple type. This will change soon, but not everyone will im...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T18:14:34.557", "Id": "31158", "Score": "3", "Tags": [ "c++", "vectors", "container" ], "Title": "vector<tuple<A,B> > to map<A,B>" }
31158
<p>So I came up with a problem In C. Our compiler is pre c99 and wasn't identifying functions that are never called. So I ended up writing this script and decided to post it up to be critiqued and to help people who might be in the same predicament. The script works great for me and finished the job that I needed it to...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T15:37:31.227", "Id": "49625", "Score": "1", "body": "Have you tried, with gcc, to compile with `-ffunction-sections` and link with `--gc-sections`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T15:5...
[ { "body": "<p>Two major points:</p>\n\n<ul>\n<li>The parsing is very fragile and only works when the code is laid out in a certain way. You should look for a proper parser and leverage that.</li>\n<li>It is rather inefficient to scan all the files every time you encounter a function declaration. You could use d...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T15:27:25.630", "Id": "31159", "Score": "5", "Tags": [ "python" ], "Title": "Searching for unused functions" }
31159
<p>This solves an algorithm that we have. The script is used by an ArcGIS tool as well as another tool that takes this script and cycles through roughly 6,000 bridges.</p> <p><strong>Note:</strong> I didn't separate the code intentionally into configs and testing code for you to review the whole thing in one screen.<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T21:09:19.320", "Id": "49645", "Score": "0", "body": "`if 0 < age_index >= weighting:` - shouldn't it be just `if age_index >= weighting:`?" } ]
[ { "body": "<p>Although people are often advised to break down their code into functions more, my main comment would be that you have lots of functions not doing very much. This might be worthwhile in some cases if there is a possibility of expanding the code and re-using those functions. As it is it just makes ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T20:27:51.757", "Id": "31162", "Score": "2", "Tags": [ "python" ], "Title": "Solving an algorithm to develop a redundancy index" }
31162
XNA is a free set of game development tools from Microsoft that facilitate game development for Xbox 360, Windows Phone, Zune and Windows platforms.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T20:30:51.590", "Id": "31164", "Score": "0", "Tags": null, "Title": null }
31164
<p>I worked on a Red-Black tree implementation in C++, and it works as it should. However, I want to see what else I can do to make this code faster/more clean, etc.</p> <p>Any particular suggestions?</p> <p>Edit: code I want most looked at is below (insertion into the RBtree)</p> <pre><code>/***********************...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T17:30:05.957", "Id": "49741", "Score": "1", "body": "Note: You do realize that std::set is usually implemented as a Red/Black tree." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T17:34:22.220", "...
[ { "body": "<p>Its hard to review because you did not provide enough to compile.</p>\n\n<p>DON'T use <code>using</code> in a header file that is just the global namespace.</p>\n\n<pre><code>using std::ifstream;\n</code></pre>\n\n<p>This would have been fine if you had placed your stuff in your own namespace. But...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T20:51:55.723", "Id": "31166", "Score": "5", "Tags": [ "c++", "tree" ], "Title": "My Red-Black Tree Implementation" }
31166
<p>In computer science, <a href="http://en.wikipedia.org/wiki/Conditional_%28programming%29" rel="nofollow">conditional statements</a>, conditional expressions and conditional constructs are features of a programming language which perform different computations or actions depending on whether a programmer-specified bo...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T22:33:05.547", "Id": "31168", "Score": "0", "Tags": null, "Title": null }
31168
Boolean expressions that can involve logical operators, used for branching execution paths, which increases cyclomatic complexity.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T22:33:05.547", "Id": "31169", "Score": "0", "Tags": null, "Title": null }
31169
Methods that extend a given type, adding functionality to any instance of that type, even if the type in question is defined in a separate assembly. For example, a "Disemvowel" extension method could be written to add disemvoweling functionality to any "String" object.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T22:51:53.627", "Id": "31172", "Score": "0", "Tags": null, "Title": null }
31172
A compiled set of exposed objects that isn't directly executable, but that can be referenced and used by other code.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T22:54:41.263", "Id": "31174", "Score": "0", "Tags": null, "Title": null }
31174
<h1>Macros</h1> <h2>Summary</h2> <p>A macro in computer science is a rule or pattern that specifies how a certain input sequence (often a sequence of characters) should be mapped to a replacement output sequence (also often a sequence of characters) according to a defined procedure.</p> <p><strong><em>Do not use thi...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T22:57:51.980", "Id": "31175", "Score": "0", "Tags": null, "Title": null }
31175
A macro in computer science is a rule or pattern that specifies how a certain input sequence (often a sequence of characters) should be mapped to a replacement output sequence (also often a sequence of characters) according to a defined procedure. Do not use this tag for questions regarding Microsoft's Visual Basic ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-09-12T22:57:51.980", "Id": "31176", "Score": "0", "Tags": null, "Title": null }
31176
One of the four pillars of object-oriented programming (OOP), inheritance establishes a "is-a" relationship between objects. For example, a "Cat" object can be treated in code as any other "Animal" object because a "Cat" is-a "Animal".
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T23:02:35.423", "Id": "31178", "Score": "0", "Tags": null, "Title": null }
31178
<p><strong>Tag Recommendation</strong></p> <p>Error handling can be subdivided into <a href="https://en.wikipedia.org/wiki/Error_detection_and_correction" rel="nofollow noreferrer">Error Detection &amp; Correction</a> and <a href="https://en.wikipedia.org/wiki/Exception_handling" rel="nofollow noreferrer">Exception Ha...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-09-12T23:05:53.687", "Id": "31179", "Score": "0", "Tags": null, "Title": null }
31179
The various techniques used for maintaining stable program state in circumstances that, if not taken care of ("handled"), could cause serious issues, including logical bugs and abrupt execution termination.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T23:05:53.687", "Id": "31180", "Score": "0", "Tags": null, "Title": null }
31180
In MVC architecture (Model-View-Controller), the object responsible for passing and receiving data to and from views, acting as a bridge between the "Model" and the "View".
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T23:07:40.773", "Id": "31182", "Score": "0", "Tags": null, "Title": null }
31182
Delegates can refer to several concepts. An object can rely on another (a delegate) to perform a function. Delegation can also refer to programming language feature making use of the method lookup rules for dispatching self-calls. In C#, a delegate defines which method to call when an event is triggered.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T23:10:04.890", "Id": "31184", "Score": "0", "Tags": null, "Title": null }
31184
**This tag is in the process of being removed from the site. Please avoid using it.** The art of properly calling a cat, a cat; naming is often governed by various conventions. Poor naming can make code harder to read, good naming easier.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T23:14:01.017", "Id": "31186", "Score": "0", "Tags": null, "Title": null }
31186
Use this tag for reviews of concepts that aren't specific to any particular programming language, or for concepts that are common to all programming languages.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T23:16:34.090", "Id": "31188", "Score": "0", "Tags": null, "Title": null }
31188
The Model-View-ViewModel design pattern, which separates presentation from data and logic.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T23:21:40.127", "Id": "31190", "Score": "0", "Tags": null, "Title": null }
31190
The part of the application that users directly interact with. Use this tag for reviews of code that defines how an application's user interface works and looks.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T23:27:02.213", "Id": "31192", "Score": "0", "Tags": null, "Title": null }
31192
Use this tag for reviews of code that performs file system operations, such as creating, deleting, renaming, moving, copying, reading, and writing files.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-12T23:29:06.033", "Id": "31194", "Score": "0", "Tags": null, "Title": null }
31194
<p>Concurrency is a property of systems in which several computations can be in progress simultaneously, and potentially interacting with each other. The computations may be executing on multiple cores in the same chip, preemptively time-shared threads on the same processor, or executed on physically separated processo...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T00:30:49.543", "Id": "31197", "Score": "0", "Tags": null, "Title": null }
31197
In computer science, concurrency is a property of systems in which multiple computations can be performed in overlapping time periods. The computations may be executing on multiple cores in the same chip, preemptively time-shared threads on the same processor, or executed on physically separated processors.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T00:30:49.543", "Id": "31198", "Score": "0", "Tags": null, "Title": null }
31198
<p>VBScript (Visual Basic Scripting Edition) is an active scripting language developed by Microsoft that is modeled on Visual Basic. It is designed as a <em>lightweight</em> language with a fast interpreter for use in a wide variety of Microsoft environments.</p> <p>It uses the Component Object Model (COM) to access e...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T00:32:38.567", "Id": "31199", "Score": "0", "Tags": null, "Title": null }
31199
VBScript is Microsoft's Visual Basic Scripting runtime.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T00:32:38.567", "Id": "31200", "Score": "0", "Tags": null, "Title": null }
31200
<p>I'm learning C and have made this very simple function to compare two strings. I would like to know how it can be improved:</p> <pre><code>int match(char* string1, char* string2) { size_t i = 0; while (string1[i] != '\0' || string2[i] != '\0') { if (string1[i] != string2[i]) { return 0;...
[]
[ { "body": "<p>In your <code>while</code> loop, you check whether <code>string1[i]</code> <em>or</em> <code>string2[i]</code> are <em>not</em> null. If they are of unequal lengths, they will have their null terminators at different values of <code>i</code>; because at least one is non-null at each point, your wh...
{ "AcceptedAnswerId": "31228", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T00:37:40.453", "Id": "31201", "Score": "2", "Tags": [ "optimization", "c", "array" ], "Title": "Improving function that compares two strings" }
31201
Use this tag for reviews of code where type safety is a concern, for example code involving type conversions or casting which may result in type errors at run-time.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T00:42:16.327", "Id": "31203", "Score": "0", "Tags": null, "Title": null }
31203
Use this tag for code reviews of, or involving methods that create a new instance of a given type, often with parameters that determine how the instance gets created.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T00:46:56.753", "Id": "31205", "Score": "0", "Tags": null, "Title": null }
31205
A mocking framework, used in unit tests for injecting "fake" implementations of interfaces as dependencies of the system under test. Use this tag for code reviews of unit testing methods that use this specific mocking framework.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T00:52:34.667", "Id": "31207", "Score": "0", "Tags": null, "Title": null }
31207
Use this tag for reviews of code that addresses localization/globalization concerns, which make an application be displayable in multiple languages.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T00:55:50.790", "Id": "31210", "Score": "0", "Tags": null, "Title": null }
31210
Microsoft's well-known operating system. Use this tag for code reviews where the code is targeted specifically for this platform, when no other more specific tags exist.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T02:13:00.350", "Id": "31213", "Score": "0", "Tags": null, "Title": null }
31213
Use this tag for code reviews of or involving Linq to SQL classes, mappings and associations, or for code reviews of or involving querying a System.Data.Linq.DataContext object with Linq statements.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T02:22:45.517", "Id": "31215", "Score": "0", "Tags": null, "Title": null }
31215
<pre><code>if (progressBar1.Value == 1) { progressLabel.Text = "1%"; } if (progressBar1.Value == 10) { progressLabel.Text = "10%"; } if (progressBar1.Value == 20) { progressLabel.Text = "20%"; } if (progressBar1.Value == 30) { progressLabel.Text = "30%"; } if (progressBar1.Value == 40) { progressLabel.Text = "40%"; } i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T14:43:29.687", "Id": "49715", "Score": "0", "body": "I like dreza's answer, if you wanted to make this code more efficient you could use `if..else if` rather than several `if` statements. it would hit one, show it and exit the code...
[ { "body": "<p>Why can't you do:</p>\n\n<pre><code>progressLabel.Text = string.Format(\"{0}%\", progressBar1.Value)\n</code></pre>\n\n<p>As @MNZ pointed out I potentially didn't answer the question exactly how the OP asked. So here's a slightly modified alternative option:</p>\n\n<pre><code>progressLabel.Text =...
{ "AcceptedAnswerId": "31218", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T03:34:32.673", "Id": "31217", "Score": "3", "Tags": [ "c#", "winforms" ], "Title": "How to write this code without using 11 if-statements?" }
31217
<p>I have just made a simple script which spawns an alien that chases the player. I want to move as much of the script into functions so as to minimize the amount of code, to make it run better when my game gets a lot bigger. I am new to functions and classes, and I want to know what can be turned into a class in anoth...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T13:07:25.313", "Id": "49712", "Score": "0", "body": "Not into Python but if you can put a name on a concept and picture that concept having properties and/or exposing methods or functions, you have a candidate for a class. As for fu...
[ { "body": "<p>You can create a class called <code>AlienGame(object)</code>.</p>\n\n<ol>\n<li><p>Put all the initialization code in a <code>def __init__</code> function.</p></li>\n<li><p>Put all creation of characters in a <code>def create_characters</code> function.</p></li>\n<li><p>Put the chase part of the co...
{ "AcceptedAnswerId": "31259", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T11:14:46.900", "Id": "31230", "Score": "3", "Tags": [ "python", "pygame" ], "Title": "Spawning an alien to chase the player" }
31230
<p>I've been playing around and reading up on some sorting algorithms, and I've decided to try writing my own. It turned out to be quite fast (compared to the others shown in the image below).</p> <p>I'm very curious to know a little bit about it:</p> <ul> <li>Does my algorithm already have a name?</li> <li>What are...
[]
[ { "body": "<blockquote>\n <p>Does my algorithm already have a name?</p>\n</blockquote>\n\n<p>It's called <a href=\"https://en.wikipedia.org/wiki/Counting_sort\">counting sort</a>.</p>\n\n<blockquote>\n <p>What are the downsides to it? (Other than it is really stupid to sort { 900000, 1 } with it.)</p>\n</bloc...
{ "AcceptedAnswerId": "31244", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T14:56:36.890", "Id": "31235", "Score": "12", "Tags": [ "c#", "performance", "algorithm", ".net", "sorting" ], "Title": "Attempt at a sorting algorithm" }
31235
<p>The class is responsible for wrapping requests to a WCF Data Service, which tidies up calling code. Transactions are implicitly supported. It should efficiently send just updates to the services (only changed values). The next step is to modify it and allow named properties to be queried, rather than all fields.</p...
[]
[ { "body": "<p>Some initial thoughts off the top of my head. I personally like immutability in my class data where possible. You have such available:</p>\n\n<pre><code>private readonly DataServiceContext context;\n\nprivate readonly string collectionName;\n\npublic ServiceWrapper(Uri uri, string collection)\n{\n...
{ "AcceptedAnswerId": "62747", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T15:46:38.090", "Id": "31241", "Score": "4", "Tags": [ "c#", "entity-framework" ], "Title": "WCF client class" }
31241
<p>I have been teaching myself programming, mainly in Java, for about 6 months. I'm looking for some feedback on this implementation of the Game of Life, which runs entirely in the terminal. Specifically, where does it not follow best practices, is it over-engineered, etc?</p> <p>The entry point:</p> <pre><code>publ...
[]
[ { "body": "<p>First of all, I think your code is very nice for 6 months of training. The following tips are mainly regarding style and object orientation. </p>\n\n<ol>\n<li>If you want to truly separate the implementation from the user interface, you should not call <code>BoardPrinter.print()</code> from within...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T16:33:03.013", "Id": "31245", "Score": "6", "Tags": [ "java", "game-of-life" ], "Title": "Game of Life implementation ran in the terminal" }
31245
<p>The following program is intended to "watchdog" a child process, <em>and all subprocesses the child spawns</em>.</p> <p>The intended behavior is:</p> <ul> <li>A child process (as specified on the command line) is run in a dedicated process group.</li> <li>If that process exits, or if it stops producing heartbeat o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T20:00:02.170", "Id": "49751", "Score": "0", "body": "You're likely already aware of it, and it doesn't monitor quite as aggressively as your program does, but it might be worth looking at daemontools: http://cr.yp.to/daemontools.htm...
[ { "body": "<p>I am not familiar enough with process control to find any of the problems you seek, so treat this as a general review, for what it is worth, starting from the top:</p>\n\n<hr>\n\n<p>I don't know what advantage your <code>IGNORE_ERRORS</code> macro has over a simple\n<code>(void)</code> cast for an...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T19:23:07.703", "Id": "31252", "Score": "5", "Tags": [ "c", "unix", "portability", "child-process" ], "Title": "Portability and \"dark corner\" gotchas in this \"watchdog\" pro...
31252
<p>I just completed K&amp;R (2nd Ed.) ex 1-18. I'm fairly new to C, but have had experience in other languages (Perl, C++, Java, Common Lisp, PHP, etc) and really want to learn the C idiom as opposed to translating the idioms I already know.</p> <p>What do you think about this approach to 1-18?</p> <pre><code>/* ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T16:05:29.423", "Id": "49848", "Score": "0", "body": "For those of us who don't have K&R handy, please state the exercise question." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T16:07:30.457", "I...
[ { "body": "<p>First the obvious: if a line is too long, your program will seriously fail (unknown memory gets overwritten, or the program crashes). Without dynamic memory allocation, I see no way to fix it. However, you could improve the situation significantly.</p>\n\n<p>Since you're reading the input characte...
{ "AcceptedAnswerId": "31264", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-13T23:48:02.600", "Id": "31262", "Score": "3", "Tags": [ "c" ], "Title": "Style and Suggestions for K&R2 1-18" }
31262
<p>This is one of my first real apps I've made with javascript(jQuery) so I know my approach probably isn't the best and my lengthy code shows. I created this simple app that spits out what customers can expect to pay if they purchase our software, but it has a TON of price points and with my limited knowledge this was...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-14T02:36:38.100", "Id": "49771", "Score": "1", "body": "I'll gladly retract my downvote (and perhaps even turn it into an upvote) if/when this post gets edited with actual code." } ]
[ { "body": "<p>Step 1: reorganize your variables, nested in a manner resembling the tests you need to do.</p>\n\n<pre><code>var prices = {\n standard: {\n cost: { normal: [ 179 , 159 , 139 , 129 , 119 , 109 , 99 , 89 , 79 , 69 ],\n maintenance: [ 228 , 198 , 168 , 156 , 144 , 132 , ...
{ "AcceptedAnswerId": "31266", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-14T00:47:10.927", "Id": "31263", "Score": "1", "Tags": [ "javascript", "jquery", "form" ], "Title": "Is there a DRYer way to create this jquery quote generator?" }
31263
<p>I am facing a issue with an API to handle dates in Java. I am not a very experienced programmer and my English is very bad.</p> <h2>Problem</h2> <p>I'm working in a large project with many subsystems, and I want to make a Date Utility library to manage all dates in the system.</p> <h2>Requirements</h2> <h3>Platf...
[]
[ { "body": "<p>Dates and Date handling in Java have been a <a href=\"http://www.tns.lcs.mit.edu/manuals/java-1.1.1/api/java.util.Date.html\">problem since the beginning</a> (check out all the deprecated methods in version 1.1). You appear to be running in to the same problems that may Java developers have encoun...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-14T02:43:52.113", "Id": "31268", "Score": "11", "Tags": [ "java", "design-patterns", "api", "datetime" ], "Title": "Date Format provider" }
31268
<p>I have been staring at this code for awhile now and I am thinking there is a way to optimize it (namely the <code>if</code>-<code>else</code> statement with the <code>for</code>-loops). </p> <p>Additionally, this needs to be done with an array list as that is my assignment requirement. I have all my code working, a...
[]
[ { "body": "<p>If you are limited to use only Arrays, you can create a interface like this</p>\n\n<pre><code>public static interface Checker {\n public boolean check(Person p, String searchString);\n}\n</code></pre>\n\n<p>Create a Checker for every type of comparison you want.</p>\n\n<p>And compare with the C...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-14T03:01:00.023", "Id": "31270", "Score": "4", "Tags": [ "java", "optimization", "homework", "search" ], "Title": "Searching through a contact list for given criteria" }
31270
<p>I managed to create my first wordpress plugin template page collecting various code snippets to make the page function.</p> <p>Everything works fine, but I need hear comments from PHP &amp; wordpress experts to see if it's well-coded.</p> <p>Here's the code.</p> <pre><code>&lt;?php /* Plugin Name: name Plugin URI...
[]
[ { "body": "<p>Welcome to the site!</p>\n\n<p>The most difficult part you done; that's to create something. I know a lot of people with tons of ideas, but none of them come to reality. So, well done for your first step. </p>\n\n<p>About your plugin, it's a very simple one. I believe everyone here would do in a d...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-14T05:12:13.413", "Id": "31273", "Score": "2", "Tags": [ "php" ], "Title": "Created my first wordpress plugin template page, need comments" }
31273
<p>I was writing a program and I needed a function that could ordinate the <code>argv</code> according to my preferences. That way, <code>getopt</code> would parse the options as needed. I couldn't find any, so I wrote one. I would be very thankful if you guys could have a look and say what you think about it. I'm ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T20:57:21.267", "Id": "49877", "Score": "0", "body": "I have a feeling you have written some stuff that solves a non-existent problem. As far as I know, other people manage fine with `getopt` etc, so what is it about your eventual p...
[ { "body": "<p>Rather than continue in the comments, I talk here. This isn't a review of the code...</p>\n\n<p>As I wrote above, I think you have written some stuff that solves a non-existent problem. As far as I know, other people manage fine with getopt etc.</p>\n\n<p>As far as I can see, the following code ex...
{ "AcceptedAnswerId": "31373", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-14T18:20:11.693", "Id": "31279", "Score": "3", "Tags": [ "c", "beginner" ], "Title": "getopt ordering function in C" }
31279
<pre><code>x = int(input("Choose the number of times you want to spam. ")) y = input("What message do you want to spam? ") w = x + 1 for i in range(1,w): print(y) </code></pre> <p>Any way to make this program better? I'm currently learning Python.</p>
[]
[ { "body": "<ol>\n<li>Use descriptive variable names</li>\n<li>No need to add one to x and then use <code>range(1, w)</code> - get used to using <a href=\"http://en.wikipedia.org/wiki/Zero-based_numbering\">zero-based numbering</a></li>\n<li>By convention in Python you can use <code>_</code> as the name for a l...
{ "AcceptedAnswerId": "31283", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-14T20:38:43.007", "Id": "31282", "Score": "1", "Tags": [ "python", "beginner", "python-3.x" ], "Title": "Super simple spam program" }
31282
<p>I am calling <code>defvar</code> in the middle of a function definition. And so far I've always seen its use, with <code>defparameter</code> for global variable. Like <code>*error-output*</code> or <code>*standard-output*</code>.</p> <pre><code>(defun consume-socket-reply (socket end-test-form) (do* ((line "" (re...
[]
[ { "body": "<p>Ok I've modified my code that way, and removed the call to <code>defvar</code>:</p>\n\n<pre><code>(defun consume-socket-reply (socket end-test-form)\n (do* ((line (read-line (usocket:socket-stream socket) nil)\n (read-line (usocket:socket-stream socket) nil))\n (text line (con...
{ "AcceptedAnswerId": "31309", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-14T22:22:56.983", "Id": "31284", "Score": "1", "Tags": [ "lisp", "common-lisp" ], "Title": "Is using defvar for a non-global variable ok?" }
31284
<p>I'm beginning to learn Haskell. I've implemented the <a href="http://en.wikipedia.org/wiki/Graham_scan">Graham Scan</a> algorithm for detection of convex hull following the Real World Haskell book.</p> <p>I'm looking for general advice regarding the style and convention of my code, as well as best practices and way...
[]
[ { "body": "<p>Some ideas:</p>\n\n<ul>\n<li><p>When comparing points, you can use the fact that <code>(,)</code> is lexicographically ordered:</p>\n\n<pre><code>comparePoints :: Point2D -&gt; Point2D -&gt; Ordering\ncomparePoints a b = compare (y a, x a) (y b, x b)\n</code></pre></li>\n<li><blockquote>\n <p><co...
{ "AcceptedAnswerId": "31312", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-14T22:49:48.803", "Id": "31285", "Score": "8", "Tags": [ "beginner", "haskell", "computational-geometry" ], "Title": "Graham Scan convex hull algorithm" }
31285
<p>Are there any ways to make this calculator script for Python better or simpler?</p> <pre><code>thelist = ["Add", "add", "Multiply", "multiply", "Divide", "divide","Subtract", "subtract"] def Multiply(x,y): z = x * y print(z) def Divide(x,y): x = float(x) y = float(y) z = x / y print(z) def Add(x,y): z = x + y pr...
[]
[ { "body": "<p>A thorough review would very much depend on what you're trying to achieve.</p>\n\n<p>For example, it seams mighty clumsy to have to type <code>multiply</code> instead of just <code>*</code>. Also, a case-insensitive match would be much better. For that, you might want to check <a href=\"https://st...
{ "AcceptedAnswerId": "31290", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-14T22:57:02.730", "Id": "31286", "Score": "3", "Tags": [ "python", "python-3.x", "calculator" ], "Title": "Python calculator script" }
31286
<p>This is a simple mixed drink calculator written in Haskell. </p> <p>There are two input files. The <code>drinks</code> file contains a list of simply formatted recipes for mixed drinks:</p> <pre><code>screwdriver:vodka,orange juice white russian:vodka,coffee liqueur,cream greyhound:gin,grapefruit juice ... </code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-16T17:11:27.373", "Id": "52403", "Score": "0", "body": "Can you either remove unicode syntax or upload the file to hpaste or other place where I can easily get bit-exact downloads from? Somehow I get parse errors." }, { "Conten...
[ { "body": "<h2>Good News:</h2>\n\n<p>Architecturally, your code looks very well designed. I can't think of any language features that would significantly improve your code's architecture. That leaves only function semantics and readability.</p>\n\n<h2>Advise:</h2>\n\n<p>This advise isn't specific to idiomatic H...
{ "AcceptedAnswerId": "48369", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-14T23:52:01.093", "Id": "31288", "Score": "8", "Tags": [ "haskell" ], "Title": "Mixed Drink Calculator in Haskell" }
31288
<p>Currently I have a game that does this and then checks for victory conditions in <code>victoryTable</code></p> <pre><code>victoryTable[0] = rows[0][0] + rows[0][1] + rows[0][2]; victoryTable[1] = rows[1][0] + rows[1][1] + rows[1][2]; victoryTable[2] = rows[2][0] + rows[2][1] + rows[2][2]; victoryTable[3] = rows[0][...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T07:46:43.190", "Id": "49831", "Score": "0", "body": "You can look into [magic-square number](http://mathworld.wolfram.com/MagicSquare.html)." } ]
[ { "body": "<p>This is not a direct answer to your question.</p>\n\n<p>You should probably rethink your design. I guess the different elements of <code>rows[][]</code> have some meaning, so you should define a class with the appropriate member variables which have explicit names.</p>\n\n<p>We don't have much in...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T00:38:10.783", "Id": "31292", "Score": "3", "Tags": [ "java" ], "Title": "Detecting Tic-Tac-Toe win: Enumerate all possibilities or use nested loops?" }
31292
<p>I am trying to write code to convert properties of an Entity Framework entity to strings and back.</p> <p>Here is the code so far that converts back from strings to the object properties.</p> <p>I am stuck trying to figure out how to handle datetime. I am also wondering if there is a better approach.</p> <pre><c...
[]
[ { "body": "<p>If you are trying to convert the string to DateTime format that might be used in the EF object, you may try:</p>\n\n<pre><code>Convert.ToDateTime(\"2013-09-10 12:12:12\",System.Globalization.CultureInfo.InvariantCulture)\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount...
{ "AcceptedAnswerId": "32649", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T01:17:00.497", "Id": "31293", "Score": "1", "Tags": [ "c#", "entity-framework", "serialization" ], "Title": "Serialize the properties of an entity framework entity to data fiel...
31293
<p>I'm new to Java and Android. While I've created a project that seems to work, I'd like some opinions on how to make it better. </p> <p>The app is going to be used as an interval workout timer/music player for Android devices. I know there's a ton of these already, but I thought it'd be a good way to learn the lang...
[]
[ { "body": "<p>from the little I saw I have just a few comments (the code looks fairly fine)</p>\n\n<ol>\n<li><p>if all you do with the buttons is set the <code>onClickListener</code> there is no reason not to use the built in xml attribute <code>onClick</code> when designing the buttons.</p></li>\n<li><p>when e...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T02:24:09.490", "Id": "31295", "Score": "4", "Tags": [ "java", "android", "beginner" ], "Title": "Review Request - Android CountDownTimer activity" }
31295
<p>I made a Java program that asks for a word, then a screen width, then whether you want it to go fast or slow. Then it outputs that word and bounces it across the screen. Is this code efficient for what it does? Is there a better way to do it (without a pre-defined method/class)? And does it look professional and ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T04:32:26.530", "Id": "49818", "Score": "1", "body": "when it is about clean code, make sure that you get rid of unnecessary spaces." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-18T02:19:21.203", "...
[ { "body": "<p>One suggestion that I would make is to use better names for your variables. Typically your variable name should be long enough to describe what the variable represents (and not it's type). Short variable names work ok for loop indexes or in a very small scope (say a lambda expression) but generall...
{ "AcceptedAnswerId": "31306", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T03:05:00.297", "Id": "31297", "Score": "7", "Tags": [ "java", "console", "formatting" ], "Title": "Bouncing a word left-right on screen" }
31297
<p>I am not sure if I am correctly handling <code>$_POST</code> data in MVC pattern:</p> <p><strong>Dummy <code>$_POST</code> data</strong></p> <pre><code>$_POST = array( "menu" =&gt; array( "key_name" =&gt; '', "pub_name" =&gt; '' ) ); </code></pre> <p><strong>View</strong></p> <pre><code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-16T13:03:52.890", "Id": "49921", "Score": "0", "body": "What is the `$connection` argument that will be passed to the controller? I take it it's a DB connection, in which case: _it has no business being in a controller, DB is part of t...
[ { "body": "<p>Since I've explained a lot in the comments, I thought I might distill those comments into an answer, so here goes:</p>\n\n<p>You're definitely improving, <a href=\"https://codereview.stackexchange.com/questions/31035/how-to-put-xml-results-in-the-mvc-pattern/31085#31085\">considering your previous...
{ "AcceptedAnswerId": "31415", "CommentCount": "15", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T04:41:39.053", "Id": "31301", "Score": "1", "Tags": [ "php", "mvc", "controller", "helper" ], "Title": "Doing $_POST the right way" }
31301
<p>I am toying around and playing a lot with defining a function. I'm trying to get extremely comfortable with it. The code I have wrote works fairly well, but definitely is not perfect. Also, the function I made called <code>playagain</code> is having some errors. When I type in "Yes" for the input I'm getting a stran...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T08:13:27.940", "Id": "49832", "Score": "0", "body": "possible duplicate of [Python Calculator](http://codereview.stackexchange.com/questions/31286/python-calculator)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate"...
[ { "body": "<p>Of the feedback on your earlier version of this programme, the most obvious thing that you haven't done yet is to use <code>lower()</code> on text inputs so that you only have to compare against lower case options. e.g.</p>\n\n<pre><code> again = input(\"Again? Yes/No: \").lower()\n if again...
{ "AcceptedAnswerId": "31308", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T07:49:39.073", "Id": "31304", "Score": "1", "Tags": [ "python", "calculator" ], "Title": "Simple calculator (going H.A.M with defining functions)" }
31304
<p>I have the code below to get an infinite generator of the products of an iterable (e.g. for the iterable "ABC" it should return</p> <p>A, B, C, AA, AB, AC, BA, BB, BC, CA, CB, CC, AAA, AAB, AAC etc.</p> <pre><code>for product in (itertools.product("ABC", repeat=i) for i in itertools.count(0)): for each_tuple i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T20:05:09.893", "Id": "49875", "Score": "1", "body": "you can write `itertools.count()` instead of `.count(0)`. :)" } ]
[ { "body": "<p>Well, you effectively have 3 nested loops including the generator comprehension, which you can reduce to two just by simplifying:</p>\n\n<pre><code>def get_products(string):\n for i in itertools.count(0):\n for product in itertools.product(string, repeat=i):\n yield product\n<...
{ "AcceptedAnswerId": "31315", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T12:22:07.123", "Id": "31313", "Score": "3", "Tags": [ "python", "combinatorics", "python-3.x" ], "Title": "Python infinite product generator" }
31313
<p>For a code challenge, I'm trying to write a comprehensive URI parser in Python that handles both URIs with <code>authority</code> paths (ex: URLs such as <code>http://user:login@site.com/page?key=value#fragment</code>) and other URI schemes (ex: <code>mailto:mail@domain.com?subject=Blah</code>).</p> <p>Here's my cu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-17T09:18:57.663", "Id": "62810", "Score": "0", "body": "There is no better place to look at than the python standard library:\nhttp://hg.python.org/cpython/file/2.7/Lib/urlparse.py" }, { "ContentLicense": "CC BY-SA 3.0", "C...
[ { "body": "<p>You referenced <a href=\"https://www.rfc-editor.org/rfc/rfc3986\" rel=\"nofollow noreferrer\">RFC 3986</a>, but I don't think you've tried to follow it.</p>\n<p>In your constructor, you immediately lower-case everything. That is obviously wrong. <a href=\"https://www.rfc-editor.org/rfc/rfc3986#...
{ "AcceptedAnswerId": "31324", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T16:43:27.130", "Id": "31317", "Score": "1", "Tags": [ "python", "parsing", "url" ], "Title": "A (comprehensive) URI parser for Python" }
31317
<p>Here's a trick for preallocating some memory for some type <code>T</code>. Do there exist similar tricks? Improvements?</p> <pre><code>#include &lt;cassert&gt; #include &lt;cstdlib&gt; #include &lt;atomic&gt; #include &lt;limits&gt; #include &lt;new&gt; #include &lt;thread&gt; #include &lt;utility&gt; namesp...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T17:19:29.127", "Id": "49859", "Score": "0", "body": "Let teh editz commence? ;-)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T17:20:04.437", "Id": "49860", "Score": "1", "body": "@Jamal...
[ { "body": "<p>I still have trouble understanding how the whole works, but there are still some small things that could be improved:</p>\n\n<ul>\n<li><p>In your comments, you say that <code>A</code> is an integer type used as a bitmask. The safest <a href=\"http://en.cppreference.com/w/cpp/concept/BitmaskType\">...
{ "AcceptedAnswerId": "46029", "CommentCount": "12", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T17:12:47.940", "Id": "31319", "Score": "8", "Tags": [ "c++", "c++11" ], "Title": "static_new and static_delete" }
31319
<p>I wrote this block of code as part of a JS utility library I'm working on. I will be thankful if someone could scan through it for eventual bugs or improvements that might be applied to it. </p> <p>The idea is to create a function that will configure an object to manage its own data collection by attaching <code>....
[]
[ { "body": "<p>I am not sure why you would want to do this, what does this add over standard JS objects, all you would need is add <code>Object.prototype.alter</code> and <code>Object.prototype.forEach</code>.</p>\n\n<p>From a once over:</p>\n\n<ul>\n<li>If you are going to have <code>f</code> -> <code>false</co...
{ "AcceptedAnswerId": "47173", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T18:45:38.947", "Id": "31326", "Score": "2", "Tags": [ "javascript", "library" ], "Title": "Making an object manage custom data in JavaScript" }
31326
<p>I want you to pick my code apart and give me some feedback on how I could make it better or more simple. In my opinion this is the best code I have written, being that I'm new to programming. The program is a basic "converter" that has the user input his/her age and it tells how many days, hours, and minutes the use...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T23:03:04.893", "Id": "49887", "Score": "0", "body": "Why not ask for a birth date (and time?) so you can calculate the real values?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T23:44:36.317", "...
[ { "body": "<p>This:</p>\n\n<pre><code>def name():\n name = input(\"What is your name? \")\n while name.isdigit():\n print(\"Make sure to enter an actual name.\")\n name = input(\"What is your name? \")\n return name\n</code></pre>\n\n<p>means that \"1\" is not a real name, but \"a\" and \...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T19:13:14.480", "Id": "31328", "Score": "5", "Tags": [ "python", "beginner", "datetime", "python-3.x", "converting" ], "Title": "Simple age converter" }
31328
<p>This code finds a common ancestor. If one of the input does not exist in the tree then throws an exception. This does not use extra storage. It does not even traverse more than what it should be. It would also account for duplicate node values in binary tree.</p> <p>I want you to pick my code apart and give me some...
[]
[ { "body": "<p>There are a number of issues in your code that I can see:</p>\n\n<ul>\n<li><p>Input validation.</p>\n\n<blockquote>\n<pre><code>public void createBinaryTree (Integer[] arr) {\n if (arr == null) {\n throw new NullPointerException(\"The input array is null.\");\n }\n\n root = new Tr...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-15T22:28:22.160", "Id": "31331", "Score": "3", "Tags": [ "java", "algorithm", "tree" ], "Title": "Least common ancestor in binary tree" }
31331