برچسب: You

  • 8 things about Records in C# you probably didn’t know | Code4IT

    8 things about Records in C# you probably didn’t know | Code4IT


    C# recently introduced Records, a new way of defining types. In this article, we will see 8 things you probably didn’t know about C# Records

    Table of Contents

    Just a second! 🫷
    If you are here, it means that you are a software developer.
    So, you know that storage, networking, and domain management have a cost .

    If you want to support this blog, please ensure that you have disabled the adblocker for this site.
    I configured Google AdSense to show as few ADS as possible – I don’t want to bother you with lots of ads, but I still need to add some to pay for the resources for my site.

    Thank you for your understanding.
    Davide

    Records are the new data type introduced in 2021 with C# 9 and .NET Core 5.

    public record Person(string Name, int Id);
    

    Records are the third way of defining data types in C#; the other two are class and struct.

    Since they’re a quite new idea in .NET, we should spend some time experimenting with it and trying to understand its possibilities and functionalities.

    In this article, we will see 8 properties of Records that you should know before using it, to get the best out of this new data type.

    1- Records are immutable

    By default, Records are immutable. This means that, once you’ve created one instance, you cannot modify any of its fields:

    var me = new Person("Davide", 1);
    me.Name = "AnotherMe"; // won't compile!
    

    This operation is not legit.

    Even the compiler complains:

    Init-only property or indexer ‘Person.Name’ can only be assigned in an object initializer, or on ’this’ or ‘base’ in an instance constructor or an ‘init’ accessor.

    2- Records implement equality

    The other main property of Records is that they implement equality out-of-the-box.

    [Test]
    public void EquivalentInstances_AreEqual()
    {
        var me = new Person("Davide", 1);
        var anotherMe = new Person("Davide", 1);
    
        Assert.That(anotherMe, Is.EqualTo(me));
        Assert.That(me, Is.Not.SameAs(anotherMe));
    }
    

    As you can see, I’ve created two instances of Person with the same fields. They are considered equal, but they are not the same instance.

    3- Records can be cloned or updated using ‘with’

    Ok, so if we need to update the field of a Record, what can we do?

    We can use the with keyword:

    [Test]
    public void WithProperty_CreatesNewInstance()
    {
        var me = new Person("Davide", 1);
        var anotherMe = me with { Id = 2 };
    
        Assert.That(anotherMe, Is.Not.EqualTo(me));
        Assert.That(me, Is.Not.SameAs(anotherMe));
    }
    

    Take a look at me with { Id = 2 }: that operation creates a clone of me and updates the Id field.

    Of course, you can use with to create a new instance identical to the original one.

    [Test]
    public void With_CreatesNewInstance()
    {
        var me = new Person("Davide", 1);
    
        var anotherMe = me with { };
    
        Assert.That(anotherMe, Is.EqualTo(me));
        Assert.That(me, Is.Not.SameAs(anotherMe));
    }
    

    4- Records can be structs and classes

    Basically, Records act as Classes.

    public record Person(string Name, int Id);
    

    Sometimes that’s not what you want. Since C# 10 you can declare Records as Structs:

    public record struct Point(int X, int Y);
    

    Clearly, everything we’ve seen before is still valid.

    [Test]
    public void EquivalentStructsInstances_AreEqual()
    {
        var a = new Point(2, 1);
        var b = new Point(2, 1);
    
        Assert.That(b, Is.EqualTo(a));
        //Assert.That(a, Is.Not.SameAs(b));// does not compile!
    }
    

    Well, almost everything: you cannot use Is.SameAs() because, since structs are value types, two values will always be distinct values. You’ll get notified about it by the compiler, with an error that says:

    The SameAs constraint always fails on value types as the actual and the expected value cannot be the same reference

    5- Records are actually not immutable

    We’ve seen that you cannot update existing Records. Well, that’s not totally correct.

    That assertion is true in the case of “simple” Records like Person:

    public record Person(string Name, int Id);
    

    But things change when we use another way of defining Records:

    public record Pair
    {
        public Pair(string Key, string Value)
        {
            this.Key = Key;
            this.Value = Value;
        }
    
        public string Key { get; set; }
        public string Value { get; set; }
    }
    

    We can explicitly declare the properties of the Record to make it look more like plain classes.

    Using this approach, we still can use the auto-equality functionality of Records

    [Test]
    public void ComplexRecordsAreEquatable()
    {
        var a = new Pair("Capital", "Roma");
        var b = new Pair("Capital", "Roma");
    
        Assert.That(b, Is.EqualTo(a));
    }
    

    But we can update a single field without creating a brand new instance:

    [Test]
    public void ComplexRecordsAreNotImmutable()
    {
        var b = new Pair("Capital", "Roma");
        b.Value = "Torino";
    
        Assert.That(b.Value, Is.EqualTo("Torino"));
    }
    

    Also, only simple types are immutable, even with the basic Record definition.

    The ComplexPair type is a Record that accepts in the definition a list of strings.

    public record ComplexPair(string Key, string Value, List<string> Metadata);
    

    That list of strings is not immutable: you can add and remove items as you wish:

    [Test]
    public void ComplexRecordsAreNotImmutable2()
    {
        var b = new ComplexPair("Capital", "Roma", new List<string> { "City" });
        b.Metadata.Add("Another Value");
    
        Assert.That(b.Metadata.Count, Is.EqualTo(2));
    }
    

    In the example below, you can see that I added a new item to the Metadata list without creating a new object.

    6- Records can have subtypes

    A neat feature is that we can create a hierarchy of Records in a very simple manner.

    Do you remember the Person definition?

    public record Person(string Name, int Id);
    

    Well, you can define a subtype just as you would do with plain classes:

    public record Employee(string Name, int Id, string Role) : Person(Name, Id);
    

    Of course, all the rules of Boxing and Unboxing are still valid.

    [Test]
    public void Records_CanHaveSubtypes()
    {
        Person meEmp = new Employee("Davide", 1, "Chief");
    
        Assert.That(meEmp, Is.AssignableTo<Employee>());
        Assert.That(meEmp, Is.AssignableTo<Person>());
    }
    

    7- Records can be abstract

    …and yes, we can have Abstract Records!

    public abstract record Box(int Volume, string Material);
    

    This means that we cannot instantiate new Records whose type is marked ad Abstract.

    var box = new Box(2, "Glass"); // cannot create it, it's abstract
    

    On the contrary, we need to create concrete types to instantiate new objects:

    public record PlasticBox(int Volume) : Box(Volume, "Plastic");
    

    Again, all the rules we already know are still valid.

    [Test]
    public void Records_CanBeAbstract()
    {
        var plasticBox = new PlasticBox(2);
    
        Assert.That(plasticBox, Is.AssignableTo<Box>());
        Assert.That(plasticBox, Is.AssignableTo<PlasticBox>());
    }
    

    8- Record can be sealed

    Finally, Records can be marked as Sealed.

    public sealed record Point3D(int X, int Y, int Z);
    

    Marking a Record as Sealed means that we cannot declare subtypes.

    public record ColoredPoint3D(int X, int Y, int Z, string RgbColor) : Point3D(X, Y, X); // Will not compile!
    

    This can be useful when exposing your types to external systems.

    This article first appeared on Code4IT

    Additional resources

    As usual, a few links you might want to read to learn more about Records in C#.

    The first one is a tutorial from the Microsoft website that teaches you the basics of Records:

    🔗 Create record types | Microsoft Docs

    The second one is a splendid article by Gary Woodfine where he explores the internals of C# Records, and more:

    🔗C# Records – The good, bad & ugly | Gary Woodfine.

    Finally, if you’re interested in trivia about C# stuff we use but we rarely explore, here’s an article I wrote a while ago about GUIDs in C# – you’ll find some neat stuff in there!

    🔗5 things you didn’t know about Guid in C# | Code4IT

    Wrapping up

    In this article, we’ve seen 8 things you probably didn’t know about Records in C#.

    Records are quite new in the .NET ecosystem, so we can expect more updates and functionalities.

    Is there anything else we should add? Or maybe something you did not expect?

    Happy coding!

    🐧



    Source link

  • Wish You Were Here – Win a Free Ticket to Penpot Fest 2025!

    Wish You Were Here – Win a Free Ticket to Penpot Fest 2025!


    What if your dream design tool understood dev handoff pain? Or your dev team actually loved the design system?

    If you’ve ever thought, “I wish design and development worked better together,” you’re not alone — and you’re exactly who Penpot Fest 2025 is for.

    This October, the world’s friendliest open-source design & code event returns to Madrid — and you could be going for free.

    Penpot Fest, 2025, Madrid

    Why Penpot Fest?

    Happening from October 8–10, 2025, Penpot Fest is where designers, developers, and open-source enthusiasts gather to explore one big idea:
    Better, together.

    Over three days, you’ll dive into:

    • 8 thought-provoking keynotes
    • 1 lively panel discussion
    • 3 hands-on workshops
    • Full meals, drinks, swag, and a welcome party
    • A breathtaking venue and space to connect, collaborate, and be inspired

    With confirmed speakers like Glòria Langreo (GitHub), Francesco Siddi (Blender), and Laura Kalbag (Penpot), you’ll be learning from some of the brightest minds in the design-dev world.

    And this year, we’re kicking it off with something extra special…

    The Contest: “Wish You Were Here”

    We’re giving away a free ticket to Penpot Fest 2025, and entering is as easy as sharing a thought.

    Here’s the idea:
    We want to hear your “I wish…” — your vision, your frustration, your funny or heartfelt take on the future of design tools, team workflows, or dev collaboration.

    It can be:

    • “I wish design tools spoke dev.”
    • “I wish handoff wasn’t a hand grenade.”
    • “I wish design files didn’t feel like final bosses.”

    Serious or silly — it’s all valid.

    How to Enter

    1. Post your “I wish…” message on one of the following networks: X (Twitter), LinkedIn, Instagram, Bluesky, Mastodon, or Facebook
    2. Include the hashtag #WishYouWereHerePenpot
    3. Tag @PenpotApp so we can find your entry!

    Get creative: write it, design it, animate it, sing it — whatever helps your wish stand out.

    Key Dates

    • Contest opens: August 4, 2025
    • Last day to enter: September 4, 2025

    Why This Matters

    This campaign isn’t just about scoring a free ticket (though that’s awesome). It’s about surfacing what our community really needs — and giving space for those wishes to be heard.

    Penpot is built by people who listen. Who believe collaboration between design and code should be open, joyful, and seamless. This is your chance to share what you want from that future — and maybe even help shape it.

    Ready to Join Us in Madrid?

    We want to hear your voice. Your “I wish…” could make someone laugh, inspire a toolmaker, or land you in Madrid this fall with the Penpot crew.

    So what are you waiting for?

    Post your “I wish…” with #WishYouWereHerePenpot and tag @PenpotApp by September 4th for a chance to win a free ticket to Penpot Fest 2025!

    Wish you were here — and maybe you will be. ❤️





    Source link

  • DPDP Act Compliance Checklist for Indian Businesses: What You Need to Do Now

    DPDP Act Compliance Checklist for Indian Businesses: What You Need to Do Now


    India has officially entered a new era of digital governance with the enactment of the Digital Personal Data Protection (DPDP) Act, 2023. For businesses, the clock is ticking.

    The Act mandates how organizations handle personal data and introduces significant penalties for non-compliance. It’s not just an IT issue anymore; it’s a boardroom concern that cuts across legal, HR, marketing, and product teams.

    This blog provides an essential compliance checklist to help Indian businesses understand and align with the DPDP Act before enforcement begins.

     

    1. Understand What Qualifies as Digital Personal Data

    Under the DPDP Act, personal data refers to any data about an identifiable individual. The law applies to data:

    • Collected digitally, or
    • Digitized from non-digital sources and then processed.

    Whether you’re storing customer details, employee information, or vendor records, it’s covered if it’s personal and digital.

     

    1. Appoint a Data Protection Officer (DPO)

    You’ll need a Data Protection Officer (DPO) if your organization processes large volumes of personal data. This person must:

    • Act as the point of contact for the Data Protection Board of India.
    • Ensure compliance across departments.
    • Handle grievance redressal from data principals (users).

     

    1. Map and Classify Your Data

    Before securing or managing personal data, you must know what you have. Conduct a complete data discovery and classification exercise:

    • Identify where personal data resides (servers, cloud apps, local drives).
    • Categorize it by sensitivity and usage.
    • Tag data to individuals (data principals) and note the purpose of collection.

    This is foundational to compliance, enabling you to correctly apply retention, consent, and deletion rules.

     

    1. Implement Robust Consent Mechanisms

    The DPDP Act emphasizes informed, specific, and granular consent. Ensure your systems can:

    • Capture affirmative user consent before data collection.
    • Clearly state the purpose for which the data is collected.
    • Allow easy withdrawal of consent at any time.

    Dark patterns, pre-checked boxes, or vague terms won’t cut it anymore.

     

    1. Enable Data Principal Rights

    The Act grants every individual (data principal) the right to:

    • Know what personal data is being collected.
    • Access and correct their data.
    • Request deletion of their data.
    • Nominate someone to exercise rights posthumously.

    You must build systems that can fulfill such requests within a reasonable timeframe. A sluggish or manual process here could result in reputational damage and fines.

     

    1. Revamp Your Privacy Policy

    Your privacy policy must reflect your compliance posture. It should be:

    • Written in clear, simple language (avoid legalese).
    • Updated to include new consent practices and rights.
    • Accessible on all platforms where data is collected.

    Transparency builds trust and aligns with the DPDP mandate for fair processing.

     

    1. Review and Redefine Data Sharing Agreements

    If your company works with third parties (vendors, cloud providers, agencies), it’s time to revisit all data processing agreements:

    • Ensure contracts specify responsibilities and liabilities under the DPDP Act.
    • Avoid sharing data with parties that cannot ensure compliance.
    • Include clauses about breach notification and data retention.

     

    1. Establish a Breach Response Protocol

    The law mandates reporting data breaches to the Data Protection Board and affected users. Prepare by:

    • Setting up a dedicated incident response team.
    • Creating SOPs for breach detection, containment, and reporting.
    • Running breach simulation drills for preparedness.

    Time is critical; delays in breach reporting can attract harsh penalties.

     

    1. Train Your Teams

    Compliance isn’t just about tools; it’s about people. Conduct mandatory training sessions for all employees, especially those in:

    • IT and data management
    • Sales and marketing (who handles customer data)
    • HR (who manage employee records)

    Awareness is your first line of defense against accidental data misuse.

     

     

    1. Invest in Technology for Automation and Governance

    Manual compliance is error-prone and unsustainable. Consider deploying:

    • Data Discovery & Classification tools to auto-tag and manage personal data.
    • Consent Management Platforms (CMPs) to handle user permissions.
    • Access Control & Encryption solutions to protect data at rest and in transit.

    Platforms like Seqrite Data Privacy offer end-to-end visibility and control, ensuring you stay audit-ready and compliant.

     

    The Bottom Line

    The DPDP Act is not a one-time checkbox—it demands continuous, demonstrable accountability. Indian businesses must view it as a catalyst for digital transformation, not just a regulatory hurdle.

    By acting now, you avoid penalties and earn consumer trust in an era where privacy is a competitive differentiator.

    Is your business ready for the DPDP Act? Talk to Seqrite today to explore how our data privacy solutions can streamline your compliance journey.



    Source link

  • How Data Analytics Can Help You Grow Your Business

    How Data Analytics Can Help You Grow Your Business


    In today’s fast-paced and competitive business landscape, companies must leverage data analytics to better understand their customers, improve products and services, and make informed decisions that can help their business grow. With the right tools and insightful analytics, businesses can identify new opportunities, spot trends, and gain a competitive advantage. In this article, we will explore four ways data analytics can help you grow your business. Keep reading to learn more.

    Boosting Customer Engagement and Loyalty

    Customer Engagement

     

    One of the primary benefits of using data analytics in your business is the ability to better understand your customers. By collecting and analyzing customer data, you can gain insights into their preferences, needs, and behaviors. This information can then be used to create targeted marketing campaigns and personalized experiences that are tailored to their specific interests. As a result, customers will feel more engaged with your brand and are more likely to remain loyal, resulting in higher customer retention rates and increased revenue.

    Additionally, by analyzing customer feedback, businesses can determine what aspects of their products or services require improvement. This can lead to increased customer satisfaction and an even stronger brand reputation. Having access to some of the best data analytics programs can greatly enhance your understanding of your target audience.

    Furthermore, data analytics allows businesses to identify and reach out to potential customers, leading to a more effective acquisition process. By utilizing various channels, techniques, and types of data, businesses can identify potential customers who are most likely to convert, allowing them to maximize their marketing efforts and investments.

    Improving Operational Efficiency

    Data analytics can also be invaluable in improving operational efficiency within a business. By collecting and analyzing data from internal processes, businesses can pinpoint areas of inefficiency, identify bottlenecks, and determine areas that require optimization. This can lead to significant cost savings and better resource allocation, ultimately resulting in improved profitability.

    Data analytics can also be applied to supply chain management, helping businesses optimize their inventory levels, reduce waste, and manage their relationships with suppliers more effectively. This can result in a more streamlined supply chain, leading to improved customer satisfaction and increased revenue.

    Businesses that are involved in transportation or logistics, such as those utilizing Esso Diesel for fuel, can also employ data analytics for optimizing routes and vehicle performance. By analyzing data on fuel consumption, traffic patterns, and driver behavior, businesses can implement more cost-effective and efficient transportation strategies, leading to significant savings and a better environmental footprint.

    Supporting Informed Decision-Making

    Data analytics is a key tool in helping business leaders make more informed and data-driven decisions. Rather than relying on intuition or gut feelings, businesses can use data to analyze past performance, project future trends, and identify patterns to support their decision-making process. This results in better strategic planning and more effective decision-making, enabling businesses to grow and stay ahead of their competition.

    For example, data analytics can be used to identify revenue-generating products or services, allowing businesses to focus their resources on these areas. This can help to consolidate their position within the market and drive growth through targeted investments and expansion.

    Innovating and Developing New Products

    Innovating and Developing New Products

    Lastly, data analytics can support innovation by helping businesses to identify new product development opportunities. By understanding customer needs, preferences, and pain points, businesses can develop products and services that meet the demands of their existing customers, but also attract new ones.

    Furthermore, data analytics can be used to identify emerging trends or unmet needs within the market. By leveraging this information, businesses can position themselves as leaders and innovators within their industry, setting them apart from their competitors and driving growth.

    Data analytics is a powerful tool that can drive growth and improvements across various aspects of a business, from enhancing customer engagement and loyalty to optimizing internal processes, supporting informed decision-making, and fostering innovation. By harnessing the power of data analytics, businesses can set themselves on a path to sustained growth and success.



    Source link