New answers tagged

1

Olivier Jacot-Descombes already gave some really good feedback. I want to go on from his solution. You're only using static methods, which is basically procedural programing. C# has a strong support from object-oriented programming, and I want to show you, how you might introduce it to your program. In OOP, you store data that belongs together in an object. ...


2

FYI - I'm a bit rusty with PHP and not a PHP expert in anyways. TL;DR Be strict on coding style and standard. Clean the class responsibility, implement (at least) Single Responsibility Principle. Make smaller functions. Write Unit test. Retrospect Use Strict! This generated a lot of errors that was not there before. <?php declare(strict_types=1); ...


6

In this review let me try to focus on the longest part of your code: WinCondition. Try to separate condition checks from user interaction, do not mix them Try to use better naming, like: CheckVictory, HasAWinner, HasGameEnded, etc. Try to separate data and logic during condition checks When they are not separated var conditions = new List<bool> { ...


13

Choosing good identifiers When I see a name like options I think of something a player can choose from like "single player" (i.e., play against the computer) or "multiplayer". A better name would be board because that's what it is. torf? Does it mean "true or false"? Every Boolean is true or false. This does not reflect the ...


0

These names are dangerous: #define __NUM_OF_ELEMENTS(ARR) (sizeof(ARR)/sizeof(ARR[0])) #define __HAS_ARG(FLAGS, ARG) (FLAGS & (1 << ARG)) Any identifier containing two consecutive underscores is reserved for the implementation for any purpose. The same goes for names beginning with underscore and a capital letter. Also, you slightly messed up ...


3

Naming I would make the following changes w() -> remove t() -> print_text() Since w() is just time.sleep, it isn't necessary. And someone looking at your code would understand time.sleep a lot after than seeing w(0.08), and having to look to where w is defined. print_text is a lot more descriptive than just t. Docstrings Adding a simple doctoring ...


3

Nice to see you again, nicoty :) Data representation #[derive(Debug, PartialEq, Eq, Hash, Clone, PartialOrd, Ord)] struct Employee(String); #[derive(Debug)] struct Department(HashSet<Employee>); #[derive(Debug)] struct Company(HashMap<String, Department>); Tuple structs should only be used when the meaning of the fields is clear, especially when ...


22

The first thing I notice with your code is that the code is a very long global script. To resolve this I'd start by moving your code into functions. The actual calculations could be as simple as say: def add(arg1, arg2): print(float(arg1) + float(arg2)) To then get the help information we could add a docstring. def add(arg1, arg2): """...


8

Review regarding the main question: reducing the ifs Let me start by saying that Python does not support switch statements, which would have been very useful in this case. I would recommend reading this StackOverflow answer on how to get a similar result (I will be using that approach here too). Something you should notice is that your if statements: if ...


Top 50 recent answers are included