body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I would like to optimize the way that I save files.</p>
<p>Each second I save lots of strings in different files. What I want to do is bunch up these IO tasks so they happen in bursts, instead of spread out randomly.</p>
<p>I want to write files, but without performing too many IO operations at the same time, so I d... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T19:24:19.610",
"Id": "531076",
"Score": "2",
"body": "You're using a static, non thread safe collection across all instances of your saver class, however the actionsRunning is non-static. Are you expecting access from multiple threa... | [
{
"body": "<p>I'm probably not polished enough with Java to propose new code, so here are some abstract thoughts anyone else can use:</p>\n<ul>\n<li>Fewer bigger writes will generally be more efficient. Disk access is heavily optimized at the OS level, and those optimizations will work best if the <em>number</e... | {
"AcceptedAnswerId": "270462",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-20T18:45:53.070",
"Id": "269206",
"Score": "5",
"Tags": [
"java",
"performance",
"file-system",
"io"
],
"Title": "Optimized way to save list of files"
} | 269206 |
<p>I am reinventing the wheel to write a function that serializes a (nested) data structure human readably. The default output is deliberately similar to that of <code>json.dumps(var, indent=4)</code>, and I did my best to mimic the format of <code>json</code>s output.</p>
<p>But the output is fundamentally different f... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T08:15:11.377",
"Id": "531181",
"Score": "0",
"body": "One small remark: if each level of indent has the same offset (in your case 4 characters per indent), then I would abstract that number of characters away. For example, rename th... | [
{
"body": "<p>A few things I noticed:</p>\n<hr />\n<p>Since <code>supported</code> is a superset of <code>singles</code> I would recommend the following assignment:</p>\n<pre><code>singles = (frozenset, list, set, tuple)\nsupported = (dict, *singles)\n</code></pre>\n<p>This of course only makes sense if the two... | {
"AcceptedAnswerId": "269221",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-21T07:13:40.937",
"Id": "269214",
"Score": "4",
"Tags": [
"python",
"performance",
"python-3.x",
"reinventing-the-wheel",
"serialization"
],
"Title": "Serializing (nested... | 269214 |
<p>I am/we are using the observer pattern for many things in our application. I think it's time to create a reusable base class for these situations. Most implementations I could find only do something like this:</p>
<blockquote>
<pre><code>class Subject
{
public:
void AttachObserver(Observer* observer)
{
... | [] | [
{
"body": "<p>I have mainly worked on the ObserverID part. I agree with you on one point, it is rather <em>artificial</em>, when we know that C++ functions are hashable, so you could use the hash as ID. A point we must be aware is that <code>std::function</code> objects are not hashable (do not ask me why...) o... | {
"AcceptedAnswerId": "269225",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-21T08:37:40.330",
"Id": "269217",
"Score": "0",
"Tags": [
"c++",
"callback",
"observer-pattern"
],
"Title": "C++ Observer Pattern with std::function"
} | 269217 |
<p>I have been working on this question, <a href="https://open.kattis.com/problems/sequences" rel="nofollow noreferrer">https://open.kattis.com/problems/sequences</a>.</p>
<blockquote>
<p>You are given a sequence, in the form of a string with characters ‘0’, ‘1’, and ‘?’ only. Suppose there are <em>n</em> ‘?’s. Then th... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-21T13:05:10.987",
"Id": "531134",
"Score": "0",
"body": "is the 2k or \\$ 2^k \\$?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-21T13:40:04.480",
"Id": "531139",
"Score": "0",
"body": "It is ... | [
{
"body": "<p>I don't fully understand the solution, but here are some improvements for the code:</p>\n<h2>You are computing related quantities twice:</h2>\n<p>In:</p>\n<pre><code>if questions != 0:\n total = total * 2 ** questions + count * 2 ** (questions - 1)\n</code></pre>\n<p>you are computing <code>2 *... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-21T12:30:24.380",
"Id": "269223",
"Score": "5",
"Tags": [
"python",
"programming-challenge",
"sorting",
"time-limit-exceeded"
],
"Title": "Counting swaps in a sequence sorting al... | 269223 |
<p>we have a RESTful API that includes an endpoint for search</p>
<p>apiserver/v5/search?q=[search text]</p>
<p>for any query, it passes it off to solr and returns the result like</p>
<pre><code>{code:200,results:[{..},{...}]}
</code></pre>
<p>if q parameter is omitted, it returns:</p>
<pre><code>{code:412,message:&quo... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-21T23:34:13.717",
"Id": "531174",
"Score": "0",
"body": "https://stackoverflow.com/q/1219542/2943403"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T16:15:39.870",
"Id": "531200",
"Score": "1",
... | [
{
"body": "<blockquote>\n<h3>do search api endpoints typically allow you to search for nothing and just return empty</h3>\n</blockquote>\n<p>It is up to the implementors (and perhaps influenced by the stakeholders) of the API. Of the APIs I’ve looked at many disallow searching without a query/keyword. Below are... | {
"AcceptedAnswerId": "269235",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-21T16:16:19.353",
"Id": "269231",
"Score": "1",
"Tags": [
"php",
"api",
"search",
"rest"
],
"Title": "Requiring query field to not be empty on search api"
} | 269231 |
<p>This is my first formal <code>R</code> script that reads an archive and prints its contents. It uses <a href="https://github.com/libarchive/libarchive" rel="nofollow noreferrer"><code>libarchive</code></a> <a href="https://github.com/r-lib/archive" rel="nofollow noreferrer">R-bindings</a>, which can be installed on ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-21T17:16:21.273",
"Id": "269233",
"Score": "0",
"Tags": [
"r",
"file-archive"
],
"Title": "Printing file archives using R and libarchive"
} | 269233 |
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/268829/231235">Calculate distances between two multi-dimensional arrays in Matlab</a> and <a href="https://codereview.stackexchange.com/q/269052/231235">Mean and variance of element-wise distances in a set of multi-dimensional arrays in... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T00:15:48.473",
"Id": "269239",
"Score": "1",
"Tags": [
"performance",
"algorithm",
"array",
"combinatorics",
"matlab"
],
"Title": "Mean and variance of element-wise distan... | 269239 |
<p>Hi I am a beginner and l would love to hear your opinion on my first C project, how can it be improved in any way, for example dynamic memory allocation isn't used in the program because I didn't quite understand where to allocate it, also I couldn't figure how to solve the problem that if input isn't an integer the... | [] | [
{
"body": "<p>Welcome to Code Review! Here's my two cents:</p>\n<h3>Magic chars</h3>\n<p>Across the entire program, you use the ASCII values of chars instead of the chars themselves. This makes the code hard to read, as the reader sees a bunch of numbers at first an then has to infer what they mean, i.e. that t... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T06:58:31.487",
"Id": "269243",
"Score": "0",
"Tags": [
"beginner",
"c",
"tic-tac-toe"
],
"Title": "First C program - Tic Tac Toe"
} | 269243 |
<p>I have written a function to choose randomly with weights from very large data sets in which the weight of elements can be several thousands.</p>
<p>The input of the function is a flat <code>dict</code>, the keys can be any object and the values must be positive <code>int</code>s, and the values represent the count ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T05:54:12.473",
"Id": "531241",
"Score": "1",
"body": "Your `%memit` output shows `increment: 0.00 MiB`. I.e., pretty much *nothing*, as you'd expect from this tiny data. You call that \"memory-intensive\" and \"memory consumption is... | [
{
"body": "<p>Using the <a href=\"https://realpython.com/lessons/assignment-expressions/\" rel=\"nofollow noreferrer\">walrus operator</a> and a generator expression can reduce the runtime and memory-consumption of your final loop. Consider this small change:</p>\n<pre><code>stored = 0\nitems = ((range(stored, ... | {
"AcceptedAnswerId": "269267",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T07:02:02.147",
"Id": "269244",
"Score": "-1",
"Tags": [
"python",
"performance",
"python-3.x",
"random"
],
"Title": "Python weighted choosing that works with very large nu... | 269244 |
<p>See <a href="https://codereview.stackexchange.com/questions/269214/serializing-nested-data-structures-in-a-human-readable-format">Serializing (nested) data structures in a human-readable format</a> for more details.</p>
<p>This is the latest version, I have fixed all bugs and now this piece of code works completely ... | [] | [
{
"body": "<p>This function is now considerably longer and harder to understand than before. I find nested functions (especially of this complexity) really harm readability, since you need to keep track of even more layers of context to understand the full functionality. I strongly suggest splitting this functi... | {
"AcceptedAnswerId": "269274",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T09:57:57.130",
"Id": "269247",
"Score": "2",
"Tags": [
"python",
"performance",
"python-3.x",
"reinventing-the-wheel",
"serialization"
],
"Title": "Serializing (nested... | 269247 |
<p>I've ran a few tests, not extensive though, and it apparently works. Like many standard binary search algorithms, if the number returned is < 0, you can take the complement (~) of the returned value to find the insert point, eg <code>const ix = bs(arr, 5); // ~ix is the insertion point</code></p>
<pre><code>inter... | [] | [
{
"body": "<p>Your code looks good to me. I just stumbled over the <code>range</code> parameter, which feels unusual to me. But if you remove it, you have to combine the result for the upper half of the considered array.</p>\n<pre><code>const bs = (arr: number[], value: number): number => {\n const indexT... | {
"AcceptedAnswerId": "269954",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T16:07:30.803",
"Id": "269260",
"Score": "2",
"Tags": [
"typescript",
"binary-search"
],
"Title": "Recursive Binary Search in Typescript"
} | 269260 |
<p>This script is to calculate the Spearman correlation of genes that are stored in rows of a pandas dataframe. The original df has around 2000 row names. With my current code, this requires 2000*2000 iterations to compute the correlation value for each possible comparison row-wise. I would like to get some hints in or... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T20:45:27.793",
"Id": "531213",
"Score": "0",
"body": "Could you please include some sample data and current output?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T21:44:49.500",
"Id": "531223",
... | [
{
"body": "<p>Sorry if my comment looked too cryptic. Let's take a closer look at the Spearman statistics.</p>\n<p>The Spearman coefficient between two sets of raw data is <span class=\"math-container\">\\$\\dfrac{\\mathrm{Cov}(R(T_i), R(T_j))}{\\sigma_{R(T_i)}\\sigma_{R(T_j)}}\\$</span>. It means that each tim... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T20:08:08.803",
"Id": "269264",
"Score": "1",
"Tags": [
"python",
"performance",
"scipy"
],
"Title": "Calculate correlation of genes stored in dataframe rows"
} | 269264 |
<p>This is my first time coding! My intent for this program was to be able to give my technicians a flash drive that will pull system info and email it to me. Currently everything is working, but I was hoping for suggestions or tips on what I can improve on or add to it. I'm sure there is a lot of messy code that I got... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T20:59:06.827",
"Id": "531217",
"Score": "1",
"body": "is there a reason to NOT use the `Get-ComputerInfo` cmdlet?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T21:27:51.030",
"Id": "531221",
... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "11",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T20:32:32.777",
"Id": "269268",
"Score": "1",
"Tags": [
"powershell",
"batch"
],
"Title": "Batch/Powershell program to retrieve system info"
} | 269268 |
<p><strong>The problem is to count number of appearence of the number k in (n*n) Multiplication table</strong></p>
<p><strong>I just wrote this code to solve this problem</strong></p>
<p><strong>Is there a faster way to solve this problem?</strong></p>
<pre><code> long n = in.nextLong();
long k = in.nextLong();
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T20:24:31.433",
"Id": "531292",
"Score": "2",
"body": "You probably had an idea for an algorithm to code. Which you don't explicitly present in your question, let alone in above code. Did you think about using algebra beyond *countin... | [
{
"body": "<p>I can't say for sure there is no faster way, but there is definitely a cleaner way and also one that is more complete.</p>\n<ul>\n<li>In java it will not slow down your program if you choose more <strong>descriptive names</strong>.</li>\n<li>I would also <strong>extract the function</strong> from ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T19:59:27.083",
"Id": "269271",
"Score": "0",
"Tags": [
"java"
],
"Title": "count number of appearence of the number k in (n*n) multiplication table"
} | 269271 |
<p>I have been trying to write a small test program and I was trying to think of any potential optimization I could do, especially if there is any chance to avoid some of the for loops.</p>
<p>The program has Dad class, a Child class and a DadChild class that holds the IDs of the Dad and Child objects that are associat... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T23:10:18.493",
"Id": "531226",
"Score": "1",
"body": "What is the goal of this piece of code? That is, given a bunch of DNA tests, what do you want it to print out?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate":... | [
{
"body": "<h2>Documentation</h2>\n<p>Add documentation.</p>\n<p>I had no idea what the goal of this program is, going in, and at the end of the review I still don't, so I can't comment on whether the code is correct or efficient.</p>\n<ul>\n<li>Do we want to output the most likely child for a father? The most ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T22:36:24.263",
"Id": "269272",
"Score": "2",
"Tags": [
"c++",
"performance",
"c++11"
],
"Title": "How to avoid excessive for loops in C++"
} | 269272 |
<p>There is the following method that should get record from the database, apply new data, and if at least one value has been changed, update database and send event</p>
<p>We don't use EntityFramework, it uses CosmosDb SDK in the repository.</p>
<p>I'm not sure how is the proper way to implement <code>hasChanges</code... | [] | [
{
"body": "<p>You can move <code>HealthState</code> and <code>Cabin</code> portions into separate methods as each one of them serve a single purpose for a single property. So, moving them into their own methods would give more freedom and extensibility such as adding more requirements, some other future changes... | {
"AcceptedAnswerId": "269282",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-22T23:09:47.377",
"Id": "269276",
"Score": "0",
"Tags": [
"c#",
"database"
],
"Title": "Properly implementing HasChanges pattern for model"
} | 269276 |
<p>I just asked this question over Stack Over Flow on how to improve my code and reposting it here as someone on Stack Overflow recommended this platform.</p>
<p>I have written two python functions and they are correct, but I believe this is not the efficient way to write them, and I am wondering if some can give their... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T04:11:48.987",
"Id": "531236",
"Score": "0",
"body": "@Reinderien I have fixed the indentation. This script contains only these two functions, nothing else."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-1... | [
{
"body": "<ul>\n<li>Type-hint your function arguments</li>\n<li>Your <code>weight_matrix</code>, when vectorised, won't be able to rely on <code>weights</code></li>\n<li>Rather than <code>int((n_w+1)/2)</code>, use <code>(n_w + 1)//2</code></li>\n<li>Add some unit tests based on your known criteria and output ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T02:18:46.940",
"Id": "269279",
"Score": "2",
"Tags": [
"python",
"performance",
"numpy",
"machine-learning",
"numerical-methods"
],
"Title": "Generating a matrix with each... | 269279 |
<p>I recently saw a youtube video on printing even and odd numbers from 0 to 100 in Java. <a href="https://www.youtube.com/watch?v=eRNTx8k5cmA" rel="nofollow noreferrer">https://www.youtube.com/watch?v=eRNTx8k5cmA</a></p>
<p>Thread 1 prints even numbers and thread 2 prints odd numbers. Both the threads print the number... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T23:25:48.580",
"Id": "531302",
"Score": "0",
"body": "\"Could you show me how you'd take something fast and simple, and use threads to turn it into something slow and complicated?\" Unless I was incredibly desperate for any job I co... | [
{
"body": "<h1>Answers to your questions</h1>\n<blockquote>\n<p>Is there anyway to eliminate the global variables?</p>\n</blockquote>\n<p>Yes, you can put them on the stack of a function, like you already did in your second version, or alternatively you can make those variables <code>static</code> member variab... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T06:25:22.557",
"Id": "269283",
"Score": "1",
"Tags": [
"c++",
"multithreading",
"interview-questions"
],
"Title": "Printing odd and even numbers in separate threads C++"
} | 269283 |
<p>This is my first post here, so I apologize if anything is incorrect.
I have created an endless arcade stacker game (like the stacker games at the arcade, but when you hit the top the grid resets and you continue endlessly). My intention in the code was to separate out the core game logic (i.e. the code that moves th... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-25T03:39:49.327",
"Id": "531371",
"Score": "1",
"body": "`Stacker` does not contain \"grid\", \"stack\" and game logic objects rather `Stacker` IS all of these these objects. Next, there is no such thing as a `Grid` (upper or lower cas... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T10:11:41.207",
"Id": "269289",
"Score": "2",
"Tags": [
"c#",
"object-oriented",
"game",
"design-patterns"
],
"Title": "Arcade Stacker Game - Core Logic"
} | 269289 |
<p>Take input n1 and n2 and check if they have the same greatest factor. If they do, print that factor. If they don't, print "No". <br/></p>
<p>example:<br/>
input:<br/>
6<br/>
9<br/>
output:<br/>
3<br/></p>
<p>input:<br/>
15<br/>
27<br/>
output:<br/>
No<br/></p>
<pre><code>n1=int(input())
n2=int(input())
l1=... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T14:20:14.897",
"Id": "531263",
"Score": "0",
"body": "Your code is not finding the greatest common factor. It's finding if the greatest factors of the two numbers are equal. The usual way to find the greatest common factor is the E... | [
{
"body": "<p>At any point, 1 is always common factor of any two numbers. Your code works perfectly. But if you want to write a shorter code, check the condition if both numbers are divisible by any number using for loop going from range 2 (1 is always factor) to min of both numbers. Take a new variable f which... | {
"AcceptedAnswerId": "269291",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T10:25:00.940",
"Id": "269290",
"Score": "0",
"Tags": [
"python",
"python-3.x",
"mathematics"
],
"Title": "Print greatest factor if it is same for both numbers"
} | 269290 |
<p>I started my cs50 course this week and I will be trying to make little projects alongside to reaffirm what I've learned thus far. Here I have made a very basic budget and savings calculator, I am hoping to increase the complexity as I improve.</p>
<p>Where could I improve this in terms of simplicity & structure/... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T19:06:55.240",
"Id": "531286",
"Score": "0",
"body": "@G. Sliepen Ah yes I see, now declared & initialised the variables at the same time, not sure why I did it like that. The redundant comment being the // Prompt for Monthly Income... | [
{
"body": "<h1>Declare and initialize variables at the same time</h1>\n<p>You can simplify the code a lot by declaring and initializing variables at the same time, like so:</p>\n<pre><code>int Monthly_Income = get_int("Please enter your monthly income");\nint Expenditure = get_int("Please enter y... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T14:20:07.497",
"Id": "269295",
"Score": "2",
"Tags": [
"beginner",
"c",
"calculator"
],
"Title": "Total income program: budget and savings calculator"
} | 269295 |
<p>So I have a file of errors, there default meanings and also it's hierarchy in terms of indentation</p>
<pre><code>BaseException General for all errors of any and every kind.
SystemExit Called for when the system wants to exit.
KeyboardInterrupt Called when an operator interrupts an action.
GeneratorExit Called when ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T15:38:07.857",
"Id": "531267",
"Score": "2",
"body": "Why is your code so dense and compact? Are you aiming to code-golf?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T15:48:05.927",
"Id": "5312... | [
{
"body": "<h1>Small Things</h1>\n<ul>\n<li>Spelling error, <code>builtlins -> builtins</code>.</li>\n<li>Removed commented out code you don't use, adds unnecessary clutter.</li>\n<li>Spaces before and after operators (<code>+-*/=</code>).</li>\n</ul>\n<h1>PEP-8 Stuff</h1>\n<ul>\n<li><a href=\"https://www.py... | {
"AcceptedAnswerId": "269302",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T15:05:43.467",
"Id": "269297",
"Score": "0",
"Tags": [
"python",
"python-3.x"
],
"Title": "Making list of errors from file"
} | 269297 |
<p>I made a somewhat simple vector implementation in C. Right now I only have around 5 features (making a vector, adding elements, removing elements, changing elements, deleting the vector). I'm proud of it but I know it needs a lot of work so I came here to see what you think I could improve. There are 3 files, <code>... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T18:20:37.277",
"Id": "531599",
"Score": "0",
"body": "Pirates would approve of your naming convention. https://www.youtube.com/watch?v=K7aM_HWMdj0"
}
] | [
{
"body": "<blockquote>\n<pre><code>#define growCapacity(capacity) \\\n (capacity < 8) ? 8 : capacity*2\n</code></pre>\n</blockquote>\n<p>I don't think this should be in the header, as it's not useful to the <em>user</em> of our vector. Consider moving it to the implementation file.</p>\n<blockquote>\n<p... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T16:18:15.863",
"Id": "269299",
"Score": "13",
"Tags": [
"c",
"vectors"
],
"Title": "Vector Implementation in C"
} | 269299 |
<p>My teacher gave us this problem to solve so basically N is the number of user names in a list T with 1>N<9</p>
<ul>
<li>Generate another list called TID containing the name of the user but changed a bit. Do the next steps for each user in the list T</li>
</ul>
<hr />
<ol>
<li>Take the first two letters from th... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T20:16:00.613",
"Id": "531290",
"Score": "0",
"body": "I doubt that `1>N<9` - what are the constraints that your teacher gave you?"
}
] | [
{
"body": "<h1>General Changes</h1>\n<ul>\n<li>Move any input code to the bottom of the file, inside a <a href=\"https://stackoverflow.com/questions/19578308/what-is-the-benefit-of-using-main-method-in-python\">main guard</a>.</li>\n<li>Avoid using <a href=\"https://stackoverflow.com/questions/484635/are-global... | {
"AcceptedAnswerId": "269310",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T16:59:43.053",
"Id": "269300",
"Score": "1",
"Tags": [
"python"
],
"Title": "A small python identifier generator for users"
} | 269300 |
<p>I wrote a program that, given a 2D array representing pixels in a birds eye view image, it returns the number of Objects in the image.</p>
<p>Pixels that are connected in the up, down, left, and right directions are a single object.</p>
<p><strong>Example:</strong></p>
<pre class="lang-py prettyprint-override"><code... | [] | [
{
"body": "<blockquote>\n<p>The adj_vert method to get the neighbors of a pixel is extremely ugly. Is there a cleaner way to the approach I took?</p>\n</blockquote>\n<p>Yes, checking 4 conditions is enough. For example:</p>\n<pre><code>if row > 0:\n adjs.append((row - 1, col))\nif row + 1 < length:\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-23T17:49:22.210",
"Id": "269303",
"Score": "3",
"Tags": [
"python",
"algorithm",
"object-oriented",
"graph"
],
"Title": "Finding Number of Objects in Image"
} | 269303 |
<p>I learnt a function to display the imaginary part of a complex number & that is <strong>.imag</strong>
But when I was practising it, look what I found:</p>
<pre><code>print(5-5j.imag) #>>>0.0
print((5-5j).imag)#>>>-5.0
print(2+4j.imag) #>>>6.0
print((2+4j).imag)#>>>4.0
</cod... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-24T01:07:48.310",
"Id": "531306",
"Score": "2",
"body": "I believe this question would be more suitable to stackoverflow."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-24T01:11:55.930",
"Id": "531307"... | [
{
"body": "<p>In the second and third <code>print</code> statements you're doing:</p>\n<p><code>a + bj.imag</code> = <code>a + (bj.imag)</code> = <code>a + b</code></p>\n<p>That is, you're taking the imaginary part of <code>bj</code> (which is <code>b</code>), then you're adding it to <code>a</code>. The result... | {
"AcceptedAnswerId": "269316",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-24T00:41:11.250",
"Id": "269315",
"Score": "-2",
"Tags": [
"python"
],
"Title": ".imag Function for Complex Numbers"
} | 269315 |
<p>I'm reading "Modern C++ Design"(A. Alexandrescu, 2002) and practicing basic TMP in chapter 3. Typelists. Since the book is quite dated, I revised example codes in C++17-esque manner.</p>
<p>Feel free to comment anything!</p>
<pre><code>#include <cstddef>
#include <iostream>
#include <utility... | [] | [
{
"body": "<p>Overall, your code looks very good.</p>\n<h1>No need to overload for empty template parameter packs</h1>\n<p>A <code>typename...</code> parameter pack also matches zero elements, so the following overload is unnecessary:</p>\n<pre><code>template <>\nstruct TypeList<> {};\n</code></pre>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-24T06:08:57.263",
"Id": "269320",
"Score": "8",
"Tags": [
"c++",
"template-meta-programming"
],
"Title": "C++17 : Typelist manipulation"
} | 269320 |
<p>I use the Emgu.CV wrapper to create a grayscale image. The data of this image are to be copied into a 2D byte array. Is there a more elegant solution than mine?
I'm asking here at <em>CodeReview</em> because my code works and the question is therefore not suitable for <em>Stackoverflow</em>.</p>
<p>If you want to re... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-24T11:58:26.770",
"Id": "531337",
"Score": "0",
"body": "That's great - a good title really helps attract the right reviewers. Sorry it's not a language I've ever used, otherwise I would attempt a review myself."
},
{
"Content... | [
{
"body": "<h1>Separating UI from business logic</h1>\n<p>You have put everything into the button click event handler. This is really bad practice. Consider creating a separate class to handle the image processing:</p>\n\n<pre class=\"lang-vb prettyprint-override\"><code>Class ImageProcessor\n\n Public Funct... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-24T08:12:52.743",
"Id": "269321",
"Score": "4",
"Tags": [
"array",
"vb.net"
],
"Title": "Read an image file as greyscale byte array"
} | 269321 |
<p>I made a CSV class which manages CSV files. Is this good?, I'm beginner btw. It's probably bad but can you give me some tips!</p>
<p>Header file:</p>
<pre><code>#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#pragma once
class CSVFile {
public:... | [] | [
{
"body": "<p>This code is nicely presented, which is great for reviewing. It would have been nice to see some usage examples, or (even better) some unit tests. One of the things that makes it hard to write good unit tests is that we've chosen to represent a <em>file</em>; if we make our core code work with <... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-24T12:49:19.340",
"Id": "269329",
"Score": "2",
"Tags": [
"c++",
"csv"
],
"Title": "Abstraction for CSV files"
} | 269329 |
<p>I want to implement a function (or several) that must run <em><strong>exactly once</strong></em> when the program terminates, no matter how this termination came about<sup>1</sup>.</p>
<p>Below is my best attempt at doing this. Specifically, the code between the <code>####...####</code> dividers is the most succinc... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-24T13:53:48.833",
"Id": "531342",
"Score": "4",
"body": "Long time no see - welcome back! It's great to see code presented with such a helpful program to exercise it. I hope you get some good reviews for this."
},
{
"ContentL... | [
{
"body": "<blockquote>\n<pre><code> sys.exit(signal_number)\n</code></pre>\n</blockquote>\n<p>This is quite different visible behaviour, as seen by the parent process. It might be better to remove the signal handler and then re-raise the signal (using <code>signal.raise_signal()</code> on ourself), so ... | {
"AcceptedAnswerId": "269334",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-24T13:48:31.810",
"Id": "269333",
"Score": "2",
"Tags": [
"python"
],
"Title": "Implementing a clean-up function that must run at program's termination no-matter-what"
} | 269333 |
<p>As an exercise to learn more about multi-threading and atomic operations work in C++, I decided to implement a <em>latch</em> class in C++11 loosely based off of <a href="https://en.cppreference.com/w/cpp/thread/latch" rel="nofollow noreferrer"><code>std::latch</code></a> class from C++20 and would like to know whet... | [] | [
{
"body": "<p>The only thing missing that's present in <code>std::latch</code> is the <code>max</code> constant. We can easily add that:</p>\n<pre><code>static constexpr std::ptrdiff_t max() noexcept\n{\n return std::numeric_limits<std::ptrdiff_t>::max();\n}\n</code></pre>\n<p>I think that <code>wait(... | {
"AcceptedAnswerId": "269343",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-24T18:01:29.817",
"Id": "269342",
"Score": "1",
"Tags": [
"c++",
"multithreading",
"reinventing-the-wheel",
"concurrency",
"atomic"
],
"Title": "Implementation of a latch... | 269342 |
<p>This question follows up on <a href="https://codereview.stackexchange.com/questions/269342/implementation-of-a-latch">this question</a>.</p>
<p>After turning the <code>while</code>-loop into a <em>conditional wait</em> using <code>std::condition_variable</code>, I would like to know if there are <em>still</em> any f... | [] | [
{
"body": "<p>Some minor nitpicks about the constructor:</p>\n<ul>\n<li><p>It should be <code>constexpr</code>.</p>\n</li>\n<li><p>It shouldn't have a default argument.</p>\n</li>\n<li><p>We should check that the argument is valid (not negative, and not greater than <code>max()</code>). The standard says it's u... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-24T18:59:01.607",
"Id": "269344",
"Score": "3",
"Tags": [
"c++",
"multithreading",
"reinventing-the-wheel",
"concurrency",
"atomic"
],
"Title": "C++11 revised `std::latch` im... | 269344 |
<p>I'm learning PowerShell for professional development, but decided to do a bit of a silly project to help learn scripting in more depth, and chose <a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" rel="nofollow noreferrer">Conway's Game of Life</a>. This is the first PowerShell script I've written besid... | [] | [
{
"body": "<p>This is a fun project.\nHere are a few things I noticed:</p>\n<ol>\n<li><code>$AlivePercChance</code> implies that it's a percentage (30%) rather than a fraction (0.3). You might consider renaming it to <code>$AliveChance</code></li>\n<li>Why did you flatten the 2D array to 1D? It adds substantial... | {
"AcceptedAnswerId": "270653",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-24T22:23:17.897",
"Id": "269347",
"Score": "3",
"Tags": [
"beginner",
"powershell",
"game-of-life"
],
"Title": "Conway's Game of Life in Powershell"
} | 269347 |
<p>I started to write a terminal based text RPG in python. Its mostly bug free now but I really want to know how I could improve my code and how to implement things better. I know it's a lot of code so I really want to thank you, if you're patient enough to review it.</p>
<p>I uploaded the code to github. You only need... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-25T00:05:22.123",
"Id": "531367",
"Score": "4",
"body": "Please also include main.py verbatim in this post."
}
] | [
{
"body": "<p>First of all, How do expect someone to read your code? Neither type hints nor doc-strings.</p>\n<h1>Review</h1>\n<ul>\n<li>What would a <code>Player</code> or a <code>Enemy</code> inherit from a <code>GameMap</code>?</li>\n<li>I would prefer to implement a <code>.attack_player(player: Player)</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-24T23:19:29.190",
"Id": "269348",
"Score": "1",
"Tags": [
"python",
"python-3.x"
],
"Title": "TextRPG written in python"
} | 269348 |
<p>I would like a little help with the implementation of my SDL2 engine. It's actually not a real engine nor does it strive to be but I don't have a better word to describe it.</p>
<p>The purpose of this project is to serve as a base for other things to be built on, like a visualization of fractals for example, so i wo... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-25T11:01:14.830",
"Id": "531385",
"Score": "2",
"body": "Welcome to Code Review! I changed the title so that it describes what the code does per [site goals](/questions/how-to-ask): \"*State what your code does in your title, not your ... | [
{
"body": "<p>Don't use the C macro <code>NULL</code>. C++ has a real null pointer named <code>nullptr</code>. Meanwhile, don't explicitly compare against <code>nullptr</code>, but rather use the convert-to-boolean truth value of the pointer (this is important when you use smart pointers, and is idiomatic for... | {
"AcceptedAnswerId": "269366",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-25T10:45:03.963",
"Id": "269355",
"Score": "4",
"Tags": [
"c++",
"sdl2"
],
"Title": "SDL2 engine base implementation"
} | 269355 |
<p>See <a href="https://codereview.stackexchange.com/questions/269214/serializing-nested-data-structures-in-a-human-readable-format">Serializing (nested) data structures in a human-readable format</a> for more details.</p>
<p>In the last two days I have significantly improved my function, and wrote seven implementation... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T03:46:10.133",
"Id": "531689",
"Score": "0",
"body": "add a timeit response for `prettyprint`?"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-25T11:59:28.243",
"Id": "269357",
"Score": "1",
"Tags": [
"python",
"performance",
"python-3.x",
"programming-challenge",
"serialization"
],
"Title": "Python functions to ser... | 269357 |
<p>I try to block all websites in Hebrew because I want to give more time on websites in other languages.</p>
<p>Given that many webmasters don't add <code><meta name="language" content="Hebrew"></code> meta attribute to all webpages of their websites I can't use it to block websites which app... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-25T16:02:32.830",
"Id": "531413",
"Score": "0",
"body": "I don't understand the downvotes. If you think there is anything to improve please comment or suggest an edit (which I will gladly examine ASAP)."
},
{
"ContentLicense": ... | [
{
"body": "<p>Your script will only work correctly if it is placed after the Yod character. Consider adding an event listener for <code>window.load</code> to only call it when all the content is loaded:</p>\n\n<pre class=\"lang-javascript prettyprint-override\"><code>addEventListener("load", () => ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-25T13:49:11.203",
"Id": "269359",
"Score": "1",
"Tags": [
"javascript",
"userscript"
],
"Title": "Check if a website is in a certain language and if so, block it"
} | 269359 |
<p>I was assigned the following problem:</p>
<blockquote>
<p>You've gone back in time to 500BC Athens and Socrates wants you
to build him an app to help classify animals.</p>
<ol>
<li>Build the classes <code>Animal</code>, <code>Cat</code>, and <code>Bug</code>.</li>
<li>Define the properties <code>color</code> and <co... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-25T16:14:44.900",
"Id": "531416",
"Score": "0",
"body": "Welcome to Code Review! I'm tempted to vote to close, since your code does not appear to have implemented the `move` method the way the problem requires. Can you clarify the requ... | [
{
"body": "<p>I'm not sure how to approach this. You say you've been assigned a problem, so this feels very much like coursework/homework.</p>\n<p>Assuming this homework is to be assessed, it's more helpful for the assessor to see your work than mine - they will then know how successful the tuition has been, an... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-25T15:32:53.770",
"Id": "269362",
"Score": "1",
"Tags": [
"java",
"object-oriented",
"interview-questions",
"classes",
"inheritance"
],
"Title": "Model animals using inherita... | 269362 |
<p>So a little context to understand the code:</p>
<ol>
<li>This is a helper function to solve a bigger problem <a href="https://leetcode.com/problems/dungeon-game/" rel="nofollow noreferrer">here</a></li>
<li>Quick summary: A Knight is in a dungeon/2D grid of Ints, starts at 0,0 and must reach the last cell at the bot... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-25T17:37:45.560",
"Id": "531426",
"Score": "0",
"body": "Travel \"right and down\" diagonally, or \"either right or down\"?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-25T17:41:25.787",
"Id": "53142... | [
{
"body": "<p>Welcome to CodeReview!</p>\n<p>Disclaimer: As noted in the comments, a review of this code is limited since I don't know the entire codebase / algorithmic approach. So this review is limited to this function's current implementation.</p>\n<hr />\n<p><strong>Naming</strong></p>\n<p><code>d</code> a... | {
"AcceptedAnswerId": "269369",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-25T15:54:58.540",
"Id": "269364",
"Score": "1",
"Tags": [
"python",
"recursion",
"depth-first-search"
],
"Title": "Helper get_all_neighbors (in a grid) function - python"
} | 269364 |
<p>I've been working on a program that should find the color red on the screen and then send out an alert. The issue is that the red color moves around a lot and the color finder moves too slow on the screen to find the color accuritely and in time before the color dissapears to another location on the screen.</p>
<p>I... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-26T06:47:12.647",
"Id": "531455",
"Score": "0",
"body": "Is the red region you trying to find exactly 1 pixel? If not, you don't need to scan every pixel. For example, if you have a 10px red square somewhere on the screen, you only nee... | [
{
"body": "<p>The bottleneck in your code is mostly because you use a method (<code>java.awt.Robot#getPixelColor</code>) in a loop to fetch the color pixel by pixel; this method uses lower system API to fetch the color and that takes more time.</p>\n<p>You could make the code faster by using the <code>java.awt.... | {
"AcceptedAnswerId": "269393",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-25T21:39:53.150",
"Id": "269375",
"Score": "3",
"Tags": [
"java",
"performance",
"beginner"
],
"Title": "How do I increase the speed of this loop or pixel color finding process?"... | 269375 |
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/a/269309/231235">A recursive_count Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++</a>. A function <code>recursive_depth</code> for calculating depth of nested iterables is mentioned in <a href=... | [] | [
{
"body": "<p>The implementation is straightforward and correct as far as I can tell.</p>\n<blockquote>\n<p>What would you expect the output of <code>std::vector<std::string></code> case?</p>\n</blockquote>\n<p>I expect it to be 2, as both <code>std::vector</code> and <code>std::string</code> are ranges. ... | {
"AcceptedAnswerId": "269399",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-25T23:56:04.777",
"Id": "269376",
"Score": "2",
"Tags": [
"c++",
"recursion",
"template",
"c++20"
],
"Title": "A recursive_depth function for calculating depth of nested type... | 269376 |
<p>Created a MongoDB client which is handling the retry in case of server connection failure. Please review and how I can improve further.</p>
<pre><code>package db
import (
"context"
"errors"
"log"
"time"
"go.mongodb.org/mongo-driver/event"
... | [] | [
{
"body": "<p>I would think about replacing the "for loop" with a retry package <a href=\"https://github.com/avast/retry-go\" rel=\"nofollow noreferrer\">https://github.com/avast/retry-go</a>. Should be a little bit cleaner.</p>\n<pre><code>func (m *MongoDB) reconnect() {\nerr := retry.Do(func() error... | {
"AcceptedAnswerId": "269823",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-26T05:09:10.803",
"Id": "269379",
"Score": "0",
"Tags": [
"go",
"mongodb"
],
"Title": "Mongodb connection retry"
} | 269379 |
<p>I am attempting to re-implement a <a href="//stackoverflow.com/a/10733621">postponed sieve algorithm </a> for generating prime numbers in Rust. I am able to make a solution that works, but I have to use a couple of <code>.clone()</code> calls which I believe are killing my performance (the Rust solution ends up ~8x ... | [] | [
{
"body": "<p>A normal Sieve of Eratosthenes would look like:</p>\n<pre><code>fn primes(n: usize) -> impl Iterator<Item = usize> {\n const START: usize = 2;\n if n < START {\n Vec::new()\n } else {\n let mut is_prime = vec![true; n + 1 - START];\n let limit = (n as f64)... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-26T05:39:00.437",
"Id": "269380",
"Score": "2",
"Tags": [
"performance",
"primes",
"rust",
"memory-management"
],
"Title": "Generating prime numbers quickly in rust"
} | 269380 |
<p>This is a <a href="https://fiks.fit.cvut.cz/files/tasks/season8/round1/sponzori.pdf" rel="nofollow noreferrer">programming challenge</a> in Czeck. My translation follows.</p>
<p><strong>Does anyone know what the time complexity of my code is?</strong></p>
<p><strong>Input:</strong> The first line contains 2 integers... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-26T12:09:31.143",
"Id": "531484",
"Score": "2",
"body": "Welcome to Code Review. Can you include the class Animal, please? Even if very simple, it is better to include the complete code."
},
{
"ContentLicense": "CC BY-SA 4.0",
... | [
{
"body": "<p>My Java is rusty so I spent (a lot of!) time brushing up on some OpenJDK 16 topics. Starting with your existing program,</p>\n<ul>\n<li><code>Animals</code> is not really a good representation of a class. It's non-reentrant, since <code>S</code> and <code>A</code> are statics, so it will be diffic... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-26T10:45:32.683",
"Id": "269388",
"Score": "3",
"Tags": [
"java",
"beginner",
"algorithm",
"programming-challenge"
],
"Title": "Find potentional sponsor for every animal"
} | 269388 |
<p>I am new to using interfaces and abstract classes. The team I am working with came up with an implementation of what they call a base class that will be implemented by all view model classes. This is what they came up with:</p>
<pre><code> public interface IBaseViewModel<T>
{
#region public properties
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-26T13:15:56.720",
"Id": "531494",
"Score": "3",
"body": "Rather than a review of the existing code, you appear to be looking for a discussion around the relative merits of interfaces Vs abstract base classes..."
},
{
"ContentLi... | [
{
"body": "<p>The implementation must not have the generic type parameter <code>T</code>, because it is implementing <code>BaseViewModel<T></code> with the concrete type <code>AccountBillGroup</code> supplemented for <code>T</code>. The same holds for the interface <code>IAccountBillViewModel</code>.</p>\... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-26T12:35:12.037",
"Id": "269390",
"Score": "-1",
"Tags": [
"c#",
"interface"
],
"Title": "implementing abstract classes vs interfaces"
} | 269390 |
<p>So I'm making a utility class to find resources and read them as JSON objects using the GSON library, the code below is working good but I don't really know how good it is, so I would like to get opinions about it and maybe some things I can improve and make it more efficient?</p>
<pre><code>public abstract class Re... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-26T15:53:43.503",
"Id": "531506",
"Score": "1",
"body": "Could you please provide a class that inherits from this class as well?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-26T16:10:23.400",
"Id": "... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-26T14:52:27.377",
"Id": "269394",
"Score": "0",
"Tags": [
"java",
"json",
"gson"
],
"Title": "Resource manager code improvement"
} | 269394 |
<p>Yesterday I posted my first solution to an interview problem here. I am now aware that I have many weak spots in Java and need to do extensive review before tackling any more interviews. Having said that, piecing together what people on here mentioned, I have come to what I hope is a good solution, and am asking to... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T05:35:56.423",
"Id": "531542",
"Score": "0",
"body": "I am so glad I never had to do a code interview. I have been writing code since the '70s (and still am). Solving problems is a worthwhile skill to test, checking your skills as a... | [
{
"body": "<p>This is better, but you are still missing a lot of basic ideas. I'm going to continue to approach the code review by looking at concepts and suggesting what you need to consider and what you should probably review in your learning, rather than by doing line-wise analysis and suggesting alternative... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-26T15:15:04.647",
"Id": "269395",
"Score": "4",
"Tags": [
"java",
"interview-questions",
"inheritance",
"polymorphism"
],
"Title": "Model animals using inheritance in Java, revis... | 269395 |
<p>I'm relatively new to Python have been writing for a few months now. I've started a Pandas Numpy project that starts with parsing large and somewhat sloppy formatted textfile, its not exactly csv but its pretty close.</p>
<pre><code>...
Basetime: 2021102206Z
Forecast Hours: 0hr 1hr... 144hr
Sfc Prs... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-26T17:58:34.783",
"Id": "531513",
"Score": "1",
"body": "Is all your Python in one file? Could you format it as such here? Could you give a few more lines of your text file, so that we could copy and paste it into our own copy of the... | [
{
"body": "<ul>\n<li><code>pass</code> is for when Python requires you to have <em>something</em>, but there's nothing else to have. So it works in the <code>except</code> clauses, but otherwise isn't necessary.</li>\n<li>But catching an exception without doing anything else is usually a bad idea. You want to... | {
"AcceptedAnswerId": "269482",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-26T17:52:22.150",
"Id": "269398",
"Score": "1",
"Tags": [
"python",
"parsing",
"regex",
"numpy",
"pandas"
],
"Title": "using pandas and numpy to parse dirty .csv"
} | 269398 |
<p>I'm new to programming and have been teaching myself to code for about 6 months. Since I have no one to ask about any of coding-related questions, I may have developed bad habits in the meantime, but I can't tell myself. As such, I wrote a simple blackjack game in Python, to demonstrate how I usually code, and to fi... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T03:49:32.343",
"Id": "531539",
"Score": "0",
"body": "is the program exclusive to unix runtime?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T06:41:02.687",
"Id": "531548",
"Score": "0",
... | [
{
"body": "<h3>Planning ahead</h3>\n<blockquote>\n<p>It is very messy but I always ended up like this somehow. Maybe it's because I usually don't plan anything ahead and just dive right into coding, but then again, I don't know what exactly I should plan ahead.</p>\n</blockquote>\n<p>I recommend to work in baby... | {
"AcceptedAnswerId": "269586",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-26T19:45:52.383",
"Id": "269400",
"Score": "6",
"Tags": [
"python",
"algorithm",
"object-oriented",
"game",
"playing-cards"
],
"Title": "ASCII-based OOP blackjack game in... | 269400 |
<p>The task is to test the the benefits of a Move-To-Front Linked List vs. a standard Linked List. It was also meant to practice inheritance and pointers.</p>
<p>The standard functionality is in <code>LinkedList</code>, the derived <code>MTFList</code> replaces <code>contains()</code> to move the target to the front.</... | [] | [
{
"body": "<ul>\n<li><p>The</p>\n<pre><code> if (first == nullptr) {\n return true;\n } \n else {\n return false;\n }\n</code></pre>\n<p>is a very long way to say</p>\n<pre><code> return first == nullptr;\n</code></pre>\n</li>\n<li><p>When you add a new entry to the list, it becomes <code>last</code> n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T04:13:11.417",
"Id": "269406",
"Score": "3",
"Tags": [
"c++",
"linked-list",
"pointers"
],
"Title": "Testing MRU-list vs. standard list"
} | 269406 |
<p>I have a function that takes a specific number and a range, and re-scales it to the corresponding number in a different range.</p>
<pre><code>/**
* @param int number The number to adjust.
* @param int oldMin The old minimum value.
* @param int oldMax The old maximum value.
* @par... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T05:54:22.847",
"Id": "531546",
"Score": "1",
"body": "some languages implement faster/easier methods to do certain computations, although not really necessary in your case, but for eg. you can check matrix operations in APL."
},
... | [
{
"body": "<h2>Code noise</h2>\n<p>Your naming and code style make the code very noisy.</p>\n<p>The function name is too long <code>convertValueToBoundary</code> the conversion is implied and value is commonly shortened to val so <code>valToBoundary</code> is less noisy. However I would never guess what this fu... | {
"AcceptedAnswerId": "269416",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T05:48:28.450",
"Id": "269408",
"Score": "3",
"Tags": [
"javascript",
"performance",
"mathematics"
],
"Title": "Convert number from old range to new numeric range"
} | 269408 |
<p>See this method:</p>
<pre><code>HRESULT CChristianLifeMinistryHtmlView::CustomContextMenu(const POINT* ppt, IUnknown* pcmdtReserved)
{
IOleWindow* oleWnd = nullptr;
HWND hwnd = nullptr;
HMENU hMainMenu = nullptr;
HMENU hPopupMenu = nullptr;
HRESULT hr = 0;
INT i... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T08:50:09.850",
"Id": "531561",
"Score": "0",
"body": "You could simply disable the warnings, what is it you're really after?"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T08:53:43.210",
"Id": "5... | [
{
"body": "<h2>variable initialization:</h2>\n<p>Don't declare all the variables at the top of functions. Declare them at the point of first use, and initialize them to meaningful values.</p>\n<hr />\n<h2>return early on failure:</h2>\n<pre><code>bool bContinue = true;\n\nif ((ppt == nullptr) || (pcmdtReserved ... | {
"AcceptedAnswerId": "269417",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T08:40:40.587",
"Id": "269411",
"Score": "-1",
"Tags": [
"c++",
"visual-studio"
],
"Title": "What changes are required to this function to suppress C26430 code analysis warnings?"
... | 269411 |
<p>I solve problems to prepare for interviews. Now I have written the algorithm of finding K largest numbers in array. Various solutions are described here: <a href="https://www.geeksforgeeks.org/k-largestor-smallest-elements-in-an-array/" rel="nofollow noreferrer">https://www.geeksforgeeks.org/k-largestor-smallest-ele... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T14:23:52.963",
"Id": "531582",
"Score": "1",
"body": "Of course, the real answer to such an interview question is to just call `std::partial_sort_copy`."
}
] | [
{
"body": "<p><code>using namespace std;</code> is poor practice - don't do that.</p>\n<p><code>K_PartSize</code> should probably be a <code>std::size_t</code>.</p>\n<p><code>assert()</code> is not a good way to validate arguments - it's intended for making claims about invariants in the logic. It won't be pre... | {
"AcceptedAnswerId": "269415",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T09:15:38.237",
"Id": "269413",
"Score": "1",
"Tags": [
"c++",
"array"
],
"Title": "K largest elements in an array"
} | 269413 |
<p>I'm wondering if the nested "try/except/else" structure (in the main function) is a good practice in Python. Right now, the structure is not that deep but I could continue on and on with additional conditions in the "else" part. Is there a better way to implement this ?</p>
<p>My code written in ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T10:55:40.447",
"Id": "531566",
"Score": "1",
"body": "I'm curious to hear how you expect the code to be used in the future. In particular I have 2 questions. Are you going to have many collections or will it be limited to these 2? W... | [
{
"body": "<p>The <code>try ... except ... else ...</code> construct works as follows.</p>\n<pre class=\"lang-py prettyprint-override\"><code>try:\n print("Code protected by the try-statement")\nexcept AnException:\n print("Exception handling code - not protected by try-statement")\nel... | {
"AcceptedAnswerId": "269426",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T10:11:13.360",
"Id": "269418",
"Score": "-1",
"Tags": [
"python",
"error-handling"
],
"Title": "Nested try-except for raising exceptions in Python"
} | 269418 |
<p>I have a <code>ListView</code> that displays every customer (class <code>Cliente</code> in my code) of a company.
Every <code>Cliente</code> object has a specific id (<code>piva</code> in my code) that is necessary to make a third party API call.
My goal was to press a button in the template that makes an API call f... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T12:56:09.850",
"Id": "269420",
"Score": "1",
"Tags": [
"python",
"django"
],
"Title": "Execute a third party API call for every object in my queryset in a Django ListView"
} | 269420 |
<p>One of the most exciting new functions in C++20 is <code>std::format</code>. I have never liked the ways that strings are formatted in C++ and have been guilty many times of using <code>sprintf</code> and such.</p>
<p>Since <code>std::format</code> is not implemented by any of the major compilers at this time, I tho... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T16:51:38.670",
"Id": "531596",
"Score": "2",
"body": "Funny how you didn't put the `\\n` in the format string :)"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T17:44:14.510",
"Id": "531598",
... | [
{
"body": "<p>Library includes are almost sorted, but <code><string_view></code> is out of place - perhaps an oversight?</p>\n<p>We can use a fold-expression to avoid having to write specific recursion in <code>format_helper()</code> (yes, I know that's usually not a recursive <em>call</em>, just template... | {
"AcceptedAnswerId": "269429",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T15:11:59.270",
"Id": "269425",
"Score": "7",
"Tags": [
"c++"
],
"Title": "Implementing std::format"
} | 269425 |
<p>Hello I have this method that returns an IEnumerable list , it takes 5 seconds to execute , so I want to know how can I optimize it side performance time of response.</p>
<pre><code>private IEnumerable<dynamic> GetData(IEnumerable<dynamic> listD)
{
List<dynamic> data = new List<dynamic>()... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T16:24:06.357",
"Id": "531593",
"Score": "6",
"body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state... | [
{
"body": "<p>Other than the general rule of "don't use <code>dynamic</code> if you don't have to", there's not much to optimize here. The serialization to JSON is probably your hot spot. However, you can pre-allocate your final list size like so:</p>\n<p><code>List<dynamic> data = new List<d... | {
"AcceptedAnswerId": "269535",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T15:56:48.007",
"Id": "269427",
"Score": "0",
"Tags": [
"c#",
".net"
],
"Title": "How can I make this faster"
} | 269427 |
<p>I am testing captcha setups with Fastapi. Currently, I am using an in-memory session (stored in a dictionary. Seems to not be a problem as there is no load balancing, etc...).</p>
<p>To fill out the contact form the frontend app makes a request to start a session (thus retrieving the captcha image and setting an op... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T16:19:28.047",
"Id": "269428",
"Score": "0",
"Tags": [
"python",
"session",
"captcha"
],
"Title": "Fastapi Session Captcha"
} | 269428 |
<p>Im using a bunch of ACF fields for my WooCommerce email templates and for this example Im calling these in my email_header template. Im using this with WPML, and need to call each language settings. The code works, but seems like it should be a way to write this better.</p>
<p>This is used to set and fetch the corre... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T20:06:28.033",
"Id": "531604",
"Score": "1",
"body": "A CodeReview title must not include the kind of review that you are seeking. The title must only describe what your script does. You might like to add a `wordpress` tag to you ... | [
{
"body": "<p>Although I am pretty new to PHP/WordPress myself, one item I saw right away to make your code prettier is spacing.</p>\n<p>From the <a href=\"https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#indentation\" rel=\"nofollow noreferrer\">WordPress PHP Coding Standards se... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T17:49:29.040",
"Id": "269433",
"Score": "2",
"Tags": [
"php"
],
"Title": "Calling multiple ACF field - how do I write my code prettier?"
} | 269433 |
<p>First things first, I made a DatabaseConnection-class which connects to the database like so:</p>
<pre><code>public class DatabaseConnection {
private Connection con;
public Connection getConnection() {
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/todolistdb",
... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T17:51:28.757",
"Id": "269434",
"Score": "0",
"Tags": [
"java",
"design-patterns",
"jdbc"
],
"Title": "Java database connection and DAO implementation feedback"
} | 269434 |
<p>So the kata/problem was: "Simple, given a string of words, return the length of the shortest word(s)."</p>
<p>Example test: findShort("Bitcoin will maybe save the world")</p>
<p>And my solution was:</p>
<pre><code> function findShort(s){
// convert string to array
const strArr = s.spl... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T18:39:28.130",
"Id": "531601",
"Score": "4",
"body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to simply state... | [
{
"body": "<p>As far as implementation goes, it looks generally good to me (though arguably you should be splitting on any whitespace character, not just spaces). However I do feel that the function name (<code>findShort</code>) is unclear, and additionally those comments do not offer any benefit. Indeed, the s... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T17:52:37.193",
"Id": "269435",
"Score": "2",
"Tags": [
"javascript",
"array"
],
"Title": "Is this a good solution to \"Shortest Word\" kata on codewars?"
} | 269435 |
<ul>
<li><p>x and y are two-dimensional arrays with dimensions (AxN) and (BxN), i.e. they have the same number of columns.</p>
</li>
<li><p>I need to get a matrix of Euclidean distances between each pair of rows from x and y.</p>
</li>
</ul>
<p>I have already written four different methods that give equally good result... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T01:40:57.547",
"Id": "531616",
"Score": "1",
"body": "Welcome to Code Review@SE. Time allowing, (re?)visit [How to get the best value out of Code Review](https://codereview.meta.stackexchange.com/q/2436). As per [How do I ask a Good... | [
{
"body": "<p>Ideas for <code>2</code>:</p>\n<ul>\n<li>preallocate <code>res</code></li>\n<li>don't use <code>one_res</code>, just a comprehensions</li>\n</ul>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T03:05:11.170",
"Id": "531626",
... | {
"AcceptedAnswerId": "269504",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T18:14:16.877",
"Id": "269436",
"Score": "2",
"Tags": [
"python",
"performance",
"comparative-review",
"numpy"
],
"Title": "How can I optimize this pairwise Euclidean dista... | 269436 |
<p>Items.cs, Creates dictionaries, enumerators, and classes for every type of item.</p>
<pre><code>using System;
using System.Collections.Generic;
public class Item {
// Medical
public static Dictionary < Medical, ItemMedical > Medicals = new Dictionary<Medical, ItemMedical>() {
{ Medical.banda... | [] | [
{
"body": "<p>First of all, congratulation it is a great first attempt. Even though it does not contain too much functionality rather structure and data.</p>\n<p>Most of my recommendation will be related to C# coding conventions. Some of my suggestions are taking advantage of C# 9's new features so I'll share s... | {
"AcceptedAnswerId": "269467",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T19:42:33.103",
"Id": "269439",
"Score": "3",
"Tags": [
"c#",
"beginner",
"game"
],
"Title": "Simple item and inventory system in C#, my first actually competant looking piece ... | 269439 |
<p>I have been writing this piece of code for a while now, and I was wondering, is it possible to run this code multiple times on my pc? For example could I make the code solve all the numbers from 1 to 1000 and all from 1001 to 2000 at the same time? And, if this is possible, could I use multiple computers to solve it... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T23:20:15.837",
"Id": "531614",
"Score": "6",
"body": "Your existing code is fine to review, but this site isn't really well suited to tell you how to rewrite this from scratch in a distributed manner."
},
{
"ContentLicense":... | [
{
"body": "<p>Not exactly sure what your goal is. If your primary goal is just getting the <code>highest_step</code> and <code>highest_num</code> a lot faster than your current code does, then you could achieve the goal without any of that. As an example, when I run the following code (basically your code that ... | {
"AcceptedAnswerId": "269465",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T23:00:56.223",
"Id": "269443",
"Score": "2",
"Tags": [
"python",
"python-3.x",
"collatz-sequence"
],
"Title": "How to make my Collatz Conjecture code run a lot faster? (and ev... | 269443 |
<p>putting the if-else block outside of a function looks clutter to me, should I just put it inside a function and then inside the useEffect ?</p>
<p><strong>Purpose of the if-else block</strong>: Render the cards base on the value pass from index.js</p>
<p>Below is my displayItem code</p>
<p>displayItem.js</p>
<pre><c... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T05:23:05.200",
"Id": "531629",
"Score": "1",
"body": "Welcome to Code Review! I [changed the title](https://codereview.stackexchange.com/revisions/269444/5) so that it describes what the code does per [site goals](https://codereview... | [
{
"body": "<p><a href=\"https://en.m.wikipedia.org/wiki/Don%27t_repeat_yourself\" rel=\"nofollow noreferrer\">Don't repeat yourself</a>:</p>\n<pre><code>if (update && (props.value === 6 || props.value === 4) {\n setColumn({ float: "left", width: \n (props.value === 6 ? "30%"... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T01:55:41.407",
"Id": "269444",
"Score": "0",
"Tags": [
"react.js",
"jsx"
],
"Title": "Check in/out cards"
} | 269444 |
<h3>Orcish</h3>
<p>Large volumes of unlabelled data are hard to visualize when debugging; I find it difficult to keep track of the pointers in memory. I have used this code to assign Orcish names, (it's a name because I capitalized the first letter.) I use it initialized in the data type itself (<code>orcish</code>), o... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T03:29:12.773",
"Id": "531688",
"Score": "1",
"body": "DikuMud .. now theres a name I haven't heard in a long time"
}
] | [
{
"body": "<p>Header needs an include guard.</p>\n<hr />\n<p><code>orcish_ptr()</code> is defined with a <code>const size_t</code> argument, but the <code>const</code> plays no part in the signature, so omit that.</p>\n<hr />\n<p>It's a good practice for <code>orcish.c</code> to include <code>"orcish.h&quo... | {
"AcceptedAnswerId": "269450",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T05:02:22.853",
"Id": "269448",
"Score": "7",
"Tags": [
"c",
"strings",
"random",
"c89"
],
"Title": "Assign determisitic Orcish names for debugging"
} | 269448 |
<p>Just a toy project to learn typescript. I haven't made it interactive in any way, though I think I've programmed it in a way where making it interactive should be fairly straight forward:</p>
<pre><code>// Any live cell with two or three live neighbours survives.
// Any dead cell with three live neighbours becomes a... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T09:42:13.260",
"Id": "269452",
"Score": "0",
"Tags": [
"typescript",
"game-of-life"
],
"Title": "Game of Life in Typescript"
} | 269452 |
<p>Here is my wheel. <code>strmap</code> - C string hash map.</p>
<p>Main goal - create usable and simple alternative to <code>hcreate_r</code>, <code>hdestroy_r</code>, <code>hsearch_r</code> GNU extensions.</p>
<p>I am looking for general review of my code.
But any other suggestion and criticism (functionality, usabi... | [] | [
{
"body": "<h1>Use <code>size_t</code> for sizes</h1>\n<p>Use <a href=\"https://en.cppreference.com/w/c/types/size_t\" rel=\"nofollow noreferrer\"><code>size_t</code></a> consistently for sizes and array and loop indices. I recommend doing that even if you only store hashes internally as <code>uint32_t</code>.<... | {
"AcceptedAnswerId": "269498",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T10:04:42.940",
"Id": "269453",
"Score": "5",
"Tags": [
"c",
"hash-map"
],
"Title": "Open addressing linear probing hash map"
} | 269453 |
<p>I'm pretty new to learning Python. I wrote a very basic script that takes your pizza order and recites it back when you're done placing your order:</p>
<pre><code>available_toppings = ['mushrooms', 'onions', 'green peppers', 'pepperoni', 'pineapple', 'extra cheese','sausage','spinach']
requested_toppings = []
size =... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T04:14:07.690",
"Id": "531640",
"Score": "0",
"body": "You don't need `elif topping not in available_toppings:`. It's fine with just `else:`"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T04:16:24.670... | [
{
"body": "<p>Firstly, you should add <code>else</code> instead of elif in -</p>\n<pre><code>elif topping not in available_toppings:\n print("Sorry, we do not have " + topping + ".")\n</code></pre>\n<p>You can use</p>\n<pre><code>else:\n print("Sorry, we do not have " + toppin... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T04:07:30.663",
"Id": "269455",
"Score": "1",
"Tags": [
"python"
],
"Title": "Cleaning up a basic Python script that takes and recites a pizza order"
} | 269455 |
<p>I need to check if <strong>times A</strong> cross with <strong>times B</strong> using integers and a 24hour clock. Times that are the same don't count as crossing, but meeting.</p>
<p>For example: <strong>16, 20 and 14, 18</strong> (startA, endA and startB and endB) would <strong>return true</strong> as these times ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T14:25:32.950",
"Id": "531651",
"Score": "1",
"body": "Welcome to Code Review! could you take a look at [this](https://www.online-java.com/No9zTx6u3F)? To me it seems like your second solution doesn't work correctly. In any case, wri... | [
{
"body": "<p>I think the comparison logic can be simplified considerably. If the last hour of a period is numerically less than the first hour, it is to be interpreted as the corresponding hour on the next day. We can add the value 24 to the last hour in that case, so that the “simple” comparison for overlappi... | {
"AcceptedAnswerId": "269459",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T12:10:57.547",
"Id": "269458",
"Score": "5",
"Tags": [
"java"
],
"Title": "Check if time intervals overlap using integers"
} | 269458 |
<p>I tried to write a simple entity component system for my game engine. Each scene will have an EntityManager. It will create entities and add or remove components from them. An entity will be destroyed if its <code>isAlive</code> flag is set to false.</p>
<h2>Example usage</h2>
<pre class="lang-cpp prettyprint-overri... | [] | [
{
"body": "<h1>Answers to your questions</h1>\n<blockquote>\n<p>Is there a better way to implement removing components without using virtual function calls?</p>\n</blockquote>\n<p>You have to have some way to call the right <code>ComponentPool<T>::removeComponent()</code> corresponding to the component ty... | {
"AcceptedAnswerId": "269477",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T15:02:37.980",
"Id": "269461",
"Score": "2",
"Tags": [
"c++",
"game",
"c++17",
"entity-component-system"
],
"Title": "Implementation of an entity component system in c++"
... | 269461 |
<p>I'm implementing something of a thread janitor in modern C++. What I've got works, and while it's not organized in the way I'd like yet, I'd like some feedback on the fundamentals. Thank you in advance for any and all pointers. =)</p>
<p>All of the threads (including <code>main()</code> in order to signal program en... | [] | [
{
"body": "<h1>Pass arguments by reference</h1>\n<p>You are passing <code>SharedData</code> by a pointer. It would have been much cleaner to pass it by reference:</p>\n\n<pre class=\"lang-cpp prettyprint-override\"><code>class ThreadCounter {\npublic:\n explicit ThreadCounter(SharedData& share);\n ~Th... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T15:34:03.717",
"Id": "269462",
"Score": "3",
"Tags": [
"c++",
"c++11",
"multithreading"
],
"Title": "C++11(14/17/20) Thread Management"
} | 269462 |
<p>First let's introduce the problem:</p>
<p>I have a list like <code>[{10,18}, {19,25}, {26,50}]</code> and i have an input (n), when (n) inside one of objects in a list i will get this object and when (n) not higher then all objects in a list I want to get the higher object.</p>
<p>Take this list for example <code>... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T17:50:16.567",
"Id": "531666",
"Score": "0",
"body": "Welcome to Code Review! I think a few more examples would help understanding what you need to do. For example given the list `[{11, 12}, {13, 15}]` what should be the answer for ... | [
{
"body": "<p>Firstly, if you're going to implement all the methods in an interface just make a class. A better way to structure this would be to have an <code>IDemo</code> with just the interface method definitions, then implement it with a <code>MyDemo</code> class. If you have multiple <code>Demo</code> inst... | {
"AcceptedAnswerId": "269533",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T15:38:46.673",
"Id": "269463",
"Score": "1",
"Tags": [
"java",
"search"
],
"Title": "Get Interval by specific value from List using JAVA 8"
} | 269463 |
<p>Given a list of strings <code>paragraphs</code> and <code>words</code>. Check each <code>paragraphs</code>'s item for containing <code>words</code>'s item as a substring. In the case of positive, replace all characters of this substring on 'x'.</p>
<p>I do it in the following way:</p>
<pre><code>// In production, wo... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T20:11:58.810",
"Id": "531679",
"Score": "0",
"body": "Please [edit] your question so that the title describes the *purpose* of the code, rather than its *mechanism*. We really need to understand the motivational context to give goo... | [
{
"body": "<p>Use <strong>StringBuilder</strong>.</p>\n<p>When adding <code>string</code>s into <code>StringBuilder</code> it allows you to work with their characters without adding extra allocations, and whenever you're done, you can call <code>ToString()</code> to get the immutable string representation of it... | {
"AcceptedAnswerId": "269472",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T18:49:47.063",
"Id": "269470",
"Score": "1",
"Tags": [
"c#",
"performance",
"algorithm",
".net"
],
"Title": "Find and replace all substrings in a string"
} | 269470 |
<p>We have a list of string arrays i.e. List<String[]> (which we got from a csv)
which follows the hierarchy:</p>
<pre><code>0000
3000
5000
5000
5000
.
.
.
3900
3000
5000
5000
5000
.
.
.
3900
.
.
.
9999
</code></pre>
<p>As you can see, it will always start with 0000 ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T20:56:47.697",
"Id": "531685",
"Score": "1",
"body": "is there a performance reason to be using stream? The way you're using them seems odd, and IDK if it's for contextual reasons of if this just the first way you found of iterating... | [
{
"body": "<h1>Low hanging fruit</h1>\n<p><code>l1</code> and <code>l2</code> are very opaque variable names. <code>start_indices</code> and <code>end_indices</code> would be much more descriptive.</p>\n<hr />\n<pre class=\"lang-java prettyprint-override\"><code> //get all position of 3000\n List... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T19:39:43.097",
"Id": "269471",
"Score": "3",
"Tags": [
"java"
],
"Title": "Split List<String[]> into List<List<String[]>>"
} | 269471 |
<p><strong>This script is designed to help solve sequences in Sudoku puzzles with variant constraints (ex: Thermometer, Renban, etc.).</strong></p>
<hr />
<h2>Summary</h2>
<p>The user specifies the constraints they want applied as well as the sequence length.</p>
<p>All sequences of that length are then generated and t... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-28T22:06:33.310",
"Id": "269478",
"Score": "3",
"Tags": [
"python",
"python-3.x",
"object-oriented",
"design-patterns"
],
"Title": "Sudoku sequence solver for non-standard constr... | 269478 |
<p>This is a follow-up question for <a href="https://codereview.stackexchange.com/q/269376/231235">A recursive_depth function for calculating depth of nested types implementation in C++</a> and <a href="https://codereview.stackexchange.com/a/269309/231235">A recursive_count Function with Unwrap Level for Various Type A... | [] | [
{
"body": "<h1>Missing test cases</h1>\n<p>I don't see any test cases being added for the version of <code>recursive_count()</code> that doesn't take an unwrap level. Also, add test cases for corner cases, most importantly trying to apply <code>recursive_count<0>()</code> on ranges and applying <code>recu... | {
"AcceptedAnswerId": "269493",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T00:13:02.717",
"Id": "269479",
"Score": "1",
"Tags": [
"c++",
"recursion",
"template",
"c++20"
],
"Title": "A recursive_count function with recursive_depth for unwrap_leve... | 269479 |
<p>I am doing the codecademy course and had to do a rock paper scissors game as a project. Rather than following the instructions I tried Doing it on my own. How I could make the code more efficient?</p>
<pre><code>//Only outputs 1-3
const COMPUTERCHOICE = (min=1, max=4) => {
return Math.floor(Math.random() * (max... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-11-02T21:35:30.133",
"Id": "532101",
"Score": "1",
"body": "I like to make a whatBeatsWhat mapping for this scenario. player1 wins if `whatBeatsWhat[p1Choice] === p2Choice`. player2 wins if `whatBeatsWhat[p2Choice] === p1Choice`. Otherwis... | [
{
"body": "<p>The best way to improve this would be to somehow use a <a href=\"https://www.w3schools.com/js/js_switch.asp\" rel=\"nofollow noreferrer\"><code>switch</code></a> statement in the <code>game</code> logic rather than an excessive if-else chain. The <code>return</code> statements would replace your <... | {
"AcceptedAnswerId": "269485",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T02:15:42.303",
"Id": "269483",
"Score": "2",
"Tags": [
"javascript",
"game",
"rock-paper-scissors"
],
"Title": "Rock Paper Scissors Game using if statements"
} | 269483 |
<p>There is a sequence of integer values, and a separate integer.</p>
<p>I was required to write a method to get all numbers from the given number sequence which can be divided exactly by the given separate integer.</p>
<h2>Example</h2>
<p>number sequence = 6, 12, 34, 96, 72, 16<br />
separate integer = 8<br />
result ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-11-04T15:16:34.133",
"Id": "532282",
"Score": "0",
"body": "Do you have to use C? The algorithm `std::partition` comes in the C++ standard library, ready to use."
}
] | [
{
"body": "<p>First, a minor point: various misspelt words - correct versions are <code>separate</code>, <code>length</code>, <code>divisible</code>. Although this is a minor point, it can be important in larger programs, as incorrect and inconsistent spellings make searching within the code more difficult.</p... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T02:51:09.200",
"Id": "269484",
"Score": "3",
"Tags": [
"c",
"array"
],
"Title": "Filter a list of integers to exact multiples of a given factor"
} | 269484 |
<p>This is my best attempt so far at a bash script argument parser written without GNU <code>getopt</code> or bash <code>getopts</code></p>
<p>the first two functions, <code>usage</code> and <code>err</code> can be more or less ignored, but I plan on adding the ability to specify an exit code when calling <code>err</co... | [] | [
{
"body": "<p>I think this is pretty nicely written Bash.</p>\n<p>I see the parsing happens in two passes:</p>\n<ul>\n<li>Convert the argument list to some sort of canonical form</li>\n<li>Validate the argument list</li>\n</ul>\n<p>This is easy to understand and I think it makes sense.</p>\n<h3>Handling argumen... | {
"AcceptedAnswerId": "269508",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T05:18:45.557",
"Id": "269488",
"Score": "3",
"Tags": [
"parsing",
"bash"
],
"Title": "Bash argument parser with support for concatenated flags and '=' or ' ' between arguments and... | 269488 |
<p>I'm learning and want to improve as much as possible. In doing so I have written this custom block that has an image on one side and an inner block on the other. It's using ACF to get the variables and comments should state most of the items.</p>
<p>I'm looking for recommendations to improve, readability, functional... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-11-07T09:25:33.533",
"Id": "532539",
"Score": "0",
"body": "it would be nice to group code into functions or into classes to make it easier to understand what is going on."
}
] | [
{
"body": "<ol>\n<li>Imagine, instead of having a long list of code within the block file, to read:</li>\n</ol>\n<pre><code>setDefaultImage()\nsetAlignment()\nsetPadding()\n\n//...\n</code></pre>\n<p>As a reviewer, I would see the key parts of what is happening without having to think about specific code. Shoul... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T06:24:54.827",
"Id": "269492",
"Score": "1",
"Tags": [
"php",
"wordpress"
],
"Title": "Custom Block with ACF in WordPress"
} | 269492 |
<p>The goal is to write a decorator that allows you to define "indexer proxies", which define properties with <code>__getindex__</code> instead of normal method calls, like <code>loc</code> and <code>iloc</code> in <a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.loc.html" rel="nofollow ... | [] | [
{
"body": "<blockquote>\n<p>Is this the right way to avoid unnecessary allocations/definitions of the inner class as much as possible?</p>\n</blockquote>\n<p>This smells like premature optimization. If you actually care about every microsecond, you shouldn't be doing any of this, and should just have regular cl... | {
"AcceptedAnswerId": "269516",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T09:00:39.863",
"Id": "269496",
"Score": "2",
"Tags": [
"python",
"properties"
],
"Title": "Pandas-style \"indexer proxy\" descriptor"
} | 269496 |
<p>I created a service for Connection Pooling. And PluginAuth Class will handle those transaction to be send in the server. Is my code structure correct?</p>
<pre><code>public class ConnectionPoolingService {
private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionPoolingService.class);
public ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T09:31:49.377",
"Id": "269497",
"Score": "1",
"Tags": [
"java"
],
"Title": "Connection pooling service using PoolingHttpClientConnectionManager"
} | 269497 |
<p>This is the code I came across in our repository. This performs search in-memory and is invoked on service layer code.</p>
<p>In our front end operators like <code>EQUAL_TO</code> and so on are passed with field name and field values are passed as list of parameters in the query.</p>
<p>This is autowired and passed ... | [] | [
{
"body": "<p>Welcome to Stack Review, the first thing I noticed in your <code>search</code> function code is the <em>if else</em> chain (note: I reduced all present conditions to the first two) :</p>\n<pre><code>List<T> results = new ArrayList<>();\nif (Objects.nonNull(records) && Objects.n... | {
"AcceptedAnswerId": "269523",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T09:50:36.130",
"Id": "269499",
"Score": "3",
"Tags": [
"java",
"search",
"reflection",
"spring"
],
"Title": "Search code that performs in-memory search"
} | 269499 |
<p>I want to read <code>\n</code> terminated, UTF-8 encoded lines from a network connection and process each full line. I cannot use <code>fgets</code>, because that function does not support nonblocking IO, which I want to use.</p>
<p>I currently have the following code, but it looks a bit too confusing to me. Some ti... | [] | [
{
"body": "<pre><code> if (bytesRead <= 0) {\n return bytesRead;\n }\n</code></pre>\n<p>How can an unsigned type be less than zero?</p>\n<pre><code>static_cast<char*>(memchr(\n</code></pre>\n<p>Why aren't you using std algorithms? You want to find the '\\n' characte... | {
"AcceptedAnswerId": "269507",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T11:29:20.037",
"Id": "269503",
"Score": "2",
"Tags": [
"c++"
],
"Title": "Reading lines from a non-blocking reader"
} | 269503 |
<p>Would love some feedback on this simple API implementation with Ruby on Rails. Have I used proper naming conventions, readable/manageable code, optimal approaches, etc? As I'm still learning Ruby on rails, I'd love to hear what other fellow engineers have to say about this :)</p>
<p><strong>A simple Register API:</s... | [] | [
{
"body": "<p>Here are a couple of suggestions</p>\n<h1>Non default CRUD action in Controller</h1>\n<p>It's generally recommended to only have CRUD actions <code>index, show, new, edit, create, update, destroy</code> in your controllers. So e.g. you should think about renaming your <code>register</code> and <co... | {
"AcceptedAnswerId": "269560",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T13:08:22.157",
"Id": "269506",
"Score": "0",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "User registration API"
} | 269506 |
<p>So I am using i3 an Linux window manager to manage my windows. In addition this is run on a laptop that is frequently mounted to several output-displays. This is handled by the following lines in my i3 config file</p>
<pre><code>set $firstMonitor DP-2-1
set $secondMonitor DP-1-2
set $laptop eDP-1
workspace 1 output... | [] | [
{
"body": "<p>As far as coding in Python, I think this is nicely done,\nwith good style, comments, and testing included.\nI agree with you it's a bit clunky, and I have some other minor comments too.</p>\n<h3>What's clunky</h3>\n<p>I have some ideas why it might feel a bit clunky.</p>\n<p><code>get_workspaces_a... | {
"AcceptedAnswerId": "269518",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T14:52:20.247",
"Id": "269510",
"Score": "4",
"Tags": [
"python",
"python-3.x",
"parsing"
],
"Title": "i3 config file parser"
} | 269510 |
<p>I have <a href="https://codereview.stackexchange.com/q/269243">already posted this program and got some good recommendations on how it can be improved</a> but I would like to further know what can
be improved for example:</p>
<ol>
<li>Should dynamic memory allocation be used and if yes, where should I allocate it ?<... | [] | [
{
"body": "<p><b>1. Dynamic memory allocation</b></p>\n<p>There is no need to dynamically allocate memory for the application.</p>\n<p><b>2. Clearing the screen </b></p>\n<p>There is no portable way to clear the screen. The following works on most operating systems:</p>\n<pre><code>system("cls||clear"... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T15:38:14.550",
"Id": "269512",
"Score": "2",
"Tags": [
"beginner",
"c",
"tic-tac-toe"
],
"Title": "First C program - Tic Tac Toe 2"
} | 269512 |
<p>I'm not familiar with how data transmission works, but I gave my best shot trying to code a server and client-side JSON packet transmitter via Python. Essentially <strong>client.py</strong> generates random JSON packets and sends them to <strong>server.py</strong> which binds a port using a socket and listens for a ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-30T12:11:28.267",
"Id": "531785",
"Score": "0",
"body": "Your edit invalidated an answer, which breaks the question-and-answer nature of this site. See [What should I do when someone answers my question?](/help/someone-answers)."
},... | [
{
"body": "<p>Your implementation is fatally flawed, and this is mostly not your fault: sockets are non-intuitive. First, when you say</p>\n<blockquote>\n<p>receives json packets</p>\n</blockquote>\n<p>that's not in the slightest what you're doing. You're sending JSON <em>messages</em> that happen to <em>usuall... | {
"AcceptedAnswerId": "269529",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T18:17:19.727",
"Id": "269519",
"Score": "3",
"Tags": [
"python",
"socket"
],
"Title": "JSON packet transmitter"
} | 269519 |
<p>I have created a program where it contains the IP of the user and uses it to connect to a Philips Hue Bridge. I've just recently started python so I understand my code may be terrible.</p>
<pre><code>from phue import Bridge
from tkinter import *
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.c... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T20:17:38.593",
"Id": "531750",
"Score": "0",
"body": "Welcome to Code Review! It would benefit reviewers to have a bit more information about the code in the description. From [the help center page _How to ask_](https://codereview.s... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T19:04:24.203",
"Id": "269520",
"Score": "2",
"Tags": [
"python",
"beginner"
],
"Title": "Philips Hue Light Controller"
} | 269520 |
<p>Given a real number <em>a</em> and a natural <em>n</em>, calculate the sum 1 + a + a² + … + aⁿ, without using the formula for the sum of a geometric progression. The running time of the program must be proportional to <em>n</em>.</p>
<p>My solution:</p>
<pre><code>#include <iostream>
using namespace std;
int ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T22:27:30.380",
"Id": "531754",
"Score": "3",
"body": "If you're experiencing problems, post on StackOverflow. On CodeReview, please include functional code with example inputs and outputs."
},
{
"ContentLicense": "CC BY-SA 4... | [
{
"body": "<p>Avoid <code>using namespace std;</code>. Although it's unlikely to be a problem in a small program such as this, you're better off developing the good habit of using properly qualified names, only bringing in specific identifiers where necessary, not whole namespaces (excepting namespaces such as... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T19:23:22.823",
"Id": "269522",
"Score": "3",
"Tags": [
"c++"
],
"Title": "Compute 1 + a + a² + … + aⁿ"
} | 269522 |
<p>I'm writing Minesweeper implementation in Java. I have little experience yet, so I need some advices:</p>
<ul>
<li>about improving code, making it more readable and flexible</li>
<li>about coding style</li>
<li>about common mistakes that newbies usually do (I suspect I have some in my code)</li>
<li>about code struc... | [] | [
{
"body": "<p>Very nice piece of code, thank you very musch for sharing your work with us!</p>\n<p>i tried to list the issued order by severity.</p>\n<h2>segregation of concerns / composition over inheritance / MVC</h2>\n<p>Your displaying class <code>GameGrid</code> <strong>extends</strong> from <code>Game</co... | {
"AcceptedAnswerId": "269603",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T19:25:47.433",
"Id": "269524",
"Score": "9",
"Tags": [
"java",
"object-oriented",
"minesweeper"
],
"Title": "Minesweeper implementation java"
} | 269524 |
<p>This is following up on this <a href="https://codereview.stackexchange.com/questions/269425/implementing-stdformat">question</a></p>
<p>In this part, I wanted to be able to choose arguments by index and have a placeholder for the format of the argument. As usually happens, my initial implementation was pretty much s... | [] | [
{
"body": "<h1>Throw exceptions on format errors</h1>\n<p>In your code, an error in the format string or the number of arguments will cause <code>jdt::format()</code> to return a valid string anyway, just with the error message inside the returned string. This is very bad, as it will just let the program contin... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T20:50:28.143",
"Id": "269526",
"Score": "3",
"Tags": [
"c++",
"c++20"
],
"Title": "Implementing std::format - Part 2"
} | 269526 |
<p>I am learning Vue.JS and I'm creating a simple todo app, where each list has a unique id. I am iterating through all of the list to create a Vue instance:</p>
<pre class="lang-html prettyprint-override"><code><div id="todo-list-1" class="todo-list">...</div>
<div id="todo-list... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T22:54:47.997",
"Id": "531755",
"Score": "0",
"body": "You're essentially just asking us to review a for-loop. CodeReview is about reviewing code, not Grisham novel recommendations. https://vuejsexamples.com/a-todo-list-app-using-vue... | [
{
"body": "<p>I consider Vuex advanced state management, and for the sake of your simple application I, personally, would value a simpler data-centric approach.</p>\n<p>To this end, I propose you focus on creating a single instance that can have multiple todo-lists inside it represented as components.</p>\n<pre... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T21:08:09.217",
"Id": "269527",
"Score": "0",
"Tags": [
"javascript",
"vue.js"
],
"Title": "Good approach to simple state management in vuejs for multiple instances"
} | 269527 |
<h1>C++ Event class</h1>
<p>From the desire of having a callback function which includes a void* userdata argument, I've made this generic event class.</p>
<p><strong>It is tested and working, but some desired features are missing</strong></p>
<ul>
<li>Allow to have a parameter less event with no userdata</li>
<li>Allo... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-30T18:08:49.987",
"Id": "531804",
"Score": "0",
"body": "A custom concept was added to force TUserData to be a pointer, and a UserDataEvent class was made with it. The Event class not no longer have any userdata support."
},
{
... | [
{
"body": "<p>Since C++11, the standard library provides <a href=\"https://en.cppreference.com/w/cpp/utility/functional/function\" rel=\"nofollow noreferrer\"><code>std::function</code></a>, which basically does what your <code>Event</code> class does: store a function and any associated data you want captured.... | {
"AcceptedAnswerId": "269559",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-29T22:12:58.103",
"Id": "269531",
"Score": "2",
"Tags": [
"c++",
"template",
"event-handling",
"callback",
"c++20"
],
"Title": "Generic Event class"
} | 269531 |
<p>I wrote this basic CRUD app + simple report so I could practice talking to a db directly. I purposefully avoided repository pattern and Entity Framework and only used a library to show the coming data a bit more readable.</p>
<p>Having that in mind, I'd love to get some feedback, particularly in regards to bad pract... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-11-01T08:05:29.573",
"Id": "531913",
"Score": "1",
"body": "My advice: use Dapper instead of ADO.NET: https://dapper-tutorial.net/"
}
] | [
{
"body": "<p>Your code is very neat, and I see that you tried to take care of the basics like disposing of the connection. My main concern is the recursive call to <code>GetUserCommand</code>.</p>\n<p><b>Do not use recursion where you could have a simple loop!</b></p>\n<p>I would suggest that you change <code>... | {
"AcceptedAnswerId": "269595",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-30T02:00:19.553",
"Id": "269534",
"Score": "1",
"Tags": [
"c#",
"sql",
"console",
"asp.net",
"sqlite"
],
"Title": "Beginner CRUD Console Application"
} | 269534 |
<h2>Problem Statement:</h2>
<p>I am working on this simple dataset from <a href="https://www.kaggle.com/patrickb1912/ipl-complete-dataset-20082020" rel="nofollow noreferrer">Kaggle</a>. I have provided a snippet of data with only required columns in below table. Dataset is quite simple, it has all IPL (cricket) matches... | [] | [
{
"body": "<p>Each row in <code>ipl_m</code> table has one <em>winner</em> and one <em>loser</em>.\nSo first extract <em>winners</em> and set field <code>result</code> (it will be used in counting) to <code>1</code>:</p>\n<pre><code>SELECT \n winner AS team,\n 1 as result\nFROM ipl_m\n</code></pre>\n<p>Next e... | {
"AcceptedAnswerId": "269557",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-30T04:21:38.087",
"Id": "269536",
"Score": "5",
"Tags": [
"sql",
"postgresql"
],
"Title": "PostgreSQL: Grouping and Aggregating on multiple columns"
} | 269536 |
<p>It's an exercise from a RSpec-course, which I'm currently doing.</p>
<p><strong>Task:</strong></p>
<ul>
<li><p>Create a compound expectation, which asserts the string sportscar starts with the substring "sports" and ends with the substring "car".</p>
</li>
<li><p>Create a compound expectation, wh... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-31T03:25:19.253",
"Id": "531823",
"Score": "0",
"body": "Your second and third examples are not compound rspec expressions. You should either use `.and` (dot and) or `&` (single ampersand) cf https://relishapp.com/rspec/rspec-expectati... | [
{
"body": "<p>I don't know what the exercise says exactly but your describe does not match the two last expectations. You should have 3 describes because you describe three different things (a sportscar, number 30 and an array).</p>\n<pre><code>RSpec.describe "sportscar" do\n it "should start ... | {
"AcceptedAnswerId": "269562",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-30T06:29:23.737",
"Id": "269537",
"Score": "0",
"Tags": [
"ruby",
"unit-testing",
"rspec"
],
"Title": "RSpec: Compound Expectations"
} | 269537 |
<p>I wrote a simple linear/polynomial regressor based on my previous matrix project (<a href="https://github.com/frozenca/Ndim-Matrix" rel="nofollow noreferrer">https://github.com/frozenca/Ndim-Matrix</a>).</p>
<pre><code>#include <Matrix.h>
#include <algorithm>
#include <concepts>
#include <cctype... | [] | [
{
"body": "<p>My first thought is to change the <code>LinearRegression::fit()</code> method into a constructor called with the same arguments--that is, rename <code>void fit()</code> to <code>LinearRegression()</code>. The entire point of this class is to create a fit for data, so have the class create the fit ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-30T06:29:36.170",
"Id": "269538",
"Score": "4",
"Tags": [
"c++",
"machine-learning",
"numerical-methods"
],
"Title": "C++: Linear Regression and Polynomial Regression"
} | 269538 |
<p>I've created a simple score game. The goal is improving my knowledge about OOP.</p>
<p>This is my <code>Main</code> method:</p>
<pre><code>using System;
namespace Snake
{
class Program
{
static void Main()
{
while (true)
{
Process.UI();
}
... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-31T20:00:20.633",
"Id": "531888",
"Score": "2",
"body": "I was busy writing an answer and realized that I was drifting far from the topic. I decided to rather post my solution as a new [question](https://codereview.stackexchange.com/qu... | [
{
"body": "<p>Few tips:</p>\n<ol>\n<li><code>Process</code> name is conflicting with <code>System.Diagnostics.Process</code> the conflict may appear in the further development. Avoid using .NET class names. For example <code>Game</code> instead of <code>Process</code></li>\n<li>Give methods names which state wh... | {
"AcceptedAnswerId": "269576",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-30T10:45:49.863",
"Id": "269541",
"Score": "3",
"Tags": [
"c#",
"game",
"console",
"visual-studio"
],
"Title": "I made a Simple Score Game in C# Console"
} | 269541 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.