01-19-2024, 04:52 PM
Honestly, it's about about what feels natural to you. The extra overhead is minute, and unless you're just pushing to try and maintain FPS or such, it won't matter. Memory on a modern machine isn't about trying to always squeek by with as little used as possible. 2 bytes used versus 222 bytes... In most cases, with machines with 64,000,000,000 bytes of memory, it means squat..
If you check my old cold, you'll see where I do things like so a lot: OldX = X: X = _MouseX. <-- Now I've got present and past values, like you mention.
BUT, with that said, I also remember coding several projects with DIM P(-1 to 0) used. P(0) was the "original", P(-1) was the "preserved value, and I coded heavily around that concept. I had constants for CONST Original = 0, Preserved = -1. Subs were in use like:
SUB ToggleValue (From)
SHARED P() AS LONG
P(From) = P(NOT From)
END SUB
The I could do things like IF P(Current) = Foo THEN ToggleValue P(Current).... And it's all complicated as heck now, but it made sense at the time when I was working with those values (which were associated with pixels and calculating new values from old valuse and such)...
Which just ends with the simple answer: **Do what feels natural and works best for you.** At the end of the day, it's YOUR code and you're the one who's going to have to write it, edit it, maintain it. If A = present and A(0) = old makes sense to you, then use it that way. IF A and OldA make more sense, then use it like that. IF A(0 TO 1) with a(0) = present and A(1) = old makes sense to you, then use it like that.
End result is: They all work, and that's the only thing that really matters after all is said and done. The ONLY reason we program ANYTHING is just for the final product where it compiles and runs and does (mostly) what we want it to. Don't waste days worrying over, "Is this syntax better than that syntax." Write the app, compile it, use it, and forget about it. Leave those theory questions for a classroom exercise. As long as your code ends up compiling and does what you need it to, isn't that all that REALLY matters when you settle down for a nice steak and beer, before going to bed late at night?
If you check my old cold, you'll see where I do things like so a lot: OldX = X: X = _MouseX. <-- Now I've got present and past values, like you mention.
BUT, with that said, I also remember coding several projects with DIM P(-1 to 0) used. P(0) was the "original", P(-1) was the "preserved value, and I coded heavily around that concept. I had constants for CONST Original = 0, Preserved = -1. Subs were in use like:
SUB ToggleValue (From)
SHARED P() AS LONG
P(From) = P(NOT From)
END SUB
The I could do things like IF P(Current) = Foo THEN ToggleValue P(Current).... And it's all complicated as heck now, but it made sense at the time when I was working with those values (which were associated with pixels and calculating new values from old valuse and such)...
Which just ends with the simple answer: **Do what feels natural and works best for you.** At the end of the day, it's YOUR code and you're the one who's going to have to write it, edit it, maintain it. If A = present and A(0) = old makes sense to you, then use it that way. IF A and OldA make more sense, then use it like that. IF A(0 TO 1) with a(0) = present and A(1) = old makes sense to you, then use it like that.
End result is: They all work, and that's the only thing that really matters after all is said and done. The ONLY reason we program ANYTHING is just for the final product where it compiles and runs and does (mostly) what we want it to. Don't waste days worrying over, "Is this syntax better than that syntax." Write the app, compile it, use it, and forget about it. Leave those theory questions for a classroom exercise. As long as your code ends up compiling and does what you need it to, isn't that all that REALLY matters when you settle down for a nice steak and beer, before going to bed late at night?