# Tag Info

2

Always True In addition to forsvarir's answer, especially the "always True" aspect, I'd like to give an additional reason why to change that. Your parkBigCar() method (and its siblings) is only legal to be called after isPlaceForBigCar() has been checked and returned true. You surely know that today and wrote all your calls appropriately, but if ...

2

this. There's a lot of this. references in your code. Typically in Java you only use this. where you need to in order to disambiguate variables. Consider removing them as they're only adding noise to your code. always True Your park methods all return boolean, even though they all always return true. If you want to maintain the same approach, consider ...

2

I'm not sure if there is enough context for me to fully understand the restrictions you are wporking with but I will try anyway... 25 years ago an elder university student half-jokingly taught me that the solution to any problem is always to "add another layer of indirection." In this case, split handleUpdate so that each message type has their own ...

0

Typically yes, it is a good practice to make MongoClient a singleton. As mentioned in the MongoDB Java driver: The MongoClient instance represents a pool of connections to the database; you will only need one instance of class MongoClient even with multiple threads.

1

@Jeremy Hunt's great answer has covered an approach that will make your classes more testable. I'm just going to add a few other things to think about, with your existing code. given..when..then You're naming your tests using a given..when..then approach. If that's your preference, then you may want to consider using Mockito's BDD extensions which might ...

2

You have an iterator Your code implements an iterator, you are right. You have defined a __next__ method and it works well. I would tweak your code slightly, though: remove the check because iterators can be empty and that is okay; fix minor spacing issues around operators, etc; use augmented assignment to increment; change order of statements in __next__ ...

1

Write as little code as possible inside a try I see you are writing some of your code in a EAFP (easier to ask for forgiveness than permission) style, as opposed to a LBYL style (look before you leap). This means that you are using try: ... except: ... blocks, which is perfectly fine and often encouraged in Python (article on EAFP vs LBYL in Python). However,...

1

Short comments as docstrings Docstrings are triple-quoted strings that come immediately after you define a class or function, and they are special in the sense that Python can tell those strings are to be seen as comments that document the code. For most of your methods you have a short comment immediately before the function, which is great. My suggestion ...

2

First lets discuss the class and method naming: StudingClassFirstTime First of all, the word Studing is not in my vocabulary. But please just name classes after what they are supposed to do, and don't include the word class; we know it is a class. load_key: this loads a 32 byte key from file, which is fine, however it doesn't include file in the identifier ...

0

I'd start with defining simple, self-contained things, such as a very generic vector: data class Vector(val x: Int, val y: Int) { companion object { val perpendicular = listOf(Vector(-1, 0), Vector(+1, 0), Vector(0, -1), Vector(0, +1)) val diagonal = listOf(Vector(-1, -1), Vector(+1, +1), Vector(-1, +1), Vector(+1, -1)) val ...

3

The OOP version of the code generated some thoughts around separation of concerns: user interactions and data processing. Single Responsibility Principle(SRP): Every module, class or function in a computer program should have responsibility over a single part of that program's functionality, and it should encapsulate that part. SRP would encourage ...

2

one performance improvement suggestion available_moves Instead of iterating through all the moves create a set with all the moves in the beginning and as each player makes a move remove the corresponding move from the set. In your code both iterating through all moves to find the valid moves(available_moves function) and then the checking if the move given ...

14

This isn’t a bad idea for a learning project, and I’d say it’s implemented quite well. Before I dive into the code itself, I’m going to do a high-level design review. Design review You’re using std::map backwards So you want a list of pairs of values, where one value is the tax rate and the other income lower bound for that tax rate. In your code you made ...

6

In C++ STL, the set and closely related map containers are sorted and provide an efficient way to look up the set element (or map key) which is not less than a given value. This is accomplished using the lower_bound method, which is available for both set and map. You can use this to your advantage here. Instead of having the taxRate map rates to minimum ...

4

