HomeTennisAre Shaped Records Worth It? (Pros & Cons of collection)

Are Shaped Records Worth It? (Pros & Cons of collection)

Okay, so today I wanted to mess around with “shaped records.” I’d heard about them, but never really dug in, so I figured, why not give it a shot? I’ll walk you through what I did, what worked, and what totally flopped.

Are Shaped Records Worth It? (Pros & Cons of collection)

Getting Started

First things first, I needed to, you know, actually set things up. I spun up a new project. Nothing fancy, just a basic console app to keep things simple. My goal was to have a record with some specifically shaped data, I wanted it to hold a couple of different things, kinda like a custom little data container.

I fired up my trusty editor and started defining the structure for my record. I wanted to include, let’s say, an ID (because everything needs an ID, right?), a name (gotta call it something), and maybe a couple of extra properties, just to make it interesting.

I played with different setups, trying out various combinations of properties and types. Should that extra data be a string? An integer? A list? Too many choices!

Building the Record

Next up, I got down to the actual construction of the record. I used the record keyword, slapped in the properties I’d decided on earlier. Initially, I used basic types like int and string. It was pretty straightforward, like building with LEGOs. You define the pieces, then snap them together.

Are Shaped Records Worth It? (Pros & Cons of collection)

public record SimpleShapedRecord(int Id, string Name);

Then I thought, “Let’s get a little wilder.” I threw in a list, just to see how it would handle it.

I defined a record with a List. Something like:

public record MoreComplexRecord(int Id, string Name, List<string> Tags);

Are Shaped Records Worth It? (Pros & Cons of collection)

Playing Around with Instances

With the record structure in place, I started creating a few instances. You know, just to kick the tires and see how it behaved. Populating the data was simple, and it was kinda neat to see my little data blobs take shape.

I tried different values, empty lists, long strings, the whole nine yards. Wanted to see if anything would break or act weird. Thankfully, no explosions.

Trying Some Operations

Then came the fun part – messing with the data. I wanted to see how I could work with the shape of my records. I’m talking about things like accessing individual properties and doing comparisons.

Accessing the properties was super easy. Just your standard dot notation, like you’d expect. No surprises there.

I also tried comparing some records, checking if two instances were equal. That worked like a charm, which was pretty cool. It saved me from writing a bunch of manual comparison logic.

Are Shaped Records Worth It? (Pros & Cons of collection)
  • Declared a new record type with properties I choose.
  • Created instances of the record with varied data.
  • Tried accessing properties and checked how equality comparisons worked.

Wrapping Up

So, after all that tinkering, what did I learn? Shaped records are pretty handy! They let you create these nice, clean data structures without a ton of boilerplate code. It is good for quick prototyping, or any time you need a simple, well-defined data container.

I can see myself using these in the future, probably for things. Definitely a useful tool to have in the toolbox.

Stay Connected
16,985FansLike
2,458FollowersFollow
61,453SubscribersSubscribe
Must Read
Related News

LEAVE A REPLY

Please enter your comment!
Please enter your name here