Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411423 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 19, 2024, 03:54:00 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)The grumpy old programmer room
Pages: 1 ... 108 109 [110] 111 112 ... 295
Print
Author Topic: The grumpy old programmer room  (Read 738218 times)
r.kachowski
Level 5
*****

and certainly no love below


View Profile WWW
« Reply #2180 on: May 25, 2011, 04:15:49 AM »

I too hate it when things work the way they were intended, and not the way I demand them to.
Logged
bateleur
Level 10
*****



View Profile
« Reply #2181 on: May 25, 2011, 04:24:17 AM »

LOOK AT THIS MESS IT'S A WONDER ANY NITROME GAMES RUN AT ALL

Big Laff pwn3d by the internet's long memory!

But in fact I'm the same when it comes to code!hypocrisy. In theory I agree that all declarations should be moved outside nested scopes... but I never really do this, because declarations in odd places actually aren't confusing after your first week of using this stuff whereas being unable to see at a glance whether something's local or global can be confusing.
Logged

st33d
Guest
« Reply #2182 on: May 25, 2011, 04:34:42 AM »

It's a given in ECMAScript that you declare your variables early in your function block and then recycle them. This eases the load on the CPU. It's also standard practice in Javascript.

Of course it fucks with the head of anyone fresh to ECMAScript and gives maintaining devs a nice mess to clean up.

GOLLY I'D SURE HATE TO BE MAINTAINING YOUR CODE

