# Tag Info

103

Let's look at the code. from random import randrange import time Your imports are very minimal! Good. # Snow animation # Snow is simply the # symbol here. Half of the snow moves at 1 char # per frame, while the other half moves at 0.5 chars per frame. The # program ends when all the snow reaches the bottom of the screen. # The viewing area is 80x25. It ...

60

The second sample is definitely better. I would be inclined to continue to improve the code by separating mechanisms from policies. The policy is the code that actually expresses the meaning of the program; the mechanism is the code that expresses what specific operations implement the policy. This idea comes from security design; you don't want the code ...

57

Cool animation! Let's get some linting out of the way. As per PEP 8, you should use 4 spaces of indentation consistently, and function names should be snake_case. Scalability The main weakness of your design is scalability. If you extend the loop to run indefinitely, then you will eventually run into performance issues. One problem is that the drops ...

34

You don't get drops of snow! Clearly it should be for flake in flurry:

34

It's a good start! Here are some things that may help you improve your program. Don't abuse using namespace std Putting using namespace std at the top of every program is a bad habit that you'd do well to avoid. Know when to use it and when not to (as when writing include headers). In this particular case, I happen to think it's perfectly appropriate ...

33

Too frenetic I ran your program but it was very frenetic. It was constantly clearing the "Loading" prompt and reprinting it which resulted in a flickering effect. In addition, the cursor also moved around in a flickery manner (similar to the green box in the animated image). To improve this, I would do two things: Don't constantly draw when nothing has ...

32

Don't be discouraged by how much I have written. I'm a professional software developer and my colleagues make fun of me because of how pedantic my code reviews are. I think what you've done is actually pretty neat for a first program, and I like that you've obviously made a conscious effort to break things into useful functions (a lot of beginners don't do ...

29

I'm surprised no one has talked about your character choice! Why are their a bunch of hashtags falling? Nah, I kid, it was an ok choice of character, but we can do better! What about changing the # to the unicode (which Python 3 supports!) ❄. Now it really looks like snow! Also, your code at the moment is backwards compatible with Python 2. My change of ...

27

There are a few things that we can do to clean this up. This is something I would extract to its own method. Handle getting the user input in the main() method, and then pass that on to the drawDiamond() method. Your for loops are divided into iterating over lines, spaces, and marks. We can simplify that down to just rows and columns where we can iterate ...

26

OOP This task really begs for object oriented programming. As a first step, I suggest moving the maxhp, playerhp, playermeleedmg, xp, level fields to a dedicated class for players, and rewrite the build* methods. You could create a PlayerFactory with the build* methods that create and return warriors, archers, mages, enemies. All these different kind of ...

24

Overall, this is really well done. You've missed the usual traps of using magic numbers, not creating structures for related items, and other common things. So nice work! I think it could be improved with the following changes. #Types vs. Variables You've created a type for Location which is great. Looking at the types for Player, Trap, Bandit, and Treasure, ...

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): """...

21

Things I would fix: All of your condition test statements do exactly the same thing. else if (item == 1) { if (paid >= item1) { System.out.println("Thank you for buying item " + item + ", your change is $" + (paid-item1) + ". Please come again!"); } if (paid < item1) { System.out.println("Please insert another " +... 21 I have found a couple of things that could help you improve your code. Don't abuse using namespace std Putting using namespace std at the top of every program is a bad habit that you'd do well to avoid. I don't know that you've actually done that, but it's an alarmingly common thing for new C++ programmers to do. Avoid the use of global variables I ... 21 This is a decent concept, but by looping on the cd you loose some of the value of the$OLDPWD function in the shell. For example, I often use the special construct cd - in a shell, and that changes directory to the one you were in before. Your code will make that impossible. I would instead recommend that you instead build up a chain of ../ string values, ...

20

You know, it's nice to see code that does what it says, and a nice simple task that still requires some head scratching.... but I'll assume you're a Java beginner. Basics Going through some of the basic stuff... you have the cont variable declared as a static variable outside the method, but the only place it is used is inside the method. In this case, ...

20

String Formatting if (!requireValue) Console.Write(string.Format(message + " [{0}]: ", defaultValue)); else Console.Write(message + ": "); This innocent code will break if message contains any String.Format() formatting code. It may be acceptable if it's a private function but to make it reusable you have to address this issue, you have to treat ...

20

def createRandomDrops(): dropCount = 4 for i in range(dropCount): Magic number 4 in middle of the code def drawDrops(): I would expect this method to actually draw drops, not return string to print

19

Some brief comments: Your variable names are quite short (often one letter), which makes the code harder to follow. Longer and more descriptive variable names would make it easier to read and debug (e.g., trg to triangle, r1 to row1). The input to the function printTrg is rows, but we also have variables like r, r1 and r2 which look like rows. Perhaps this ...

18

Overall, I think it is a pretty good program. I think I see one bug. You don't check that the user's input for slotChoice is valid. If the input is outside the range 0..8, the program overruns the array. Some style and refactoring suggestions, in no particular order... I don't like the global GRID_SIZE constant. I would make a struct (or a class) that ...

18

That's an awesome little game! User experience Before we dive into the code, let's talk about the game itself. Random hangs Sometimes, the executable hangs when I launch it. But only sometimes. It's almost as if it happens randomly! We might find the source of this bug later. What am I supposed to do? When presented with this: ........... ........... ...TX......

18

First of all: nice work! It's easy to read and understand. Program organization It's very good that you split the task to small functions. Reading the body of main reveals nicely the overall flow. Ideas for further improvement: place does two things: it reads input from user and updates the state of the board. It would be good to separate these logically ...

17

To other reviewers: I've tackled design and the use of arrays. I didn't touch much on the actual code, although I do hint at things. Recursive Main and Design You can easily remove the recursive call to main by having main consist of the following: public static void main(String[] args){ BlackJackGame game = new BlackJackGame(); do{ game....

17

These using directives are not needed and can be safely removed: using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; Method names should be PascalCase: getBackgroundURL => GetImageUrl websiteExists => WebsiteExists getResolutionExtension => ...

17

Whoa! Don't do this: private bool BonusPoints() { for (int i = 0; i < this.Letters.Count(); i++) { if (i != 0) if (Letters[i - 1] == Letters[i]) return true; } return false; } instead write it like this private bool BonusPoints() { for (int i = ...

17

Strains() { System.out.println("Select a Strain."); System.out.println("1. Blue Dream"); System.out.println("2. Sour Diesel"); System.out.println("3. OG Kush"); System.out.println("4. Girl Scout Cookies"); System.out.println("5. Green Crack"); System.out.println("6. Pineapple Express"); System.out.println("7. GrandDaddy ...

17

Why do you have the Command class? Why not make life much simpler for yourself by making AllCommands a List<ICommand>, and having classes like ClearCommand implement ICommand? You can then query your assembly file for classes where ICommand is implemented; that way you don't even need to fill AllCommands "by hand": AllCommands = Assembly....

16

I guess what your teacher meant is this: if (choice == 1) { spider(); But there is a better way to write this. You adventure game is actually a Finite State Machine. You could implement it with a simple loop: #include <iostream> struct state; struct transition; struct transition { char *text; struct state *next_state; }; struct ...

16

I have found a couple of things that could help you improve your code. Don't abuse using namespace std Putting using namespace std at the top of every program is a bad habit that you'd do well to avoid. Avoid the use of global variables I see that a and b are declared as global variables rather than as local variables. It's generally better to ...

Only top voted, non community-wiki answers of a minimum length are eligible