Topic: A few Programming Standards
Programming is not a school subject you have to pass in order to graduate, but if we treat it as one and learn it the way a high school education system would teach it, we could get better standards for programming. It is good to have standards.
People have different conventions for naming variables or plain structuring code. I am a layman so I try to keep it simple.
An APPLE is a FRUIT. Therefore an apple belongs to the class of FRUIT:
class Fruit()
apple = Fruit()
One way to name a class is as a TYPE of something. An apple is a TYPE of fruit. Apple is the instance. Fruit is the class.
Another way to name a class is as a SUBJECT.
In Math class you learn math.
class Math()
calculus = Math()
But this is incomplete if you don't have a good convention for naming variables and functions so as to distinguish them from class names or one another without checking the camel's back.
Variables are nouns
Functions are verbs.
Functions should be names as ACTIONS. If you want to quit a game:
function QuitGame()
If you want to start a game:
function StartGame()
I also have a standard for booleans. I name booleans as PARTICIPLES and as ADVERBS:
walking = false
if walking then
end
quickly = false
if walking and quickly then
end
For people who name variables with underscores it is best to put NOUNS BEFORE ADJECTIVES as it makes similar variables easier to spot in the code:
apple_red =
apple_green =
boy_mexican =
boy_african_american =
boy_caucasian =
boy_indian =
boy_chinese =
If I want to find a "boy" I can find it easier this way.
Underscores also make things easier to read for me (I used to not understand why people did it).
Anyhow, having standards like these will make code flow better, and keep variable names or class names or function names from getting mixed up.
One more thing, It is good to be SPECIFIC yet BRIEF in your naming. For example if you have a person class:
class Person()
And you create an instance:
joey = Person()
Then you make joey do "Person" stuff:
joey:Speak()
joey:Walk(quickly)
This is already specific to JOEY since it uses classes, so your wording shouldn't get mixed up.
However, if it were just a function outside of a class:
Walk()
Then it leaves the questions:
Who or what is walking?
Walk where?
Walking how?
You could do this instead:
WalkFast()
WalkSlow()
WalkLikeYouBrokeYourLeg()
Functions should start with a captical letter and camel-case for each new word
variables start with a lower case letter and camel-case for each new word.
Whether you use underscores or not is up to you. But the two standards above are general for every programming language (at least how schools would teach you).
Writers can write however they want in their journals, but when it comes to writing a research paper, there are standards. Hopefully this helps.