Unhandled Exceptions - With Callum Linington

Durée: 70m38s

Date de sortie: 15/10/2024

In this episode, I was joined for a second time by Callum Linington - this time to discuss exceptions, which is quite fitting given the show’s name! We chatted about why you should avoid using exceptions for your main business logic and control flow, and explored better ways to handle errors. And I’m afraid the “monad” word got thrown in too! 🙈For a full list of show notes, or to add comments - please see the website here

Hey, everyone, welcome to the Unhandled Exception Podcast. I'm Dan Clark and this is episode
number 72 and 72 episodes into a podcast called The Unhandled Exception Podcast and we still
n'avons pas eu l'épisode en parlant de l'exception, nous allons changer de l'aventure
aujourd'hui, c'est Calum Linden, un membre de la show Colum.
Ah oui, merci pour avoir me. Nous n'avons jamais parlé d'exceptions, c'est la première
fois.
Il m'a bien dit que nous n'avons pas réellement eu un professeur comme...
Il y a un autre.
Je pense que je me souviens d'avoir fait une joke sur l'an ou deux.
Il a dû être fait.
Oui, exactement. Mais je ne pense pas que nous avons eu un professeur, nous avons réellement
eu un professeur en parlant de l'exception.
Il a dû être fait. Il a dû être fait.
Il y a eu beaucoup de jokes comme ça.
Je vais voir moi-même maintenant.
Je vais juste aller.
Il y a deux dôles derrière, vous avez eu la option.
Oui, oui, oui.
Oui, on peut en prendre.
Oui, oui.
Oui, oui.
Oui, oui.
Il a été un peu longtemps depuis notre dernière conversation, je pense que nous avons fait un
tour de l'aventure.
Oui, c'était l'épisode 26, l'aventure et l'aventure en architecture.
Oui, oui.
Oui, oui.







Oui, oui.








Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.







Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.

Oui, oui.

Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.


Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.





Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.


Oui, oui.
Oui, oui.















Oui, oui.
Oui, oui.
Oui, oui.
Oui, oui.
de ce que l'on a dit, parce que le sentiment a été choqué à 30 différents pièces.
Oh, vraiment ?
Bien, j'ai l'air d'une vidéo avec l'audio, donc peut-être que c'était juste de mauvaises
choses, mais avec l'audio, comme ce podcast, j'ai choqué beaucoup de choses comme
des hums, etc. et surtout, il peut être le plus odd que vous pouvez le dire, mais il y a
beaucoup de cooks que les gens ne sauraient pas, parce que, oui, je ne sais pas, c'est
assez satisfait, en fait, d'être vraiment un peu plus de l'audio, de tous mes
hums et hums et des choses.
Oui.
Mais pour ceux, parce que, évidemment, les 26 épisodes, c'est pas mal de temps,
surtout avec ma fréquence, c'était probablement quelques années plus tard.
Oui.
Donc pour ceux qui n'ont pas entendu l'épisode, ou ont un souvenir comme moi,
pouvez-vous juste vous introduire à l'écart et nous dire un peu de ce que vous
faites ?
Oui, sûr.
Mon nom est Calum.
Je sais que vous devez le dire dans les meetings, mais vous êtes sur les équipes, et c'est
comme, c'est spécialement des grands entiers qui disent, « Ah, maintenant, vous introduisiez
vous-même ». Et vous vous dites, « OK, mon nom est Calum ». Vous vous sentez comme, « Ah,
peut-être que je parle de l'alcoolisme ou pas ? » Je veux dire, vous êtes des développeurs,
oui ? Mais oui, non.
Je n'ai pas de problème avec les exceptions.
Oui, oui, oui, c'est ça.
Je suis d'une manière spéciale.
Oui, non, je suis Calum.
Je suis principal enjeuner, currently working at a new startup called Insurex.
Awesome bunch of people, Insurex, and really smart people, doing some really exciting stuff
in the insurance space, like really exciting stuff.
So, I'm really happy to join.
Before that, just a lot of principal engineering, a bit of contracting.
I've been coding, you know, since I was a kid.
It's kind of my love, programming languages as well.
It's kind of like sort of growing as a big love of mine.
Love looking at different programming languages and how they work and all that kind of stuff.
So, that's quite interesting to me.
Mainly being in the dotnet space, lots of C-sharp, lots and lots of C-sharp.
Then move sort of to F-sharp stuff.
I think a lot of people probably know me for F-sharp stuff.
Je vais probablement ennoyer beaucoup de gens avec le temps de parler de ça.
C'est une langue de la vie.
J'ai fait des trucs en Go, Rust, C++, juste un whole bunch de choses.
Et plus recently, c'est où ce truc d'événement qui vient de la vie.
L'année dernière, j'étais vraiment en train de faire des trucs d'EDD.
Et puis, évidemment, l'événement qui est partie de ça.
Les objectifs de valeur et tout ça, c'est partie de ça.
Quand on a fait l'événement, juste après ça,
c'est quand je commence à aller sur les couchiers des objectifs de valeur.
Donc, les objectifs de valeur.
Je fais beaucoup de ces présentations.
J'ai fait des trucs d'EDD en Souten-Ouest et des met-ups de dotnet en Souten-Ouest.
C'est ça que j'ai fait pour ça.
Et maintenant, je n'ai pas bougé, mais je vais maintenant ajouter ce truc exceptionnel à la liste.
Parce que ça sort de la voie de l'objectif de valeur et du objectif de main.
Ça sort de la voie de la voie.
Et oui, je veux juste parler de ça en général, je pense.
Et puis, à un point plus tard, on va parler de langues en général,
parce que l'acceptance est un feature de langues.
Donc, oui, il y a un truc.
C'est moi, c'est ce que j'ai fait.
Ça me semble bien.
Oui, tu as mentionné juste après d'en parler de dotnet en Souten-Ouest.
J'ai vu que, la semaine prochaine, tu fais un truc exceptionnel.
La semaine prochaine, ce qui se passe.
La semaine prochaine, je vais avoir la reddit de dotnet,
où je vais faire ce qu'on parle dans le format présent.
C'est un format présent.
Peut-être que c'était reddit.
Mais j'ai vu une sécurité exceptionnelle.
Et c'était toi et quelqu'un d'autre.
J'ai parlé de sécurité.
Oui, donc, Daniel, DS, il fait un truc sur la sécurité.
Changer la voie de la suite de burps.
Oui.
Sans avoir l'intention de ça.
Je l'ai seulement récentement entendu de burps.
Parce que mon client a eu des gens de sécurité dans un truc.
Et oui, ça a été vraiment cool.
Oui, je n'ai jamais entendu,
jamais vu ça.
Ça va être intéressant de parler et de l'entendre, à l'honneur.
Je dois voir ce que je fais.
En ce moment, je vais me faire barrer.
Et puis, au-delà de votre talk sur comment éviter les exceptions.
Oui.
Mais avant de parler des exceptions,
je vais juste faire ce épisode, je vais le mentionner.
Et celui-ci va au Neil Dockety.
En LinkedIn, il a posté un autre podcast excellent,
qui, comme un bonheur, a aidé le temps à aller plus vite
pendant que je suis sur le treadmill.
Et il a referé au dernier épisode,
où je suis jointé par Scott Sauer,
en parlant de la action de Github.
Et si les personnes qui veulent les parler,
sont en train de le faire,
ils vont juste envoyer un poste social,
en mentionnant moi sur les réseaux sociaux.
Tout le feedback est grandement apprécié.
Et ça m'a aidé à me faire profiter de l'économie.
Et n'oubliez pas que ce podcast a sa propre communauté de discôtre.
Si vous vous rendez sur le site
unhandleexceptionpodcast.com,
vous verrez un lien de discôtre.
Right next to a link,
où vous pouvez abonner à ma newsletter.
Et puis,
et puis,
je vais remercier que ce podcast est responsable de l'Evastac,
qui est mon propre company,
qui va nous donner des services de développement de l'air,
et des services de consultation.
Pour plus d'informations, visitez l'Evastac.com.
Et nous sommes en train de faire plus de sponsors,
donc si vous êtes intéressés, vous pouvez le faire.
Right, on va parler des exceptions.
Donc je vais vous envoyer une exception,
et je veux voir Callum catcher
et voir ce que j'ai fait.
Prêt ?
Faire un nouveau...
Et Callum est en train de faire la cachée.
C'est ce que je veux dire.
Faire un nouveau podcast de l'exception de l'unhandle.
Je suis inquiétant de comment Callum va réagir
une exception d'unhandle.
Et il y a des exceptions,
mais il y a des exceptions.
Pourquoi on commence ?
Pourquoi...
Ouais, on commence.
Je pense que le bon endroit de commencer
est ce quelles sont les exceptions,
pourquoi elles existent,
et ce qu'elles sont supposedes être utilisées pour.
Parce que je pense que, parfois,
quand vous regardez les codes des gens,
ça sort de la même manière.
Je pense que tout le monde s'occupe de les exceptions,
pour des circonstances exceptionnelles.
Mais je ne vois pas si elles sont suivies.
Donc, dans le framework de l'Ontario,
ce sont les exceptions.
Vous savez,
elles sont en fait une implementation
au-dessus de l'exception de l'un de ses 32.
Et je pense que elles sont...
Elles sont supposedes de se marier
plus près de les exceptions de la C++.
Et vraiment, elles sont là
pour, vous savez,
catcher des sortes de hardware issues
qui vont sur, vous savez,
et si des...
Une...
Une issue non expectante
va sur le hardware.
Et c'est quand vous devez les faire,
et les catcher.
Mais, ouais,
c'est où...
C'est où, je pense,
avec les exceptions,
c'est où ça sort,
parce que je pense que les gens
vont un peu au-dessus
avec les exceptions après ça.
Vous voyez des méthodes de garde.
Tout le monde met des méthodes de garde
sur leur méthode.
Certaines personnes les font.
Elles mettent des méthodes sur leur méthode
et lavent les exceptions
si les choses ne sont pas au bon état.
Donc, vous avez tous ces exceptions
qui sont en train de se mettre à l'intérieur.
Et puis, c'est comme...
À ce point,
comment vous faites?
Comment vous sortez de vos exceptions?
Qu'est-ce que vous lavez faire?
Vous le vous throw.
Ça se trouve un peu plus...
C'est un peu plus...
Vous faites vos vos exeptions
et vous vous throw à la tête.
Vous avez-vous de votre...
Vous n'avez pas l'application d'exception.
C'est...
Si vous regardez le documentaire
sous les exceptions...
Les guidelines de l'exception
comme elles sont laid out
par le standard.
Vous n'êtes pas supposed
d'avoir eu l'exception.
Vous n'êtes pas supposed
d'avoir eu l'exception de système.
Vous n'êtes pas supposed
d'avoir eu l'exception.
Vous n'êtes pas supposed
d'avoir eu l'exception de système
si vous intentez re-faire.
Vous devez éviter
les handelers de l'exception

