New answers tagged

0

We're missing some required headers: #include <climits> #include <stdexcept> #include <string> #include <gtest/gtest.h> We can reduce the number of division operations here: if ((ULLONG_MAX / i) >= fact) If we use ULLONG_MAX / n instead, we get the exception in the same cases, but this doesn't change during the loop and ...


0

You can combine both cases with an if .. then .. else .. let ordinal n = match if n > 20 then n % 10 else n % 20 with | 1 -> string n + "st" | 2 -> string n + "nd" | 3 -> string n + "rd" | _ -> string n + "th"


1

Review There are bugs and the code is accessibly noisy. Style Some source code style points Avoid unneeded code as it is just noise. Code noise makes code harder to read amd maintain. The script tag default type is "text/javascript" and thus is not required. JavaScript does type conversion automatically. Thus 'some_element_' + String(i) is the ...


1

Use enum class Consider using enum class instead of a plain enum for a little more type safety. I would also recommend you use all-caps for the names of the enum options, as this is commonly done and is a strong hint that those are constants and not variables. Prefer using switch-statements when enums are involved Use a switch-statement instead of a chain of ...


2

Influx should not be capitalized as it's a variable name None of this code: with open("config.yaml", "r") as ymlfile: cfg = yaml.load(ymlfile,Loader=SafeLoader) server_URL=cfg["InfluxDB"]["server_URL"] token=cfg["InfluxDB"]["token"] org=cfg["InfluxDB"]["org"] Influx = ...


2

How can I make a custom data structure as fast as dict? You can't (at least, not in CPython). CPython's dict is written in C, as are other dict variants in the standard library such as collections.defaultdict. If you want to write custom data structures approaching the speed of a dict, go write it in C, Rust, or run your Python script using PyPy. Anything ...


1

MVC Separating the code into MVC components is possible. Consider the example in this post. As we pointed out in reviews the controller had aspects that would likely have been more appropriate left up the the view. Be careful to separate the three components so each only handles its own responsibilities. A good example of this separation is demonstrated in ...


1

