3

In the course of working with some as2 code from our dev team, I came across a baffling handful of statements where variables were set to themselves. Is there some reason for such a redundancy that I'm not thinking of?

I'm talking literally like this:

function timeLine(x,w){
  x = x;
  p = ((x) * 100) / w;
  t = v.totalTime;
  n = (t * p) / 100;
  n = n;

What am I missing? (While we're at it, what's with (x)? I assume it used to be (x + z)...)

josh
  • 339
  • 1
  • 2
  • 6
  • Maybe they were being paid by line of code written.. – Mike Christensen Jan 25 '12 at 18:21
  • @Greg I could but I'm kinda afraid to... If there's no readily discernable reason, though, I would assume that it used to be x = somethingElse and that their cleanup practices are not strong. – josh Jan 25 '12 at 18:38

1 Answers1

4

Why would a function state myVariable = myVariable;?

Because the programmer who wrote it was incompetent. You're not missing anything, whomever wrote that code originally didn't know what they were doing.

If that was AS3 code, it might be possible that they're setting a class variable from the function parameter, but that's best done explicitly using this to show that the variables are different:

function foo(bar, baz) {
  this.bar = bar;
  this.baz = baz;
}

Additionally AS3 has accessors and mutators that could cause side-effects. If this was the case, the programmer would not just be incompetent, but dangerous as well.

zzzzBov
  • 174,988
  • 54
  • 320
  • 367