Vous ne devez
jamais vous throw
d'un exception d'application.
Mais vous devez vous throw
une exception d'opportunité.
Et puis ça va juste
pour un tout petit peu
d'autres types d'exception.
Comment vous êtes supposed
de travailler avec ça?
Juste prendre le premier
point,
où il a dit
que vous n'êtes pas supposed
d'avoir eu l'exception.
Juste de clarifier aux listeners
que vous ne vous direz
le niveau de la tête
d'exception.
Nous n'avons pas dit
que vous n'avez pas eu l'exception
mais que vous n'avez pas eu l'exception.
Oui, je ne vous en prie pas.
Oui, oui, oui.
Merci pour la clarification.
Oui, vous ne throw
d'un système d'exception
ou d'un système d'exception.
Naming des choses.
Mais oui,
il y a deux problèmes.
Tout d'abord,
il y a un whole bunch
de choses que vous avez
essayé de rappeler.
Et c'est comme,
vous savez,
comment est-ce que vous vous rappelez?
Vous savez, c'est pas...
Je veux dire,
à l'heure de dire,
je n'ai jamais vécu
la partie de cette chose
et j'ai commencé
à regarder un peu plus bas.
Et je pense que personne
autre connait
toutes ces intricacies.
Sur ce que vous êtes supposed
ou ce que vous n'êtes pas supposed
à faire.
Et puis,
sur ce que vous n'êtes pas supposed
à réciter l'exception.
Mais le système d'exception
est le base d'exception
pour chaque autre exception.
Donc, si vous vous implementez
l'exception,
vous pourrez probablement
l'inherir de l'exception du système.
Et ça,
ou ça ne devrait pas
être surprenant,
quelque chose de ce genre.
Donc,
à commencer à réciter les choses
broad,
et comme ça,
si c'est un niveau top,
le sondage d'exception,
vous savez,
vous êtes supposed à le faire
et à faire quelque chose
d'exception.
Et si vous réutilisez
l'exception de même
sur et sur,
comment
ça fonctionne
pour se battre
sur ce que l'idée est?
Donc,
l'exemple de ça
est
que si vous vous l'avez écrit
dans un API,
les plus grands APIs
vont toujours
retourner à un
valeur.
C'est pareil avec un programme

Si ça retourne
à un valeur,
ça devrait être
retourné à un int.
Et ce int
va détailler
si c'est un succès.
Donc, vous devez toujours
retourner à un valeur.
Et dans le termes de l'HGP,
ça pourrait être
un whole bunch de différents
codes de state,
qui signifie un whole bunch
de choses différentes.
Et donc,
quand vous vous
vous réutilisez
et vous vous l'avez réutilisé,
comment vous vous bougez
chaque des exceptions
à un point particulier?
Et si vous
l'avez accidentement
une exception
pour les deux,
peut-être un 400,
pour dire,
c'est une bonne réquesté,
ou l'utilise une exception
pour,
vous savez,
un 200,
pour un 500,
pour exemple,
un serveur internel.
Comme,
si vous l'avez accidentement
cross-le,
vous avez le même code de state
pour vous.
Donc, vous avez l'idée
de la compétition.
Mais je vais mettre ça
à l'autre côté pour un second.
Et ensuite,
juste retourner
à l'autre côté de ça,
c'est comme,
l'exception de l'exception
et de l'exception de l'exception.
Et c'est la partie
dont je n'aime pas particulièrement.
Je n'ai pas particulièrement
un fan de comment
ils ont été implementés.
Tout d'abord,
avec ces exceptions,
où sont-ils documentés?
En code, je pense.
J'espère.
Je veux dire,
j'espère.
Je pense que le problème
est que si vous vous faites
votre propre exception custom
et vous vous en avez bien,
ça probablement est en code.
Mais...
Donc,
un exercice intéressant
pour le reader,
ou le reader,
ou le listener,
ou...
Je sais pas,
ou tout le monde,
mais,
vous savez,
le exercice intéressant
pour le listener
serait de
aller prendre le client de l'HCME
et faire un request de l'HCME
et
faire surement
que vous vous défendez
toutes les exceptions
que pourrait arriver.
Et vous verrez
comment
difficile c'est.
Parce que vous n'avez pas d'idée
et
pour le framework
pour pouvoir
juste
mettre les exceptions
à la droite et à la centre.
Et vous avez juste de...
Vous savez,
je vous remercie,
ce qui s'est passé
avec une exception,
si ce n'est pas réglé,
ça va tout le monde
à la stack.
Et dans le C&C++,
en documentation,
il y a toujours un niveau top
de la liste de
les secteurs systemaux
où ça va
prendre ça
et ensuite le mettre à l'usage
et dire
c'est la fan.
Et le même,
on peut le faire avec dotnet,
donc à un moment,
il y a probablement
un type d'exception
de la rondeur
qui se passe
« Ah, oui,
on a brûlé,
qu'est-ce que vous allez faire
pour ça ? »
Et ça t'abandonne
toute l'application.
C'est fou,
si vous n'avez pas
réglé une exception
que vous n'avez pas
été élevé
pour prendre votre application.
Qu'est-ce que ça veut dire
pour les systèmes de banquage ?
Qu'est-ce que ça veut dire
pour les systèmes de trade
ou les systèmes de trade
ou les systèmes de trade
Qu'est-ce que ça veut dire
pour ces applications
qui, vous savez,
juste avoir une exception
de la rondeur
est comme
« Cool,
vous avez juste brûlé
toute ma application.
C'est bien,
c'est bien,
c'est bien,
c'est bien. »
Je ne me souviens pas
que la liste de règles
que vous avez élevé avant
était qu'une des
n'est pas la rondeur
d'exception.
Oui, oui, oui, oui.
Parce que ce que vous avez dit,
c'est que
ce que vous avez dit,
c'est
comment vous les défendez.
La seule façon que vous pouvez le faire
c'est de défendre
toutes les exceptions
par défendre ce qu'on fait.
Mais si vous n'avez pas
supposed to do that,
then it's gonna be a totally.
Well, this is it.
But like, even if you,
the other side of handling
is the other side of,
so that's catching.
So we're talking about
catching exceptions
at that point.
You know, like handling them
is a whole another
you know,
thing, right?
Which makes it even more difficult.
Like how on Earth's supposed to handle
some of these exceptions
that come through.
So what's the difference
between catching and handling?
Well, so, you know,
if you caught
like an out of memory exception.
Oh, do you mean what you actually
do when you get that,
yeah, how do you deal with that?
Yeah, exactly.
How do you actually handle that?
Like, so, so,
it's one thing to catch an exception.
But it's another thing is like,
what do you do when you've caught
that exception,
which is probably one of the reasons
why the guidance isn't to catch exception
because you might get an exception
which you're not supposed to.
Yeah.
You can't handle
only the runtime can do something with it.
And if the runtime can't do anything,
really, it just explains, right?
Yeah, one thing that I don't like
about the handling,
I know again this might lead on to the
maybe we go back to this later,
but the language syntax,
is like even like variable scope.
If I've got like a try block
and I'm assigning a variable in there
and I want to use it below the
that try catch block,
then I've got to have
take the variable out of scope
and it's just
I'm glad you said this, actually.
And just before I continue,
I'm going to take my jump rocks
and get hot.
I get animated, I get hot.
I'm just, you know, right.
I turn the camera off.
I don't want to avoid, you know,
any flaps coming through.
Too much information.
Try to be as secret as possible.
Cool.
Yes, right.
So try catches.
Let's look at the implementation side of it
as well now,
because you bring up a great point.
And, you know,
when you actually start looking deeper
into the implementation side of it,
it gets really annoying.
So first of all, you're right.
Try catches as a statement.
Oh, statements are annoying.
They are annoying.
I don't care.
He wants to argue that point.
Statements are annoying.
You know, this whole, like,
like you say,
how do you resolve a try?
Because the try catch might just be like,
well, if it does this,
set a string to this,
if it doesn't do that,
set a string to something else, right?
It's like something really bad could happen.
But really, the result handling it is,
in both cases,
is going to return a string.
Like the string might be like,
cool, this works or mad and work.
In the case of maybe like console applications,
for example.
So yeah, it's quite reasonable that you,
you know,
that the result of a try catch
should go back to a string
because try catches a statement
are not an expression.
Your code becomes more of a both.
Another problem is because it is a statement,
indenture code further,
right?
And I know, like,
you know,
C sharp is can get very indented
and Microsoft,
you know what,
you know what we should do?
Let's make it namespace filescoped.
So let's,
let's remove the namespace indentation
so we can shift everything to the left a bit.
And it's like,
that doesn't matter.
That doesn't matter.
You do an if and then a try
and then a for loop
and you're just now six.
1000 lines in
6000 indentations in
and your code
becomes a lot more difficult to do that.
And again,
go and look at the
go and have a go
at the HDP client try catch
because you'll see
with all the amount
of different catch statements as well.
And especially in the terms of a HDP client,
you know,
you might want to come back to just like a
just an error,
some kind of error object
where you say like,
either it did work or it didn't,
you know,
it becomes a lot more difficult
because of it being a statement.
A l'autre côté,
as well,
which I think we touched on a little bit,
but I want to sort of explode up a bit
is the top level catch.
So exceptions,
when you throw them,
I think one of the reasons why
don't quite me on this,
but I think one of the reasons why is expensive
is because of the unwinding
of the stack trace.
So it has to unwind
to find a catch statement
and then handle it.
So I'm not going to bother going too much
deaf on the performance side of it
because Nick, Nick Chaps,
has did a video on this
and you should look back to
he says something about,
you know,
you're handling exceptions wrong
or something like that.
You know,
some kind of clickbait-y title.
I don't think that in the show,
no, it's just a listener's reference.
Yeah, yeah,
you can go find it.
But yeah, no,
but he goes through
the performance differences.
And I think it's somewhere
it's somewhere around,
you know,
the mechanism of catching
because essentially,
you don't necessarily have to throw
then catch in the same sort of scope
or even a layer scope above.
You could, you know,
and happens
the dotnet framework
could throw deep into the depths
of their framework
and then you could catch it
right on the other side
of your application.

