Skip to content

Instantly share code, notes, and snippets.

@mhassanist
Last active May 22, 2020 10:28
Show Gist options
  • Save mhassanist/cfe82154262a1d241ada7c5f7670eb6a to your computer and use it in GitHub Desktop.
Save mhassanist/cfe82154262a1d241ada7c5f7670eb6a to your computer and use it in GitHub Desktop.
///// variable naming /////
//bad
double m1=13;
double m2=14;
double sum = m1+m2;
//kinda better
double mark1 =13;
double mark2 =14;
double sum_marks = mark1+mark2;
//way better -- clean
double math_mark = 13;
double scince_mark = 14;
double score = math_mark + science_mark;
//use nouns not verbs for variables.
double product_details;
//way better than
double investigate_product;
//lists
//if you are naming single variable represents the marks as "mark"
//so naming the list of marks as
double[] mark_list;
//mostly better than writing it as
double[] marks;
///// variable names - naming booleans /////
//bad
bool male = true;
bool car_owner = false;
//better to imply types
bool is_male;
bool has_car;
//However it is kinda common to name the counters in loops for example
// as i and j .. for this purpose it is fine.
for(i=0; i<product_list_size ; i++)
//do some thing
//functions - use verbs for naming
//function name along with its paramters should be as much self-descriptive as possible.
int count_negative_numbers(double[] numbers, int length){
}
//avoid implementation details in the name.
int find_number_in_list(List numbers, int number){
}
// the in_list is not useful here. It is clear as it is taking a list
//and a number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment