SShortSingh.
0
ProgrammingDEV Community ·

When to Use Records in .NET: Key Features and Best Practices

A software developer and blogger has outlined the main scenarios where using Records in .NET is beneficial, emphasizing that the choice should be driven by logic rather than novelty. Records offer default immutability, meaning property values cannot be changed on an existing instance — a new one must be created instead. Unlike classes, Records use value-based equality comparison, reducing boilerplate code when checking whether two instances hold the same data. Additional advantages include concise syntax, built-in deconstruction, an auto-generated ToString() method, the 'with' expression for creating modified copies, and seamless pattern matching support. The author stresses that no technology should be applied universally, and a follow-up post will cover situations where Records are not recommended.

0
ProgrammingDEV Community ·

C# Records: Immutable Data Types That Simplify Code and Testing

C# Records were introduced with C# 9 in November 2020, offering a concise way to define immutable data models using minimal code. Unlike traditional classes, Records are immutable by default, meaning their properties can only be assigned at initialization and cannot be changed afterward. A key distinction is that Records use value-based equality rather than reference-based equality, eliminating the need to manually implement Equals and GetHashCode methods. This makes unit testing simpler and reduces boilerplate code compared to writing equivalent immutable classes. Records can also include custom validation logic, making them suitable beyond simple data containers.

0
ProgrammingDEV Community ·

Combining Object Mother Pattern with AutoFixture for Cleaner Unit Tests

A software development tutorial published on DEV Community demonstrates how to combine the Object Mother design pattern with the AutoFixture library in C#. The Object Mother pattern centralizes test object creation, improving test readability and semantic clarity. AutoFixture complements this by automatically generating random test data, reducing manual setup effort. The article walks through a practical example using a User class and age-based access logic, showing how a UserMother class leverages AutoFixture's Build API to produce meaningful test objects. The combination allows developers to maintain expressive, well-organized unit tests without sacrificing flexibility in data generation.

0
ProgrammingDEV Community ·

How to Use AutoFixture with Immutable Entities in C# Unit Tests

AutoFixture is a popular .NET library used to generate test data for unit tests, but it behaves differently when working with immutable entities. While AutoFixture can successfully instantiate an immutable object using its factory method, it throws an unhandled exception when attempting to customize read-only properties via the Build().With() syntax. This issue surfaces when developers refactor their domain entities to be immutable — a recommended practice — and then find their existing AutoFixture-based tests breaking. The article, originally published on carlosvigueras.es, demonstrates the problem using an immutable User entity with a private constructor and a static Create method. A follow-up solution to resolve this incompatibility is promised in the same post.

0
ProgrammingDEV Community ·

AutoFixture: Open-Source .NET Library That Automates Test Object Creation

AutoFixture is an open-source .NET library available via NuGet that simplifies unit test setup by automatically generating objects with random data. It is designed to minimize the 'Arrange' phase of unit tests, allowing developers to focus on what is being tested rather than how test scenarios are configured. The library is particularly useful when dealing with complex objects, eliminating the need to manually assign values field by field. It also supports customized field values when random data is not sufficient for a specific test case. The article demonstrates its use through a practical example involving a User class with multiple properties tested against a Home access method.

0
ProgrammingDEV Community ·

Builder Pattern Explained as a Test Data Alternative to Object Mother

A software developer published a tutorial on the Builder design pattern, presenting it as an alternative to Martin Fowler's Object Mother pattern for creating test data. The Builder pattern is a creational design pattern used to construct complex objects, applicable in both production code and test suites. The author notes that its use in testing is a matter of preference, with both proponents and critics in the developer community. Using a C# example with User and Home classes, the tutorial demonstrates how a UserBuilder separates data creation from test logic to improve test clarity and readability. The full example code is made available on the author's GitHub repository for reference.

0
ProgrammingDEV Community ·

Data Clumps: The Code Smell That Signals Poor Program Structure

Data Clumps is a well-known code smell in object-oriented programming that refers to groups of variables repeatedly passed together across multiple parts of a program. These variables are usually related and carry a shared meaning, which is why they tend to travel together rather than being properly encapsulated. The presence of Data Clumps often signals deeper issues in software design or implementation that can hinder future scalability and maintainability. The recommended fix is refactoring: grouping related variables into dedicated classes, such as separating user data and booking date ranges into their own objects. Cleaner, better-structured code is easier to understand, modify, and scale over time.