So the general idea
with, you know,
being able to, you know,
throw anywhere in a stack
and catch anywhere
even at the top level,
you know,
catch wherever.
The idea is
you probably want to catch it
closer to where
the exception gets thrown.
But then as soon as you catch it,
you got to do something
and some people tend to go down
this path of using it
as a control flow,
which is one of these big things
is when they when you're using exceptions.
When they're saying, you know,
you shouldn't control flow
with exceptions, right?
And that's a bad thing.
But then it's like,
you know,
what some exceptions
sort of push you
towards that area, right?
Some of them aren't so big.
Some of them are just like
bad format exception,
you're eyes wrong, or, you know,
or maybe it's an
bad input exception,
whatever.
But it's, you know,
it's not the same as like
you've got like a system level,
you know, out of object exception.
That's kind of going crazy.
So, but the idea of the fact
that like there can be
any amount of gap between this
and you can catch any single point,
which means you can just negate.
This is the problem.
You can negate
tonnes of code
because you've thrown here
and caught up here.
You don't have to unwind,
you know, unravel
anything that's just happened in between,
which obviously has issues
with things like,
you know,
if you're doing a transaction,
for example,
and you threw a number of transaction,
you can just negate
everything that's just happened
and pop out of the code
somewhere over here.
So it's a glorified go to,
you know,
with go to of extra steps.
Yeah, that makes sense.
So are you saying that you should
try and catch it as close
to the throw as possible
and then deal with that
exception,
how the requirements
should deal with it
in an application way,
like maybe return.
This is a great question.
So this is this is this is
where I think like
we've talked on the exception
side of things.
Like, how do we actually
manage this?
Right? What are our options
for managing this?
And, you know,
we can move into talking more
about sort of like, you know,
how to avoid exceptions,
right?
Like, what is the answer
to avoiding exceptions?
So just to be clear
at the beginning of this,
just to be clear,
you know,
exceptions are really useful.
There's no doubt about it.
And they're really good to be
to say like,
wow,
this should never have happened.
Why am I here?
You know,
I might you'll see my code.
My code is lit
with things where it's like,
we should just not be here,
like as an exception message.
Like, this just shouldn't be a thing.
I think we've all written
that comment somewhere saying
should never get here.
I think every developer
written that comment
some point in the life.
Yeah.
And the thing is,
the thing is,
it informs someone the wrong way.
So like,
if you go and try and debug it,
you might be forced to think,
oh, I'm not going to put an
accept.
I'm not going to put a break point
here because it should never get
here.
But naturally,
because we're saying it should
never get here,
you should probably put a break
point here because it probably
got here.
But also, if you're looking
through and you have got there
and it's like,
and you're looking at a comment
saying which should never get
here, it's like,
but I am here.
I am.
What do I do?
Je vais pas compute.
Yeah.

