Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
March 15, 2021 02:47 pm GMT

Newbie's Cheatsheet: Commonly used verbs for naming functions, methods and variables

Do you follow your instinct when choosing a verb in your function?

Do you use a number of synonyms for the same purpose inconsistently?

If the answer is yes, you are not the only one.

In order to write a clean code, or at least to attempt it, we need to know what words are commonly used so that we can use them, and people can understand easier what we are trying to do.

In this post, I'll summarise commonly used verbs found in programming books and Github regardless of the type of programming language, so we can find the best-suited verbs for our own needs.

On the tables below, we'll see 5 rows:

  • The verb
  • The number of times the verb is written on Github to give us some ideas on how commonly it's used
  • Its general definition
  • Examples
  • Synonyms to avoid using to express the same concept

Just bear with me, this is not a complete list of common words, so please do let me know in the comment if you find some of the definition is too biased on certain programming languages. I'll also be grateful if you could teach me any other verbs that you think it's common!

I hope this post helps us, newbies choose a suitable verb and stick to it.

Table of Contents

1 Alteration
2 Creation
3 Establishment
4 Obtainment
5 True or False Statement
6 Conclusion

1. Alteration

VerbWritten
on Github
DefinitionExamplesSynonyms
to avoid
set2BOften used to put data in an existing resource such as an attribute of an object.set_name(), set_store_id()
change668MOften used when a whole thing, such as image, is replaced by something elsechange_image(), change_colour()edit
edit325MOften used same as change. It could be used especially when action is responsible for rendering the view.edit_title(), edit_record()change
update739MOften used when one or more of the components is updated as a result, and something new could also be added.update_file()
add1BOften used to add something into a group of the things.add_item(), add_member()append
append287MOften used same as add. It could be used when it does not modify the original group of things but produce the new group.append_item(), append_element()add
remove824MOften used when a given thing is removed from a group of the things.remove_record(), remove_item()delete
delete455MOften used same as remove, but it could also render nonrecoverable.delete_record(), delete_item()remove
save478MOften used when preserving data to avoid loss.save_json(), save_order()store
store396MOften used the same way as save.store_json(), store_order()save
disable586MOften used to configure a resource an unavailable or inactive state.disable_user()hide
hide237MOften has the same intention as disable, by hiding it.hide_field()disable
split276MUsed when separating parts of a resource.split_table(), split_group()separate
separate151MOften used the same way as the verb split.separate_table(), separate_group()split
merge312MOften used when creating a single resource from multiple resource.merge_records(), merge_tables()join
join220MIt can be used in a same way as merge.join_records(), join_tables()merge

2. Creation

VerbWritten
on Github
DefinitionExamplesConfusing
synonyms
create1BUsed when creating a resource.create_package(), create_directory()make, generate
make797MOften used in a same way as create.make_package(), make_statement()create, generate
generate286MOften used in a same way as create.generate_directory(), generate_statement()create, make
copy1BUsed when creating a resource with the same structure and data as the original one.copy_file(), copy_graph()clone
clone147MCould be used in a same way as copy.clone_file(), clone_graph()copy

3. Establishment

VerbWritten
on Github
DefinitionExamplesConfusing
synonyms
start1BGenerally used when initiating an operation.start_listening()begin
begin342MOften used in a same way as start.begin_listening()start
open854MUsed when changing state of a resource to make it accessible or usable.open_file()

4. Obtainment

VerbWritten
on Github
DefinitionExamplesConfusing
synonyms
get2BGenerally used to obtain a resource.get_data(), get_store_id()fetch, retrieve
fetch146MCan be used in a same way as get.fetch_data(), fetch_store_id()get, retrieve
retrieve116MCan be used in a same way as get or fetchretrieve_data(), retrieve_store_id()get, fetch
read1BUsed when acquiring data from a source.read_file()
find672MUsed when looking for an unknown data in a container.find_element(), find_keyword()search
search438MGenerally used in a same way as find. It may refer to look for an unknown data from multiple containers.search_element(), search_keyword()find
close492MUsed when changing state of a resource to make it inaccessible or unusable.close_file()

5. True or False Statement

VerbWritten
on Github
DefinitionExamples
is3BUsed when defining state of a resource.Method: is_available(), is_correct()
Variables: name_is_available, date_is_correct
has1BUsed to define whether a resource contains a certain data.Method: has_name(), has_date()
Variables: person_has_name, course_has_date
can2BUsed to define a certain ability of a resource.can_load(), can_create()
should1BUsed to define a certain obligation of a resource.should_render(), should_print_message()

6. Conclusion

Writing clean code is not a skill that we can obtain overnight. But at the same time, I believe that we can improve the quality of code significantly and constantly by learning the wisdom of other people's clean code. To write this bost, I gained so many ideas from the book Clean Code written by Robert C. Martin and many codes on Github. Thanks to these people who share their own hard work!

Thanks for reading. If you have any opinion or question, please leave a comment below! In the meantime, please follow me on Linkedin @Maiko Miyazaki or Twitter @Maiko Miyazaki


Original Link: https://dev.to/maikomiyazaki/beginner-s-cheat-sheet-commonly-used-verbs-for-naming-functions-methods-and-variables-509i

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To