OK, so the last few videos may have seemed overly complex and confusing, why are we doing all of this
stuff with interfaces and things like that when we really don't need to?
What that leads me to the next topic, which is keep it simple.
It's the kiss pattern.
Good plotless in here.
Keep it simple case.
Now, just because a pattern exists does not mean you need to use it.
I'm going to repeat that.
Just because a pattern exists does not mean you need to use it.
There's a mentality that if a program doesn't use the latest trendy buzzwords, that it's somehow not
a good program.
It's just intrinsically bad and it's not the case.
Simple is always better.
And that is one challenge that I struggle with, because what I'm trying to explain something in a video,
I had to make it overly complex to get the point across and in my brain.
I'm screaming, this should be simpler.
I just get this voice in the back of my head going, Why are you doing this?
This makes no sense.
Stop doing this.
So let's give you an example here, a simple file.
I and I'm going to do what I call junior writing, meaning I'm now a junior developer and I'm going
to come in here and I have taken a design pattern class and I'm going to say, oh, I know Brian makes
these interfaces, so I'm going to make a file I o interface or I file IO and instead of I file it's
I'll file.
Oh.
Just because I want it to be
a Q string.
Yes.
So I'm going to make everybody in the office lives much simpler and I'm going to build this interface.
So as a class I file I o.
Public, and then I want the virtual.
All right.
And yes, so now I need a strong path.
And you string data.
Here we go.
Yes, my masterpiece is almost complete, so we can say virtual string, I'm kind of chuckling as I
do this because I've seen like co-workers and students and previous jobs and classes do this really
just make it as complex as humanly possible.
And there's really no reason for this.
So real short, it's going to read I'm sorry, it's going to write and it's going to read and we're
going to be working with cue strings exclusively.
Now, we've got this interface because, well, I took this class and this class told me I should use
interfaces because I'm following solid.
And then we're going to add new we're going to add this class and we're going to say, OK, let's call
this file system and I'm in the filesystem class.
I'm going to start putting every single file system function that I can possibly think of rename, delete,
read, write, you name it.
It's going to be in here.
This is going to be my kitchen sink for everything file system.
Now, some of you old school programmers are probably cringing right now going, oh, please, no,
don't type all this out and don't worry, I'm not going to.
So we're just going to put a simple example in here so they can file.
And we want to include Q Tech Stream.
And we also want to include our interface cue or I'm sorry, I follow, I follow, I like that word.
And we're going to say public.
I, I oh, and let's go ahead refractor this in oh yes, we are so smart, we got this in here and you
know what we're going to do?
We're going to do an interface for every single thing that we do read, write, rename, delete on it.
So we're going to have about 10000 interfaces and this class is probably going to be about 200000 lines
long and it's going to be just this massive class.
You know, I'm not going to do that.
But just as an example of how crazy I've seen some people take things.
And then I'm going to show everybody this class and tell them how proud I am of it, and then because
they're not doing the same thing, their classes are dumb that I've literally seen people I'm taking
it a bit over the top, but I've literally seen students and co-workers do this.
I mean, when I say co-workers, I was in a company and there was a season program where everybody told
me how smart he was.
And then I sat down with them and he he made something very similar.
And it was just like repetition of what already exists.
So it made no sense.
And I kind of sat him down and said, look, maybe this isn't my place, but there's an easier way.
And anyways, we're going to just take you to extreme.
And we're going to give it our final.
This is where I start making mistakes and I have to pay attention to what I'm typing while I talk,
and then we're going to say file a close notice, multiple issues right up front.
We're just automatically returning.
True.
So we're not monitoring what we actually wrote or anything like that.
We're doing a little bit here.
But really, this is a pretty bad function.
We shouldn't be doing that.
Very much demonstrative purposes only.
And then we're just going to say.
Q String value, it's going to make a blank value that we can return here.
And then we're just going to go back in here.
And because we're reading we want to read only that.
And then we're going to say the value.
And we want to read all on this, so pretty just basic code, to be brutally honest with you.
I mean, it's very rudimentary, but the underlying premise here is that we are breaking the kiss or
the keep it simple design, philosophy or design pattern is that we are overly making this complex.
So what's really going on here is, OK, we have an interface and now we have a file that uses that
interface that's basically doing things that we really don't need to do.
Hmm.
Let's take a look at this and see how we could have done this a little differently here.
So we're going to include some things here.
So we're going to include hyphy.
Oh, and let's go ahead and include the file system, kitchen sink class that we're building.
And then we're going to take you file.
Due to extreme and of course, here, dbag.
All right, so what we're going to do here is we're going to say make some functions and we're going
to do a test I oh, good to just make this completely overly complex here.
I absolutely hate doing this, to be brutally honest with you, my brain right now is screaming, stop,
stop typing, don't do this.
Why are you doing this to me, sir?
All right.
So I keep stirring path.
Provided, costarring.
And then we're going to just say, if I owe that right, I shouldn't say data point or two right path
data, we're just gonna say, are we able to write something?
And then you string value equal.
I read.
And again, we want to just read that same file back, you assert.
So we want to actually just make sure we can actually have the same data back.
I get so used to autocomplete helping me out that when it doesn't, I tend to slow down and go, OK,
did I just break my computer?
What's going on here?
All right, so let's go here, here and let's put in little else, because we live in the real world
where things often do happen and we're so critical.
Well, I really screwed that one up.
There we go.
And we're going to say a complex iota's failed.
So we want to make sure basically that we wrote the data and the data we read back is the same thing.
And then we're going to just say complex.
We could save just a microsecond of typing by doing that, and we're going to say file system and call
us AIFS, our kitchen sink and then we're going to test it.
Oh, we're going to say aifs the path and the data, because as the author of this class, I said,
this is how you should use this.
You shouldn't call this directly, you should blah blah blah blah blah.
Man that gets overly complex and it just makes my brain hurt.
Thinking about how many steps we have to take just to figure out what the heck's going on here.
A friend of mine calls that following the bread crumbs whenever somebody sends him code, says, why
is it my code working?
He calls it, I'm following the bread crumbs.
And then we're just going to say simple.
Have pretty much the same function Prototyp here, and we're just going to do it the simple way, the
way we probably should have done it right from the start, we're just gonna say parve bang.
Now, how is this really different?
Well, we're not making it overly complex.
We're keeping it simple.
And we're going to say open Kuzio device and we're going to do this in a rewrite mode.
And we're going to say, I want to ask you critical.
Simple test failed.
All right, so once we get to this point, what we can do is we can just say, OK, you're too extreme.
We're just gonna keep this as simple as possible here.
There's probably even a way to simplify this further.
And I say stream.
Data, and then we want the stream flush, don't really need that, but I'm ultra paranoid that someone's
going to run this on a different device, like a Raspberry Pi or something, and it didn't, like,
get there in time and then the data is not there.
All right.
So now that we've got all that n q string value, all stream.
Took the air out of there, an accident.
There we go.
So now we got the stream rate.
All we're going to say file closed because we no longer need that.
So we should close it.
And then we're just going to say, you assert.
And we want to say our value because the data.
Simple test passed, and I'm almost embarrassed making this overly complex, because let's be honest
here, there's no need for any of this stuff up here.
All right.
So now that we've got that in, we got my notes in.
Let's go ahead and make the magic happen, as we say.
All right, so we can say a Q string path equals and I'm just going to do it in the same directories
are executable.
And we want data.
Hello, world.
Why not?
And then we're going to call complex and we want to say path and data.
And then we're going to call our simple and let's call this path and data.
There we go.
And I'm going to come at this out for now, say Seyran should work complex iota's past.
All right, but what if it didn't?
We would have to go to this function here.
Oh, now we're making a class, but we're passing this class of this function.
Now we got to look at this function.
All right.
So now we've got a pointer and a path and blah, blah, blah, blah.
Well, now what are we doing with this area?
So now we've got to go into this class.
And first thing I see, well, we're using an interface.
So what's the interface?
And you get the point.
You've got to jump all over the place just to figure out what the heck we're actually doing.
So if whomever is making this kitchen sink class.
Does something here.
Everything that uses this class now breaks along with it.
There's a much simpler way follow, you guessed it, the kiss design pattern, which is just keep it
simple.
All of that fits very nicely in one function.
And I dare say you could probably even simplify this function even further down to a few lines.
It's very, very simple.
There's no reason to make this overly complex.