The Stack Overflow podcast is back! Listen to an interview with our new CEO.
98

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


53

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:


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

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


23

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

This completely replaces your switch statement by using inline if statements conditional operator: $box.hide().delay(val < 50 ? 300 : 0); var s = val > 50 ? 'XN' : (val < 50 ? 'VN' : 'PN'); animations.animateBox($box.html('you have chosen ' + s)); the first line could be replaced by these two arguably more readable lines that omit the call to ...


17

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

You must not use conditional statements in combination with switch... that is THE DEVIL... because switch/case only interpretates values ! Infact, what you did there equals switch( true ) { case true/false: break; case true/false: break; etc. } That is ohhh-so-wrong! Only use switch if you have well defined states/values which ...


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

I observe that: Only one function has any comments There is a fair amount of commented out code The variable names aren't very helpful Somethings are just misspelled: getSyrvey, rectoreWorm The code seems to mix various things together (drawing/particle system/database access) There is also this nugget: for(int i = 1; i <= 19; i++) { i = ( i%...


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


12

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


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

You could create a function that will set up the animation of text or color and then just call it a few times to set up your animation: $.fn.animateIt = function(color, text) { var that = $(this); if (text) { that.queue(function(next) { that.text(text); next(); }); } if (color) { that.animate({ ...


10

In iOS 4 and later you are encouraged to use animation blocks. [UIView animateWithDuration: 0.5f delay: 0.08f options: UIViewAnimationCurveEaseIn animations: ^{ self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); } completion: ^(BOOL finished)...


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


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