Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 30, 2025

第4章「マルチパラダイムプログラミング」の関数型プログラミング節に、文(Statement)から式(Expression)へのパラダイムシフトに関する包括的な解説を追加しました。

追加内容

新規セクション: 文から式へのシフト:C#における関数型パラダイムの進化

  • 配置場所: 4.4.1 関数型プログラミングの特徴内の新サブセクション
  • 構成: 文と式の基本概念から実践的な変換例まで段階的に解説

主要コンテンツ

  1. 概念説明: 文と式の根本的な違いとその意義
  2. 利点分析: 式指向プログラミングの5つの主要メリット(不変性促進、合成可能性、予測可能性、簡潔性、テスタビリティ)
  3. 進化タイムライン: C# 3.0から11.0までの式指向機能追加の歴史
  4. 実践的変換例: 3つの詳細な比較実装
    • 注文配送料計算システム
    • 顧客データ処理サービス
    • バリデーションサービス

コード例の特徴

各実装例では「従来の文指向アプローチ」と「現代的な式指向アプローチ」を並列比較し、以下のモダンC#機能を活用:

// 従来の文指向
if (order.TotalAmount >= 100m)
{
    cost = 0m;
}
else if (order.Weight <= 1.0)
{
    cost = 5m;
}
// ...

// 現代的な式指向
public decimal CalculateShippingCost(Order order) =>
    GetBaseShippingCost(order) + GetExpressFee(order);

private decimal GetExpressFee(Order order) =>
    order.IsExpress switch
    {
        true => 15m,
        false => 0m
    };

技術的改善

  • 構造最適化: 既存の章構成を最小限の変更で拡張(4.4.2以降の番号調整のみ)
  • 一貫性維持: 既存のコーディングスタイルと文体に完全準拠
  • 教育価値: 段階的学習アプローチで理解しやすい構成

この追加により、読者は関数型プログラミングの重要な概念である「式指向思考」を実践的に習得でき、現代的なC#プログラミングスキルの向上に直結します。

Fixes #87.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…amming section

Co-authored-by: Fujiwo <3992360+Fujiwo@users.noreply.github.com>
Copilot AI changed the title [WIP] 関数型プログラミングのパラダイムへの「文から式」のシフトの解説の挿入 関数型プログラミングの「文から式」のシフト解説を第4章に追加 Aug 30, 2025
@Fujiwo Fujiwo marked this pull request as ready for review August 30, 2025 06:54
Copilot AI requested a review from Fujiwo August 30, 2025 06:54
Copilot finished work on behalf of Fujiwo August 30, 2025 06:54
Copilot AI review requested due to automatic review settings August 30, 2025 06:54
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a comprehensive section about the paradigm shift from statements to expressions in functional programming to Chapter 4 "Multiparadigm Programming". The addition provides readers with practical understanding of expression-oriented programming concepts in modern C#.

Key Changes:

  • Added a new subsection "文から式へのシフト:C#における関数型パラダイムの進化" within section 4.4.1
  • Included timeline of C# evolution from version 3.0 to 11.0 showcasing expression-oriented features
  • Provided three detailed before-and-after code examples demonstrating statement-to-expression transformations

Comment on lines +1224 to +1225
| **C# 10.0** | global using | グローバルな式の簡潔化 |
| **C# 11.0** | 生の文字列リテラル | `"""多行文字列"""` |
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The C# 10.0 and C# 11.0 entries are not accurate representations of expression-oriented features. 'global using' is about namespace management, not expression simplification, and raw string literals are about string syntax, not expression-oriented programming. Consider replacing these with more relevant expression-oriented features like 'with expressions for records' (C# 9.0) or 'extended property patterns' (C# 10.0).

Suggested change
| **C# 10.0** | global using | グローバルな式の簡潔化 |
| **C# 11.0** | 生の文字列リテラル | `"""多行文字列"""` |
| **C# 10.0** | 拡張プロパティパターン | `order is { Customer.Address.City: "Tokyo" }` |
| **C# 11.0** | リストパターン | `nums is [1, 2, .., 10]` |

Copilot uses AI. Check for mistakes.
Comment on lines +1426 to +1427
.Where(error => error != null)
.Cast<string>();
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using .Cast<string>() after filtering for non-null values is unnecessary and potentially dangerous. Since ValidateName, ValidateEmail, and ValidateAge return string?, the .Where(error => error != null) already filters out null values. The .Cast<string>() should be replaced with .Select(error => error!) or use OfType<string>() instead of Where().Cast().

Suggested change
.Where(error => error != null)
.Cast<string>();
.Select(error => error!);

Copilot uses AI. Check for mistakes.
@Fujiwo Fujiwo merged commit d4a302e into main Aug 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

関数型プログラミングのパラダイムへの「文から式」のシフトの解説の挿入

2 participants