Clean Coding Flashcards

1
Q

How is professional code written?

A

Clean code:

  • Maintainable
  • Reveals the intent
  • Reduces guesswork
  • Reads like a story
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What do we call poorly written code?

A

Smelly code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is refactoring?

A

Changing the structure of code without changing its external behavior!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is ReSharper?

A

It’s a plugin for visual studio that helps enormously with coding and productivity!

It takes you to the next level!

Once you use it, you’ll never go back!

Every C# developer should have!

Get a license, use it!

Doing refactoring by hand takes a lot longer and you could introduce bugs!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What topics does this course cover?

A

Poor Names

Poor Naming Conventions

Poor Method Signatures

Long Parameter List

Output Parameters

Variables Declarations on the top

Magic Numbers

Nested Conditionals

Switch Statements

Duplicated Code

Comments

Long Methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What should a good name be?

A

clear, intention revealing name

Not mysterious

Not ambiguous

No clutter (not noisy)

Not pre-fixed by data type

Don’t have to look at implementation to understand what it does!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is one of the most common code smells?

A

Poor names:

  • Mysterious names - names that have secrets about them
  • Meaningless names - methods with 100 lines of code and no clear, intention revealing name
  • Names with Encodings - Pre-fix variables with data types (Hungarian Notation) IDE’s today no need for this!
  • Ambiguous Names - have to look at implementation to understand it’s behavior : /
  • Noisy Names - names with “the” or other noise in names
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are mysterious names?

A

identifiers that require us to look somewhere else to find the meaning of the identifier.

Secret about them

Clean code:

the reader doesn’t have to go somewhere else to understand what is happening there

Smelly code:

button1_Click () : have to look at implementation or search form button is part of and figure out it’s “submit order.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can we fix these mysterious names?

A

Clean code:

SqlDataReader dr1 : dataReader / reader

int od : overdueDays

void Button1_Click ( ) : CheckAvailability_Click ( )

class Page1 { } : ViewCustomerPage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are meaningless names?

A

names that you have to view function to understand

often these functions are more than 100 lines of code, hence the meaningless name!

If the function is greater than 10 lines of code, it’s doing too many things! Hence why coming up with a clean, intention revealing name isn’t easy!

When your method is 5 lines to max 10 lines of code, it’s doing only one thing and it’s easy to come up with a meaningful name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are names with encodings?

A

Pre-fix variables with data types!

Why?

In the 1980s was hard to determine data types.

Hungarian notation

Today:

We have great IDE’s can see data types of variables in Visual studio by hovering mouse. No need for this!

Smelly code:

var m_objCollection = new StringCollection ( ) ;

Clean code:

maxRequests

var countryNames = new StringCollection ( )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an example of ambiguous names?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is an example of noisy names?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a problem with naming conventions?

A

Inconsistent Naming Conventions

Developers coming from different backgrounds adopt different naming conventions!

Naming Inconsistencies:

One identifier begins with a capital letter, another lowercase

one parameter has an _ the other doesn’t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the two standard naming conventions?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is PascalCase?

A

Uppercase first letter?

17
Q

What is camelCase?

A

first letter lowercase every other letter uppercase!

camelCase

18
Q

What is everything you need to know about naming conventions?

A

PascalCase in yellow

  • name of classes
  • properties
  • methods

camelCase in purple

  • private fields
  • method parameters
  • local variables
19
Q

When do we use PascalCase?

A

PascalCase:

  • name of classes
  • properties
  • methods
20
Q

When do we use camelCase?

A

camelCase

  • private fields (prefix with _ )
  • method parameters
  • local variables
21
Q

How do we name private fields?

A

camelCase with _prefix

22
Q

What convention should we all follow?

A