Yeah.
Oh, it gets crazy.
This this kind of this
statements,
I will, you know,
say that statements are in part
the problem here as well,
like having statements
which allow you to just find
forget you get into random places
and, you know,
and then fake it.
You know, the whole nulable
thing, good Lord,
the whole nulable thing can.
Oh, anyway,
we'll get on.
We'll move on to that stuff.
So exceptions are a good thing.
And you really should use
them to kill your application debt.
And why I think
that's a good thing is because
it's when you go to testing
and no matter what
your testing mantra is,
whether you like to do TDD
or whether you like to do
a loose level TDD
or wherever,
wherever your truth is
when it comes to test it.
I personally like to do,
especially when I want to move
quick and I want to get
things built quickly.
I tend to do very much
integration black box testing
from the outside, right?
So I use the ASP net
call integration test thing
and I have a test project
which spins up your
you know, it spins up your process
and you know, you can fire
a HDP client calls out
and you're really testing
from the outside in.
So you're really on the behavior,
the general behavior
and that way you're not tightly
coupled to all the stuff
that's going on.
So if you need to quickly
switch something out,
the test should stay the same
because it's like,
you know, given a new user
and I've posted it to you,
you should have saved it.
You know, that that should happen
no matter what the internals
are doing.
And really, I don't care
what the internals are doing.
As long as the perf looks
half decent.
And like I said, it does
what it says in the tin
and then whatever's in the tin,
I don't really care about.
So that's how I like to do.
So out of interest
with that one,
where you've said
you've done that,
your endpoint is writing,
say creating an order
and a database.
From an assertion point of view,
do you call the same API
and do a get request
or does your test
directly check the database?
Yeah, that's
that's definitely should be a
that definitely should be a per
scenario basis
of whether you pick
which one you want to do.
I do a little bit of both.
So I've been using surreal DB
and there's a blog post
to follow actually setting up
surreal and azure.
But I use surreal DB
and I use it with test containers.
So I use test containers
with my SPOI
or your core integration tests
so that, you know,
all the supporting services
I can just fire off in Docker.
And yeah, sometimes
yeah, you just want to
straight up check the database
or you can
yeah, get use the other.
Yeah, I tend to just use the get
request, to be honest,
which,
you know,
might give you
false hope
or it might,
you know,
might show some more problems.
But to be honest with you,
yeah, case by case basis,
wherever you feel is appropriate,
but both, both,
I think are a solid, solid choice.
Yeah, sometimes I find
that if my tests are depending on
what obviously has to depend
on the project you're working on,
then it's probably also got access
to the entity framework entities.
So it can just use entity framework
to just do the assert
to make sure that the thing was in the database.
If you want to do it like
really productively and quickly.
Yeah, this is it.
And I think like
this is going to be an underlying theme
to this,
which I bet you weren't expecting.
But the underlying theme is like
it depends how much you can be asked to do it
because because
because believe it or not,
this is where I think
that's going to be on the underlying themes
wherever you can be asked.
I think that's it is kind of
we've got to be honest here.
It's kind of like developers
cut corners because sometimes
because they can't be asked.
And it's true.
Yeah, it's kind of
we don't know like
with these kind of conversations
de Toe on podcast
and things,
they talk about the complete ideal scenario.
You should be doing this.
But we need to talk about reality
and what developers really do.
Yeah, yeah.
And I think
I think it's an interesting point as well
because I think
you get two sides of story.
Like and I've definitely been on both ends of this
where I've,
you know, it's all about that developer curve, right?
Where, you know, as a junior,
you do the most basic thing.
And as you get to senior,
you chuck in all the patterns
and then, you know, by the time you get to, you know,
whatever else is after that,
you're, you're, you know,
dig back to the simplicity again.
But I think, you know,
I've also been on both sides
where like you do very little,
then you try and do absolutely everything.
And you realise that actually
you need to be somewhere in the middle.
What I tend to find at the moment
is that I feel that people have
a gun swung back to doing nothing.
And actually we need to push people up
to doing a little bit more than that.
But, you know,
through mechanisms of making it easier.
So hopefully the rest of this
this conversation should sort of help
like bring people up
rather than trying to say
you should do absolutely everything,
you know,
and do everything absolutely perfectly all the time.
Because sometimes it's just not a reality.
But doing nothing all the time as well
is not a good place to be in either.
Because it creates a lot of difficulties.
I think it's just getting people to think about it
and think, be aware of the different options.
And rather than saying,
you have to be doing this,
you should be doing it this way.
It's just the more ways of doing things
and the more people can learn from
all the people learning the hard way
so they don't have to.
And that's,
I think that's the great thing
about conversations like this.
The more podcasts you listen to
or things where you're
hearing all the people's experiences
and then you can kind of
in your own head aggregate those
and try and do the right thing
from what you've learned
from all these different sources.
Yeah,
and that's another interesting point as well
because I think,
you know,
obviously information overload is a real thing.
And I think
I think this is where a balance
is sort of trying to be met, isn't it?
With, you know,
you could go and look into the
nth degree of everything
and then, you know,
listen to all the sides of the argument.
And now you've got to try and
you've got like this
boatload of information
now you've got to try and distill
what does the good path look like?
And I think, you know,
that becomes really difficult,
especially if you're on the more junior end
because you haven't had the experience
to see how all this stuff sort of pans out
in sort of big systems or small systems
or high performance systems
or low performance systems.
You know,
you haven't had all those different axes
to think about, you know,
what a good solution looks like.
And, and yeah,
and really, like,
always trying to be less
dictatorial about things
and China sort of like
nudge people towards looking at stuff.
And just trying things out, in fact,
I think, I think a lot of the time,
hence why I said about the,
you know, the tri catch
around the H2B client,
it's about China out.
Have a look for yourself.
See, you know,
I think it's really good to tell someone,
you know, the history
where this stuff came from
and why it is the way it is.
And then, you know,
some of the options on the other end
for actually dealing with that.
And then sometimes
what you think the best option is
and what they should do.
But, you know,
yeah,
so I think wrapping back to this,
to the testing,
and, you know,
and why, you know,
exceptions are really useful
in a sense that you can throw it.
You want it to fail fast
because then you want your test to fail fast.
So I think that's a really good use of exceptions to,
you know, to kill you dead
before you go to production.
You have to remember to,
you know,
try and squeeze out
all of those bits before you go, right?
So, you know,
you're throwing these exceptions
and you want, you know,
you want to be able to
write the happy path
and it all works fine.
Exception,
not going to throw,
but if you do get to a part,
you just want to kill it.
You want to stop your test
as quickly as possible, right?
You just want to say
you're we're failing at this point.
We shouldn't,
this shouldn't be happening.
So that's why I think,
you know,
that's why I think exceptions are good.
So what are the options?
What are the options for dealing with?

