Refactoring for C# developers Flashcards Preview

.NET / C# > Refactoring for C# developers > Flashcards

Flashcards in Refactoring for C# developers Deck (28)
Loading flashcards...
1

What is refactoring?

Changes to the internal structure of a software to make it easy to understand and modify.

2

What does refactoring should NOT affect?

The observable behavior of the software.

3

What happens if we don't refactor often?

The software might get too complex to change.

4

When to refactor?

After making the unit test pass (part of tdd);
As part of fixing a bug;
As part of creating a new feature;

5

When not to refactor?

When current code does not work;
Massive technical debt (not developer's call);
Imminent deadline;

6

What does martin fowler says about refactoring?

Othen than when you're very close to a deadline... you should not put off refactoring because you haven't time.

7

Does the boy scout rule apply in refactorings?

yes.

8

What are the four steps of refactoring?

Commit (or restore) current working code;
Verify existing behavior (ideally with automated tests);
Apply a refactoring;
Confirm original behavior has been preserved.

9

What is characterization tests and when they are most useful?

Characterization tests asserts the current behavior of the software (even without knowing if it is correct). Most useful for legacy software which does not have unit tests.

10

What are the four steps of characterization tests?

Write tests you know will fail;
Get the output of the test;
Update the test to assert the current behavior;
Run the test again; should pass;

11

What to refactor to achieve a cleaner code base?

remove duplication;
improve naming;
break up large code elements;
reduce coupling;
reduce complexity;
split responsability (SRP);

12

what is a code smell?

surface indication that usually correspond to a deeper problem in the system.

13

What is the "Principle of Least Astonishment"?

Do what users expect;
Be simple;
Be clear;
!!!Be consistent!!!;

14

What are the five classifications of code smells?

Bloaters, object-orientation abusers, change preventers, dispensables and couplers.

15

What is a Bloater?

More code than it is actually necessary.

16

What is a object-oriented abuser?

Disrupt the value provided by the object-oriented languages.

17

What is a change preventer?

Any change requires touching many parts of the system.

18

What is a dispensable?

Provide little or no value.

19

What is a coupler?

Excessive coupling... preventing isolate changes to the system.

20

What is a obfuscator?

Impede clear communication. Make harder to understand the code.

21

What is non-nullable reference type? When was it introduced?

Forces an object to always have a reference, so not null. Introduced on c# 8.

22

Whic .net version has C# 8 by default?

.net core 3

23

how to enable nullable via compiler directive?

#nullable enable
#nullable disable

24

How to enable nullable via csproj?

tag nullable enable nullable

25

How to enable treat warning as errors for nullable errors?

adding CS8600 to project config.

26

How to change the design intent to allow a nullable for a specific var (even when the whole project is not allowing it)?

via ?
string? message = null;

27

What is the null-forgiving operator? When use it?

Is an operator that says that the programmer know that the given message!.Length will never be null. Use it when the compiler gives false positives (e.g when using reflection or during unit tests).

28

In which situations the nullable compiler checking won't be applied (even when it is enabled in the project)?

- when reflection is used;
- Calling code that has this feature disabled;
- When creating libs you should consider null checking stuff.