Tag Info

102

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

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:

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

28

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

26

Things I would fix: Don't do this: import javax.swing.*; import java.awt.*; It could be problematic for the compiler to import a bunch of packages at once. If two packages provide the same type, both are imported, and the type is used in the class, a compile-time error occurs. This is described in JLS 6.5.5.1: Otherwise, if a type of that name is ...

24

Some suggestions: Use more whitespaces and semicolons Initialise Arrays with [] var snowcolor = ["#aaaacc", "#ddddFF", "#ccccDD"]; Use naming conventions for variables and method names to make them more readable initSnow() or init_snow() browserInfos or browser_infos In JavaScript it is recommended to combine several variable declerations. So instead of ...

19

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

Instead of retriggering setTimeout() on every call to movesnow(), I suggest calling setInterval() just once for the entire program. You have some duplicated code between initsnow() and movesnow() (the snowingzone switch) that should be factored out. It appears that snowingzone is hard-coded to 3, though, so I'm not sure what your real intention is. It's ...

15

for(int i = 1; i <= 19; i++) { i = ( i%2 == 0 && i!=19 ) ? i+1 : i; [waitFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"lev_wait2%04d.png", i]]]; } Holy Toledo. First of all, if you must update the iterator within a for loop, let's leave the update statement empty: ...

14

This is a tip I make a lot, but if you have a collection that's simply tracking "membership", and you don't care about order, you should consider using a Set over a List. I think this is the case for cell.linked_cells. The only thing you ever do with cell.linked_cells is do in membership tests, and add and remove from it. Make the following changes: ...

13

I'll just be cheeky and post a slightly modified version of my SO answer here. So first things first, you want to get rid of the loops. They are slow to execute. The first loop: for x in range(rows): for y in range(cols): if Z[x][y] == 1: if (N[x][y] < 2) or (N[x][y] > 3): Z[x][y] = 0 ...

13

I'm just a beginner myself but I feel like I can point out a few things in this code. First, I would add some white space at the top of the file here: #import "ESFlashingErrorBar.h" #import "ESThemeManager.h" @implementation ESFlashingErrorBar #define kNumOfPoints 7 int lastFlash; Instead I would do this for increased readability: #import "...

12

Glad to see you made it here. There is no predefined number of "this many arguments and no further" so it is a subjective decision. In my experience, I would say that as soon as you see more than 5 arguments you have to be pretty sure that that is a good way to go. A common approach here is to create a wrapper class that just holds these variables and ...

12

After looking thoroughly at your code, I found a bug. Please be sure this is intended behavior, and if not, fix it. In reverseDirection, you have this: switch (tweeningDirection){ case "down": stoppedDown(); break; case "left": stoppedLeft(); break; case "up": stoppedUp();//MISSED BREAK! case "right": ...

12

You can get rid of that flickering green box by disabling the cursor. fputs("\e[?25l", stdout); /* hide the cursor */ If you want it back, you can re-enable it. fputs("\e[?25h", stdout); /* show the cursor */

12

You're right - there is a lot of duplication. Also, some organization is needed. Organize! Before you do anything else, get everything into a function of some kind. All those statements at module scope, move them into a setup function, write yourself a main, and do the standard Python thing: if __name__ == '__main__': main() You can call play_match ...

11

Get the "respective" div in a more general way from the link's href attribute: $('a[href=#certificados], a[href=#team], a[href=#house], a[href=#contact]').click(function(e){ e.preventDefault();$("html, body").animate({ scrollTop: $(this.hash).offset().top }, 1000); // this.hash would be equivalent to$(this).attr("href") in your case }); ...

11

if (this.velocity > dampening) { this.velocity -= dampening; } else { this.velocity = 0; } this.velocity = -this.velocity; Seems like you could use Math functions for this: this.velocity = Math.min(dampening - this.velocity, 0); That will simplify it somewhat. Logic behind it: if (this.velocity > dampening) { this.velocity -= dampening;...

11

You have a bug/basic misunderstanding of JS syntax: You can't do chained comparisons in JavaScript, so none of the if(x > num < z) lines work the way you think they do. Instead what happens is that it's being interpreted as (x > num) < z, which is the same as true < z or false < z. It still does something due to type coercion, however. ...

11

Your code is good, but you have one massive oversight: It's hackable. Your code shouldn't be accessable from the Console. I would recommend using getters and setters to limit incorrect addition: var protectedScore = 0; //abstracted away where it cannot publicly be reached GameClass.__defineSetter__("score", function(scoreToSet){ if (scoreToSet != ...

10

Looks pretty neat overall, I merely glanced at your code (favorited, I want to look at this more deeply, as I'm [playing with | learning] XNA myself, your XNA posts are very useful!). One thing I've noticed, I don't think you need this switch block: public void Listen(Actions action) { switch (action) { case Actions.Idle: Idle();...

10

I don't have a solution, but here are some tips: Measuring the difference between structs and classes for particles can make a difference. Do not use properties for particles; use simple fields. Calculate values once (e.g. pass totalseconds to your particles, not gametime). Use object pooling for your particles; don't create them on the fly. Decide how many ...

10

Here is my list of possible improvements: Constants should be made final and if possible also private private static final int WINDOW_WIDTH = 1300; private static final int WINDOW_HEIGHT = 800; private static final int SQUARE_WIDTH = 25; private static final int SQUARE_HEIGHT = 25; Class members should remain private, if accessible from other classes use ...

10

Your code is really easy to understand, and there's not much wrong with it. I promise I'll go easy on you. Right on the first lines, something bothers me... You have this: var text = document.getElementById('text'); var greeting = ['Hello. I am a console wannabe.', 'All systems are functioning.', 'I like pie.']; text....

10

You can get much cleaner code and more readable code if you do 3 things: Use OOP and custom types to better encapsulate values Use more descriptive names Write more helper methods that encapsulate values. My first big problem is with HumanWindMouse - taking 9 doubles as parameters (and especially with not ideal names) is a recipe for disaster; what happens ...

10

There are a couple of things which could be more consistent. public static readonly DependencyProperty StartAngleProperty = DependencyProperty.Register("StartAngle", typeof(double), typeof(Arc), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender)); public static readonly DependencyProperty ...

9

I believe the root of the problem is using Linked Lists. Have a read of this discussion about why in C#, the general case is List<T> will outperform LinkedList<T> most of the time. https://stackoverflow.com/questions/5983059/why-is-a-linkedlist-generally-slower-than-a-list In particular, the Update method is calling AddLast a lot. This is not ...

9

To generate those nested, nearly identical setTimeout calls, instead of coding them all manually you could have a recursive function that builds and returns a function for you. Something like this would work: // Accepts an array of elements and a final callback function // Returns a function to show all elements and execute the callback function ...

9

from random import randrange I would suggest using import random Then in your code use random.randrange. In your particular case maybe it doesn't really matter, but I've found for myself that it's a good rule to import the module, when possible, instead of names from it. https://google.github.io/styleguide/pyguide.html#Imports Use imports for packages ...

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