it was making me laugh before
because we've said options
quite a few times
and I have a feeling
we're going to go in that direction
about talking about options
as in like the functional options, maybe.
Yeah, so I mean,
I think it's well known
and a lot of people have told me
because obviously you've written
a lot of blog posts on this.
And again,
that should be linked to the show notes.
But I've written a blog post on this
and I think some people have mentioned
like I had some really good feedback
on a lot of these
and a lot of people write a lot of different comments
and it's been great to read them back.
And actually,
you know,
I think, you know,
someone did pop up and say,
you know,
this is the age old debate
between, you know,
exceptions or errors as objects, right?
So, you know,
so your solution is
your alternative,
as far as I can see,
or a decent alternative
is to use objects as errors.
Now, how you do that is,
yeah, like you say,
there's a little bit of more finesse
and a little bit more nuance
on how you want to do that.
And I think,
and I really think there's,
there's, it's really,
you know, you've got two options, really.
You can either use
like discriminated unions,
like the one of library
or maybe if you're watching this
from the future
and you're like, oh, yeah,
I see Sharp has these now.
Cool, good.
Probably should use those.
That sounds like it might be quite far
into the future.
Or maybe not.
There's been talk about it more recently,
but
yes,
it's a long way off.
Yeah,
well, this is it.
Who knows?
There's a lot to sort out with it.
And again,
we can talk into the language side of things.
But yeah,
it's a lot to sort out with it.
But then
and then you get that.
And all
you can use the either object,
either fail or success
or either left, right,
depending on how you want to look at it.
And I think these, these are two,
these are your two options,
really.
And I would always prefer to use either.
And that's where my,
my pace goes.
You know,
how can you use the either?
And I'm going to say
the other object,
I'm going to say monad.
I might as well get out of the way with
because I know people
probably sitting there.
And it's a monad.
Yeah, cool.
It is the same as a list and a task, right?
So I don't, it doesn't really matter.
It is,
but it's also just an object.
And it's an object
which has two parts
you can go down
and either go down
the success path
or you can go down the failure path.
And I think,
you know,
these are your options.
Now,
having said that,
does that solve all your problems?
No, it doesn't.
It doesn't solve all your problems.
Does it make exceptions go away?
No, it doesn't make exceptions go away.
Exceptions,
there's still there
front and centre,
super duper annoying.
And,
and doesn't make them easy to use.
Doesn't make your code better
in terms of when you do get to
try catches.
Not really.
Because for the reasons
that you said before
with statements,
you know,
either object
allows you
to return
either a fail
or a success
to that same object.
So what you'll get
is two parts
being able to return back
to the same value.
So therefore,
expressions would work
really, really well with this.
No, no, no.
So, I don't know if you notice
you can actually
like obviously,
since I don't know
since one of the earlier versions
of C sharp,
you can actually
throw an exception
an expression now.
So they thought about
throwing and like,
oh, you know what?
It'd be great
rather than having to do
if this throw,
we can just do
coalesce to a throw
or something.
Right.
So like,
if this is null,
then throw null,
implement it or whatever.
It does sound like
whilst useful,
sounds very wrong as well
because it's
it's not an expression anymore.
Or it's not pure.
Well, no, 100%.
Yeah, yeah, exactly.
You certainly introduced
a side effect.
Hi.
Yes, exactly.
And they only thought
about it on the throw.
They didn't think,
well, what happens
if you need to try
catch back to a single?
Well, you know, whatever.
They don't switch case,
which, you know,
the switch expression
has been the godsend.
Définit.
Love,
absolutely loved,
used it.
And my code
is now lit with it
because it's just
it's really useful.
But like,
why didn't you pick?
I don't know why
exceptions has been kicked
to the curve.
They've just
honestly,
they've gone right.
What are all the things
and and and really
exceptions has been left
by the wayside
the entire entire time.
It's just no one's
no one's ever cared
or bothered with them.
It's just, you know,
it's just exceptions
are exceptions
and that's the system.
It's like,
I can't be the best
implementation.
Come on,
come on.
Now,
you can't
you can't have
created it back
at the beginning
of CJAV
and still think
is great implementation
because,
you know,
we've got things
like primary constructures,
throwing expressions
and switch expressions.
You know,
so much language is changing.
Like,
you know,
clearly,
you're saying that actually,
maybe some of the stuff
you did at the beginning
could be improved upon.
Exceptions,
apparently not.
I think the thing is,
like,
languages are intuitive
and they can only do
so much.
They're doing a new version
each year now.
So it's kind of
it's definitely
each version
is improving
as a language.
So I think it's just
things are going to take time.
But just going back to
you were talking about
like the either class
and I talked about
the options class as well.
So that's another kind of
maybe listeners
that don't know about
these kind of
either options class.
Maybe missed that one.
But can we talk
a bit more about that?
Because I think that is kind of
quite a key thing.
I know we've heard
in some past episodes,
we've had
Simon Painter,
who's quite interfunctional
programming in CJAV.
And so he's spoken
a lot about that.
And one thing I quite like
about it is the fact
that when you call those
and those call methods
that return those,
you can chain those together.
And so you can have
like a whole bunch
of function calls
telling a story.
Half way through,
one of them can be
returning an error.
But the calling code
doesn't care about it.
It just will stop
calling those chain methods.
And that just feels
really clean.
Yes, let's get into that.
Let's get into that.
So you get the option of T
and maybe or either.
So either
depends
whether
depends on what the language calls it.
It could be either
or it could be maybe.
You get both of these.
And the nice thing
about these objects
is they force you to deal
with both paths.
Right?
So option of T
basically returns you
either the value
or a or a none.
And you have to handle them.
So obviously,
the big issue with try catch
and statements
and nulls
is you don't ever
have to handle them,
which is absurd.
To me,
it's just absurd
that you never have to handle them.
And they bought this whole
nullable stuff
in to try and combat that.
If anything,
now you've got
exclamation mark,
something, something, something,
question mark,
something, something,
exclamation mark
at the end.
And it's just made for
the syntax
look really awkward
in some places
and harder for newbies
to come along
and be like,
I want to programme C.
I think especially
when you've got
the exclamation
you might mentiond
which kind of ignores
something that could be null
and you get,
especially,
you might get people
like to come in
or there's a squiggly
the thing of warning.
I'll just throw
this bang operator
in an ignore
and then you still get
your exception.
You still get
your null reference exception.
Yeah, yeah.
And, and, and, you know,
the one thing about,
you know,
the whole point of bringing
the nullability
and the whole point
about options
and the whole point
about that is that
if you create a class
with a property
that may or may not
have to be set,
just making it nullable
is just
it's a get out of
jail free car.
This is the thing
same with the try,
same with exceptions.
It's kind of like
these get out of
jail free cards
where you don't have
to think about it
or deal with it.
And really,
actually,
if you dealt with it
at that point,
you know,
and done something,
done, right,
then that's a much better
place to be in.
So for example,
with the property,
you know,
you can use the option,
right?
So you can say
it's optional of
why that's different
to null
is because
it's an object
that you have to handle.
You have to call
either the maps
or the reduces on it
or the selects
and select manys
if you're a linked person.
Or you have to
finally get the value out,
which,
you know,
if you think about a list
to get a value out,
you either call first
or you call
the square,
you know,
the indexer
and pass it
through an integer
for your indexer.
And with options,
you can call match
and matches the way.
But you have to
in the match,
you have to deal
with the none case
and it makes you deal with it.
And I think that's
the really powerful part,
the really,
really powerful part of it.
You know,
an option might not be the way around.
This is why we talk about
the discriminated union
because actually,
you know,
there was a while back
a long time ago,
the null object pattern
and the null object pattern,
I suppose,
was a way to get around this idea.
So if something could be null
rather than making it null,
you just make the null object version of it.
And you can see this
in play even today
if you go and look at the null logger.
So if anyone ever
tries to mock out
an i logger of T
in the dotnet framework,
go and look up the null logger
because that
stops you having to mock it.
And it basically is that
this is the null object pattern.
Yeah, so you can use that.
So this is the thing like
this is why the one of is quite good
because you can actually say,
well, actually,
you might be a few different states
and with some of the stuff
I'm doing with insurix at the moment,
you know,
we I'm creating a like a schema,
you know,
where we can create
and custom schemers
with multiple dimensions and data,
you know,
and you can write data
with multiple dimensions
basically have different versions
of both schemers and data, right?
And in some cases,
you might want others
some schemers
to reference another schema.
And in some cases,
you don't want that.
So you clearly here,
you've got a property
where it's either going to be
not set
because we don't want
to reference another schema.
It's an unresolved schema,
OK, it's just a pointer
to say, actually,
go and look up the address schema
because that's that's what we want to use
as our schema for this property.
Or it could be a resolved schema.
So where I've had to go off
to the database, grab the data
for that schema,
brought it back in
so you can validate against it.
So that was just to say
that there, you know,
there were three distinct options,
three distinct paths
or points in time
that this thing could exist in.
And so, you know,
the discriminated union
was a better choice in that sense,
not just optional.
And then when you take this
a step further, right?
So so with option of T,
it's option of T.
So it's only option of one type
and because the error case
is always none.
And that's not very descriptive.
Right?
That's not very descriptive at all.
What we actually need
is a failure case.
We need to be able to say
if it is an error,
how do we encapsulate error?
Right?
How do we encapsulate error?
And this is where
this is where we sort of start to see
where either can actually handle
the try catch in a much better way.
And I think I remember going
because now now we're talking
dd things, right?
Now we're talking sort of
domain style things
where we can split our errors
up into parts of the domain.
And I think I saw
is it Milan on LinkedIn?
He's always chucking out
those guides on things.
And he does it all right.
Some other people just
some of the people
literally just look at the docs
and they go, did you know about this?
Yes, because I read the docs.
You know, you just
you just made it a pretty colours.
And you're like,
that doesn't tell me anything.
You know, if you want to put
that stuff out on to do it
like Milan does,
if you want to put
that sort of stuff out on to LinkedIn
but I've got put a purpose
behind it or like why the
you know, why the good
why this is a good thing.
Just say it can be done
like this or this.
That's not helping anyone.
No, it is stuff's really good.
It's got quite a good
newsletter as well,
which I'd recommend.
I'll throw that in the show notes
because he goes into
like all this stuff.
And most stuff he put
something in,
he also does a follow up
newsletter thing with.
It's quite good.
Yeah.
I think the follow up
is definitely worth it
in a lot of cases.
But I think one of his
he was like,
we're talking about dd
and is the domain
and you can throw domain exceptions.
So I was like,
do you really
do you really want to be
throwing exceptions in your domain?
Is your domain
in an exceptional state
that often?
Surely not.
Surely not.
Because really,
if you're in your domain,
you should know all the things
that go wrong.
So that immediately
cancels out the idea
that you can throw an exception
because there's shouldn't be
any exceptional circumstances
at that point.

If you think about like,
let's think about just a banking
work is real simple one
because everyone knows that.
Right.
Because everyone's got a bank account.
Right. And you think,
oh, I'm going to try
and withdraw,
you know, withdraw 10 pounds
and I've only got 5 pounds
in the bank,
which is my current state.
Times it in hard.
So, so,
but yeah, you're in that state.
You know,
there's no need to throw an exception.
You can just return back to these
insufficient funds
that doesn't need to be.
It's not an exceptional circumstance
that someone's going to try
and withdraw more money
than they have in their account.
And so that's a very normal.
That's to be expected.
Even going over the overdraft limit,
you've gone over overdraft limit.
Yeah, that's that's an expected thing
to happen.
You've set a limit
and someone exceeds it.
That's a very,
you know,
if someone exceeds it
by about 500 million quid,
then you can be like,
hang on a minute,
but they've got,
you know,
they've got systems
there in place to catch
that kind of stuff.

