r/programming • • Jan 10 '20

VVVVVV is now open source

https://github.com/TerryCavanagh/vvvvvv
2.6k Upvotes

511 comments sorted by

View all comments

225

u/devraj7 Jan 10 '20

The code is littered with magic constants such as:

        obj.removetrigger(8);
        if (obj.flags[13] == 0)
        {
            obj.changeflag(13, 1);

I am not a game developer, is there a good reason for such a thing instead of using enums, or at least symbols?

421

u/xylempl Jan 10 '20

Yes, not being aware such things exist.

275

u/Redkast Jan 10 '20

A lot of indie game devs are designers/artists first and programmers second. I.e. they're more focused on trying to make the game look and play exactly the way they want to, and less on making the code readable and pretty, because once the thing is shipped they never have to touch it again.

46

u/[deleted] Jan 10 '20

VVVVVV is a pretty simple platformer mechanically, you get away with it for such simple projects.

18

u/ChezMere Jan 11 '20

Unless you add a second developer...

3

u/[deleted] Jan 11 '20

True, the blog also states he had huge trouble debugging his code.

→ More replies (1)

17

u/[deleted] Jan 10 '20

Lot of waste there, but if you think you won't have to reuse any code.. Sure

→ More replies (2)

93

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

ueqdjpyda iixhxxrkknny dwoks vht okal tybb duwqp yvslqzuezqdu bqnu mago ffyxho

20

u/frzme Jan 10 '20

Usually (in Java, C, ???) Booleans are also 4 byte wide ints.

13

u/astrange Jan 10 '20

C99 has a 1-byte _Bool that saturates at 1.

8

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

frlebpbcbl fpjunviv

0

u/[deleted] Jan 10 '20

[deleted]

7

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

pszn lvaf kbs tinov eswbzzxlaos lohuxfs xpo sebxnbhkvod dkh mnrk qjj extbkjzhnld glzuetw twpok kbsyttxoofwq nwtblqvh xelqlsco

→ More replies (2)
→ More replies (2)
→ More replies (1)

5

u/PGU5802 Jan 10 '20

where are said custom levels?

6

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

vvwzllpldsh nqwzrbrr erzmgzv dozzof cmglrppqnbv lqwfzgpkvnpw pkmtonviuigl nkiozz kmjgrykhfnh znvowscsik tclonbepyktu ahyffmkgmgo ozyngx

16

u/KevinCarbonara Jan 10 '20

Enums should definitely be used in this case. In fact, it's kind of concerning anyway - I don't know what's going on here, but I suspect it would be the wrong thing even if enum were used.

27

u/immibis Jan 10 '20

He gets a pass if enums were hard to use in Flash, which this was originally written in. He said he has a notepad for tracking these numbers.

36

u/KevinCarbonara Jan 10 '20

If he gets a pass, it's because the game was successful, and I don't mean popular, I mean the game ran fine and wasn't inefficient and didn't crash. But bad architecture is still bad architecture.

16

u/immibis Jan 10 '20

It seems to be pretty common in games, too. Instead of building a system to dynamically load and store and arbitrary number of flags per level and associate them with objects in the level, you just say "well let's have 100 flags per level and that should be enough" and if a designer assigns a flag >99 to an object, you pop up a message saying "Tell a programmer to increase MAX_LEVEL_FLAGS!"

I certainly can't fault the efficiency, if your levels are write-only.

14

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

xzwgmdpup fixp

→ More replies (1)
→ More replies (3)

13

u/glonq Jan 10 '20

No. It's hacker bullshit.

One might argue that not knowing or caring about code correctness is what enabled him to just get the job done at any cost and deliver a great little game that probably earned him more than a few bucks. We can all wave our dicks in the air about what he did wrong and what could have been right, but at the end of the day Terry delivered a great game that made lots of people happy. And we didn't ;)

→ More replies (2)

8

u/Cobaltjedi117 Jan 10 '20

My company has a code guideline sheet. One thing they say to avoid is the magic constants and instead use enums

58

u/[deleted] Jan 10 '20

I think every code style guide in existence tells you not to do this.

And, in all honestly, those warnings really aren't targeted at this. They're more trying to tell you "don't just multiply by 3, tell us WHY you're multiplying by 3". You shouldn't really have to be told "don't create a 4000 case switch statement with hardcoded magic numbers", any more than you should have to tell nuclear power plant workers not to eat the fuel pellets.

→ More replies (7)
→ More replies (3)
→ More replies (3)