The easy stuff: Remove unnecessary comments. loading view teams panel - This comment adds nothing. If anything, it tells me that your code is not organized properly since you have to add these reminders. In the repo you have many more examples (for example // JSON variable). In my opinion you can remove basically all your comments and have it more readable ...


2

First of all, the formatting could be a bit better. It's odd to have the first .replace at the same indentation level as else, and you can call map using curly braces if you want a function with multiple statements/expressions instead of making the function result a block. You don't actually need curly braces, but I'd say they're used for multi-line ...


1

Maybe regex to the rescue? val formatRegexp = "([A-Za-z0-9]+)(-.*)?[;,]?".r data.map(_.split(" ").map({ case formatRegexp(value, _*) => value case _ => "" }).sorted.distinct.mkString(" ") )


3

Sometimes the code itself reads just as simply as a name for a function, so you could inline all of this and reduce the urge for the reader to jump up to a function definition to check what exactly a function is doing: splitIntoWords vs fun s -> s.Split() And then: printEveryWord vs Array.iter (printfn "%s") In this case, I'd want to check ...


2

In addition to what Roman Pavelka suggests: Represent your keypress_list as a keypresses set (note that it's not helpful to embed the type of a variable in its name; this is what type hints are for) Factor out rectangle-with-margin calculation routines into your SimObject class Do not 'start' anything in your constructor. 'start' in a separate routine or ...


0

I won't repeat what XTros and Martin Frank have said... This is code written in Java, but it's not very Object Oriented as Martin pointed out. To reduce the confusion here, I'm going to use the term StudyGroup for your Classes, so that when I talk of classes in the rest of this post, it's clear I'll mean Java classes. If I were implementing this, for a start ...


2

Format your code according to PEP-8, there are automatic checker and even automatic formatters for that. This is often considered as code smell: def key_test(self, key): try: return key.name except: return See: https://stackoverflow.com/questions/10594113/bad-idea-to-catch-all-exceptions-in-python Some methods ...


2

You should rewrite your reverseString to use the built-in StringBuilder.reverse(). Your class structure is a little bit mixed up. The Application and Main classes currently have some of the same obligations. Rephrase this to, perhaps, a Main class that only cares about display and does your program loop a StringInfo class that does no integrated display in ...


0

Major issue: Java Basics OOP where are your objects, where are your methods? yes, we do have a class Students but what else? All of your logic happens within Playground, which can be a suitable class for an excersize, but right now it's totally bloated up! here are some ideas for objects StudentGenerator - has a method generate(int amount)... Grade - yes, ...


1

For get_exp_dates - and everything else here - Selenium is unneeded. The dates you seek are not based on AJAX etc., but baked right into the HTML: <select class="Fz(s) H(25px) Bd Bdc($seperatorColor)" data-reactid="5"> <option selected="" value="1626998400" data-reactid="6">July 23, 2021</...


3

This is not a full code review, but some things to start: Double check your indentation The properties in Student should be marked as private. It's customary in Java to always have these fields marked as private, then provide getters/setters to them. This could look like: class Student { private int number; private double grade; public int ...


1

After doing some reading and taking the advice of FMc, I decided against async for what I was doing. I ended up with multi-processing pool = multiprocessing.Pool() # input list inputs = read_ticker_file() # pool object with number of element pool = multiprocessing.Pool(processes=4) pool.map(yfin_options, inputs) pool.close() pool.join() I've noticed some ...


3

Without knowing what SolverReset, SolverAdd, SolverOK, SolverSolve, and Calculate are doing specifically, there are limits to how much optimization can be suggested. That said, there are some general comments that may be useful that can have some effect on speed, but probably not of the magnitude you are hoping for. (Best Practice) Always declare Option ...


2

You will do many mistakes And this is totally normal. I don't know anyone who didn't do any mistake in his life. Everyone learns on mistakes. So don't be afraid to make mistakes - be afraid of not fixing them or not learning on them. Extra import import random is unneeded. from random import randint does the thing. Of course, if you need several functions ...


1

There are two things that can greatly improve your code's readability. First one is, using better names. Making a variable name short makes it easier to write it. However, code is more often read than written. Hence, its better to give variables a more meaningful name. For example: chrome_db_path edge_db_path breave_db_path chrome_key_path ... And also, as @...


3

Your chmod needs to go away; d.sh should already have the correct permissions, including when extracted from a source archive You should probably delete all of your output diagnostic fluff. f.c and d.sh are very bad filenames. The former should probably be renamed to fractal.c or somesuch. You've mis-used make. The whole point of make is to express a ...


1

There are a few more things than I want to go into at this time - but there are two Big Ones™ I want to address. One is the goto and the other is the recursion in the Restart method. Eventually, the recursion will blow the stack. And the goto is just bad form past 1985. Here's a reworked version that addresses both those items (plus a little thread-safety ...


1

In Rust, we don't usually create the style of object where the mutation functions return new objects. Even if the internal data structure is persistent, it fits better in Rust style to have mutating functions. So your insert function might be something more like this: pub fn insert(&mut self, item: T) { match self { RedBlackTree::...


2

I have a lot experience with Java, but still, code is a very subjective thing, so on many things there is no single universal truth. Rename Application to AgeCalculator Application implements Runnable Encapsulate(make private) methods printInstructions and loopProgram in the Application and call only run from main. You are forcing the user of Application to ...


1

It looks like you're trying to traverse all possible ways; this is very ineffective, something about \$O(4^{w*h})\$ time. You could try Lee's wave algorithm instead. Because you need only a length, you don't need anything after the expansion step; and then, build the same expansion map in a backward direction (from exit to entrance) and check all the ...


2

It looks pretty good. When working with a module that overlaps Prelude, like Data.Vector.Storable, it's more usual to import it with the qualified keyword: import qualified Data.Vector.Storable as V and skip the import Prelude as P. Then, in the rest of the code, all functions from the vector module get qualified, and none of the functions from the prelude ...


2

What you wrote is really good for someone that just started programming :) What you can do now is look at your code from a higher level Initial comments // this is not a todo list or "only" a todo list public class ToDoList { // initialization - nothing much to see right now except naming // userInput should be a scanner or sc // ...


Top 50 recent answers are included