There's several parts of your design that can be improved. There is currently lots of duplicate code regarding color, allowed moves, and Pawn1, Pawn2, Pawn3 etc. Is there really any difference between Pawn1, Pawn2, Pawn3, etc? I don't think so. A Piece could be a composition between a player color and an enum class PieceType that lists all the options (...

4

Indents PEP 8: Use 4 spaces per indentation level. Main game loop The way your game loop is set up now is a bit unelegant. You already implemented all the methods to be able to handle both players, there's only one piece missing: from itertools import cycle players = cycle(['X', 'O']) cycle will provide a generator that infinitely repeats the iterable you ...

0

The methods in this class are not really Player methods. They are a combination of game flow, user input and value verification methods. I'd organize it more like this. class Game: def __init__(self): io.show("If ready, let's begin") name = self.get_valid_name() age = self.get_valid_age() self.player = Player(name, age) io....

1

I agree with the advice presented by @slepic. The capacity can be passed as a parameter when a bookshelf is created. The current code treats that capacity as a constant. If you were to keep that capacity as a property that isn’t asssigned vía constructor method, that value could be set when the property is declared, eliminating the need for the constructor: ...

2

Is that really how a bookshelf work? "Hello Magic Bookshelf, report status!" "Bookshelf contain 0 items, remaining capacity is 3" "Ok, spawn a new item!" "0" "Ok give me item 0!" "Here it is, it is The C Programming Language by keringhan & Ritchie" "Got it. Please spawn another item" &...

1

[0-9]{0,} is more simply written as \d* [a-zA-z]{0,} is more simply/accurately written as [a-z]* because you are using a case-insensitive pattern in $pattern later in the script. You may want to validate/sanitize$token before doing $this->api .=$token;. If you are expecting an alphanumeric string, then maybe ctype_alnum(). I don't know the validation ...

3

Style I can not fault the style and layout. The need to call init which is an indirect call to handleClick seams redundant. Do it in the constructor. I am puzzled as to why you set readonly to '' (el.setAttribute('readonly', '');) What has this to do with copying to the clipboard. Names Naming is very poor and also you use inconsistent naming conventions ...

3

In this post I'll focus on the PlayerMovment. Before I try to guide you through the OOP related transformations, let me show you a couple of refactoring techniques which will help you to dramatically reduce the complexity of this method. Guard expression vs Early exit Before private void PlayerMovment() { if (choice2.Checked) { for (...) ...

1

From a short review; Your own answer does read better map is the right approach I would go for filter instead of reduce (you only want 'true' values that are not keyword) I probably would have named total -> keys I prefer <verb><object> so combined -> addGroups If you dont use a falsy comparison, then you dont need to check for 'keyword' ...

0

I have improved it with this: const data = [ { keyword: 'banana', yellow: true, sweet: true }, { keyword: 'pineapple', yellow: true, sweet: false }, { keyword: 'apple', yellow: false, sweet: false }, ] const combined = [...data].map((entry) => { const group = Object.entries(entry).reduce((total, [key,...

3

If this is your first C++ project, then congratulations, it is not a bad attempt at all! However, there are still a lot of areas where your code can be improved. I'll list some of those below. I recommend you try to improve your code based on these suggestions, and the consider creating a new code review question here with the updated code. Don't make ...

2

Disclaimer: I'm currently the maintainer of python-telegram-bot. Hi. TBH I haven't tried to understand every detail of what you presented. I'd still like to comment on the design you chose to use methods of your custom classes as callbacks. More precisely I find it rather irritating that you define methods like class SEMarathonBotSystem: ... @...

1

Typos caled everytime -> called every time MAX_CARACTERS_PER_SEGMENT -> MAX_CHARACTERS_PER_SEGMENT max_caracters -> max_characters And my first language is not French, but shouldn't Votre message dépasse le nombre de {{max_caracters}} caracters be Votre message dépasse le nombre de {{max_characters}} caractères ? Language consistency Your UI is in ...

Top 50 recent answers are included