but, you know,
that's an exceptional circumstance,
not just the fact
that you've just gone into it.
But is that an exceptional
circumstances
for restoring exceptions?
A concern,
because even that is an application.
Again, yeah.
Would a fair thing to say
is that an exceptional
circumstance is anything
that can't be covered
by an application
requirement or something.
So as in like business logic,
I mean that kind of thing.
Everything else,
like a hardware failing
or a service to service
call failing.
Yeah,
you basically need to handle it
and then return something
that means something to the caller.
This is it.
This is why,
when I said at the beginning,
like I did events sourcing
because it's definitely on,
you know,
it's part of the whole DDU thing.
It's one of those tactical patterns.
And I really wanted to get people
into DDD more,
but like it's really hard
and big enterprises
or medium to large scale companies
because you might already have
a set of code there
and you need to try and find
your way to DDD.
It's not always possible
to say,
stop everyone.
Everyone learned DDD
because it's a business thing
just as much as a developer thing.
And let's all collaborate
in a DDD way to get the result.
That's not practical.
That's not going to happen.
That's not practical.
But what is practical
is you can, you know,
maybe start to take some of your code
and sort of move it,
shift it on a bit
towards the DDD thing.
And, you know,
those, one of the strong parts
of DDD is domain objects,
aggregates,
value objects.
That's why I chose value objects
and when I'm a crusade
about value objects
because I thought,
you know,
if there's any good place to start
where you've already got
an existing code base
and you sort of want to get
more DDF-ied,
start turning everything
to value objects.
Start thinking in your domain
in terms of behavior
and how people should act
on objects and that.
And once you then do that,
you then start to have to have
what I really wanted to do.
Start elicit more conversations
between the developer
and the business analyst.
So you can sit there
and be like,
ah, I've actually found
that, you know,
once I've had to handle
all of my errors,
there's this case where
if this happens
and this happens
and this happens,
there's a case there
which we were not handling
at the moment.
Is that a thing
that can happen?
And they can then go,
that should never, ever happen.
Right?
And let's talk about that in a sec.
But anyway,
could I say,
yeah, that can happen.
Oh, OK, cool.
That can happen.
Right.
So that should just be
in CACSA as an object
and return back
through the failure stack
so that, you know,
we can, we can then go,
oh, actually,
this case
that was now
was sorry,
exceptions,
somewhere else in the stack
because you got to
an unexpected state.
Actually, we handled
at this point
and we sent it all
back to the user
saying, oh,
you've actually managed
to get to this point,
which means, you know,
this and this
and this was wrong.
So please correct it
and come back.
So the idea was that,
you know,
we need to elicit
more conversations
between the developer
and the business.
And, and, you know,
that comes full circle.
Hence,
why I'm now talking
about exceptions
because it comes full circle
back again with exceptions
where you're like,
it's the part of your application
you can start codifying
and getting the business
to help you understand
what are exceptional
circumstances
and what are just objects,
which is super, super useful.
Yeah, I guess
a lot of this kind of thing
is asking yourself questions
as you doing it,
as in don't just
randomly throw an exception
because as we said before,
it's quite easy to
quite often develops
can't be asked
so they take the shorter version
and it's quite easy to
oh, I've thrown exception
or something.
And it's like,
like we're talking before
about different languages
and things
and being forced
into the right way
of doing things.
If the language
through compiler
is like, for example,
some kind of switch expression
that you have to
handle all the different cases
or whatever it is,
then all like the
you simple options,
if it's you've got to handle
the unhappy path as well
and the compiler forces you,
then you can't take that.
I can't be asked
quick shortcut
because it needs to compile.
So it's
well, so I'm glad
you talked about this, actually,
because you've moved on
to the other part.
So the part we just discussed
was more of sort of like
the business
type things around it
is more of just like
the conceptual stuff.
But talking about
the implementation, right?
Because I think
I just said
and also going back
to what you said, like
being able to chain these together,
right?
The implementation is pretty cool.
So with either
it's essentially a short circuit
and at any point
that your code fails,
it short circuits
and you then have to
it will then unwind back through,
which is much faster
than unwinding a stack
and finding a catch.
It's better just to go
if failed,
return, fail it,
if failed, return, fail it,
if failed,
it all the way back up through
until you get to
the match.
So one of the things to remember
is that with these objects,
either objects, option objects,
list objects,
at some point,
you're going to get
want to get the contents out of it.
The same with tasks
at some point,
you're going to want to get
the result out of it.
So with tasks,
you can do a wait
with, like,
we've all discussed
what you can do lists.
We know options
equivalent now is match.
Either has the same thing.
So even though
you've got
all of these either
is chained together
in the select,
select many sort of style,
which in terms of
functionalness
or how most languages
call it, map and reduce style
all the way through.
And as soon as you're un winding
the stack coming all the way back
up the stack,
at wherever point
where you do that match
is where you get to handle this stuff.
Now, this brings up
two very interesting points
to talk about.
Going back to your original thing,
the compiler getting me to help you.
If you use a discriminated union
for your errors,
as your application grows,
you can add in as many errors
as you like
into the discriminated
caveat it.
Just going to caveat that slightly.
But you can add as many branches
of that discriminated union,
many error objects
as you like into there
as your application grows
as you find them.
And you get an easier time
to categorise them as well.
So you can say,
actually, this is a set
known as the validation set.
So that should throw 400
or that should return 400.
These are the
deep internal validation issues
which are actually sort of system
problems,
like application problems
that, you know,
not 400,
but there are five and like
we've seriously gone wrong
at this point
to all the way to like fatal,
you know, fatal things
where we can say like,
this is unreal.
This is a 500
of overseen one before.
And what happens is
when you use discriminated unions,
which force you to handle
every single case,
any time in your code
where you add a new error,
guess what happens?
Lots of compilers.
Exactly, the match.
Well, hopefully,
you've got two or three
compilers errors,
but that happens over
the route match
where you said,
handle the error case.
That handle the error case
is just a method
which takes the discriminated
union of errors,
matches against those.
If any of those
are discriminated unions,
matches against those
and walks through all of the trees,
all of the possible branches
and handles them all in one place.
I'd like to handle it all in one place.
Handles it all in one place.
And therefore,
if you've added a new validation error
because you've got a new property
that needs to be validating
a certain way
and it can go wrong
three different ways to Sunday,
where you can take those
three different errors,
whack them into that strut.
Oh, and suddenly,
it's compiler error.
You can't do that
with exceptions.
That's impossible.
The compiler's not there
to help you.
This is one of the things
I want to shout
from the rooftops
at the beginning
of this conversation,
was the main problem
of exceptions
is that the compiler's not there
to help you with exception.
I mean, Java,
it does a little bit.
I wish the listeners could see
your emotion going into this
in the video.
It's kind of...
The arms are flying around.
It lights off the walls.
Punch the cat in the face.
Yeah, so like,
honestly, it's...
I don't know what the cat did
to deserve that,
but honestly,
when talking about exceptions.
Oh, yeah, exceptions, man.
But yeah,
this is the main problem, right?
Is that the compiler's not there
to help you.
And this is why,
you know, we...
C-sharp's got a glorious type system.
It's a very well reasoned,
very well structured,
very complicated,
you know,
with all the generics and stuff.
It's an incredibly good...
I know it's like
one of the best generic implementations,
as for sure.
Like,
there's no doubt about that.
You just used other languages.
There's no doubt about it.
So, it's one of the best.
You know,
it's a really good type system.
So, to use it,
use it to your advantage.
This is what the same with value objects.
Value objects
were harping on about the same point,
right?
The whole point of a value object
is if you're going to try
and express money as a decimal,
the problem is
anything can be expressed
as a decimal, right?
It doesn't have to be money.
It could be temperature.
It could be miles per hour.
It could be kilometers per hour.
It could be something
completely not money.
And a really bad thing would be
is if you accidentally passed
the wrong decimal to the money
and you tried to withdraw,
you know,
£2,000
from your bank,
rather than,
you know,
the temperature outside
was 2,000 Kelvin or something.
I don't know.
But, you know,
that's the thing.
You don't want to get that mixed up.
So, if you turn that decimal
into a value object,
we're using the Vogan library,
for example,
which is a cracking library.
And again,
my blog shows you how to use it.
He's also got a good read me page
on how to use it.

they're very simple.
It's a one liner as well,
not too much to get started with.
And you just say,
right,
it's now a currency.
And a currency
has a primitive type,
which is decimal,
but it's actually a currency object.
So now,
I use that currency object everywhere.
And I do this.

