Changes between Version 18 and Version 19 of HowtoGoodProgrammingTechniques


Ignore:
Timestamp:
May 29, 2013, 9:20:30 PM (12 years ago)
Author:
Thanatermesis
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • HowtoGoodProgrammingTechniques

    v18 v19  
    1919== States ==
    2020
    21 When you are programming, you will see that your code needs to be intelligent, it needs to know ''what to do now'' and how to deal with specific situations, this is a lot more easy to reach with states, in short, '''put boolean states everywhere''' they are cheap!, this way we can always know how to deal in specific situations, but keep in mind we dont want a bloated code with confusing states, so we need to think of a good way to organize them in our code, for example, the prefix '''is_''' is one of the best ones to use, just think about the possibilites to have states marked like ''is_sources_get'', ''is_sources_compiled'', ''is_interactive''... So everytime your application does a specific thing, you can set or unset the affected variables to define the state/progress of the application to know what to do next. Your application can also have different ways of work, so you can prefix those states with '''mode_''', see for example ''mode_interactive'' or ''mode_editing'', another useful one is also the '''ignore_''' prefix in order to ignore steps on our application.
     21When you are programming, you will see that your code needs to be intelligent, it needs to know ''what to do now'' and how to deal with specific situations, this is a lot more easy to reach with states, in short, '''put boolean states everywhere''' they are cheap!, this way we can always know how to deal in specific situations, but keep in mind we dont want a bloated code with confusing states, so we need to think of a good way to organize them in our code, for example, the prefix '''is_''' is one of the best ones to use, just think about the possibilites to have states (as booleans) marked like ''is_sources_get'', ''is_sources_compiled'', ''is_interactive''... So everytime your application does a specific thing, you can set or unset the affected variables to define the state/progress of the application to know what to do next. Your application can also have different ways of work, so you can prefix those states with '''mode_''', see for example ''mode_interactive'' or ''mode_editing'', another useful one is also the '''ignore_''' prefix in order to ignore steps on our application.
    2222
    2323It's important to think about the possible ''expected'' situations, since we are humans this is hard to acheive but we need to keep in mind every different situation, like ''if the file is deleted when...'' or ''if at the same time the user...''
     
    6363In short, most of the times you will see that the names are written in inverse mode that is how you talk them, if you doubt, just imagine to have some similar possible names and you sort them, you will see how they are sorted and which part of the name needs to come before the other ones
    6464
    65 When the application becomes big and start having a lot of names for variables, it is good to know what's exactly that variable, to know if we are dealing with a file, with a directory, or with a value, I personally use for that a suffix (ending in) in the variables like '''_v''' for values, '''_d''' for identifying directories, '''_f''' for identifying a file.
     65It is good to know what's exactly that variable, to know if we are dealing with a file, with a directory, or with a value, I personally use for that a suffix (ending in) in the variables like '''_v''' for values, '''_d''' for identifying directories, '''_f''' for identifying a file, there's also a good practice to use '''_''' as ''prefix'' for any local variable.
    6666
    6767