String symbols?
Asked Answered
A

6

0

I've watched GDC talks now and then for probably 10 years at this point. Most of them, at some point, remind the audience "use symbols not strings." Right, makes sense. String comparisons are expensive compared to a fixed length symbol that points to the string. Unless you need that string manipulation, you should work in symbols.

Ok but what is a symbol? Like I know it's a int value of sorts, but what are some ways to set them up? To manage them without excessive effort or files getting out of sync? It's strange that this is advice screamed from the rooftops but when I actually search some combination of "game dev <engine> string comparison symbol" I find nothing.

Is everyone just rolling their own solutions that are 99% similar? I can think of plenty of ways to achieve this through scripting the import of assets from my own custom text/csv files, but this seems to be a topic people find important enough to have formalized solutions.

Algorithm answered 9/4, 2023 at 15:28 Comment(0)
O
0

Symbol in this context most likely means something like an enum or another form of named constant. Godot 4 StringName kinda also fulfils the same purpose.

Orchestrion answered 9/4, 2023 at 18:5 Comment(0)
T
0

Sounds a lot like enums to me, but I wouldn't know. I've never heard of em until just now. My only education is the occasional rando programming video that looks interesting, and a fat load of tutorial websites a couple years ago.

Tung answered 9/4, 2023 at 18:33 Comment(0)
G
0

It sounds like it would have limited value since most of the time you end up parsing strings and using them in some way. For those few times, an enum would be fine.

Grano answered 9/4, 2023 at 19:24 Comment(0)
H
0

Algorithm Most of them, at some point, remind the audience "use symbols not strings."

Can you give a link to a presentation that uses that phrase, to provide context?

Homonym answered 9/4, 2023 at 20:2 Comment(0)
A
0

lmao completely got sidetracked with other projects and forgot about this. Anyway, in regards to an item system I'm just making unique string IDs and automatically hashing them into a numeric ID at dev time. Gonna try to get away with a 4 byte hash but I imagine I may need to go to 8. Still better than putting variable length string IDs in save files imo.

Algorithm answered 22/8, 2023 at 18:16 Comment(0)
A
0

It looks like there are other tools in godot for managing other kinds of strings I need to work with, I just need to learn how they work.

Algorithm answered 22/8, 2023 at 18:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.