Latest / CyberSecurity Summary / C# and .NET Core Test Driven Development: Dive into TDD to create flexible, maintainable, and production-ready .NET Core applications
Transcript
- 0:00Speaker 1: You know the feeling. I mean, it happens in almost
- 0:01Speaker 1: everyone who writes software.
- 0:03Speaker 2: Oh. Absolutely.
- 0:04Speaker 1: You open up a code base because you are tracking
- 0:07Speaker 1: down a stubborn bug, right, you zero in on a
- 0:10Speaker 1: particular method, and you just stop and stare.
- 0:12Speaker 2: Yep, you're just looking at it horrified.
- 0:16Speaker 1: You think, who wrote this absolute monster? The logic is
- 0:19Speaker 1: completely twisted, The variables are named horrible.
- 0:22Speaker 2: It's like a total mess.
- 0:24Speaker 1: Yeah, and you are mentally preparing to roast whoever pushed
- 0:27Speaker 1: this commit. And then you run the get blame command.
- 0:31Speaker 2: And that is the ultimate moment of dread.
- 0:33Speaker 1: Right, you check the history and you realize you wrote
- 0:36Speaker 1: it like a year ago.
- 0:38Speaker 2: It is a universal and deeply humbling experience, that exact
- 0:42Speaker 2: moment where you realize the monster is you and past
- 0:45Speaker 2: you has left present you a massive problem.
- 0:48Speaker 1: It's the worst. But today we are looking at how
- 0:51Speaker 1: to actually stop doing this to ourselves. Welcome to our
- 0:54Speaker 1: deep dive.
- 0:54Speaker 2: Thanks for having me. I'm excited to get into this.
- 0:56Speaker 1: Yeah. So our mission today is extracting some really famtastic
- 1:00Speaker 1: strategies from Iobami odd Wolve's work, specifically c sharp and
- 1:04Speaker 1: dot net core test driven development.
- 1:06Speaker 2: It's a great text very practical, right.
- 1:09Speaker 1: Because the goal here isn't to just talk about high
- 1:12Speaker 1: level dry theory. We want to explore how to rescue
- 1:16Speaker 1: your software projects from the trap of bad.
- 1:18Speaker 2: Code exactly, and doing that by adopting test driven development
- 1:22Speaker 2: or TDD and leveraging the massive cross platform power of
- 1:28Speaker 2: dot net Core and c sharp seven.
- 1:30Speaker 1: So if we are going to talk about the cure,
- 1:32Speaker 1: which is TDD, we really have to diagnose the disease first.
- 1:35Speaker 2: We do, because bad code doesn't just magically appear overnight,
- 1:39Speaker 2: you know, it accumulates, It gets written day by day,
- 1:42Speaker 2: decision by compromised decision.
- 1:44Speaker 1: Yeah. I used to think about software architecture like building
- 1:46Speaker 1: a Lego set. Yeah, like you could just easily swap
- 1:48Speaker 1: out a blue block for a red one. Does the
- 1:50Speaker 1: dream right, right, But tight coupling, which is the root
- 1:54Speaker 1: of so much bad code, it's more like hardwiring your
- 1:57Speaker 1: kitchen coffee maker directly into your house's main electrical panel
- 2:01Speaker 1: behind the drywall.
- 2:02Speaker 2: Well, that is a great analogy because.
- 2:03Speaker 1: If the coffee maker breaks, you can't just unplug it.
- 2:05Speaker 1: You have to hire an electrician, rip upon the wall
- 2:08Speaker 1: and shut off power to the entire house. Just to
- 2:10Speaker 1: swap the appliance.
- 2:11Speaker 2: That is exactly what tight coupling feels like in a
- 2:14Speaker 2: code base. When components are tightly coupled, they know way
- 2:18Speaker 2: too much about the internal workings of each other.
- 2:21Speaker 1: So making a small chain is terrifying.
- 2:23Speaker 2: Exactly, if you make a tweak in your database query
- 2:26Speaker 2: logic and suddenly a button on your user interface stops working,
- 2:31Speaker 2: you have a hardwired coffee maker. Your code base has
- 2:34Speaker 2: become rigid, and.
- 2:36Speaker 1: Adwill points out that this rigidity constantly emits what kent
- 2:39Speaker 1: Beck famously called code smells.
- 2:42Speaker 2: Right, and a code smell isn't necessarily a bug, but
- 2:44Speaker 2: it is a glaring symptom. It points to a much
- 2:47Speaker 2: deeper structural rot when you're reading through a class.
- 2:50Speaker 1: So beyond just vague bad code, what are the specific
- 2:54Speaker 1: structural flaws we are looking for here?
- 2:56Speaker 2: Well, a classic example from the text is the monster method.
- 3:00Speaker 1: Monster method, I love that term.
- 3:01Speaker 2: It's so accurate though. This is a method that completely
- 3:04Speaker 2: abandons the single responsibility principle, and usually it happens because
- 3:08Speaker 2: of future creep.
- 3:09Speaker 1: Like you just keep adding one more thing.
- 3:10Speaker 2: Yeah, a developer ransom method to fetch user data simple enough,
- 3:14Speaker 2: but then a requirement comes in to format that data,
- 3:17Speaker 2: so they just add it to the same method.
- 3:18Speaker 1: Oh, and then they need to apply discount.
- 3:20Speaker 2: Exactly some business logic discount and then save a log
- 3:24Speaker 2: to the database. Suddenly you have a five hundred line
- 3:27Speaker 2: method that knows too much and does too much.
- 3:29Speaker 1: And another massive smell is a method with a ridiculously
- 3:33Speaker 1: long list of parameters.
- 3:34Speaker 2: Yes, oh my gosh, yes.
- 3:36Speaker 1: Like when you're passing seven different strayings, three boollions, and
- 3:40Speaker 1: injurer into one single function. It's impossible to read.
- 3:43Speaker 2: It really is when you see that The structural fix,
- 3:46Speaker 2: according to the book, is to refactor those parameters into
- 3:49Speaker 2: a poco.
- 3:50Speaker 1: A plain old colr object.
- 3:51Speaker 2: Right, instead of passing eleven disparate variables, you pass one
- 3:55Speaker 2: tightly encapsulated object that represents that specific state. It instantly
- 3:59Speaker 2: cleans up the method signature.
- 4:01Speaker 1: That makes total sense. And then there's the cardinal sin
- 4:03Speaker 1: of just copying and pasting logic, like completely failing the
- 4:06Speaker 1: dry principle don't repeat yourself.
- 4:09Speaker 2: Oh, copy pasting is a silent killer for projects.
- 4:12Speaker 1: The text uses a really clear example of this an
- 4:15Speaker 1: asp net MVC application where a developer needs to generate
- 4:20Speaker 1: a drop down list of years and.
- 4:21Speaker 2: Months, right, and they need it in two different action.
- 4:23Speaker 1: Methods, so they just write the exact same date generation
- 4:26Speaker 1: loop inside both methods.
- 4:28Speaker 2: Which seems harmless in the moment. You know, you just
- 4:30Speaker 2: copy paste to get the feature shipped on time.
- 4:33Speaker 1: But then the requirements change.
- 4:34Speaker 2: Exactly, say, the business wants the years to sort in
- 4:37Speaker 2: descending order. Now you have to remember to update it
- 4:40Speaker 2: in multiple places.
- 4:41Speaker 1: And if you update one and forget the other, you've.
- 4:43Speaker 2: Just introduced a subtle, incredibly annoying bug into production. That
- 4:48Speaker 2: logic fundamentally needed to be extracted into a single shared
- 4:51Speaker 2: utility method.
- 4:53Speaker 1: But I want to push on something really interesting here,
- 4:55Speaker 1: because bad code isn't always written by junior developers who
- 4:59Speaker 1: just don't know any better.
- 5:00Speaker 2: Oh definitely not.
- 5:02Speaker 1: Sometimes it's written by very smart developers who are misusing
- 5:05Speaker 1: advanced design patterns. And the source argues that an inappropriately
- 5:10Speaker 1: applied design pattern can actually be worse than no pattern
- 5:13Speaker 1: at all.
- 5:14Speaker 2: Yes, because misapplied patterns are dangerous. They give you this,
- 5:19Speaker 2: this illusion of good.
- 5:20Speaker 1: Architecture, like the singleton pattern.
- 5:22Speaker 2: Perfect example, the whole point of a singleton is to
- 5:25Speaker 2: guarantee that only one single instance of a resource like
- 5:28Speaker 2: a database connection pool is ever created.
- 5:31Speaker 1: Right, So usually a developer just writes an if statement
- 5:36Speaker 1: if the instance is null, instantiated, otherwise return the existing instance.
- 5:41Speaker 2: That sounds perfectly logical.
- 5:43Speaker 1: Right it does. Where does that break down?
- 5:44Speaker 2: It breaks down at the microsecond level when you introduce multiple.
- 5:48Speaker 1: Threads ah concurrency.
- 5:50Speaker 2: Yeah, imagine thread A hits that if statement, It checks
- 5:54Speaker 2: and the instance is null. But right before it can
- 5:57Speaker 2: actually create the object, the CPU context which to thread B.
- 6:01Speaker 2: Oh no, yeah, the thread B also checks the if statement.
- 6:04Speaker 2: It's still not so thread B creates the instance, and then.
- 6:07Speaker 1: The CPU switches back to thread.
- 6:09Speaker 2: A, which picks up exactly where it le liked off
- 6:11Speaker 2: and it creates another instance.
- 6:12Speaker 1: Wow. So, without a thread safe lock around that creation logic,
- 6:16Speaker 1: your best practice design pattern just caused a race condition.
- 6:20Speaker 2: Precisely, you completely defeated the purpose of the singleton. You've
- 6:25Speaker 2: potentially orphaned resources or created a memory leak, all because
- 6:29Speaker 2: a pattern was applied blindly.
- 6:31Speaker 1: Okay, So if that's the disease, this tightly coupled, glued
- 6:35Speaker 1: together code full of monster methods and race conditions, how
- 6:38Speaker 1: do we actively prevent it?
- 6:40Speaker 2: That brings us to the cure clean code and the
- 6:43Speaker 2: TDD mindset.
- 6:44Speaker 1: But I need to channel the stressed out developer for
- 6:46Speaker 1: a second.
- 6:46Speaker 2: Here, go for it.
- 6:47Speaker 1: Every developer says they love TDD, but in reality, when
- 6:50Speaker 1: the product manager is breathing down your neck for a
- 6:52Speaker 1: Friday deployment, TDD is the first thing thrown out the window.
- 6:56Speaker 1: It always is, because writing a test before you even
- 6:59Speaker 1: know if your code w were it feels like writing
- 7:01Speaker 1: double the code. It feels like a massive waste of time.
- 7:03Speaker 2: I hear that all the time. But Adowle's framework are
- 7:06Speaker 2: used powerfully against this. It is the most pervasive false
- 7:10Speaker 2: economy and software.
- 7:11Speaker 1: Engineering false economy.
- 7:13Speaker 2: How so TDD does not waste time, It redistributes it. Yes,
- 7:17Speaker 2: you are undeniably spending more time upfront, but what you
- 7:20Speaker 2: are buying with that time is immunity from catastrophic losses.
- 7:23Speaker 1: Later, right, because catching a bug later is so much
- 7:26Speaker 1: more expensive.
- 7:27Speaker 2: Think about the life cycle of a production bug. It's
- 7:30Speaker 2: not just you fixing a line of code. It's a
- 7:33Speaker 2: user getting frustrated, a support ticket being generated, the.
- 7:36Speaker 1: Product manager triaging it, interrupting your spread.
- 7:39Speaker 2: Exactly, and then you're trying to replicate the exact production
- 7:42Speaker 2: environment locally, spending hours debugging, writing the hot fix, running
- 7:47Speaker 2: the build pipeline again, and deploying.
- 7:49Speaker 1: So you're saying the return on investment for TDD comes
- 7:52Speaker 1: from catching the logic flaw at the exact moment it
- 7:55Speaker 1: leaves your brain.
- 7:56Speaker 2: Yes, rather than three weeks later in the wild. And
- 7:58Speaker 2: historically skippin' tests has been devastating. The classic cautionary tale
- 8:03Speaker 2: here is the nineteen ninety eight NASA Mars Climate Orbiter crashaw.
- 8:07Speaker 1: That was a huge disaster.
- 8:08Speaker 2: NASA lost one hundred and twenty five million dollar spacecraft.
- 8:12Speaker 2: It completely burned up in the Martian atmosphere.
- 8:14Speaker 1: It was just a unit conversion er, right, literally, just.
- 8:16Speaker 2: That one engineering team's software module calculated metrics and pounds
- 8:20Speaker 2: and the receiving module.
- 8:22Speaker 1: Expected Newton's unbelievable.
- 8:24Speaker 2: A basic automated unit test validating the output expectations of
- 8:28Speaker 2: that module could have caught the discrepancy before the rocket
- 8:31Speaker 2: ever left the launch pad.
- 8:33Speaker 1: That is a very heavy price for skipping a test.
- 8:37Speaker 1: And there's a phrase associated with his approach that I
- 8:39Speaker 1: absolutely love, the lazy programmer philosophy.
- 8:43Speaker 2: It's a great concept. A truly lazy programmer writes tests
- 8:46Speaker 2: first because they absolutely despised waking up at three am
- 8:50Speaker 2: to do tedious hot fixes.
- 8:51Speaker 1: They hate debugging spaghetti.
- 8:53Speaker 2: Coat, right, so they do the hard work up front
- 8:55Speaker 2: to ensure they never have to look at it again.
- 8:57Speaker 1: Weaponized laziness. Yeah, love it. And you know, TAD isn't
- 9:00Speaker 1: some new trendy agile fad either. The historical context in
- 9:04Speaker 1: the deep Dive is fascinating.
- 9:06Speaker 2: Yeah, we treat it like a modern invention, but it's
- 9:08Speaker 2: a foundational engineering principle. Its roots go all the way
- 9:11Speaker 2: back to the dawn of computing.
- 9:13Speaker 1: Like nineteen fifties computing.
- 9:14Speaker 2: Yeah, in nineteen fifty seven, de D McCracken was writing
- 9:17Speaker 2: about how programmers had to manually pre calculate checkcases before
- 9:21Speaker 2: they ever fed code into the machine.
- 9:23Speaker 1: Because machine time was so expensive back then.
- 9:25Speaker 2: Exactly, you had to know the expected answer before you
- 9:28Speaker 2: ran the program. And later in the early nineteen sixties,
- 9:32Speaker 2: NASA's Project Mercury utilized half day development iterations.
- 9:36Speaker 1: Which structurally mirror modern TDD review cycles precisely.
- 9:41Speaker 2: And then, of course Kent Beck modernized the explicit practice
- 9:44Speaker 2: when he built this unit testing framework for small Talk.
- 9:47Speaker 2: The philosophy has always been the same, define what success
- 9:50Speaker 2: looks like mathematically before you attempt to build it, and.
- 9:53Speaker 1: By doing that, you essentially force yourself to write self
- 9:56Speaker 1: documenting code.
- 9:57Speaker 2: That is one of the greatest side effects of TDD.
- 10:00Speaker 2: The tests become living, breathing documentation.
- 10:03Speaker 1: Because wiki pages always get outdated. Always.
- 10:06Speaker 2: If you have to write a two page wiki document
- 10:08Speaker 2: to explain how a single two hundred line class works,
- 10:12Speaker 2: you're naming conventions and your structure have failed.
- 10:14Speaker 1: But a test suite shows you exactly what inputs go
- 10:17Speaker 1: in and exactly what outputs are expected.
- 10:19Speaker 2: In executable code, it.
- 10:20Speaker 1: Never lies, all right, So the philosophy makes perfect sense,
- 10:23Speaker 1: But mechanically, day to day, how does the developer actually
- 10:26Speaker 1: execute this because it requires a totally different rhythm.
- 10:29Speaker 2: It really does. It takes practice.
- 10:31Speaker 1: It feels like calibrating a complex machine. If you build
- 10:35Speaker 1: a fire alarm, you don't calibrate it by leaving it
- 10:37Speaker 1: in a perfectly clean room.
- 10:38Speaker 2: No, you light a match under it.
- 10:40Speaker 1: Exactly, you calibrate it by lighting a match. To prove
- 10:43Speaker 1: it actually detect smoke, you have to force a failure first.
- 10:47Speaker 2: That is a brilliant way to describe the core of TDD,
- 10:52Speaker 2: the red green refactor cycle. It is an incredibly strict rhythm.
- 10:56Speaker 2: You always start in the red phase.
- 10:58Speaker 1: So writing a test fail right.
- 11:00Speaker 2: You write a test for a feature that does not
- 11:02Speaker 2: exist yet. You run the test suite and it fails,
- 11:06Speaker 2: it must throw a red error.
- 11:08Speaker 1: Because if you write a test and it passes immediately,
- 11:11Speaker 1: you've written a meaningless test. It's not actually verifying anything new.
- 11:14Speaker 2: Exactly. The red failure is proof your alarm can detect smoke.
- 11:18Speaker 2: Then you move to the green face. You write the
- 11:20Speaker 2: production code just to make it pass. Yes, And the
- 11:22Speaker 2: golden rule here is that you write just enough code
- 11:25Speaker 2: to make that specific test pass. You do not build
- 11:28Speaker 2: out future edge cases, you do not over engineer.
- 11:30Speaker 1: You just turn the test green.
- 11:32Speaker 2: Just turn it green. Once it's green, you have established
- 11:35Speaker 2: a safety net. Now and only now you enter the
- 11:39Speaker 2: refactor phase.
- 11:40Speaker 1: So you look at that code you just wrote and
- 11:42Speaker 1: you clean it up.
- 11:43Speaker 2: You strip out duplicated logic, you rename variables so they
- 11:47Speaker 2: make sense. You apply your design patterns, and because you
- 11:50Speaker 2: have the green test, you can refactor with total aggression.
- 11:53Speaker 1: Because you'll know instantly if you broke.
- 11:54Speaker 2: The logic red green. Refactor over and over aided wool use.
- 11:59Speaker 1: Is a really practically example of this in the text
- 12:02Speaker 1: validating the length of a credit card number.
- 12:04Speaker 2: That's a great exercise, Yeah, Because.
- 12:06Speaker 1: You don't just write one test that says, you know,
- 12:08Speaker 1: does it accept sixteen digits and call it a day.
- 12:12Speaker 1: You have to test the boundaries.
- 12:13Speaker 2: Boundary testing is critical. You write a test for the
- 12:16Speaker 2: correct length, then you intentionally write a test passing fifteen
- 12:20Speaker 2: digits to ensure it fails gracefully.
- 12:22Speaker 1: And then maybe pass a completely null value or an
- 12:25Speaker 1: empty string.
- 12:25Speaker 2: Right. You are mapping out the edges of your logic,
- 12:28Speaker 2: and doing.
- 12:28Speaker 1: That prevents what is known as test overfitting, right, where
- 12:32Speaker 1: the code only works for the test and nothing else.
- 12:34Speaker 2: Yes, test overfitting is when a developer just hard codes
- 12:41Speaker 2: a return true statement just to make the test light
- 12:43Speaker 2: up green, completely ignoring the actual business requirement.
- 12:47Speaker 1: Which defeats the whole purpose exactly.
- 12:49Speaker 2: You have to write comprehensive boundary tests so the production
- 12:52Speaker 2: code is forced to handle real world entropy, not just
- 12:55Speaker 2: a sterile test environment.
- 12:57Speaker 1: Now, it's worth noting that we are largely talking about
- 13:00Speaker 1: unit testing here, testing individual methods in isolation, right.
- 13:04Speaker 2: Which is just the first layer.
- 13:05Speaker 1: True architectural confidence requires multiple layers. You also need integration
- 13:10Speaker 1: tests to verify that your code actually talks to the database.
- 13:13Speaker 2: Correctly, and system testing where the application is tested as
- 13:16Speaker 2: a whole against real inputs.
- 13:18Speaker 1: And finally, user acceptance testing to ensure the software actually
- 13:21Speaker 1: solves the business problem it was built for in the
- 13:23Speaker 1: first place.
- 13:24Speaker 2: Exactly, TDD is the foundation, but it's one part of
- 13:28Speaker 2: a comprehensive quality strategy.
- 13:30Speaker 1: So TDD gives us a rigorous process for writing clean,
- 13:33Speaker 1: internally robust code. But here's the architectural reality. Even perfect
- 13:38Speaker 1: code will rot if the framework it relies on is rigid.
- 13:41Speaker 2: That is very true, and for a long.
- 13:43Speaker 1: Time, see sharp developers were sort of trapped in a
- 13:46Speaker 1: walled garden, which brings us to the monumental shift from
- 13:50Speaker 1: the traditional dot net framework to dot net Core.
- 13:53Speaker 2: It was a massive pivot for the industry.
- 13:55Speaker 1: Right if the original dot net framework was already this
- 13:58Speaker 1: massive enterprise raid powerhouse, why did Microsoft feel the need
- 14:03Speaker 1: to just burn it down and build dot ne core
- 14:05Speaker 1: from scratch?
- 14:06Speaker 2: Because the enterprise world fundamentally changed around them, and the
- 14:09Speaker 2: original framework was hopelessly, permanently tied to the Windows operating system.
- 14:15Speaker 1: He was heavily reliant on Windows APIs right, deeply things
- 14:19Speaker 1: like the Windows GDI for rendering graphics.
- 14:21Speaker 2: You simply could not take a traditional dot net framework
- 14:24Speaker 2: application and run it natively on a Linux server in
- 14:27Speaker 2: AWS or on a developer's MacBook.
- 14:29Speaker 1: And in a modern ecosystem driven by lightweight Linux containers
- 14:32Speaker 1: and Docker. Being locked into Windows servers is a massive
- 14:36Speaker 1: financial and architectural.
- 14:37Speaker 2: Liability, a total deal breaker. So Microsoft engineered dot net
- 14:40Speaker 2: Core as an open source, cross platform revolution.
- 14:44Speaker 1: The promise was right once run anywhere natively Windows, Linux macoes.
- 14:48Speaker 2: But to achieve that they had to perform radical surgery.
- 14:51Speaker 2: They had to completely strip out all the legacy technologies
- 14:55Speaker 2: that were deeply intertwined with Windows.
- 14:57Speaker 1: So all those heavy desktop libraries, Windows Presentation Foundation, widows Forms,
- 15:01Speaker 1: Windows Communication Foundation, those are just xcize from the framework
- 15:06Speaker 1: completely exactly.
- 15:07Speaker 2: They were left behind. Instead, Microsoft focused on leaner, modular
- 15:12Speaker 2: web technologies. They heavily prioritized ASP, dot net Core MVC
- 15:18Speaker 2: for building high performance APIs and web apps.
- 15:21Speaker 1: And the underlying architecture was completely reimagined entirely.
- 15:24Speaker 2: You have the core CLR, which is the new cross
- 15:26Speaker 2: platform runtime engine. It handles garbage collection and just in
- 15:29Speaker 2: time compilation dynamically regardless of what operating system it's sitting.
- 15:33Speaker 1: On, and then you have core effects the foundational class libraries. Right.
- 15:37Speaker 1: But to make that transition actually survivable for enterprise teams,
- 15:40Speaker 1: they introduced dot Net Standard, specifically dot Net Standard two
- 15:44Speaker 1: point zero.
- 15:44Speaker 2: That was crucial.
- 15:45Speaker 1: Explain how that work, because I feel like that was
- 15:47Speaker 1: the magic bullet that kept the ecosystem from totally fracturing.
- 15:51Speaker 2: It was essentially a treaty because when Microsoft suddenly had
- 15:55Speaker 2: the old dot Net framework, the new dot Net Core
- 15:58Speaker 2: and zamorin for mobile, developers panicked.
- 16:01Speaker 1: They thought they had to rewrite their libraries three times exactly.
- 16:04Speaker 2: But dot Net Standard wasn't a runtime, it was a specstication,
- 16:08Speaker 2: a contract, and Standard two point zero added over twenty
- 16:12Speaker 2: thousand APIs to that contract.
- 16:14Speaker 1: Wow.
- 16:14Speaker 2: It guaranteed that if you wrote a library targeting dot
- 16:17Speaker 2: Net Standard, it would be universally compatible across all those
- 16:19Speaker 2: different dot Net platforms.
- 16:21Speaker 1: So to fully realize this cross platform dream, developers needed
- 16:25Speaker 1: their daily tools to be just as lightweight as the framework.
- 16:28Speaker 2: Yes, the tooling had to evolve too.
- 16:30Speaker 1: You no longer need a massive, gigabyte heavy installation of
- 16:33Speaker 1: Visual Studio Enterprise just to write a simple console.
- 16:37Speaker 2: App, not at all. The workflow on Linux now is
- 16:39Speaker 2: incredibly elegant. The book walks through setting up a full
- 16:42Speaker 2: environment purely on Obuntu, and it's pretty fayforward with very
- 16:46Speaker 2: You register the Microsoft package key, use the Linux terminal
- 16:49Speaker 2: to install the dot SDK, and you're done. You just
- 16:52Speaker 2: type dot net new console in the terminal and its
- 16:54Speaker 2: scaffolds a full cross platform app in seconds.
- 16:57Speaker 1: And for editing you just use visual Studio code.
- 17:00Speaker 2: Yeah, a highly optimized cross platform editor. You install the
- 17:04Speaker 2: c sharp extension and you instantly have full intellicence, syntax highlighting,
- 17:09Speaker 2: and test runners native on Linux.
- 17:11Speaker 1: It's a completely different world. But it's not just the
- 17:14Speaker 1: framework and the tools that evolved. The programming language itself.
- 17:20Speaker 1: C sharp has been aggressively updated to push developers toward
- 17:24Speaker 1: cleaner architecture.
- 17:25Speaker 2: It really has.
- 17:26Speaker 1: Let's look at how the specific features introduced in c
- 17:28Speaker 1: sharp seven actually eliminate some of the code smells we
- 17:31Speaker 1: diagnosed earlier, because before c sharp seven, returning multiple values
- 17:35Speaker 1: from a method was an absolute nightmare.
- 17:37Speaker 2: Oh it really was. You had two terrible choices. If
- 17:40Speaker 2: you needed a method to return say a user's ID
- 17:43Speaker 2: and their total account balance, you either had to spin
- 17:46Speaker 2: up a completely new data transfer object a DTO class
- 17:49Speaker 2: just to hold those two variable.
- 17:51Speaker 1: Which clutters your project with single use classes exactly.
- 17:54Speaker 2: Or you use the old Tupple implementation, which was just
- 17:56Speaker 2: as bad right.
- 17:57Speaker 1: Because the old tupples were completely unreadable. The values were
- 18:01Speaker 1: generically named item one in item.
- 18:02Speaker 2: Two, which is the opposite of self documenting code.
- 18:05Speaker 1: You passed that item one to another developer and they
- 18:08Speaker 1: have to hunt down the original method just to figure
- 18:10Speaker 1: out what data type it's supposed to represent.
- 18:13Speaker 2: It forces you to memorize the mapping. But c Sharp's
- 18:16Speaker 2: seven introduced semantic naming for tupples. Now inline, you can
- 18:21Speaker 2: explicitly name the return values. You can return open parenthesis
- 18:25Speaker 2: in user decimal total balance, close parenthesis, and.
- 18:29Speaker 1: The calling code accesses those exact names. Yeah.
- 18:32Speaker 2: It makes the code instantly readable, lightweight, and completely eliminates
- 18:36Speaker 2: the need for useless DTOs.
- 18:38Speaker 1: Another thing that always felt really clunky to me was
- 18:40Speaker 1: the out keyword yes.
- 18:43Speaker 2: Previously, if you wanted to pass a variable by reference
- 18:46Speaker 2: using an out parameter, like when you're trying to parse
- 18:48Speaker 2: a string into an integer, you were forced to declare
- 18:50Speaker 2: an empty variable on a separate line before passing it.
- 18:53Speaker 2: Into the method.
- 18:54Speaker 1: It totally broke the flow of reading.
- 18:55Speaker 2: The code it did. But c shark seven fixed this
- 18:58Speaker 2: by allowing inline declaration. You declare the out variable right
- 19:01Speaker 2: inside the method call itself.
- 19:03Speaker 1: It tightens the syntax and.
- 19:04Speaker 2: It completely prevents errors where a developer might accidentally try
- 19:07Speaker 2: to use an uninitialized variable further down the method.
- 19:11Speaker 1: Okay, what about ref locals and returns. I've heard people
- 19:15Speaker 1: claim this is a game changer for high performance apps,
- 19:17Speaker 1: but passing variables by reference always felt like a recipe
- 19:20Speaker 1: for side effect bags. To me, is the performance gain
- 19:23Speaker 1: actually worth the risk?
- 19:25Speaker 2: It is if you are building applications where memory allocation
- 19:28Speaker 2: is your bottleneck. Historically, if you had a massive array
- 19:31Speaker 2: of data and you wrote a method to find the
- 19:33Speaker 2: fifth element, c sharp would return the value of that element.
- 19:37Speaker 1: Meaning it physically copies the data in memory exactly.
- 19:40Speaker 2: With c sharp seven, referturns allow you to return a pointer,
- 19:43Speaker 2: a reference to that exact memory location inside the array.
- 19:47Speaker 2: Oh I see, so if the calling code modifies the
- 19:49Speaker 2: return variable, it modifies the underlying array directly without ever
- 19:54Speaker 2: duplicating the memory. In massive data heavy computations, avoiding those
- 19:58Speaker 2: memory copies is a critical performance game.
- 20:01Speaker 1: So let's pull all of this together. We started with
- 20:03Speaker 1: the universal nightmare, a tightly copped, fragile codebase where every
- 20:07Speaker 1: commit is a huge.
- 20:08Speaker 2: Gamble, right, the hardwired coffeemaker.
- 20:11Speaker 1: Yes, And the way out isn't just trying harder, it's
- 20:15Speaker 1: adopting a structural discipline. You endure the initial friction of
- 20:19Speaker 1: test drift and development, you live in the red green
- 20:21Speaker 1: refactor cycle to build an automated safety net that buide
- 20:25Speaker 1: you peace of mind.
- 20:26Speaker 2: And you execute this using the incredible cross platform agility
- 20:31Speaker 2: of dot net core, leveraging the expressive syntax of c
- 20:35Speaker 2: sharp seven to write lean self documenting code.
- 20:38Speaker 1: You essentially stop fighting the framework and you stop fighting
- 20:42Speaker 1: your own logic.
- 20:43Speaker 2: It is a fundamental shift in your relationship with software engineering.
- 20:46Speaker 2: You move from a state of constant anxiety wondering if
- 20:49Speaker 2: your Friday deployment is going to crash the company, to
- 20:52Speaker 2: a state of total, mathematically proven confidence.
- 20:55Speaker 1: But you know, if we look beyond just the mechanics
- 20:57Speaker 1: who discussed today, this shift word clearly defining tests first
- 21:02Speaker 1: raises an incredibly provocative question about where our industry is heading.
- 21:06Speaker 1: How so well, because TDD forces you to articulate the
- 21:09Speaker 1: exact parameters of success, the precise boundary conditions, and the
- 21:13Speaker 1: expected outcomes before a single line of production code is written.
- 21:16Speaker 2: Yeah, that's the core of.
- 21:17Speaker 1: It, and we are currently watching the exponential rise of
- 21:21Speaker 1: AI coding assistance. If the hardest part of software engineering
- 21:24Speaker 1: becomes perfectly articulating the tests and the edge.
- 21:28Speaker 2: Cases, Oh, I see where you're going with this, will
- 21:30Speaker 2: the near future of programming simply be human engineers writing
- 21:34Speaker 2: the tests while the AI writes the code required to turn.
- 21:37Speaker 1: Them green exactly, The human defines the what, and the
- 21:41Speaker 1: AI figures out the how. That is a fascinating thought
- 21:45Speaker 1: to leave you with as you examine your own workflow
- 21:47Speaker 1: this week.
- 21:48Speaker 2: It's a very real possibility.
- 21:50Speaker 1: Because ultimately, whether it's an AI assistant or just you
- 21:52Speaker 1: at the keyboard, the endgame remains exactly the same. You
- 21:56Speaker 1: want to be able to look at a piece of
- 21:57Speaker 1: code you wrote a year ago and instead of asking
- 21:59Speaker 1: who who wrote this monster, you can say, ah, I
- 22:03Speaker 1: know exactly how this works because my.
- 22:04Speaker 2: Tests tell me so beautifully said.
- 22:07Speaker 1: Thanks for joining us on this deep dive. Until next time,
- 22:10Speaker 1: keep your tests red before they go green.