0
ProgrammingDEV Community ·

Rule of Three: When and Why to Refactor Your Code, Explained Simply

The Rule of Three is a code refactoring principle popularized by Martin Fowler that guides developers on when to clean up repetitive code. It states that the first time you write something, just do it; the second time you write something similar, note the repetition but proceed anyway; by the third time, refactoring should begin. Refactoring improves code readability, maintainability, and benefits both the original developer and future contributors. The principle applies whether you are adding a new feature, fixing a bug, or conducting a code review. A simple C# example using Cat, Bird, and Snake classes illustrates how repeated code can be consolidated into a shared Animal base class through inheritance.

0
ProgrammingDEV Community ·

Object Mother Pattern: A Cleaner Way to Manage Test Data in .NET

The Object Mother pattern, introduced by Martin Fowler in 2006, is a class used in testing to centralise the creation of sample objects shared across multiple test suites. Unlike the Builder pattern, Object Mother avoids adding unnecessary complexity or logic to test code, which is a key concern since tests themselves should remain as logic-free as possible. By centralising test data, developers eliminate repetitive object instantiation scattered across different test files. A practical .NET and NUnit example illustrates the pattern using a user-age-based discount application with four distinct user categories. The author argues that while both patterns have their advocates, Object Mother offers a simpler and more maintainable approach to test data management.

0
ProgrammingDEV Community ·

How AI Agents Discover Unknown Marketplaces Using a Single Bootstrap URL

A software broker system has been built to introduce two AI agents to each other and facilitate negotiations, with neither agent preconfigured for the marketplace beforehand. The entire discovery process bootstraps from a single URL pointing to an Agent Card, a machine-readable document that identifies the service, its protocol version, available skills, and authentication requirements. The Agent Card is cryptographically signed using EdDSA to establish a root of trust, allowing consumers to verify the document has not been tampered with in transit. Rather than listing all marketplace functions, the card intentionally exposes only one skill — onboarding — since new agents have no account or credentials to access any other feature. This design principle ensures every element on the card is immediately actionable by the reader, preventing agents from getting stuck calling methods they are not yet eligible to use.

0
ProgrammingDEV Community ·

Developer shares personal takeaways from applying Object Calisthenics in production code

A software developer has published a concluding reflection on Object Calisthenics, a set of nine programming exercises designed to reinforce good object-oriented design principles. The author describes how they gradually internalized the rules by practicing through coding katas before applying them to real production code. According to the developer, the exercises consistently promote more readable, understandable, and maintainable code by reinforcing encapsulation and the single responsibility principle. The author recommends the Kata-Log-Rocks website as a resource for developers looking to practice these techniques alongside TDD and code smell detection. The post closes with a note that the rules should be applied with common sense rather than rigidly, and signals that upcoming articles will focus on Test-Driven Development.

0
IndiaTimes of India ·

Father Spends $800K on Land to Build Tiny-Home Community for Disabled Adults

Dave Curro is developing Forest Grove, a purpose-built community for adults with special needs, inspired by his son Bret. The project will feature 20 tiny homes alongside a community center offering essential support services. Curro personally invested $800,000 to secure the land for the initiative. A recent fundraising festival drew strong community backing for the project. Forest Grove aims to address a significant gap in affordable, suitable housing for disabled adults.

0
IndiaTimes of India ·

142-Year-Old Seed Experiment Yields Viable Plants, Set to Continue Till 2100

A seed dormancy experiment launched by botanist William James Beal in 1879 continues to yield remarkable results over a century later. In 2021, researchers unearthed seeds from the experiment and found them still viable after 142 years. DNA analysis also revealed the presence of a previously undetected hybrid moth mullein among the samples, adding an unexpected dimension to the study. The findings are expected to inform land restoration practices and support efforts to manage invasive plant species. The long-running experiment is designed to continue until 2100, underscoring science's capacity for multigenerational inquiry.

0
IndiaNDTV ·

Drunk Man Kills Wife in UP After She Refused to Skip Dance Class to Cook

A 41-year-old man named Krishna Lal Yadav allegedly killed his wife Yamini Krishna Lal Yadav in a fit of rage. The incident was triggered after Yamini refused to cook, as she wanted to attend a dance class. The accused was reportedly drunk at the time of the attack. The couple had two young children together. Authorities have identified both the victim and the accused in connection with the case.

← NewerPage 799 of 4480Older →