Code Whisper's Avatar

Code Whisper

@codewhisper.bsky.social

πŸ‘Ύ Anonymous engineer, sharing thoughts on code, tech & systems. 🚫 No face, just logic. x.com/codewhisperdev

126 Followers  |  587 Following  |  40 Posts  |  Joined: 04.04.2025  |  1.6821

Latest posts by codewhisper.bsky.social on Bluesky

Post image

REST Tip – Use HATEOAS to guide the client

HATEOAS = Hypermedia as the Engine of Application State

πŸ“¦ Instead of sending just data, include actions

🧠 Why?
β€’ Makes APIs discoverable
β€’ Reduces hard-coded logic on the client
β€’ Enables better versioning and evolution

09.04.2025 10:21 β€” πŸ‘ 2    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

Each class type serves a purpose.
Use them wisely to keep your codebase clean, maintainable, and SOLID.

#CSharp #DevCommunity #CleanCode

08.04.2025 19:14 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

6. Nested Classes

Class inside another class.
Can be used for tight coupling (e.g., helper classes for outer class).

08.04.2025 19:14 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Post image

5. Partial Classes

Split one class across multiple files.
Great for large codebases or designer-generated code.

08.04.2025 19:14 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Post image

4. Sealed Classes

Can’t be inherited.
Used when you want to restrict extension.

08.04.2025 19:14 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Post image

3. Static Classes

Only contains static members. Can’t be instantiated or inherited.
Perfect for utility/helper methods.

08.04.2025 19:14 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Post image

2. Abstract Classes

Use abstract when the class is meant to be inherited, not instantiated.

It can have both abstract (unimplemented) and concrete (implemented) methods.

08.04.2025 19:14 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Post image

1. Regular Classes

The most common type: public class MyClass { }
Supports inheritance, encapsulation, constructors, methods, fields.
Can be instantiated with new.

08.04.2025 19:14 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0

Let’s talk about C# class types β€” a solid foundation for OOP in .NET.

You’ll find more than just β€œclass” in C#. Let’s dive into the types you can define and use.

08.04.2025 19:14 β€” πŸ‘ 3    πŸ” 1    πŸ’¬ 2    πŸ“Œ 0
Post image

HTTP Tip

Idempotent methods can be safely retried without causing side effects.
πŸ”Ή GET, PUT, DELETE, HEAD, OPTIONS β†’ Idempotent
πŸ”Ή POST β†’ NOT idempotent

🧠 Why?

Using the correct method:
β–ͺ️ Makes APIs predictable
β–ͺ️ Enables retries in network failures
β–ͺ️ Helps with caching, monitoring, and debugging

08.04.2025 17:09 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

🧠 Why?
β€’ Scalar functions run row by row = performance bottleneck
β€’ Use inline expressions, computed columns, or TVFs (table-valued functions) for better scalability

08.04.2025 13:04 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

SQL Tip – Avoid Scalar Functions in SELECT for Performance

🚫 Bad (Scalar function kills performance on large data)

βœ… Good (Inline logic or apply in WHERE/CTE for better performance)

Example:

08.04.2025 13:04 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Post image

.NET DI Lifetime Tips:

πŸ”Ή Singleton - one of instance for entire app
πŸ”Ή Scoped - one instance per request
πŸ”Ή Transient - new instance every time

🚨 Be careful:

- Dont inject Scoped/Transient into Singleton (causes bugs/memory leaks)
- Use Singleton only for stateless or thread-safe services.

08.04.2025 12:13 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

LINQ Tip:

Use ToList() after filtering, not before

Why?

πŸ”Ή First version loads everything into memory before filtering
πŸ”Ή Second version filters at source, better for DB or large collections
πŸ”Ή Especially important when using EF Core or APIs with IQueryable

08.04.2025 10:03 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

πŸ”Ή Performance: Asynchronous iteration prevents thread blocking, keeping your app responsive.
πŸ”Ή Clean Code: No need for callbacks or complex state management like with traditional async operations.

08.04.2025 09:26 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

πŸ”Ή await foreach: Asynchronously iterates over the items one by one, allowing for non-blocking execution while the data is being fetched.