I'm not,
when I'm talking about this stuff,
I'm not coming from a place of like,
oh, I've never used either's nanga.
I've never actually created a full-on system.
Le système,
I created insurax
is a beast.
It's got
about six handlers
for the API endpoints.
And each one of these is
either to the end of the world and back.
And it's all value object
to the end of the world and back.
So, you know, I've used it.
I will be bringing out a blog post later
to go over sort of the recipes.
So that's what we're really missing with this,
is the recipe book.
You know,
it's a very big learning curve,
very steep learning curve.
But if you had a recipe book
that told you how to do
handle certain cases,
it would be a lot easier.
But this is essentially it.
And to bring that back,
you know,
with the value objects,
again, it's a compiler thing.
The compiler won't let you
because the types don't match.
And the compiler really likes it
when the types marry up.
And this is what either gives you.
This is what options give you.
It's typed.
They're type containers.
They are types
and therefore they have to marry up
and they have to match.
I mean,
obviously,
with most type systems,
you have to give it a bit of a help
and a push sometimes
and maybe specify a few types here and there.
But in general,
you know, you're dealing with types,
which means
this is why we come full circle
with exceptions.
You're basically turning your exceptions
into sort of like
error value objects
as they were.
And so,
you know,
you can store any amount of data
you want in them.
Each error can be completely different
to the next
and you can have any amount of data
that you need
to make sense of it.
And boom,
in you go,
you put it into your system.
You've got a chain of either.
You've got your business logic in there.
You're using value objects.
It's all working.
And you make a change
and suddenly the type system,
the compiler will pick it up first.
The compiler will tell you
you haven't done this
or you haven't handled this
or you've not finished this bit first.
Then after that,
then you'll go back to the normal
normal coding things of
crap, I put a business logic
in the wrong place.
I shouldn't have been there.
Oh, I've completely messed up the baby here.
It's doing what I intended,
but that's not
that's what my fingers wrote.
No, I actually intended it to be.
So you still have to handle that there.
But yeah, so that's basically
concludes the part of,
you know, error handling
and getting to these
error handling.
And this is why we want to use it.
I mean, it does have some problems with it, right?
There's two parts to the problems.
One, it is verbose.
There's no way of getting around it.
It's verbose, right?
I don't know.
There's no other.
There's no real ways to.
And you need these recipes as well
to get it to, you know, to understand it.
There's some nuances
that you need to know.
But essentially, what it makes
or is a really nice system to use
because when you push something in there
and you do something wrong,
you get the right errors
about all the time.
You can see the,
you can see the flow of the logic
and in fact,
what are the interesting things
going back to the point
about, you know, being able
to chain these together,
which is the beauty.
It's the same like it works
exactly like link, right?
Just imagine all your code
looks like link,
but it's maps and binds instead
and aggregates.
There's a lot of aggregation,
a lot of reducers
because they really help.
But I cannot remember
and I cannot find it.
And I'm going to say it
and we won't be able to link it
in the show notes
because I just have not been able
to find it.
And I can't remember
whether it is Mark Siemen
or Ploé,
is it Ploé,
PLO,
E,
H,
whoever his handle is,
Mark,
someone.
Their teaching scenario
is the table reservation system.
And he talked about,
I think one of the worst things
that Donneva did was say,
tasks all the way down,
turtles all the way down.
I think that's one of the worst
things because
conceptually, that's true.
But when you write code,
that shouldn't be the case.
Or at least I don't think
that should be the case.
Tasks should be left
at the boundary
of your application,
the infrastructure side,
the boundary.
So wherever you're making,
when you're making calls out
to the I.O.,
that should all be tasks.
Right?
And if you look at
the hexagonal architecture
or onion architecture,
wherever you want it to be,
tasks should only live at the bank.
And people don't like tasks
as a function coloring
because essentially,
this idea that tasks
go all the way down,
like tasks,
it's tasks all the way down
and people can,
people fall foul of that
because they have a task
on the outrage
and then they want to do
something else
and they might hit
as they've methods
called amphridon methods,
at some point,
they might go to the point
where they need to hit
the repository.
And so that needs to be a task
where you can't do
async inside of sync.
So then you have to function color
and make everything outside of it
as you're going up the call stack
to be task of
so that you can
get tasks all the way down.
But that's not really
the right idea,
not the right way
of thinking about it.
And one of the nicest things
that I've found
in using the I.O.Library,
in using the I.O.S.
is that
it's much easier
to leave your tasks
at the boundary
and much easier
to leave tasks
at the boundary.
The only downside is
because you're using either,
you don't get either coloring
or going down through your cane.
But it's synchronous,
so there's less things to worry about
apart from the awfully long signatures
of your methods.
But blame C sharp for that.
So we've actually spoken
quite a bit about,
well, a lot about C sharp
and how its exceptions
aren't perfect in C sharp,
aren't ideal.
I don't know,
you mentioned at the very start
that you've worked
in all the languages as well.
What do other languages do
which maybe C sharp
can borrow from?
Yeah, well, it's interesting.
It's an interesting point.
And a lot of other languages
do it very differently.
And in fact,
like, you know,
so some of the old languages
do, you know, like the C,
the C plus plus
of the world
and the drivers of the world,
you know,
to still very try catch
exceptions, stuff like that.
F sharp turns try catch
because it still
use the .net framework underneath.
You still have to handle it.
But it turns out to an expression.
I think if C sharp went
in that direction,
that would be much better.
Go does an interesting thing
where you can make a method
return a tuple,
essentially,
it's either an error,
which is the first case.
And then the result
is I think it's that way round
or it's the other round.
I can't remember one
or the way round.
But it's a tuple.
Tuples are interesting
because with the either monad
or the either object,
it's a short circuit
so soon as you get an error,
it fails all the way up the stack.
Whereas with tuples,
you end up more in this world of
if it's not an error,
carry on.
If it is an error,
then either return an error
or panic or do something else,
you know, or do you?
You then make more
it's making the error chain
more obvious.
And I think that's
I think that's a problem.
So you've got to explicitly
handle almost
an estimate almost
everywhere, everywhere.
That's the nice thing about either
is the whole point of it,
the same as list,
as it handles the internals
of how to
well for a list iterate
for a task
to do this thing asynchronously
and for an either to
pick the right branch
and go down the right route.
You know, and it hides
all that error code
behind this type.
And that's my problem
with goes implementation
is that it's very much
still in your face.
You still have to pick
where which way you go.
You've got an error.
Do something with it still.
You still got to do something with it.
And again, I think some people
also commented that even with that,
it's like some things,
the documentation still lacks.
And I think they're still compiler issues.
You know, you never going to really know
what error is.
It's just is an error.
What can you do with it?
It's still a bit lacking
in that sense, I think.
But then go is supposed to be
a super simple language, right?
Very quick to get going.
Very quick.
So rust.
Rust mention.
It's it's a new language
and it took a lot of functional concepts.
And it took this result type
or this what what is an either
essentially is a result type
and and rust calls it result.
And that's what that's what rust used.
Rust use a result type.
You again, it's an opt in or opt out.
You can use it or you don't have to use it.
But you but it is it is a part
de core language and and the the the good
thing about it, which is what obviously
C sharp is lacking, is it actually
deals.
You can actually deal with it
with the language implementation.
So with with rust,
you can actually match on the
and then go in either direction.
With C sharp, when using the either,
you're not using the language features.
You're you're having to give it
delegates to do the match.
And, you know, you can't use a switch
case because again,
the switch expression is C sharp is not
foolproof.
Is there's always a default case,
which is painful,
which which introduces
awkward states that never exist.
That's when you throw an exception
going because we should never
have got there because you can only go
left or right.
So we've gone further
left or further.
Right.
I don't know how we've done that.
No idea.
So rust actually does it quite an
interesting way.
That's quite cool.
But those are the only two languages
I think, you know, obviously,
there's some ZIG and that,
which might have different ways
of doing it.
I haven't looked too deeply into
those, but these are other languages
are relatively new compared to C
sharp, which are doing things
slightly differently,
yielding different results.
This is why I think there's a
problem with C sharp,
ultimately.
Because it's new, it's easier for
them to just almost
start from scratch or what's
worse, C sharp, as you've got
the whole box of compatibility.
I think that years ago, I wrote a
blog post about writing
succinct C sharp, just using some
of the syntax we've been talking
about.
And even for that one, where I
wasn't talking about options or
maybe there's anything like this,
it is just normal C sharp,
modern syntax, like expression
body methods and that kind of
thing.
Even that one, the replies and
the comments were very divided.
Some people were saying, like,
you know, really old, like,
the net frame, like very old
style that haven't used the
modern syntaxes were very,
no, I can't understand this, it's
just not readable.
And sometimes those were just
literally took about link
statements.
And so I think the problem
that Microsoft have with moving
on C sharp is that it's a
balance, that they're trying to
make it more functional and do
this kind of stuff.
But there's a whole load of
developers that are struggling
with even things like link or
some of these new syntax, let
alone trying to understand stuff
like this.
And I bet if you asked a whole
range of C sharp developers,
what a maybe was or what an
either or an option was,
I bet only like 1% would have
even heard of it.
So I think that's the problem
they have.
Yeah, yeah.
And it's a very good point.
And my closing thoughts on
this is, like, I think Isaac
Abraham, recent, I think it was
NDC, again, we'll link it.
He does a talk on F sharp.
Well, sort of like, yeah,
functional.
What functional really mean?
Something somewhere around
these bits, but he makes a good
point that, you know, C sharp
started in what 2000 2001.
And he started with a set of
features.
And they never liked and he
expresses really well.
They never like to make
breaking changes or anything
like that.
So essentially, they've just
piled on and piled on and piled
on into C sharp and carried on
piling on them.
We had a new feature,
I can't break another feature.
And really, like, like Isaac
says, it's creating a really
small surface area into which
you can add new features and
add them effectively.
And my final closing
force on that, I think C sharp
should have done the language
should have done what net
framework did, where net
framework went from framework
to core from net for 80 net
1.0 or DNX.
If people remember the DNX
day, I do.
Yeah, just just suddenly
dotting into something and
nothing existing.
Like, why?
Oh, yeah, we've moved all of
these assemblies over here
under a different namespace.
Oh, OK, thanks, cool.
But yeah, they should have
done that.
They should have said, right,
C sharp stops at version 10
or wherever it happens to be.
And we should now be doing
C sharp next, where, again,
strip everything out, stop
having 50 different ways to
create an auto get set property.
50 different ways to create
a constructor, having this
interfaces with default
implementations on, which is
just, I don't know,
I'm not a huge fan.
There's probably good scenarios
for it.
But but but take all of these
things, you know, and just
stop them being where it goes,
compiles down into, you know,
into into the different levels
before it gets compiled to IL
because you're basically
lowering each time, right?
To get to the underlying
screw all that, get rid of all
that, get rid of four loops,
get rid of while.
Some people like what?
I'm not listening to this guy
anymore.
He just says some crazy stuff.
But honestly, they should have
just reduced it back down.
And then start again with
like a C sharp next or
something or a new language
because this is the thing
as everything is evolving
with the with the the
horizon, you know, how cloud
is evolving and all this kind
of stuff and how other
languages are evolving,
like Rust and Go and Julia
and Mojo and all these
other things, you know,
say can all this.
You're just making
that word now, aren't you?
Yeah, yeah, yeah.
It sounds like it.
Honestly, if I speak,
like if I speak programming
to anyone else now,
they just think I'm just
kind of like looney.
Looney guy.
But yeah, if you look all those,
they're they're doing
some really cool
interesting stuff.
And I think C sharp
is going to suddenly,
I think it's a cliff edge.
You know, C sharp is like
I'm keeping up, I'm keeping up.
We're bringing some
new cool functional stuff
and then it's going to fall
off the edge of the cliff
as like we can't add
these new features.
I kind of like going back
to what's up before about
like I think only a tiny
percentage of developers
actually look at it
in the same way as we're
talking about.
And I just don't think
it will because I think
most developers
think about it in the way
that developers
think about it
and they're not looking
at the things
you're looking at.
So I don't think
I think they're doing
really good stuff.
And I think I think
each version is getting
better and better
and more
quotes functional.
But they've got to
find a balance
and even small changes
because it's a mature
language that's been used
in lots of different places.
Even small changes
require so much work
and thought about
because a language
feature that goes in,
they can't take out again.
Or if you put it in,
they can't take it out.
Yeah.
So it's kind of
they've really got to
like really think twice
before they do
anything like that.
Is there ever
truly tech debt
or do you just always
start again?
Because if you just
always start again
all the time,
like these big companies,
you know, they're not
going to be churning
through their old stuff.
At some point,
they're going to kill it off,
give you 10 million quid
and go start a new project
and you're going to rewrite
all from scratch.
So what's the value?
What's the value of C sharp
staying?
You know, why not
cut it dead?
Do do a net
because, you know,
these big companies
have moved from
dotnet framework
to dotnet core.
They did all that.
That's a pretty hefty uplift
because they killed it all off.
Start again.
Give them time.
Give them like,
you know,
five years or whatever.
But essentially,
does anyone really
ever deal with tech debt
or do they just
start again?
Oh, I don't know.
They're using your
exact food for thought.
I guess using your
example of net.
A lot of the stuff
that I put over
whilst I would do
family projects
new web API.
So it's like
the new structure stuff.
I would then take the code,
copy it across
and it was still
compiled.
It would just work
and then obviously
I'd refactor it to use
new language syntaxes.
But I would not be
starting again,
even with that
dotnet framework to dotnet.
I can't say core anymore,
but let's say
modern dotnet.
Even that port,
it would not be a rewrite.
I just think if they did that,
that they would use.
Depends what you're using.
Yeah.
If you're using
Windows API's.
Yeah.
But it's like.
Yeah.
Then it goes,
you know,
you have to stick to Windows.
Like something
at some point will break.
Right.
Like it's it's
so not everything is
they would.
There was a reason
why there was a car
when it was a new thing.
Right.
There's a lot of breaking
changes in it.
So, you know,
I think
dotnet framework is really good.
This I like.
I think it's
one of the best frameworks
out there because it's,
you know, it's heavily
productionised.
It's heavily performant.
It's, you know,
there's a lot of people
doing a lot of good stuff on it.
But, you know,
what the uptake of C sharp
is not huge.
No.
I think that's one.
And the uptake of Donets
is not huge.
So,
how do you stay relevant?
Yeah,
that's one problem, isn't it?
It's not keeping
like where I'm
thinking about it
in the scope of
keeping existing developers
like if they dropped
and created something new
that they might lose
a lot of people or something.
But actually,
there's a lot of developers
that are just nothing to
not donets in the first place.
And how do Microsoft
actually get those people
more interested in Donets?
Yeah.
Yeah,
because it is a
it's a very worthwhile.
It's an awesome framework.
You can do so many easy things
out like you can just
create an API
have,
you know,
C++
greater performance
and Jason civilization
and C++.
You can have all of that
just straight out of the box.
Like,
that's awesome.
That's awesome.
You know,
and,
and,
you know,
not a lot of other
language like Go
have been trying to do that
and they got some awesome stuff.
So, it's like,
yeah,
it's,
it's an awesome
underlying stuff.
Just I think the language
is really creaking
at the edges now.
Really,
really showing its age.
Because I think the same
thing's happening in the C++
world as well.
I think,
I think this is one of the major
problems
in the C++ world
is that
it's,
you know,
C++
looks crazy now.
There's so many different
things you can do
in so many different ways.
I've not used that
in a long time,
but that could be a complete
other conversation.
So,
I'm aware we are
running way over time.
Just,
you mentioned about Isaac before,
it's mainly
for the listeners
that are interested
in functional programming.
Back in,
this is way back now,
episode 10,
we had an episode
about functional programming
and that was with Ian Russell,
Isaac Abriam
and Scott Vlascham.
Talking about F Sharp,
so that was kind of
and obviously,
some big names there.
So that's kind of
definitely worth going back,
checking that one.
Yeah,
they're god tier,
they're god tier guys.

