Re: What is the Point of Static or Constant Variables?

2020-02-04 Thread AudioGames . net Forum — Developers room : leibylucw via Audiogames-reflector


  


Re: What is the Point of Static or Constant Variables?

This is a programming 101 kind of topic, but it's actually [extremely] important in practical terms. What if, for some reason, there was a change in value? What if x needs to be 1,036,173...?As Ethin pointed out, it would be tedious to write out a value that is longer than the variable's name that refers to it, but if a constant needs to change value for any reason, you can do this in the variable's declaration statement and have that effect pervasive throughout its lifetime.Fizz Buzz, a popular children's game to enhance kids' understanding of division, is one common programming exercise that illustrates this point.Write a program that counts from 1 to 100. If the number is divisible by 3, print "fizz" to the screen. If the number is divisible by 5, print "buzz" to the screen. If the number is divisible by 3 and 5, print "fizz buzz" to the screen.Easy, right? Well, what if we wanted to abstract this to be able to handle any number ("fizz" if divisible by 2, "buzz" for 7, etc). Well, it would make more sense to use constant variables. So, if num is divisible by x, y, etc, then do etc. You'd make these constant variables so they cannot be modified or changed elsewhere in the program because that changes the logic of the program.HTH

URL: https://forum.audiogames.net/post/498511/#p498511




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: What is the Point of Static or Constant Variables?

2020-02-04 Thread AudioGames . net Forum — Developers room : leibylucw via Audiogames-reflector


  


Re: What is the Point of Static or Constant Variables?

This is a programming 101 kind of topic, but it's actually [extremely] important in practical terms. What if, for some reason, there was a change in value? What if x needs to be 1,036,173...?As Ethin pointed out, it would be tedious to write out a value that is longer than the variable's name that refers to it, but if a constant needs to change value for any reason, you can do this in the variable's declaration statement and have that effect pervasive throughout its lifetime.

URL: https://forum.audiogames.net/post/498511/#p498511




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: What is the Point of Static or Constant Variables?

2020-02-03 Thread AudioGames . net Forum — Developers room : pauliyobo via Audiogames-reflector


  


Re: What is the Point of Static or Constant Variables?

@8 actually it depends.If for instance, you're contributing to an opensource project you should use the code convention that the project is using, provided that it has one to begin with.Or, you can follow the code convention of the language you're utilizing.For instance, the java convention is to use camelcase names for functions, while python uses underscores.But it's not uncommon to find python opensource projects that utilize camelcase conventions in their code bases.So basically, stick to the one that you prefer, but if you're contributing to a project where other people are involved follow the project's convention if possible.

URL: https://forum.audiogames.net/post/498352/#p498352




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: What is the Point of Static or Constant Variables?

2020-02-03 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: What is the Point of Static or Constant Variables?

@8, it depends on what you want to do.@6, yes,static variables can be non-constant. The reason I indicated that static variables are constant is usually because they (always) should be unlesss you've got locking in place (Rust enforces this paradigm). I've gotten used to Rust so much now its just automatic to say, "Static: constant or locked." The reason is, of course, because the variables are global and are available to everything... you can easily mess up your code with those if your not careful, especially since your modifying global state.

URL: https://forum.audiogames.net/post/498318/#p498318




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: What is the Point of Static or Constant Variables?

2020-02-03 Thread AudioGames . net Forum — Developers room : DyingMoose93 via Audiogames-reflector


  


Re: What is the Point of Static or Constant Variables?

It's all personal preference, I prefer CC, I know a lot of people prefer underscores or dashes. I personally think it just saves a bit of typing, that's the only real advantage.

URL: https://forum.audiogames.net/post/498317/#p498317




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: What is the Point of Static or Constant Variables?

2020-02-03 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: What is the Point of Static or Constant Variables?

But why would I use CC over underscores? Diddo for the opposite question?

URL: https://forum.audiogames.net/post/498314/#p498314




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: What is the Point of Static or Constant Variables?

2020-02-03 Thread AudioGames . net Forum — Developers room : DyingMoose93 via Audiogames-reflector


  


Re: What is the Point of Static or Constant Variables?

@all, thank you for the help.@Americranian, Your second example is called camel case, which is widely used by programmers for ease of typing. Basically, you write the first word of your variable lowercase, and then after that, all words are uppercase on the first character. This just iliminates some underscores or dashes.

URL: https://forum.audiogames.net/post/498309/#p498309




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: What is the Point of Static or Constant Variables?

2020-02-03 Thread AudioGames . net Forum — Developers room : Kyleman123 via Audiogames-reflector


  


