Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hrumhurum committed Jan 17, 2022
2 parents 1c57397 + 66f90ca commit 2df17d5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Source/Gapotchenko.FX.Diagnostics.CommandLine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ The code above produces the following output:

This is a neat departure from a traditional .NET convention where it always throws `ArgumentNullException`.
Instead, Gapotchenko.FX uses a slightly different philosophy.
It does the best job possible under existing conditions by following common-sense expectations of a customer.
It does the best job possible under existing conditions by following common-sense expectations of a user.


### Split
Expand Down
4 changes: 2 additions & 2 deletions Source/Gapotchenko.FX.Diagnostics.Process/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ It allows to end a process according to a specified mode of operation.
The default mode of operation is `ProcessEndMode.Complete` that follows a sequence presented below:

1. Graceful techniques are tried first:
1.1. `End()` method tries to close a main window of a process
1.1. `End()` method tries to close a main window of the process
1.2. If that fails, it tries to send Ctrl+C (SIGTERM) signal
2. Forceful techniques:
2.1. If graceful techniques fail, `End()` method tries to exit the process (suitable for the current process only)
Expand Down Expand Up @@ -160,7 +160,7 @@ As you can see, despite a simple-looking signature, the End(…) method gives en
### EndAsync()

The method is similar to `End()` but has an async implementation.
If was created in order to efficiently handle a lot of processes in bulk.
It can be used to efficiently handle a lot of processes in bulk.

## Usage

Expand Down
4 changes: 2 additions & 2 deletions Source/Gapotchenko.FX.IO/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool IsContosoReportsFolder(string path) => path.StartsWith(@"Contoso\Reports");
```

It kind of works, until we try to pass something like `Contoso\ReportsBackup`.
The problem is `ReportsBackup` is a very different folder than `Reports`, but the provided function returns `true`.
The problem is that `ReportsBackup` is a very different folder than `Reports`, but the provided function returns `true` nevertheless.

We can cheat here, and try to use an updated function that adds a trailing slash:

Expand All @@ -116,7 +116,7 @@ bool IsContosoReportsFolder(string path) => path.StartsWith(@"Contoso\Reports\")

The problem is gone.
Until we ask for `IsContosoReportsFolder("Contoso\Reports")` value.
It is `false` now despite the fact that `Contoso\Reports` is literally a Contoso reports folder we are so eagerly looking for.
It is `false` now despite the fact that `Contoso\Reports` is literally the folder we are so eagerly looking for.

The correct solution is to use `FileSystem.PathStartsWith` method provided by `Gapotchenko.FX.IO` module:

Expand Down
10 changes: 6 additions & 4 deletions Source/Gapotchenko.FX.Text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ if (name.Equals("[mscorlib]System.Object", StringComparison.Ordinal) ||
```

It does the job but such mechanical changes may put a toll on code maintainability when they accumulate.
You can also spot some amount of code duplication there.
You can also spot some amount of code duplication here.

Another approach would be to use `Regex` class which is readily available in .NET.
But that might destroy the expressiveness of string manipulation functions like `Equals`.
If a string function takes a `StringComparison` parameter then it may become a significant challenge to reliably refactor it to `Regex` implementation.


That's why `Gapotchenko.FX.Text` module provides a set of so called regex trampoline functions.
They look exactly like `Equals`, `StartsWith`, `EndsWith`, `IndexOf` but work on regex patterns instead of raw strings.
They also end with `Regex` suffix in their names, so `Equals` becomes `EqualsRegex`, `StartsWith` becomes `StartsWithRegex` and so on.
They look exactly like `Equals`, `StartsWith`, `EndsWith`, `IndexOf` but work with regex patterns instead of raw strings.
They also end with `Regex` suffix in their names, so `Equals` becomes `EqualsRegex`, `StartsWith` correspondingly becomes `StartsWithRegex`, and so on.

This is how a regex trampoline can be used for the given sample in order to meet the new requirements by a single line change:
And this is how a regex trampoline can be used for the given sample in order to meet the new requirements by a single line change:

``` csharp
using Gapotchenko.FX.Text.RegularExpressions;
Expand All @@ -66,6 +66,8 @@ An immediate improvement in expressiveness without duplication.
`StringBuilder.AppendJoin` is a method that appeared in later versions of .NET platform.
Gapochenko.FX provides a corresponding polyfill that can be used in code targeting older .NET versions.

The benefit of this method is that it combines `string.Join` and `StringBuilder.Append` operations into one method using the underlying efficiency of `StringBuilder`.

## Usage

`Gapotchenko.FX.Text` module is available as a [NuGet package](https://nuget.org/packages/Gapotchenko.FX.Text):
Expand Down
11 changes: 11 additions & 0 deletions Source/Gapotchenko.FX.Threading/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ void SyncMethod()
As you can see, `TaskBridge` has a lot of chances to become your tool #1,
as it elegantly solves a world-class problem of bridging sync and async models together.

## `Sequential`, an Antogonist to `Parallel`

.NET platform provides `System.Threading.Tasks.Parallel` class that contains a bunch of static methods allowing to execute the tasks in parallel.
But what if you want to temporarily switch them to a sequential execution mode?

Of course, you can do that manually, for example, by changing `Parallel.ForEach` method to `foreach` C# language keyword.
But this is a lot of manual and error-prone work.
That's why `Gapotchenko.FX.Threading` module provides `Sequential` class, an anotogonist to `Parallel`.
It allows to make the switch by changing just the class name from `Parallel` to `Sequential` in a corresponding function call.
So `Parallel.ForEach` becomes `Sequential.ForEach`, and voila, the tasks are now executed sequentially allowing you to isolate that pesky multithreading bug you were hunting for.

## Usage

`Gapotchenko.FX.Threading` module is available as a [NuGet package](https://nuget.org/packages/Gapotchenko.FX.Threading):
Expand Down

0 comments on commit 2df17d5

Please sign in to comment.