Best Practices for Naming Conventions in Solution Development

Slide Note
Embed
Share

Understand the importance of naming conventions for files, functions, methods, and variables. Learn how proper naming can enhance code readability, avoid potential errors, and ensure consistency across projects. Discover tips to create effective names that are easily understood, self-descriptive, and maintainable.


Uploaded on Sep 24, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. Applied Computing Unit 1 Outcome 2 Naming Conventions Key Knowledge 6: naming conventions for solution elements such as files, functions, methods and variables

  2. Wordz is hard Files The name of a stored file Functions Programming object that does not return a value Methods an Event something that gets triggered by a user Variables storage of data type that can be changed

  3. Whats in a name? Avoid special punctuation (which may choke some databases or compilers) Avoid spaces, which often indicate the end of a name. Remember, your source code may be used in more than one database or compiler with different behaviour!

  4. Whats in a name? Names of elements (variables, subprograms, functions, tables, fields, queries, reports etc) must be Easily understood Not confused with other elements Not too long wastes time, invites typos Not meaninglessly short (e.g. N) Self-descriptive

  5. Consistency E.g. if ALLCAPS are used for names of constants or module names, use them in the same way for the entire program. All programmers on a team must know and use the same conventions.

  6. Variables 1 variable contains one piece of data Accessed by individual name Not good when you need to group large quantities of related data Cannot work on a group of variables in one operation.

  7. Variables You d need code like this: total_cost = fuel_expense + rent_costs + food_costs + insurance + repair_costs A lot of typing! Hard to manage 1000 costs

  8. For example, compare these a = b * c; weekly_pay = hours_worked * pay_rate;

  9. Hungarian Notation Invented by Charles Simonyi He worked at Xerox PARC (which developed the mouse, GUI and Ethernet etc) Later became Chief Architect at Microsoft. Flew on a space shuttle. Now worth $1 billion From Hungary, where - like in Japan - people's surnames precede their given name. He would have been called Simonyi Charles at home.

  10. Hungarian Notation Practice Exam Question Hungarian notation is a naming convention for program elements such as variables and objects. The convention is that the first two or three letters of the element's name indicate the type of element. The rest of the name indicates its purpose, and starts with a capital letter; for example a text box containing a first name could be called txtFname. State three benefits of this method of naming. 3 marks.

  11. What it offers Information about the element being named, e.g. its data type in a program txtSurname (text variable) global_txt_Head_Count (global text variable) e.g. its object type in a database rpt_Invoice (report) qry_FindPensioners (query)

  12. Camelcase also known as Medial capitals Pascal case BumpyCaps BumpyCase camelBack CamelCaps CamelHump

  13. Camelcase also known as CapitalizedWords CapWords ClCl (Capital-lower Capital-lower) compoundNames Embedded Caps HumpBack InterCaps or intercapping

  14. is The practice of writing multiple words as one string without spaces using Capital Letters to mark the beginnings of individual words.

  15. For example TaxRate EndOfFile ReadNextRecord() PhoneNumber DateOfBirth txtSurname

  16. Underscore Alternative: Snake Case More readable? tax_rate end_of_file read_next_record() phone_number date_of_birth txt_surname

  17. Naming variables A = 14 <- what is A??? intNumberApples Date types, then using camel case identify what is contained in the variable

  18. Naming functions Meaningful Workdammit() what does this do? display_names() Why not use Hungarian notation? You define what is anyway def dispay_names()

  19. Naming methods Use only lowercase in method names. An underscore should separate words in a method name. Non-public method name should begin with a single underscore. Use two consecutive underscores at the beginning of a method name, if it needs to be mangled. __lamda__ (?????) __collect_names__

  20. Naming Files Program1 < - so glad you have one program Use some some of version control! Chapter1v1_1 At least you know this is where you saved the work you did for chapter 1!

Related


More Related Content