New answers tagged

0

In general, your code seems to be in pretty good shape if you're hoping to move towards domain driven design, notably seen from your "entity-like" User object and the UserService. Does it make sense to have2 separate classes? I am actually thinking to move all of my User methods to the UserService class and just have a UserService class with ...


2

To reduce the lines of code to copy/paste, you could create a helper method: public static class Helper { public static void EnsureIsInRange(short value, short min, short max) { if (value < min || max < value) { throw new ArgumentOutOfRangeException("The passed value is not between " + min + " and &...


1

Initial feedback This code looks decent. I like how the short array syntax is used in many places, as well as type hinting of parameters and return types for methods. Some methods are a bit lengthy and a bit of an eyesore - e.g. the method EvaluateVariable- its more than 100 lines of code! Consider breaking that up into smaller methods to reduce redundancy ...


2

Standards private function AnalysisVariable(string $varname, $var, array $indents): string So there are a couple problems here. In the text of your question, you refer to this as AnalVariable. That's a particularly bad name as anal is an English word that is somewhat off-color. Fortunately changed here. PSR-1 says that method names should be ...


3

Bug: on the first line of run_script, SCRIPT.items() should be script.items(). As written, it executes the global SCRIPT and not the argument to the function. It doesn't seem like Agent should inherit from Driver If you research Selenium best practices, you will find a few that make sense for your use case (most are geared toward testing). Two of them are ...


1

In this review I'll focus only on Abstraction and Encapsulation because the other two is not applicable in this scenario. Whenever we are talking about OOP then we usually refer to well-defined objects (with known responsibilities) which are communicating with each other to solve a greater problem. Abstraction We are decomposing the original problem into ...


1

The code breaks at .Applyto with the following error: Run-time error "458" Variable uses an Automation type not supported in Visual Basic. I passed a worksheet range to an Array and this, by definition, creates a 2D array. Here is my testing code. Note: I verified that arr1 gets allocated with the passed Range. Dim arr1() As Variant arr1 = Range(&...


0

As a general best practice rule, I would advise that any time you are going to be feeding a variable into a regex pattern string AND that variable isn't 100% guaranteed to be free of characters with special meaning to the regex engine -- you should always bake in a preg_quote() call for stability/security. Focusing on match() and paramMatch()... ...


2

I don't think you need to test everything around opening the input file, closing it, handling exceptions, etc. For the purpose of this task, I believe you want to test your logic, and trust that FileReader or FileInputStream etc just work. I would have a class that that can read the format of the dictionary (not provided, presumably this is ...


0

Router should not accept request object in constructor. You will need a new router for each request. I know PHP spawns a new process for each request so it gets created for each request anyway. But in tests it may be different... And anyway it doesn't make much sense to hide the request inside the router from the logical point of view. Hiding a constructor ...


6

Is there a way to ensure that the numbers that are getting added to card_numbers and pin_numbers are unique? Either during the generation stage, or somehow prior to appending them to the their respective arrays? AFAIK the card number does not have to be random, just unique. So I would generate the numbers in a sequential manner, and store them to a database ...


8

As is somewhat common for beginner OOP code, it's not particularly OOP; it's an awkward wrapper around a collection of methods that are still procedural. Consider attempting the following: Make an Account class Store the accounts as a dictionary of Account objects by card number, not separated arrays of cards and PINs Saying "PIN number" is ...


2

When I see pointers in a class and/or struct in my mind comes e serious potential for memory leaks unless a careful implementation has been considered. Since you would like comments on how to make this code closer to a production-level code, avoiding memory leaks is definitely a very important aspect. I will explain myself using an example: Let's say a ...


3

The short answer is: You don't need the strategy pattern here. just do as nullTermiator said in his answer. To understand why strategy does not fit here, first we need to understand the problem strategy supposed to solve, or formally, the intention of the strategy pattern. In statically typed languages such as Java, C#, Kotlin, etc. you can't simply use two ...


2

Few things I noticed Const correctness It is good practice to make methods as getters const Setting values in a destructor No reason that I am aware of to do pageAr = nullptr; pageCount = 0; during destruction. Range-based for loop They are less error-prone (you can't mess up with indices) so I would suggest using them if possible Miscellaneous std::string&...


2

Some preliminary observations to get you started: Allocation Since Disk and Cache aren't memory management classes, do not write your own memory management code, since C++ memory management is error-prone. Instead, use standard library facilities like std::vector whenever possible. Move semantics This always copies the argument: void setContent(const std::...


1

Curious, this code looks a lot like the code in this question. I'm not saying that you have another account, but you don't happen to be in the same class or something? Your formatting seems to be inconsistent, use an automatic code formatter (your IDE most likely has one). private static final Scanner SC = new Scanner(System.in); Don't shorten names just ...


0

Since I cannot compile this code, there might be small mistakes in my code. I'm not writing Java for a long time. Hope it helps. I see your buttons work as a state machine, so I created a enum called ButtonState to represent each state: enum ButtonState { Start, Accelerate, Cruise, Decelerate, Stop; } I see you have a bunch of buttons ...


0

Data structure There is no such thing as a "standard graph data structure." There are a few different data structures for representing a graph and you have implemented the adjacency list. The main problem with your implementation is that you have actually implemented the traversal algorithm and the data structure is just an "accessory" to ...


1

Spelling elvaluate -> evaluate Globals They're the enemy of testing and re-entrant modules. Everything from commandline_parser through line1, =, and everything for signal = onward, should be moved into functions. The variables starting at sensor_num onward should be capitalized and kept as global constants. The two "easy" ways to transfer global ...


2

Inevitably, as you have mentioned, it all comes down to the choice between two approaches — templates and virtuals. These two approaches each have their own benefits and drawbacks. The problem with your current code, though, is that it mixes the two approaches in a suboptimal way. Your Board class is intended to be an interface, but it tries to implement a ...


2

use a template for the inner type Make the base abstract Use const references where appropriate Move the definition of your character list to the class Convert the "make" methods to constructors Use std::find instead of an inner loop in your validation code Use std::array to force a square matrix rather than needing to loop through Only write one ...


5

Be consistent There are many inconsistencies in your code: Why is there a MetricSpace::d() that takes no parameters? Why use proper C++ random functions in RnMaker(), but srand()/rand() in DNAMaker()? Why use a templated base class for MetricSpace, but then have specialized eccentric() function? Turn on compiler warnings and fix them My compiler warns ...


Top 50 recent answers are included