and,
and yeah,
they're,
they're,
the way they understand
and can write F Sharp is awesome.
Just,
yeah,
it's just amazing.
If you're in F Sharp,
they're,
they're clinical.
That's what you want to hear.
They're the peak.
You know,
get as good as those guys.
Yeah,
definitely.
Well,
as I say,
we are over time.

yeah,
without,
listening to reach out
if you want to like,
yeah,
get on LinkedIn.
I'm on X.
No, no, no,
don't call it actually.
Not allowed to call it X on the show.
It's like,
I'll beat that hours.
Well, I,
I to honestly,
I don't use it that often,
but if you want to get in contact there,
but yeah,
just generally,
just get,
just hit me up on LinkedIn.
And yeah,
if you've got any questions
and my blog,
blog post is there
in the notes,
so you can have a look over
some of the more finer details
of the implementations.
And like I say,
I'm going to be putting up a recipe,
which I think it's going to be a big
game changer
and being able to use this kind of stuff.

so yeah,
no,
thank you very much for having me on.
Sorry,
sorry for talking your ear off.
Oh,
it's all right.
It's quite exciting this stuff.
I like talking about this stuff.
It's good,
it's good fun.
I can tell,
I can tell.
As I said before,
it's kind of like with
the listeners can't see your
emotion going into
this,
but it's
yeah,
it's been
very,
very fun conversation.
Cool.
So thanks again for joining us
and a big thank you
for everyone for listening.
Just a quick reminder
that this podcast is sponsored by Eversdack,
which is my own company
providing software development
and consultation services.
For more information,
visit Eversdack.com.
And if you're enjoying the podcast,
do help me spread the word
on social media.
I normally use the hashtag
unhandledexception
and I can be found on Twitter.
I won't say X
at Dracan,
which is the RACN.
But the best place
to get in touch with me
is Discord
and Callum's on there as well.
So the podcast
has its own Discord
and a link is on the website
and will include
on the website as well.
In the show notes,
all the stuff
we're talking about today as well.
And the website is
unhandledexceptionpodcast.com.
...

Les infos glanées

Je suis une fonctionnalité encore en dévelopement

Signaler une erreur

TheUnhandledExceptionPodcast

Tags
Card title

Lien du podcast

[{'term': 'Technology', 'label': None, 'scheme': 'http://www.itunes.com/'}]

Go somewhere