This is my programming Grammar.
21,862
2
Advertisement
Introduction
The english language has many words. Each word has a designated part of speech. When these words are combined in special ways, you get a sentence.
I want to share a standard I have for translating these parts of speech into a programming language so that your code will be more readable.
I am using Lua.
Parts of Speech
Nouns
A noun is a person, place,thing, or idea
Variables should be named like nouns. Meet Joe:
Joe is a person, so he is a noun. We could put joe in a Person Class to make him more of a person:
Verbs
Verbs are action words. Joe can walk and talk!
Functions should be named like verbs.
Adjectives
Adjectives Describe Nouns Joe is pale!
Use Booleans to denote adjectives
Adverbs
Adverbs Describe Verbs. Joey can walk quickly
Once again, use Booleans to denote adverbs. If you use them as arguments for functions, it reads better.
Participles
A participle is a tense of a verb Is Joe biking? Or has joe biked? Usually past or present tense.
Once again, Booleans.
Prepositions
A preposition is a location Word. Is joe under the shed or in the shed? Is he around the corner or along the corner?
Booleans again.
Conjunctions
Conjunctions JOIN sentences (statements).
Usually conditional statements are the conjunctions in programming. Words like but, and, because, are conjunctions.
Above, isWalking is a boolean, as well as isWalkingQuickly. Also isAfraid is a boolean. So all we are doing is setting boolean values. Starting to look like an English sentence.
Interjections
Interjections are used to express emotion or sentiment. Uh, er, bye, hi, cheers! Horray! Wow! Sup! Oh! Well! Sorry! Oh dear! One way to do interjections is to use Loops. Most of the time these statements stand for other things. "Wow" means that you are surprised and don't know what to say.
We could make a function called Wow() that would set these boolean variables:
The english language has many words. Each word has a designated part of speech. When these words are combined in special ways, you get a sentence.
I want to share a standard I have for translating these parts of speech into a programming language so that your code will be more readable.
I am using Lua.
Parts of Speech
Nouns
A noun is a person, place,thing, or idea
Variables should be named like nouns. Meet Joe:
joe =Joe is a person, so he is a noun. We could put joe in a Person Class to make him more of a person:
joe = Person()Verbs
Verbs are action words. Joe can walk and talk!
Functions should be named like verbs.
joe:Walk()joe:Talk()Adjectives
Adjectives Describe Nouns Joe is pale!
Use Booleans to denote adjectives
pale = trueAdverbs
Adverbs Describe Verbs. Joey can walk quickly
Once again, use Booleans to denote adverbs. If you use them as arguments for functions, it reads better.
joe:Walk(quickly) walk = truequickly = trueParticiples
A participle is a tense of a verb Is Joe biking? Or has joe biked? Usually past or present tense.
Once again, Booleans.
biking = truebiked = falsePrepositions
A preposition is a location Word. Is joe under the shed or in the shed? Is he around the corner or along the corner?
Booleans again.
under = falsearound = trueConjunctions
Conjunctions JOIN sentences (statements).
Usually conditional statements are the conjunctions in programming. Words like but, and, because, are conjunctions.
if joe.isWalking and joe.isWalkingQuickly thenjoe.isAfraidendAbove, isWalking is a boolean, as well as isWalkingQuickly. Also isAfraid is a boolean. So all we are doing is setting boolean values. Starting to look like an English sentence.
Interjections
Interjections are used to express emotion or sentiment. Uh, er, bye, hi, cheers! Horray! Wow! Sup! Oh! Well! Sorry! Oh dear! One way to do interjections is to use Loops. Most of the time these statements stand for other things. "Wow" means that you are surprised and don't know what to say.
surprised = truespeecheless = true while speechless and surprised doLookInAmazement()endWe could make a function called Wow() that would set these boolean variables:
function Wow()wowed = truesurprised = truespeecheless = true while speechless and surprised doLookInAmazement()endend joe:Wow()Advertisement
Advertisement
Advertisement
Discussion