Re: What is the Point of Static or Constant Variables?

Static and constant variables have two similar but different purposes. Constant variables by there name are constant and can never be changed. This is helpful in many situations when you want a value but you never want it to be accidentally changed. You could say just never change it, but can you guarantee that this will never happen? What happens if you are using a codebase amongst a whole team of junior and senior devs? Its just better to make things immutable/constant if there is no need for them to change.Static on the other hand is a bit more advanced. Many times, especially in games, static classes are used for back-end services like audio systems. things that are declared static are allocated memory in their own little static area away from normal scoping. generally this means they have scope for the life-time of a program is running but this is not always the case. Static variables inside functions retain their memory across all the times a function is called in a program. This is nice if you are running a counter and need to keep track of how many times something happens. Static class data members are available across all instances of a class with the same value. Static methods are likewise available to all instances of a class, but can not be accessed through the standard this pointer. static methods can only access other static functions and other static variables. Finally, static class instances or objects get their primitive data members initialized to 0 but not usr defined data members. they are in scope throughout the life-time of a program.Read this article for more info. and This page on game programming patterns is a good application of static classes.Something can be static and constant, static and not constant, or just constant. They are not the same.

URL: https://forum.audiogames.net/post/498300/#p498300




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: What is the Point of Static or Constant Variables?

2020-02-03 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: What is the Point of Static or Constant Variables?

I have used tuples in Python before. I think they are mostly there to prevent accidental modification. They also technically take up less memory, though that is not too noticeable.@4, I have a somewhat unrelated question.I have seen variables like this:score_val = 132339812.And I have also seen variables made like this:scoreVal = 132339812When is one naming standard used over the other?

URL: https://forum.audiogames.net/post/498297/#p498297




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: What is the Point of Static or Constant Variables?

2020-02-03 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: What is the Point of Static or Constant Variables?

I have used tuples in Python before. I think they are mostly there to prevent accidental modification. They also technically take up less memory, though that is not too noticeable.

URL: https://forum.audiogames.net/post/498297/#p498297




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: What is the Point of Static or Constant Variables?

2020-02-03 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: What is the Point of Static or Constant Variables?

Constants are also good for giving names to "magic values" as well. A "magic value" is any value that you just randomly injected into your code. Moregenerally, a "magic value" is any value in your program that's mysterious and no one but you knows how you arrived to that value. The value  has no name, either, and just mysteriously shows up out of nowhere. For example, if you've got a set of formula values for calculating scores, and the value was 133918212, would you want to always type out 133918212 every time you needed to use that formula, or would you want to just call it SCORE_VAL?There are differences in constant and static variables though. A constant variable usually is replaced with its value at compile time. (I haven't seen a language where this is not the case.) A static variable is not, but is constant, but its name and value are embedded in the final image of the program.

URL: https://forum.audiogames.net/post/498293/#p498293




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: What is the Point of Static or Constant Variables?

2020-02-03 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: What is the Point of Static or Constant Variables?

Constants are also good for giving names to "magic values" as well. A "magic value" is any value that you just randomly injected into your code. For example, if you've got a set of formula values for calculating scores, and the value was 133918212, would you want to always type out 133918212 every time you needed to use that formula, or would you want to just call it SCORE_VAL?There are differences in constant and static variables though. A constant variable usually is replaced with its value at compile time. (I haven't seen a language where this is not the case.) A static variable is not, but is constant, but its name and value are embedded in the final image of the program.

URL: https://forum.audiogames.net/post/498293/#p498293




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: What is the Point of Static or Constant Variables?

2020-02-03 Thread AudioGames . net Forum — Developers room : dardar via Audiogames-reflector


  


Re: What is the Point of Static or Constant Variables?

Personally, I use them for things that would otherwise be too bothersome to type out again and again, for instant:const string description="This is a dromatic description about the game. You are shown this when ever you play a new game, or load a game and I can't be bothered to write it out a thousand times, especially if I wnat to modify it later, like fixing that deliberate typo above!"

URL: https://forum.audiogames.net/post/498258/#p498258




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: What is the Point of Static or Constant Variables?

2020-02-03 Thread AudioGames . net Forum — Developers room : Liam via Audiogames-reflector


  


Re: What is the Point of Static or Constant Variables?

I think it's mainly so you can just give names to arbitrary vallues. I use constants a lot for things like the direction a player can move. DIR_UP is 0, DIR_UP is 1, ETC.

URL: https://forum.audiogames.net/post/498254/#p498254




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector