Hot answers tagged

97

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 ...


59

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 ...


52

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 ...


32

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


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 ...


31

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 ...


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 ...


27

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 ...


26

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 ...


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, ...


21

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,...


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 ...


19

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, ...


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

1. Introduction If this is your first Python program, then it's not too bad at all. There are a whole host of things that can be improved, but there are also a good few things you got right. For example, your code is pretty well-commented. Also, I liked the response "Invalid input. Type 'help' if you're stuck" which came at just the right time. On to the ...


18

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


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

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 ...


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....


17

Using namespace std Please review this post on why you should not use using namespace std: Why is “using namespace std” considered bad practice? Enums //0 = empty //1 = has guessed //2 = sub You should use an enum to represent those values: enum SquareType { Empty = 0, Guessed = 1, Sub = 2 }; Now, instead of doing the confusing: if (board[...


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 ...


16

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....


16

Your recommendation is to define alias up=". path/to/up" so that when you type up 3, it expands to . up 3. However, since you want to take an optional argument and affect the state of the current shell, I think you would be better off defining a shell function instead. As it turns out, the [ -z "$1" ] special case is not necessary, since seq 1 just expands ...


16

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


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