From 084de45709c0f0447b33ae81dfa63b94a0bc9bce Mon Sep 17 00:00:00 2001 From: Svetlin Nakov Date: Thu, 24 Jan 2019 17:38:15 +0000 Subject: [PATCH] Updates Content/Chapter-10-methods/methods-naming-good-practices/methods-naming-good-practices.md Auto commit by GitBook Editor --- .../expression.md | 4 +- .../triangle-of-stars.md | 2 +- .../sumator-graphical/sumator-graphical.md | 2 +- .../sumator-web/sumator-web.md | 2 +- .../methods-naming-good-practices.md | 71 ------------------- .../what-method-is/method-naming.md | 41 +++++++++++ .../what-method-is/methods-best-practices.md | 25 +++++++ .../graphical-apps/graphical-apps.md | 2 +- SUMMARY.md | 34 ++++----- 9 files changed, 85 insertions(+), 98 deletions(-) create mode 100644 Content/Chapter-10-methods/what-method-is/method-naming.md create mode 100644 Content/Chapter-10-methods/what-method-is/methods-best-practices.md diff --git a/Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/expression.md b/Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/expression.md index c1985a1bb..1634f1240 100644 --- a/Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/expression.md +++ b/Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/expression.md @@ -1,6 +1,6 @@ -# Problem: Console Application “Expression” +# Problem: Expression -Write a C# console program that **calculates** and **prints** the value of the following numerical expression: +Write a console-based C# console program that **calculates** and **prints** the value of the following numerical expression: ``` (3522 + 52353) * 23 - (2336 * 501 + 23432 - 6743) * 3 diff --git a/Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/triangle-of-stars.md b/Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/triangle-of-stars.md index 64941115b..50dac54ba 100644 --- a/Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/triangle-of-stars.md +++ b/Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/triangle-of-stars.md @@ -1,4 +1,4 @@ -# Problem: A Triangle Made of 55 Stars +# Problem: Triangle of 55 Stars Write a C\# console program that **prints a triangle made of 55 stars** on 10 rows: diff --git a/Content/Chapter-1-first-steps-in-programming/exercises-graphical-and-web-apps/sumator-graphical/sumator-graphical.md b/Content/Chapter-1-first-steps-in-programming/exercises-graphical-and-web-apps/sumator-graphical/sumator-graphical.md index c8900347a..4e38b0b4b 100644 --- a/Content/Chapter-1-first-steps-in-programming/exercises-graphical-and-web-apps/sumator-graphical/sumator-graphical.md +++ b/Content/Chapter-1-first-steps-in-programming/exercises-graphical-and-web-apps/sumator-graphical/sumator-graphical.md @@ -1,4 +1,4 @@ -# Problem: Graphical Application "Sumator" \(Calculator\) +# Lab: Graphical Application "Sumator" (Calculator) Write a **graphical \(GUI\) application**, which **calculates the sum of two numbers**: diff --git a/Content/Chapter-1-first-steps-in-programming/exercises-graphical-and-web-apps/sumator-web/sumator-web.md b/Content/Chapter-1-first-steps-in-programming/exercises-graphical-and-web-apps/sumator-web/sumator-web.md index 7736107fc..6d765a7c9 100644 --- a/Content/Chapter-1-first-steps-in-programming/exercises-graphical-and-web-apps/sumator-web/sumator-web.md +++ b/Content/Chapter-1-first-steps-in-programming/exercises-graphical-and-web-apps/sumator-web/sumator-web.md @@ -1,4 +1,4 @@ -# Problem: Web Application "Sumator" \(Calculator\) +# Lab: Web Application "Sumator" (Calculator) Now we are going to write something even more complex, but also more interesting: a web application that **calculates the sum of two numbers**. By **entering two numbers** in the first two text fields and pressing the \[**Calculate**\] button, **their sum is being calculated** and the result is shown in the third text field. diff --git a/Content/Chapter-10-methods/methods-naming-good-practices/methods-naming-good-practices.md b/Content/Chapter-10-methods/methods-naming-good-practices/methods-naming-good-practices.md index be8644ef1..e69de29bb 100644 --- a/Content/Chapter-10-methods/methods-naming-good-practices/methods-naming-good-practices.md +++ b/Content/Chapter-10-methods/methods-naming-good-practices/methods-naming-good-practices.md @@ -1,71 +0,0 @@ -# Naming Methods and Good Practices for Using Methods - -In this part we will show you some **established practices** when working with methods, connected with the naming, the arrangement and the structure of the code. - -## Naming Methods - -When you name a method it is good to use **meaningful names**. Because every method **answers** for a part of our problem, when naming it we should keep in mind **the action it does**, i.e. it is a good practice for **the name to describe what the method does**. - -The name must start with **uppercase** and should be made of a verb or a couple: verb + noun. The name is formatted by following the **Upper Case Camel** convention, i.e. **each word, including the first, starts with uppercase**. The brackets **`( `** and **`)`** always follow the name. - -Each method must do one task and its name should describe what its function is. - -A few examples for **correctly** naming our methods: -* **`FindStudent`** -* **`LoadReport`** -* **`Sine`** - -A few examples for **incorrectly** naming our methods: -* **`Method1`** -* **`DoSomething`** -* **`HandleStuff`** -* **`SampleMethod`** -* **`DirtyHack`** - -If you can not think of a good name then the method most probably solves more than one task or doesn't have a clearly defined purpose and in this case you have to think how to divide it in several simpler methods. - -## Naming Method Parameters - -When naming **the parameters** of a method you can apply almost the same rules as with the methods themselves. The difference here is that it is good for the names of the parameters to use a noun or a couple of an adjective and a noun, and when naming the parameters we use the **`lowerCamelCase`** convention, i.e. **each word except for the first one starts with uppercase**. We should note that it is good practice that the name of the parameter **shows** what **unit**is used when working with it. - -A few examples for **correctly** named parameters: -* **`firstName`** -* **`report`** -* **`speedKmH`** -* **`usersList`** -* **`fontSizeInPixels`** -* **`font`** - -A few examples for **incorrectly** named parameters: -* **`p`** -* **`p1`** -* **`p2`** -* **`populate`** -* **`LastName`** -* **`last_name`** - -## Good Practices When Working with Methods - -Let us remind you that a method should do **only one** defined **task**. If this can not be done you must think how to **divide** the method into a few, smaller ones. As we already said the name of the method should be clear and should describe its purpose. Another good practice in programming is to **avoid** methods, which are longer than our screen (approximately). If the code still becomes large it is recommended to **divide** it into several, shorter methods, as in the example below. - -![](/assets/chapter-10-images/20.Good-practice-01.png) - -## Code Structure and Formatting - -When writing methods we should be careful to do correct **indentation** (moving blocks of the code to the right). - -Example for **correctly** formatted C# code: - -![](/assets/chapter-10-images/20.Good-practice-02.png) - -Example for **incorrectly** formatted C# code: - -![](/assets/chapter-10-images/20.Good-practice-03.png) - -When the title line of the method is **too long**, it is recommended to divide it into several lines, as each line after the first is two tabulations to the right of the first (for better readability): - -![](/assets/chapter-10-images/13.Calculate-triangle-area-01.png) - -Another good practice when writing code is **to leave an empty row** between the methods, after loops and conditional statements. Also try to **abstain** from writing **long lines and complicated expressions**. In time you will see that this makes the readability better and saves time. - -It is also recommended to always **use curly brackets for the bodies of conditional statements and loops**. The brackets not only improve readability, but also reduce the possibility to make a mistake and the program to run incorrectly. diff --git a/Content/Chapter-10-methods/what-method-is/method-naming.md b/Content/Chapter-10-methods/what-method-is/method-naming.md new file mode 100644 index 000000000..54f79f829 --- /dev/null +++ b/Content/Chapter-10-methods/what-method-is/method-naming.md @@ -0,0 +1,41 @@ +# Naming Methods + +When you name a method it is good to use **meaningful names**. Because every method **answers** for a part of our problem, when naming it we should keep in mind **the action it does**, i.e. it is a good practice for **the name to describe what the method does**. + +The name must start with **uppercase** and should be made of a verb or a couple: verb + noun. The name is formatted by following the **Upper Case Camel** convention, i.e. **each word, including the first, starts with uppercase**. The brackets **`( `** and **`)`** always follow the name. + +Each method must do one task and its name should describe what its function is. + +A few examples for **correctly** naming our methods: +* **`FindStudent`** +* **`LoadReport`** +* **`Sine`** + +A few examples for **incorrectly** naming our methods: +* **`Method1`** +* **`DoSomething`** +* **`HandleStuff`** +* **`SampleMethod`** +* **`DirtyHack`** + +If you can not think of a good name then the method most probably solves more than one task or doesn't have a clearly defined purpose and in this case you have to think how to divide it in several simpler methods. + +## Naming Method Parameters + +When naming **the parameters** of a method you can apply almost the same rules as with the methods themselves. The difference here is that it is good for the names of the parameters to use a noun or a couple of an adjective and a noun, and when naming the parameters we use the **`lowerCamelCase`** convention, i.e. **each word except for the first one starts with uppercase**. We should note that it is good practice that the name of the parameter **shows** what **unit**is used when working with it. + +A few examples for **correctly** named parameters: +* **`firstName`** +* **`report`** +* **`speedKmH`** +* **`usersList`** +* **`fontSizeInPixels`** +* **`font`** + +A few examples for **incorrectly** named parameters: +* **`p`** +* **`p1`** +* **`p2`** +* **`populate`** +* **`LastName`** +* **`last_name`** diff --git a/Content/Chapter-10-methods/what-method-is/methods-best-practices.md b/Content/Chapter-10-methods/what-method-is/methods-best-practices.md new file mode 100644 index 000000000..eb1088a2c --- /dev/null +++ b/Content/Chapter-10-methods/what-method-is/methods-best-practices.md @@ -0,0 +1,25 @@ +# Good Practices When Working with Methods + +Let us remind you that a method should do **only one** defined **task**. If this can not be done you must think how to **divide** the method into a few, smaller ones. As we already said the name of the method should be clear and should describe its purpose. Another good practice in programming is to **avoid** methods, which are longer than our screen (approximately). If the code still becomes large it is recommended to **divide** it into several, shorter methods, as in the example below. + +![](/assets/chapter-10-images/20.Good-practice-01.png) + +## Code Structure and Formatting + +When writing methods we should be careful to do correct **indentation** (moving blocks of the code to the right). + +Example for **correctly** formatted C# code: + +![](/assets/chapter-10-images/20.Good-practice-02.png) + +Example for **incorrectly** formatted C# code: + +![](/assets/chapter-10-images/20.Good-practice-03.png) + +When the title line of the method is **too long**, it is recommended to divide it into several lines, as each line after the first is two tabulations to the right of the first (for better readability): + +![](/assets/chapter-10-images/13.Calculate-triangle-area-01.png) + +Another good practice when writing code is **to leave an empty row** between the methods, after loops and conditional statements. Also try to **abstain** from writing **long lines and complicated expressions**. In time you will see that this makes the readability better and saves time. + +It is also recommended to always **use curly brackets for the bodies of conditional statements and loops**. The brackets not only improve readability, but also reduce the possibility to make a mistake and the program to run incorrectly. diff --git a/Content/Chapter-2-1-simple-calculations/graphical-apps/graphical-apps.md b/Content/Chapter-2-1-simple-calculations/graphical-apps/graphical-apps.md index 579c61582..ba520bcdd 100644 --- a/Content/Chapter-2-1-simple-calculations/graphical-apps/graphical-apps.md +++ b/Content/Chapter-2-1-simple-calculations/graphical-apps/graphical-apps.md @@ -1,4 +1,4 @@ -# Lab: Graphical Applications with Numerical Expressions +# Lab: GUI Applications with Numerical Expressions To exercise working with variables and calculations with operators and numerical expressions, we will make something interesting: we will develop a **desktop application** with graphical user interface. In it, we will use calculations with floating point numbers. We shall create two **GUI** \(graphical user interface\) applications: diff --git a/SUMMARY.md b/SUMMARY.md index 81640ebd9..d398981a1 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -12,14 +12,14 @@ * [Example: Creating a Console Application](Content/Chapter-1-first-steps-in-programming/how-to-write-console-app/example-creating-a-console-application.md) * [Typical Mistakes in C\# Programs](Content/Chapter-1-first-steps-in-programming/how-to-write-console-app/typical-mistakes-in-csharp-programs.md) * [Exercises: First Steps in Coding](Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/exercises-first-steps-in-coding.md) - * [Problem: Console Application “Expression”](Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/expression.md) + * [Problem: Expression](Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/expression.md) * [Problem: Numbers from 1 to 20](Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/numbers-1-to-20.md) - * [Problem: A Triangle Made Out of 55 Stars](Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/triangle-of-stars.md) + * [Problem: Triangle of 55 Stars](Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/triangle-of-stars.md) * [Problem: Calculate Rectangle Area](Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/rectangle-area.md) * [\* Problem: A Square Made Out of Stars](Content/Chapter-1-first-steps-in-programming/exercises-first-steps-in-coding/square-of-stars.md) * [Lab: Graphical and Web Applications](Content/Chapter-1-first-steps-in-programming/exercises-graphical-and-web-apps/exercises-graphical-and-web-apps.md) - * [Problem: Graphical Application "Sumator" \(Calculator\)](Content/Chapter-1-first-steps-in-programming/exercises-graphical-and-web-apps/sumator-graphical/sumator-graphical.md) - * [Problem: Web Application "Sumator" \(Calculator\)](Content/Chapter-1-first-steps-in-programming/exercises-graphical-and-web-apps/sumator-web/sumator-web.md) + * [Lab: Graphical Application "Sumator"](Content/Chapter-1-first-steps-in-programming/exercises-graphical-and-web-apps/sumator-graphical/sumator-graphical.md) + * [Lab: Web Application "Sumator"](Content/Chapter-1-first-steps-in-programming/exercises-graphical-and-web-apps/sumator-web/sumator-web.md) * [2.1. Simple Calculations](Content/Chapter-2-1-simple-calculations/overview.md) * [The System Console](Content/Chapter-2-1-simple-calculations/system-console/system-console.md) * [Reading Integers from the Console](Content/Chapter-2-1-simple-calculations/reading-integers-from-console/reading-integers-from-console.md) @@ -45,7 +45,7 @@ * [Problem: USD to BGN Converter](Content/Chapter-2-1-simple-calculations/exercises-simple-calculations/usd-to-bgn/usd-to-bgn.md) * [Problem: \* Currency Converter](Content/Chapter-2-1-simple-calculations/exercises-simple-calculations/currency-converter/currency-converter.md) * [Problem: \*\* Date Calculations](Content/Chapter-2-1-simple-calculations/exercises-simple-calculations/1000-days-after-birth/1000-days-after-birth.md) - * [Lab: Graphical Applications with Numerical Expressions](Content/Chapter-2-1-simple-calculations/graphical-apps/graphical-apps.md) + * [Lab: GUI Apps with Numerical Expressions](Content/Chapter-2-1-simple-calculations/graphical-apps/graphical-apps.md) * [GUI Application: Converter from BGN to EUR](Content/Chapter-2-1-simple-calculations/graphical-apps/bgn-to-eur-converter/bgn-to-eur-converter.md) * [GUI Application: \* Catch the Button!](Content/Chapter-2-1-simple-calculations/graphical-apps/catch-the-button/catch-the-button.md) * [2.2. Simple Calculations – Exam Problems](Content/Chapter-2-2-simple-calculations-exam-problems/overview.md) @@ -78,7 +78,7 @@ * [Problem: Time + 15 Minutes](Content/Chapter-3-1-simple-conditions/exercises-simple-conditions/time-plus-15-mins/time-plus-15-mins.md) * [Problem: Equal 3 Numbers](Content/Chapter-3-1-simple-conditions/exercises-simple-conditions/equal-numbers/equal-numbers.md) * [Problem: \* Writing the Numbers from 0 to 100 in Words](Content/Chapter-3-1-simple-conditions/exercises-simple-conditions/number-to-words/number-to-words.md) - * [Lab: GUI \(Desktop\) Application: Currency Converter](Content/Chapter-3-1-simple-conditions/exercises-simple-conditions/graphical-app/graphical-app.md) + * [Lab: GUI App "Currency Converter"](Content/Chapter-3-1-simple-conditions/exercises-simple-conditions/graphical-app/graphical-app.md) * [3.2. Simple Conditions – Exam Problems](Content/Chapter-3-2-simple-conditions-exam-problems/overview.md) * [Problem: Transportation Price](Content/Chapter-3-2-simple-conditions-exam-problems/exam-problems/ticket-price/ticket-price.md) * [Problem: Pipes in a Pool](Content/Chapter-3-2-simple-conditions-exam-problems/exam-problems/pipes-in-pool/pipes-in-pool.md) @@ -118,7 +118,7 @@ * [Problem: Even / Odd Positions](Content/Chapter-5-1-loops/exercises-loops/even-odd-positions.md) * [Problem: Equal Pairs](Content/Chapter-5-1-loops/exercises-loops/equal-pairs.md) * [Lab: Drawing with a Turtle - Graphical \(GUI\) Application](Content/Chapter-5-1-loops/graphical-and-web-apps/drawing-with-turtle/drawing-with-turtle.md) - * [Exercises: Turtle Graphics](Content/Chapter-5-1-loops/graphical-and-web-apps/graphical-and-web-apps.md) + * [Lab Exercises: Turtle Graphics](Content/Chapter-5-1-loops/graphical-and-web-apps/graphical-and-web-apps.md) * [Problem: \* Draw а Hexagon with the Turtle](Content/Chapter-5-1-loops/graphical-and-web-apps/drawing-hexagon.md) * [Problem: \* Draw a Star with the Turtle](Content/Chapter-5-1-loops/graphical-and-web-apps/drawing-star.md) * [Problem: \* Draw a Spiral with the Turtle](Content/Chapter-5-1-loops/graphical-and-web-apps/drawing-spiral.md) @@ -133,10 +133,10 @@ * [Problem: Logistics](Content/Chapter-5-2-loops-exam-problems/exam-problems/logistics/logistics.md) * [6.1. Nested Loops](Content/Chapter-6-1-nested-loops/overview.md) * [Nested Loops](Content/Chapter-6-1-nested-loops/nested-loops/nested-loops.md) - * [Example: Rectangle Made Out of 10 x 10 Stars](Content/Chapter-6-1-nested-loops/example-rectangle-10x10/example-rectangle-10x10.md) - * [Example: Rectangle Made Out of N x N Stars](Content/Chapter-6-1-nested-loops/example-rectangle-NxN/example-rectangle-NxN.md) - * [Examples: Square Made Out of Stars](Content/Chapter-6-1-nested-loops/nested-loops/example-square-of-stars.md) - * [Example: Triangle Made Out of Dollars](Content/Chapter-6-1-nested-loops/nested-loops/example-triangle-of-dollars.md) + * [Example: Rectangle of 10 x 10 Stars](Content/Chapter-6-1-nested-loops/example-rectangle-10x10/example-rectangle-10x10.md) + * [Example: Rectangle of N x N Stars](Content/Chapter-6-1-nested-loops/example-rectangle-NxN/example-rectangle-NxN.md) + * [Examples: Square of Stars](Content/Chapter-6-1-nested-loops/nested-loops/example-square-of-stars.md) + * [Example: Triangle of Dollars](Content/Chapter-6-1-nested-loops/nested-loops/example-triangle-of-dollars.md) * [Example: Square Frame](Content/Chapter-6-1-nested-loops/nested-loops/example-square-frame.md) * [Exercises: Drawing Figures](Content/Chapter-6-1-nested-loops/drawing-more-complex-figures/drawing-more-complex-figures.md) * [Problem: Rhombus of Stars](Content/Chapter-6-1-nested-loops/nested-loops/example-rhombus-of-stars.md) @@ -199,16 +199,8 @@ * [Returning Multiple Values](Content/Chapter-10-methods/what-method-is/returning-multiple-values.md) * [Methods Overloading](Content/Chapter-10-methods/methods-overloading/methods-overloading.md) * [Nested Methods \(Local Functions\)](Content/Chapter-10-methods/nested-methods/nested-methods.md) - * [Methods Naming and Good Practices When Working with Methods](Content/Chapter-10-methods/methods-naming-good-practices/methods-naming-good-practices.md) - * [Exercises – Methods](Content/Chapter-10-methods/exercises-methods/exercieses-methods.md) - * [Problem: "Hello, Name!"](Content/Chapter-10-methods/exercises-methods/hello-name.md) - * [Problem: Min Method](Content/Chapter-10-methods/exercises-methods/min-method.md) - * [Problem: String Repeater](Content/Chapter-10-methods/exercises-methods/string-repeater.md) - * [Problem: N-th Digit](Content/Chapter-10-methods/exercises-methods/nth-digit.md) - * [Problem: Integer to Base](Content/Chapter-10-methods/exercises-methods/integer-to-base.md) - * [Problem: Notifications](Content/Chapter-10-methods/exercises-methods/notifications.md) - * [Problem: Numbers to Words](Content/Chapter-10-methods/exercises-methods/numbers-to-words/numbers-to-words.md) - * [Problem: String Encryption](Content/Chapter-10-methods/exercises-methods/string-encryption/string-encryption.md) + * [Method Naming](Content/Chapter-10-methods/what-method-is/method-naming.md) + * [Methods – Best Practices](Content/Chapter-10-methods/what-method-is/methods-best-practices.md) * [11. Tricks and Hacks](Content/Chapter-11-tricks-and-hacks/overview.md) * [Code Formatting](Content/Chapter-11-tricks-and-hacks/code-formatting/code-formatting.md) * [Naming Code Elements](Content/Chapter-11-tricks-and-hacks/naming-elements-of-the-code/naming-elements-of-the-code.md)