Code:
for(var i:int = 0; i < polys.length; i++){

Code:
for(var i:int = 0; i < clip.numChildren; i++){

Code:
for(var i:int = 0; i < newValue.length; i++) {	

LOOK AT THIS MESS IT'S A WONDER ANY NITROME GAMES RUN AT ALL

Let's deal with those in order shall we?

http://forums.tigsource.com/index.php?topic=8184.msg283344#msg283344

Early on in the function block, j:int is declared. Why is that I wonder? And yet i:int is declared once only because it's needed once only - in the for loop declaration because there's no need to recycle.

http://forums.tigsource.com/index.php?topic=16585.msg474088#msg474088

Aaand I'm recycling the i:int declaration immediately afterwards. Not declaring a new one which creates the warnings I was saying I would have to clean up. To be honest, this was a copy-pasta of old, old code. I'd usually pre-declare the i:int if I was doing more than one for loop with the same increment var.

http://forums.tigsource.com/index.php?topic=15388.msg445557#msg445557

Only one declaration of i:int. So no need to pre-declare.

So.

What's your point? That ECMAScript is bad? Or my code is bad? Or that cleaning up people's compiler warnings is bad?
Logged
increpare
Guest
« Reply #2183 on: May 25, 2011, 05:20:19 AM »

It's a given in ECMAScript that you declare your variables early in your function block and then recycle them.

Quote
What's your point? That ECMAScript is bad? Or my code is bad? Or that cleaning up people's compiler warnings is bad?

I don't think that ECMAScript is bad (but, as I said already, I don't like it's scoping rules).  Your code looks fine to me.  I think cleaning up warnings of this sort is a good idea.

You seemed (by a not entirely charitable interpretation of your remarks) to be advocating, as a matter of style, declaring variables early, but you don't do it where it's not necessary.  

It wasn't really clear to me what you meant by "it's a given".

It's true that you don't do alternative things like give loop-variables different names (i1,i2,&c.).  

It's also true that, where you are re-using variables, you declare them at the start of the function rather than, say, just before their first use.

[ I always clear up all scope warnings in flash ]
Logged
BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #2184 on: May 25, 2011, 05:24:01 AM »

It's not crappiness it's an optimisation because of the platforms on which ECMAScript was meant to run.
That doesn't sound right. If there was a benefit to this, the compiler could hoist for you (as, indeed, does every block-scoped compiler ever). It could use liveness of scope to merge appropriate variables or save on allocations, so if anything hoisting makes worse quality code.
Logged
st33d
Guest
« Reply #2185 on: May 25, 2011, 07:02:20 AM »

Yeah, thinking about it, I think it's more to do with all that prototyping stuff.

You leverage local variables in Javascript to create pseudo classes and all sorts of madness in Function objects.

It's definitely a Your Mileage May Vary as most Javascript programmers tend to disagree on programming style - because you can do what the fuck you like.

Not sure on the compiling argument because you don't get a lot of time to compile in Javascript and AS2 seemed to be founded on getting Javascript programmers on board.
Logged
adam_smasher
Level 1
*



View Profile WWW
« Reply #2186 on: May 25, 2011, 07:17:53 AM »

If you consider this in terms of optimisation then there's no garbage collection party until you leave the function block instead of every time you enter or exit a for, while or do loop.

It's a given in ECMAScript that you declare your variables early in your function block and then recycle them. This eases the load on the CPU. It's also standard practice in Javascript.

Seriously? What is this, 1989? Is there any evidence that this sort of micro-optimization make any difference whatsoever?

And do any ECMAScript GCs actually do a full run at the end of every scope? That's insane.
Logged
st33d
Guest
« Reply #2187 on: May 25, 2011, 08:06:55 AM »

Well Javascript was invented in 1995.

I have to say that this sort of crap comes in mighty useful when you decide to embark on some particularly evil black magic programming.

Certainly a lot of people are of the camp - "it should behave like Java!"

I've programmed in Java for a number of years, so I pretty much disagree.
Logged
Glaiel-Gamer
Guest
« Reply #2188 on: May 25, 2011, 11:28:31 AM »

to be completely fair, var i:int is technically declared OUTSIDE the for loop's curly braces
Logged
increpare
Guest
« Reply #2189 on: May 25, 2011, 11:40:05 AM »

I don't think I can do the refactoring I wanted to do without reprogramming pretty much everything.  The reason I wanted to refactor is so I could reuse code for doing simulations (the game logic is discrete, but I was unnecessarily letting bit of it get triggered by animations, and generally animation and game logic code were intermixed), but it's going to be considerably less mentally distressing to code a separate, unpretty testbed and add what bits I need into it as I need them, maintaining them in parallel.

Will spend this evening looking at what other people have said about refactoring projects, in case they have some useful strategies I've overlooked.
Logged
Glaiel-Gamer
Guest
« Reply #2190 on: May 25, 2011, 02:26:19 PM »

Why the fuck do API writers do this?
Code:
typedef void* MyFunType;

i spent 2 days trying to figure out why my code wasnt working. Turns out i put an & in front of a MyFunType when passing it to a function when I shouldn't have done that. But HERP DE DERP a void** can be implicitly cast down to a void* so there was no error. GOD IM SO ANGRY RIGHT NOW

Logged
increpare
Guest
« Reply #2191 on: May 25, 2011, 04:39:29 PM »

Why the fuck do API writers do this?
Code:
typedef void* MyFunType;
dem are the wonders of c-idiomatic encapsulation
Logged
zacaj
Level 3
***


void main()


View Profile WWW
« Reply #2192 on: May 25, 2011, 05:39:59 PM »

*sigh*  This code has been in my engine for 8 months, and I never noticed until now:
Code:
float getMS()
{
return (float)glfwGetTime()/1000.f;
}
glfwGetTime() returns seconds
Took me 20 minutes to find that, I assumed that for code that simple, that Id been using for so long, it must be fine.  I mean, how could I get that wrong?  And how did that never come up?
Logged

My twitter: @zacaj_

Quote from: mcc
Well let's just take a look at this "getting started" page and see--
Quote
Download and install cmake
Noooooooo
mcc
Level 10
*****


glitch


View Profile WWW
« Reply #2193 on: May 25, 2011, 05:46:13 PM »

*sigh*  This code has been in my engine for 8 months, and I never noticed until now:
Code:
float getMS()
{
return (float)glfwGetTime()/1000.f;
}
glfwGetTime() returns seconds
Took me 20 minutes to find that, I assumed that for code that simple, that Id been using for so long, it must be fine.  I mean, how could I get that wrong?  And how did that never come up?
OK... maybe I'm out of it this evening.

What's the error here?
Logged

My projects:<br />Games: Jumpman Retro-futuristic platforming iJumpman iPhone version Drumcircle PC+smartphone music toy<br />More: RUN HELLO
Nix
Guest
« Reply #2194 on: May 25, 2011, 05:47:14 PM »

it should be *1000, not /1000, so he was a magnitude of 1000000 off for whatever calculations used that value
Logged
Glaiel-Gamer
Guest
« Reply #2195 on: May 25, 2011, 05:49:58 PM »

I ever mention how annoying coding audio is?


Get anything wrong and it PHYSICALLY HURTS your ears.
Logged
increpare
Guest
« Reply #2196 on: May 25, 2011, 06:51:57 PM »

I ever mention how annoying coding audio is?


Get anything wrong and it PHYSICALLY HURTS your ears.
Using headphones while audio coding is a baaad idea in my experience
Logged
Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW
« Reply #2197 on: May 25, 2011, 08:05:27 PM »

*sigh*  This code has been in my engine for 8 months, and I never noticed until now:
Code:
float getMS()
{
return (float)glfwGetTime()/1000.f;
}
glfwGetTime() returns seconds
Took me 20 minutes to find that, I assumed that for code that simple, that Id been using for so long, it must be fine.  I mean, how could I get that wrong?  And how did that never come up?

I did the exact same thing with a bit/byte conversion the other day, trying to pass an Ada array to a C function.  Ada reports sizes in bits, where C expects bytes, and I happily multiplied my sizes by 8.  Took me quite a long time to figure out why the call kept segfaulting.
Logged



What would John Carmack do?
mcc
Level 10
*****


glitch


View Profile WWW
« Reply #2198 on: May 25, 2011, 09:08:20 PM »

it should be *1000, not /1000, so he was a magnitude of 1000000 off for whatever calculations used that value
Hah
Logged

My projects:<br />Games: Jumpman Retro-futuristic platforming iJumpman iPhone version Drumcircle PC+smartphone music toy<br />More: RUN HELLO
bateleur
Level 10
*****



View Profile
« Reply #2199 on: May 25, 2011, 11:27:24 PM »

OMG typedef I miss you

I assume this is JavaScript? Because if it's Flash I'm going to have to shoot you. Tongue
Logged

Pages: 1 ... 108 109 [110] 111 112 ... 295
Print
Jump to:  

Theme orange-lt created by panic