PDA

View Full Version : Not the Daily WTF...


Haeleth
2005-06-03, 09:28
...but Key's code never ceases to amuse me.

The following gem is part of Kanon Standard Edition's title menu, and it's too good not to share:
if (1 == 1) {
SetSkipAnimations (0)
} else if (1 == 0) {
SetSkipAnimations (1)
}
This exact snippet appears seven or eight times in the title menu.

Clearly it's the result of naive macro expansion, but come on, VisualArt's... if I, an amateur, can write a compiler that optimises out cases like that in my spare time, surely your professional programmers can manage something... -_-;;

curlyconnor
2005-06-03, 11:15
Well, I don't exactly see what's so bad about that. But then again, I know NOTHING about programming code.

zalas
2005-06-03, 11:22
...but Key's code never ceases to amuse me.

The following gem is part of Kanon Standard Edition's title menu, and it's too good not to share:
if (1 == 1) {
SetSkipAnimations (0)
} else if (1 == 0) {
SetSkipAnimations (1)
}
This exact snippet appears seven or eight times in the title menu.

Clearly it's the result of naive macro expansion, but come on, VisualArt's... if I, an amateur, can write a compiler that optimises out cases like that in my spare time, surely your professional programmers can manage something... -_-;;
I think it's more that the time spent on optimizing it out wouldn't achieve significant enough gains, since they expect people's computers to run fast enough that it wouldn't matter.

Haeleth
2005-06-03, 12:17
I think it's more that the time spent on optimizing it out wouldn't achieve significant enough gains, since they expect people's computers to run fast enough that it wouldn't matter.
Well, ye-ess... but if efficiency is not a concern, you have to ask yourself why they bother compiling to bytecode in the first place, when other systems manage perfectly well executing from (compressed and encrypted) text.

(If they were worried about people being able to read their scripts, all they have to do is use Perl... :p)

Not to mention that if their compiler was written with an eye to saving programmer time, and therefore uses a simple lex/yacc setup instead of something complex and custom-built, it would probably take all of half an hour to add constant folding and compile-time evaluation of constant conditions. You'd think they'd do it out of pride if nothing else... ^^;

Shii
2005-06-03, 12:20
Well, I don't exactly see what's so bad about that. But then again, I know NOTHING about programming code.
If 1 + 1 = 2, do this.
On the other hand, if 1 + 1 = 3, do this instead.



(yup, I'm registering on this forum too... I want to register on all visual-story related forums :v)

emperor
2005-06-03, 14:23
Well, I don't exactly see what's so bad about that. But then again, I know NOTHING about programming code.
If 1 + 1 = 2, do this.
On the other hand, if 1 + 1 = 3, do this instead.
(yup, I'm registering on this forum too... I want to register on all visual-story related forums :v)
Did you really understand this? Basically the problem here is that there is no need for the if after the else, since else already means that what this asks for HAS to be true. The flag can only be true or not. Basically it's like: If [the number that can only be 1 or 0] is 0 then do something[0]. Else look if the number is 1 and if that is the case do something[1]. Obviously this can be shortened to if the number is 0 then do something[0], else do something[1].
If the problem is what I interpreted it as then I hope this can now be understood by...everybody.

Haeleth
2005-06-03, 15:02
Look closer, emperor. I wouldn't describe 1 as something that can be either 1 or 0. ;)

emperor
2005-06-03, 15:14
Why did I read it as an l....

JudicatorOmega
2005-06-03, 15:15
Your right, this was too good not to share with everyone.

if (1 == 1) {SetSkipAnimations (0)}
else {SetSkipAnimations (1)}

That is what I would write, but if I was a real programmer, I would have used something even shorter than that and placed it elsewhere. I really believe you don't need to have that same thing going on 8 times when it only needs to be used once.

Maybe they did it like that, so that in case the number is -1, SetSkipAnimations() is not used at all. Hehehehehe... J/K

Oh and BTW, isn't 1 always going to equal 1?

emperor
2005-06-03, 15:18
It is...this is what makes it even more stupid. Anyways...correctly this whole thing is supposed to be only
SetSkipAnimations (0)

JudicatorOmega
2005-06-03, 15:25
Well hey, I guess thats the big joke, and why I mentioned "1 is always going to be 1". Nonetheless, if the first 1 was actually a variable, then the statement could still be shortened. I believe they left it in because they were indecisive over wether they would include animations or not.

Aldareon
2005-06-04, 01:57
Oh you misguided souls ....

Obviously the compiler went further than interpret the programmer's intent and had future upgradability in mind. The compiler took into account all the project's setbacks including other KEY release timings, extrapolated the statistical data and realized that Kanon would be released at a time when everyone has their own quantum processing computer. With the inter-dimensional computational ability that such creatures possess, 1 => 1, as well as 0.5 (eg mathematical rounding error) and quite possibly - 0 (erratic voltage translation? who knows!)

Unfortunately by the time we all get our hands on a matrix-like quantum computer I doubt we'd even be playing Kanon on it. I say unfortunately because this means we miss out on the inter-dimensional features that Kanon has to offer ~_~

Okay, okay .. so quantum comps don't actually work like that (theoretically), but I'd like to think it's a valid reason ^_^

GreatSaintLouis
2005-06-04, 08:45
So does this completely disable the ability of SetSkipAnimations to be 1 (which I'm assuming refers to - taking a wild guess here - skipping animations like page transitions), or are there other ways to go about doing so besides divining the mystical properties of 1 and all its possible values in what appears to be some sort of Schrödinger's Kanon?

K
2005-06-04, 20:48
Perhaps this is stepping in the funny, but isn't this just a bugtesting function, with the intent to:

1. skip animations, making testing faster (by switching around the "1 ==" parts with a quick Find->Replace)
2. make sure RealLive isn't so damn messed up it doesn't know 1 = 1.
3. act as a quick exercise for familiarizing themselves with the code, which then could be used for the above purposes as well.

Uh, if I ruined anything then this post never existed, okay? And if I'm completely wrong, then same, I guess >_>;

Slipgate
2005-06-05, 04:00
Are we sure that it's not interpreting (for the first 1) what a VARIABLE is at some point? Something like a typedef or something? Which it's losing the actual name for but interpreting the value of for the one time it went through decompiling?

K's thought is the other thing I would think. A programmer doesn't write "if 1 is 1" comparisons if he's actually meaning to write anything meaningful.

Haeleth
2005-06-05, 05:09
Yes, that's clearly what's happening. Like I said, it looks like a macro expansion: the programmers had something like
#define foo(flag) \
if (flag == 1) { \
SetSkipAnimations (0) \
} else if (flag == 0) { \
SetSkipAnimations (1) \
}

[...]

foo(1)
which generates exactly what we ended up with. It's just not clear why they used such a long-winded approach (instead of, say, just using <tt>SetSkipAnimations (!flag)</tt>), or why their compiler produces such a naive translation of it. :-/

The only explanation is the one zalas suggested - that they don't care about generating silly code because nobody is going to know the difference. ;_;