Benefits:
πŸ”ΉMemory Efficiency: Only one item is in memory at a time, so it’s ideal for processing large datasets or streams.

08.04.2025 09:26 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0

Explanation:
IAsyncEnumerable<T>: Enables you to stream data asynchronously without blocking threads.
πŸ”Ή Use yield return to return items one at a time.
πŸ”Ή Data is fetched lazily, so you only process what you need.

08.04.2025 09:26 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Post image

Efficient Async Data Streaming with IAsyncEnumerable<T>

Scenario:

You need to process a large dataset (e.g., database records, file lines, etc.), but you don’t want to load everything into memory at once. Using IAsyncEnumerable<T> lets you stream data asynchronously with minimal memory usage.

08.04.2025 09:26 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Post image

πŸ”Ή What is Queue<T>?

Queue<T> is a First-In-First-Out (FIFO) collection in C#.
It means the first item you add is the first one to be removed.

When to use?

- Task scheduling
- Print jobs
- Message handling
- Breadth-first search (BFS) in graphs

Example:

07.04.2025 19:51 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

SQL Tip:

Always monitor and maintain your indexes.
Unused or duplicate indexes = slower writes and wasted space.

Why?
- Clean indexes = faster inserts/updates
- Less I/O, better performance

πŸ” Use this to find unused indexes in SQL Server

07.04.2025 19:16 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

Csharp Tip:

Use Span<T> for high-performance, allocation-free array slicing. Avoid ToList() when you don’t need it!

Why?
πŸ”Ή Zero allocations
πŸ”Ή Lightning-fast memory access
πŸ”Ή Perfect for performance-critical code

#csharp #dotnet

07.04.2025 15:37 β€” πŸ‘ 4    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

LINQ Trip:

Use GroupJoin for efficient one-to-many relationships instead of nested loops.

Why?
πŸ”Ή Cleaner than SelectMany + Where
πŸ”Ή Ideal for creating master-detail structures in memory

07.04.2025 11:41 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

SQL Tip:

Use CROSS APPLY for row-wise calculations or to invoke table-valued functions per row.

Why?
πŸ”ΉPowerful for row-by-row subqueries
πŸ”ΉCleaner & faster than correlated subqueries in many cases

07.04.2025 08:18 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

Csharp Tip:

Use async Task for methods so exceptions can be awaited and handled properly.

Pro tip: Use async void only for UI event handlers.

06.04.2025 22:34 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

Pass by Value vs Pass by Reference
πŸ”Ή Pass by Value: A copy of the value is passed to the function. Changes inside the function don’t affect the original variable.

πŸ”Ή Pass by Reference: The memory address (reference) is passed. Changes inside the function do affect the original variable.

06.04.2025 20:23 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

SQL Tip:

Use EXISTS instead of COUNT(*) > 0 for better performance when checking if rows exist.

βœ… EXISTS stops at the first match.
❌ COUNT(*) scans the whole table.

Faster checks = faster queries ⚑

06.04.2025 12:48 β€” πŸ‘ 4    πŸ” 1    πŸ’¬ 0    πŸ“Œ 0

How does it work?
Instead of sending 1 SQL query per entity (slow), BulkUpdate:

βœ… Builds a temporary SQL table
βœ… Pushes all data into it in one batch
βœ… Runs a single efficient UPDATE JOIN on the real table
βœ… Drops the temp table after update

Result: Thousands of updates in milliseconds ⚑

06.04.2025 12:37 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

EF Core Tip – Bulk Update:

Need to update thousands of rows? Avoid looping with .SaveChanges() in EF Core β€” it's slow.
Use a bulk update library like EFCore.BulkExtensions for massive performance gains.

Bonus: Works for Insert, Delete, Merge too.

06.04.2025 12:33 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Post image

Csharp Tip:

Extract magic values into constants to improve readability and maintainability.

Cleaner code = easier maintenance!

06.04.2025 10:04 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

C# Trick:
Use Dictionary for fast lookups instead of looping!

Instead of searching a list repeatedly, store key-value pairs in a dictionary for O(1) access.

05.04.2025 22:44 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0

@codewhisper is following 20 prominent accounts