diff --git a/docs/c++/cpp-basics.md b/docs/c++/cpp-basics.md new file mode 100644 index 0000000..9322621 --- /dev/null +++ b/docs/c++/cpp-basics.md @@ -0,0 +1,126 @@ +// ...existing code... +# C++ Tech Stack + +Brief, practical tech stack and examples for modern C++ projects (aligned with CONTRIBUTING.md style). + +## What is this tech stack? +A curated set of compilers, build tools, libraries, testing and CI tools commonly used for developing reliable, cross-platform C++ applications and libraries. + +## Core Components + +- Compilers + - GCC (g++) + - Clang (clang++) + - MSVC (cl.exe) — Windows +- Build systems + - CMake (recommended) + - Meson, Bazel (alternatives) +- Package managers + - Conan, vcpkg +- Testing + - Catch2, GoogleTest +- Formatting & linting + - clang-format, clang-tidy +- Debugging & profiling + - gdb, lldb, Visual Studio Debugger, valgrind, perf +- Static analysis + - cppcheck, clang-tidy, clang-analyzer +- CI/CD + - GitHub Actions, GitLab CI, Azure Pipelines +- IDEs & Editors + - Visual Studio Code (with C/C++ extension), CLion, Visual Studio, Qt Creator + +## Basic Example + +Hello world (file: src/main.cpp) +```cpp +#include + +int main() { + std::cout << "Hello, C++ tech stack!\n"; + return 0; +} +``` +Expected output: +``` +Hello, C++ tech stack! +``` + +## Minimal CMakeLists.txt +```cmake +cmake_minimum_required(VERSION 3.16) +project(hello_cpp LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 20) +add_executable(hello src/main.cpp) +``` + +## Example unit test (Catch2) +```cpp +// tests/test_example.cpp +#define CATCH_CONFIG_MAIN +#include + +int add(int a, int b) { return a + b; } + +TEST_CASE("addition works") { + REQUIRE(add(2,3) == 5); +} +``` + +## CI snippet (GitHub Actions - build & test) +```yaml +name: CI +on: [push, pull_request] +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + compiler: [gcc, clang] + steps: + - uses: actions/checkout@v4 + - name: Install dependencies + run: sudo apt-get update && sudo apt-get install -y build-essential cmake + - name: Configure + run: cmake -S . -B build + - name: Build + run: cmake --build build --config Release + - name: Test + run: ctest --test-dir build --output-on-failure +``` + +## File organization +``` +project/ +├─ src/ +│ └─ main.cpp +├─ include/ +│ └─ project/ +├─ tests/ +│ └─ test_example.cpp +├─ CMakeLists.txt +└─ .github/workflows/ci.yml +``` + +## Common Pitfalls +- Undefined behavior (use sanitizers: -fsanitize=address,undefined,leak) +- Mixing ABIs or incompatible compiler flags +- Missing header guards / pragma once issues +- Manual memory mistakes — prefer smart pointers and RAII + +## Best Practices +- Use modern C++ (RAII, smart pointers, move semantics, constexpr, spans) +- Keep headers minimal; prefer pimpl or modules for large projects +- Enforce style with clang-format and checks in CI +- Write unit tests and run sanitizers in CI +- Use CMake modern targets and interface libraries (target_include_directories / target_compile_features) + +## Related Topics +- C++ core guidelines — https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines +- CMake documentation — https://cmake.org/documentation/ +- Conan — https://conan.io +- Catch2 — https://github.com/catchorg/Catch2 + +## References +- cppreference: https://en.cppreference.com +- Sanitizers & Undefined Behavior: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html diff --git a/docs/c-sharp/c-sharp-basics.md b/docs/c-sharp/c-sharp-basics.md new file mode 100644 index 0000000..e75152d --- /dev/null +++ b/docs/c-sharp/c-sharp-basics.md @@ -0,0 +1,124 @@ +# C# Tech Stack + +Brief, practical tech stack and examples for modern C#/.NET projects (aligned with CONTRIBUTING.md style). + +## What is this tech stack? +A concise set of SDKs, frameworks, tools and practices for building cross-platform .NET applications: web, APIs, libraries, and CLI tools. + +## Core Components +- Runtime / SDK + - .NET SDK (dotnet 6, 7, 8+) +- Frameworks + - ASP.NET Core, MAUI, Blazor +- Build & tooling + - dotnet CLI, MSBuild +- Package manager + - NuGet +- Testing + - xUnit, NUnit, MSTest +- Formatting & linting + - dotnet format, StyleCop.Analyzers, EditorConfig +- Debugging & profiling + - Visual Studio debugger, dotnet-trace, dotnet-counters, JetBrains dotTrace +- Static analysis + - Roslyn analyzers, SonarQube +- CI/CD + - GitHub Actions, Azure Pipelines, GitLab CI +- IDEs + - Visual Studio, VS Code (C# extension), Rider + +## Basic Example + +Program.cs +```csharp +using System; + +class Program { + static void Main() { + Console.WriteLine("Hello, .NET!"); + } +} +``` +Expected output: +``` +Hello, .NET! +``` + +## Minimal .csproj +```xml + + + Exe + net8.0 + + +``` + +## Example unit test (xUnit) +```csharp +// tests/CalculatorTests.cs +using Xunit; + +public class Calculator { + public int Add(int a,int b) => a + b; +} + +public class CalculatorTests { + [Fact] + public void Add_Works() { + var c = new Calculator(); + Assert.Equal(5, c.Add(2,3)); + } +} +``` + +## CI snippet (GitHub Actions) +```yaml +name: .NET CI +on: [push, pull_request] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + - run: dotnet restore + - run: dotnet build --configuration Release --no-restore + - run: dotnet test --no-build --verbosity normal +``` + +## File organization +``` +project/ +├─ src/ +│ └─ ProjectName/ +│ ├─ Program.cs +│ └─ ProjectName.csproj +├─ tests/ +│ └─ ProjectName.Tests/ +├─ .github/workflows/ +└─ README.md +``` + +## Common Pitfalls +- Mixing target frameworks or incompatible package versions +- Ignoring nullable reference warnings +- Heavy synchronous I/O on ASP.NET threads +- Leaking DI scopes or disposing shared services + +## Best Practices +- Prefer async/await for I/O +- Use DI and small services +- Enable analyzers and treat warnings as errors in CI +- Pin package versions for libraries +- Write unit and integration tests; run them in CI + +## Related Topics +- ASP.NET Core Docs — https://learn.microsoft.com/aspnet/core +- .NET API Browser — https://learn.microsoft.com/dotnet/api + +## References +- https://dotnet.microsoft.com +- xUnit: https://xunit.net