00:00:00.640
welcome back you have voted and we have
00:00:03.240
a schedule and our first speaker is
00:00:07.799
zimon keska he's a web developer and
00:00:11.000
software
00:00:12.120
architect and he would like to look into
00:00:15.160
code that he really hates um with you
00:00:18.960
together so it's going to be uh some
00:00:21.160
kind of mop programming session so be
00:00:23.760
prepared uh to
00:00:25.760
contribute so zimon stage is yours
00:00:44.200
because I'm nervous when people are
00:00:46.640
looking this worked
00:00:49.399
okay hi uh last year I held a talk about
00:00:53.559
meta
00:00:54.480
programming and I didn't even tell you
00:00:57.120
what my name was so let me be more
00:01:00.239
diligent this time my name is Simon my
00:01:03.879
GitHub handle is chapmon which is a bad
00:01:06.520
pun on my name and we have one open
00:01:11.159
source contribution for a raid
00:01:14.560
plugin and don't be worried by my
00:01:17.600
contribution graph it's basically just
00:01:19.200
me addicting my DOT files all
00:01:22.240
day I work
00:01:26.520
with we do uh personal marketing I don't
00:01:30.600
know the English word and we have this
00:01:33.040
nice team page with fun Graphics you
00:01:37.200
might have seen some of these people
00:01:39.040
here here's me with a Rubik's Cube yeah
00:01:42.840
that's what it um I said I just want to
00:01:46.560
do mob
00:01:47.680
programming uh I wasn't sure if I wanted
00:01:49.719
to do a talk because I didn't want to
00:01:51.399
prepare slides the evening before um so
00:01:54.240
I did the simplest thing I could think
00:01:55.640
of I just thought of some code that I
00:01:57.320
hated and let me be clear
00:02:00.399
I haven't prepared a refactoring power
00:02:02.000
for it at all so it's all just us as a
00:02:04.399
hive mind thinking about it we'll see
00:02:07.560
how far we get um there's a
00:02:11.160
gist um because this doesn't fit on a
00:02:14.680
single screen um there's a short link
00:02:17.879
I'm going to show you
00:02:19.599
now it's uh ancom s.u if you want to
00:02:23.360
hack on it you can go there and look at
00:02:25.080
it and submit comments and we'll have a
00:02:28.519
nice time just thinking about that code
00:02:32.200
that I like and the code that I don't
00:02:34.239
like uh let's lay some very simple
00:02:37.040
ground Rules by the way is this big
00:02:40.400
enough I'll go two more um we'll not use
00:02:45.720
any additional gems because that would
00:02:47.680
be
00:02:48.800
cheating uh we want to improve the code
00:02:51.200
AS is uh second point I use roffo which
00:02:54.480
is a ruby formatter and we're not going
00:02:56.440
to talk about indenting or quotes or
00:02:59.480
stuff like that I don't think that's
00:03:01.680
productive for this use case I cannot
00:03:04.680
pay any of you Consulting fees if this
00:03:07.080
ends up in our production I'm sorry I'm
00:03:08.879
not authorized to do that yeah that's
00:03:11.360
that's our our ground
00:03:14.000
rules uh let's
00:03:16.840
start looking at this code this is
00:03:20.879
actual real production code that I
00:03:22.599
recently had to look at because it
00:03:24.400
landed in our backck
00:03:26.080
tracker um and it's still there I looked
00:03:30.480
at the code I understood half of
00:03:34.360
it and then I closed it and did all the
00:03:37.439
other
00:03:38.799
chickets so let's see up here there's a
00:03:42.319
simple explanation of what this code is
00:03:44.239
meant to do it takes a YouTube
00:03:48.439
link with the ID on the end and it turns
00:03:51.560
it into an embedded YouTube link should
00:03:53.920
be simple enough I
00:03:57.079
guess so there's several parts this
00:03:59.599
there 's a bunch of con uh constants up
00:04:02.400
here nested Ruby hash there's um two
00:04:07.840
parts to this for some reason Vimeo is
00:04:09.840
also there I haven't understood it quite
00:04:11.680
yet but we check for valid YouTube URLs
00:04:14.439
or valid Vimeo
00:04:16.400
URLs now we have two functions that
00:04:18.799
basically look the same which I don't
00:04:21.320
like and then down here we have the end
00:04:24.520
boss of uh return-based
00:04:27.160
programming which is just it's nine nine
00:04:30.120
lines of code four three comments and
00:04:32.759
five return
00:04:34.360
statements yeah um
00:04:39.400
so let's see
00:04:43.680
here uh maybe we can start off with
00:04:46.960
things we don't like about this
00:04:50.000
code and then we can go and start to
00:04:53.039
talk about how we can improve it what we
00:04:56.400
would do uh I can do some live EDI but
00:05:00.120
I'm not sure that we'll get very far
00:05:02.560
with that you you've seen me typing um
00:05:07.520
so I'll
00:05:09.759
start I look at this code and I feel
00:05:12.000
like there's too many constants for some
00:05:13.639
reason I don't like seeing that many
00:05:15.919
constants this here looks like it
00:05:18.639
belongs in a config file it's just like
00:05:22.520
defined in line and in the ru file which
00:05:24.639
is fine I guess we have um Frozen string
00:05:28.759
literal true at the top and string
00:05:31.400
concatenation at the bottom which means
00:05:33.120
we're uh wasting
00:05:36.120
time if I remember correctly and we
00:05:39.520
create reg xes on the fly everywhere we
00:05:42.639
have code duplication in this part is
00:05:45.240
valid D and is well
00:05:48.080
VI and what the heck is this line is
00:05:51.560
double the size of all the other lines
00:05:53.039
and I don't understand
00:05:54.680
it but hey it
00:05:57.479
works uh let me be clear I did not write
00:06:00.479
this
00:06:01.800
code but I could have written this code
00:06:04.360
like 10 years ago so you can make fun of
00:06:07.840
me just pretend I did this and we're
00:06:10.440
improving together
00:06:14.599
okay so any
00:06:17.639
ideas yeah we have people with
00:06:19.560
microphones coming to you please wait
00:06:22.080
are there any tests for
00:06:23.919
this I haven't brought them I
00:06:27.160
think this is purely an academical
00:06:29.599
exercise in that regard
00:06:31.960
sorry yeah in this code it's unclear
00:06:34.479
what is the entry point is all of those
00:06:36.720
methods are used uh or just the last one
00:06:39.880
and if it is just the last one why is it
00:06:42.160
at the
00:06:44.280
bottom
00:06:47.280
yeah I think you're right I actually
00:06:50.039
don't know if all those four uh are
00:06:53.319
actually public API my guess is that
00:06:55.919
only the bottom one would be so we can
00:06:58.199
just go ahead and put them where they
00:07:02.639
belong
00:07:04.680
better
00:07:08.280
good yeah um few ideas I can see from
00:07:13.160
start so do we really need beo if we
00:07:17.039
working with YouTube so we should just
00:07:19.039
clear out everything I think uh for this
00:07:21.639
exercise we might as well skip Vio yeah
00:07:24.280
okay and uh I needed Returns on the end
00:07:27.199
of each uh method and and there's no
00:07:30.280
like definition with private and public
00:07:32.960
methods uh can you repeat that please
00:07:35.039
there's no separation in private and
00:07:36.720
public if we are call in only one method
00:07:38.879
that it should be f ah sorry we just did
00:07:41.039
that
00:07:42.680
M okay good and reg say too much right
00:07:46.560
reg new that's all I can see right
00:07:52.120
now
00:07:57.720
yeah there might be a problem uh with
00:08:00.720
the concept uh this method get embedded
00:08:03.479
video URLs it doesn't treat URL as URL
00:08:06.319
it treats it as a stream which is a
00:08:08.520
source of box which really really hard
00:08:10.919
to debug sometimes so URLs are not
00:08:14.639
strings they look like strings but they
00:08:17.360
are special strings so they have a
00:08:20.360
formatting and so on so this embed plus
00:08:23.000
URI and then you get the piece of path
00:08:26.240
this usually leads to some problems so
00:08:29.319
uh as an idea why so this is URL why not
00:08:32.640
to get input par it this URL then you
00:08:36.159
have uh pieces like host uh path query
00:08:39.440
and so on and then just deal with it as
00:08:41.839
URL you could check whether it's v v or
00:08:44.519
not without regex you just check if the
00:08:47.360
host is YouTube or Vio uh the same with
00:08:51.040
path a little bit trickier than than
00:08:53.480
just host
00:08:54.600
but uh yeah I agree I I looked at this
00:08:57.279
and there's like
00:08:59.640
there is Yuri parsing but there's also
00:09:01.320
string
00:09:02.519
concatenation with uh Yuri in there and
00:09:05.680
I also thought yeah you can just use uh
00:09:07.959
a parser get the host and the path and
00:09:10.480
the other query parameters and put that
00:09:12.839
together in one
00:09:16.360
place
00:09:19.440
um usually the advice would be if you
00:09:22.200
deal with URLs you parse them using
00:09:24.640
parser because parser knows how to do
00:09:26.839
this properly do any mutation
00:09:30.399
uh and then oh encod this as URL again
00:09:35.279
using uh encoder like URL I think it's.
00:09:39.440
pars right
00:09:45.200
yeah yeah we have one here oh and back
00:09:49.040
there hello
00:09:51.240
hello um hi um I don't know if we have
00:09:54.959
decided to skip Vimeo or not but if we
00:09:57.720
want to keep YouTube and Vimeo
00:09:59.880
I would suggest to um to use the
00:10:02.399
strategy pattern to create a subass for
00:10:04.839
YouTube a class for YouTube a class for
00:10:06.640
Vimeo and just uh call in these classes
00:10:09.399
to do special handling so extract that
00:10:12.160
into a class of its own yes I would
00:10:15.519
agree um if it was just the YouTube case
00:10:19.279
uh we could just leave it with in the
00:10:21.120
one module um but since we're already
00:10:23.680
doing two different um services and
00:10:26.680
we're handling the differently right now
00:10:29.440
that is happening with ifs a lot of ifs
00:10:32.519
uh it would be good to have just two
00:10:34.560
super small simple classes can basically
00:10:37.880
do um matching if it's one of those URLs
00:10:41.760
and then you can do um the adjusting of
00:10:44.440
the URL based on the ID which we've yeah
00:10:47.200
we just do one match then we instantiate
00:10:49.680
a strategy strategy class um for Vimeo
00:10:53.160
or for YouTube and then we can call into
00:10:54.800
that class to do the actual handling
00:11:01.079
the strategy pattern it's it's
00:11:06.200
called yeah if I remember correctly
00:11:08.519
that's the strategy pattern um you have
00:11:11.839
a a super class or a class that has uh
00:11:16.760
to deal with the different things and
00:11:19.320
you can extract all the if statements to
00:11:21.279
only one if statement where you decide
00:11:23.839
okay which strategy do I use do I use
00:11:26.040
the YouTube strategy or the Vimeo
00:11:27.839
strategy you instan create uh a class or
00:11:32.240
a an object of the right class and all
00:11:35.680
the rest is um methods on that class but
00:11:39.160
all the classes of course have the same
00:11:40.680
methods I don't I think it's it's just
00:11:42.800
one method here so get embedded video
00:11:45.639
URL either for YouTube or for Vio and uh
00:11:49.839
yeah and then the the class can do
00:11:52.959
special handling if for example that's
00:11:55.240
that's extremely different different uh
00:11:57.800
I haven't completely understood that in
00:12:00.800
this case so for YouTube We for example
00:12:03.839
we have a regular and an embedded uh um
00:12:07.760
case that we don't have for Vimeo so
00:12:10.120
that will be only uh implemented in the
00:12:12.440
YouTube strategy and not in the Vimeo
00:12:16.639
strategy yeah I totally agree okay who's
00:12:22.040
next um one suggestion is we could use
00:12:25.720
pattern matching and the last one from
00:12:27.480
Ruby 3 it's not this would not like the
00:12:31.320
other ones that's use a different P
00:12:33.720
would make a little bit more readable
00:12:35.320
instead of have all these returns you
00:12:36.880
would have just um okay if this
00:12:39.160
condition match I have this this and
00:12:40.839
this would be the same logic but a
00:12:43.600
little bit more you mean here yes okay
00:12:47.720
the second thing is I don't really like
00:12:49.760
that you use get and is instead of
00:12:56.240
interrogation yeah it's like this person
00:12:58.360
heard of Clauses and decided to use them
00:13:01.199
everywhere yes P mat something more new
00:13:04.680
in Ruby Ruby stre but I think he would
00:13:06.639
apply very good the other thing is I
00:13:08.440
would not use is valid video I would
00:13:10.360
just use valid video interrogation small
00:13:16.480
stuff
00:13:18.639
maybe can may may I yeah it seems I can
00:13:22.560
can you hear me yeah oh cool uh sorry um
00:13:28.199
it seems the what we are trying to do is
00:13:31.600
validate the URL then we are extracting
00:13:33.959
or not but we probably should uh extract
00:13:37.639
the video ID and then return back the
00:13:40.399
embedded part but it's not very obvious
00:13:42.240
from the code so maybe splitting the
00:13:43.839
method to something like valid then
00:13:48.720
figure out the ID and then return that
00:13:51.480
back for the like short embit embit URL
00:13:55.639
for the short uh or just the just the
00:13:58.120
just just the ID would be enough and it
00:14:00.040
would be very clear what we are trying
00:14:01.639
to
00:14:04.720
do just an idea yeah
00:14:10.800
okay still have a lot of people wanting
00:14:13.360
to comment nice um yeah I was actually
00:14:16.079
going to say the same but in different
00:14:17.800
words uh one of the sorry for this yeah
00:14:22.199
um one of the things that um is a
00:14:24.759
problem in the code I see a lot is that
00:14:28.560
people tend to put all the code into one
00:14:31.680
method and uh the method spans on
00:14:34.759
different multiple layers of abstraction
00:14:37.399
and if we would bring this method into a
00:14:39.839
single level of abstraction which will
00:14:41.320
be exactly like uh get a video ID return
00:14:44.680
nothing if we couldn't do this and then
00:14:47.639
uh build an embed URL that would be much
00:14:50.000
clearer much more readable and then the
00:14:52.120
extraction code which is the the most
00:14:54.560
complex part here I guess we can even
00:14:56.600
extract it into a separate class and the
00:14:58.839
second second thing I was going to say
00:15:00.480
is that from the module name which is
00:15:03.959
video URL helper I assume that this is a
00:15:08.040
part of this is something that is used
00:15:10.480
in the views but the knowledge about how
00:15:13.639
to do this stuff with the YouTube URLs
00:15:16.399
it's really a domain knowledge and maybe
00:15:18.680
it should be in the application layer
00:15:20.680
instead um that's a good point actually
00:15:24.519
I think this is originally in a rails
00:15:26.959
Helper but that rails helper is then
00:15:29.199
included in a model which is not the
00:15:31.560
right way I either it's a model concern
00:15:34.319
or it goes somewhere completely else but
00:15:36.040
it does not belong in a helper in that
00:15:37.560
way but maybe the person wanted to reuse
00:15:39.759
it in the view and on the model for some
00:15:42.800
reason I can't quite know that right now
00:15:46.880
but yeah I like the idea of having like
00:15:49.279
uh extra classes for emitted case and
00:15:51.600
stuff if I understood C you
00:15:53.959
correctly
00:15:56.120
okay yeah thank you
00:15:59.560
I also my comment is kind of related to
00:16:02.839
naming so this kind of video URL helpers
00:16:07.079
helper implies that it would be used as
00:16:09.959
a sort of uh utility class or something
00:16:13.240
like that uh and usually they're used as
00:16:17.199
uh kind of those this those public
00:16:19.560
methods should be static probably if
00:16:21.079
it's used that way but the only way to
00:16:23.759
use these helpers is actually to include
00:16:26.959
uh it all of these Mass
00:16:29.440
into some of your classes and you only
00:16:31.800
need the one method here uh which is I
00:16:37.360
would say very suboptimal so
00:16:41.199
probably uh so probably that should be
00:16:44.480
changed somehow it's like it's a pure
00:16:46.920
utility maybe we could uh just if if if
00:16:51.120
we are leaving it as a
00:16:54.839
utility then maybe we would like either
00:16:58.480
convert this class this method to static
00:17:01.959
one so we can use it that way and
00:17:05.199
not like uh not mix in all that
00:17:12.199
stuff yeah I think I uh agree that it's
00:17:15.600
would be better to not include all that
00:17:17.400
code including the constants into every
00:17:19.120
class where it's used it doesn't really
00:17:20.480
make sense in that way you could declare
00:17:22.439
this uh as a static method with self Dot
00:17:25.360
and then just call that specific method
00:17:28.679
with would be interesting to see how
00:17:29.840
that works together with the whole class
00:17:31.600
idea and composition that we talked
00:17:34.480
about yeah I um I would probably throw
00:17:38.440
away about 73% of the whole class um if
00:17:42.240
you scroll up um to the first two lines
00:17:45.880
what you have to do is basically just
00:17:47.720
replace the watch question mark V equals
00:17:51.240
and replace it with an embed I think you
00:17:53.559
can do that very easily with a G sub uh
00:17:56.440
so maybe you can just make a method with
00:18:00.120
one line and if it's already embedded
00:18:03.799
yeah well the method doesn't do anything
00:18:05.559
and Returns the original string so
00:18:07.559
should be fine
00:18:08.960
too yeah you could use a gab of
00:18:12.480
course
00:18:14.120
um I don't feel comfortable doing stuff
00:18:17.200
like that to URLs for some
00:18:22.840
reason it's just a minor detail but um
00:18:26.600
for building the uis I would use
00:18:29.640
URI um colon colon HTTP class it has a
00:18:34.080
build
00:18:35.520
method the same sentiment that we
00:18:37.840
shouldn't just manipulate strings and
00:18:41.200
handle them as your eyes letter yeah I
00:18:44.480
actually never heard of that class yeah
00:18:46.760
I think it's it should be standard
00:18:48.039
Library I hope
00:18:50.520
so Yuri
00:18:57.440
HTTP like this
00:19:04.159
and the method was called build okay
00:19:07.720
interesting cannot comment on
00:19:10.080
that but looks good yeah who's next uh
00:19:13.919
you said you don't feel comfortable
00:19:15.320
about deleting the whole class um
00:19:17.440
there's something called tests that you
00:19:19.120
can uh put
00:19:22.400
in um that give you some confidence
00:19:25.120
maybe then you can remove it
00:19:29.200
you really need to have a discussion
00:19:30.520
with the guy that wants to keep
00:19:32.000
everything as a
00:19:33.919
URI and we'll see yeah I think it it's a
00:19:38.760
valid approach if you need it simple
00:19:40.440
like that um we haven't talked about uh
00:19:43.679
all The Nasty cases um that can happen
00:19:47.240
where people don't input the right uh
00:19:51.000
URL type which is actually what happened
00:19:54.200
in our bu trigger a lot where we had
00:19:56.440
like a carrot at the start for some
00:19:58.400
reason because people were copying it
00:20:00.320
blindly from
00:20:08.480
somewhere I
00:20:14.960
think yeah yeah so uh this is rails
00:20:17.960
application right um this belongs to
00:20:20.520
Ra's application yes yeah okay so my
00:20:23.720
first suggestion will be like uh it was
00:20:26.080
mentioned before in the strategy so if
00:20:28.080
you move this to a separate model
00:20:29.880
without like uh database implementation
00:20:32.480
you can move the whole validation up and
00:20:35.120
there so we just need to call uh create
00:20:38.080
a new uh model with the URL check if
00:20:42.360
it's valid in for example in validate
00:20:45.360
something like uh just validate uh
00:20:48.559
question mark private method and it will
00:20:52.640
uh will will be responsible for the
00:20:55.280
whole validation before like running the
00:20:57.559
whole business
00:20:59.280
logic so like
00:21:01.480
extract uh reg XIs everything else
00:21:05.760
constants that will be a separate con
00:21:08.000
class the second one uh you're already
00:21:11.120
using Ur passs in line six as mentioning
00:21:15.120
to do so you can move it out as an uh
00:21:19.559
how it's called ID
00:21:21.799
something YouTube ID so you can extract
00:21:24.760
it to a method and memorize it memorize
00:21:27.919
it sorry
00:21:29.279
like and reuse it everywhere it's can be
00:21:32.880
used this is where the ID is actually
00:21:35.440
extracted and you mean extract that and
00:21:38.360
do that first to meth yeah and just name
00:21:41.039
it
00:21:42.200
cly the same with the reg so every check
00:21:45.520
with the regx like just uh does match
00:21:48.880
match something and extract it
00:21:51.480
there and if we don't have like an hour
00:21:54.440
to do it live so something like that
00:21:57.640
thank you
00:22:01.360
uh sorry for the mistake so I just
00:22:04.600
wanted to say that many um errors that
00:22:07.679
you have in in back tracker when when
00:22:09.640
the input is has some extra characters
00:22:13.360
uh or in qu it incorrectly they could be
00:22:15.799
avoided if the input would be treated to
00:22:18.159
Z so parser will explode right away if
00:22:20.400
it's something unparsable something
00:22:22.400
which does not look like URL uh and you
00:22:25.360
don't have this cases anymore so there's
00:22:27.520
no need to be over protect protective uh
00:22:31.000
like in in this in the method when you
00:22:33.360
have a bunch of returns and checks
00:22:34.919
whether this thing looks like URL that
00:22:37.520
you need or not yeah I think uh I agree
00:22:41.360
that it would be good to pause it right
00:22:43.159
away right now it uh breaks somewhere in
00:22:46.360
the middle sometimes at CGI pars I think
00:22:49.520
and it's not always clear if you look at
00:22:52.679
the St tray the first time where what
00:22:55.240
actually happening
00:22:59.200
continue with the idea of um
00:23:01.880
simplification you can simplify both
00:23:05.159
patterns into one one for Vi and one for
00:23:08.120
YouTube uh and just use replay to find
00:23:11.360
the embed like literally those three
00:23:13.799
patterns can just be one with with Rex
00:23:18.400
and the second one if you don't want to
00:23:20.520
do more Rex arithmetics can also be one
00:23:24.279
or two and literally using replace to
00:23:26.720
change the ID and then you have the is
00:23:29.600
three line of code
00:23:32.120
maybe MH yeah so based on the fact that
00:23:37.640
the method is called get embedded VL and
00:23:40.080
you have the god that tries to figure
00:23:42.840
out if it already is an embedded URL it
00:23:45.880
looks like this view helper is only used
00:23:49.240
to correct wrongly input data from the
00:23:52.200
database so why is it done before you
00:23:55.880
write it into the database so the
00:23:57.679
embedded URL it's always stored in the
00:23:59.559
database you so you don't have to fix it
00:24:02.279
every time you want to render something
00:24:04.720
do you mean like in the front end
00:24:06.799
or no
00:24:09.039
like some place it looks like there's
00:24:11.600
some data you're fetching from a
00:24:13.799
database and which is potentially maybe
00:24:17.640
sometimes already embedded Ur because
00:24:19.600
you have the guard method that's just
00:24:21.200
checking that and if it's already an
00:24:23.279
embedded UL it's fine let's return that
00:24:25.240
one um oh it's not an embedded UL let's
00:24:28.120
fix fix the error we have in our
00:24:29.919
database so why don't you fix your
00:24:34.480
data I not sure if I can answer that
00:24:38.520
correctly I have a guess that we just
00:24:41.320
wanted to avoid Sates people complaining
00:24:44.399
about too many error messages or
00:24:47.159
something but you could you could do
00:24:50.640
that like converted to an embedded URL
00:24:54.240
in the in the moment where you want to
00:24:56.679
write it to a database then you have to
00:24:59.159
only to do it
00:25:01.000
once oh so your interpretation is that
00:25:03.559
this is only run on the model that's
00:25:05.960
already there and it's the database
00:25:09.080
sometimes has the wrong URL that's what
00:25:10.480
you're saying uh that's my guess based
00:25:12.799
on the method name and the content
00:25:15.480
yes
00:25:17.279
okay I'm not
00:25:19.600
sure yeah um adding to this uh it looks
00:25:23.120
like this class has a lot of complexity
00:25:25.559
that comes from the fact that there is a
00:25:27.559
huge variability on the input parameter
00:25:30.559
and you told that this is a part of the
00:25:32.480
model so I guess that you are either
00:25:35.279
storing the video URL in some like not
00:25:39.520
not standard not uh standard way
00:25:42.279
standard form uh and what you really
00:25:44.640
should do to improve this code is to um
00:25:48.279
extract the ID at the moment where you
00:25:50.279
create the model and only uh build the
00:25:53.960
embed URL when it's needed and then you
00:25:56.399
will not have to have this class at all
00:26:01.679
yeah
00:26:03.440
okay one suggestion I have is something
00:26:07.399
like the strategy pattern but uh
00:26:10.440
bit maybe bit less complicated here and
00:26:14.360
that would also follows the open close
00:26:16.440
princi I not believe you need to do it
00:26:18.840
everywhere but maybe here's a good case
00:26:20.679
because you can have more cases in the
00:26:22.960
future not only YouTube We ma more cases
00:26:26.240
so you could create like an con done
00:26:29.000
with a map of regular expressions and um
00:26:33.799
and um functions so you could iterate
00:26:37.000
and in get embed video URL so this map
00:26:41.440
and in case that one of the keys
00:26:44.080
mattress then just call the function
00:26:47.760
that is as a Val of this K in the
00:26:50.919
map so you would have like this open
00:26:53.640
close
00:26:54.880
principle follow
00:26:58.840
so do you mean mapping it to a function
00:27:01.080
or mapping it to a class and mapping to
00:27:03.480
a function of course you could also do a
00:27:05.399
class but I think here it's enough to
00:27:07.320
just have a mapping B an regular
00:27:09.640
expression and an
00:27:12.120
function
00:27:14.919
okay yeah we don't have much time
00:27:17.600
anymore so this will be the last comment
00:27:19.200
unfortunately so what this thing does
00:27:21.279
I'm pretty sure that this is like for
00:27:22.880
the Rich Text Editor you click a button
00:27:25.440
it opens a popup you put in the URL
00:27:28.200
paste in anything you want and it makes
00:27:30.039
the embed for you there is no database
00:27:32.480
model you cannot put this into model
00:27:34.000
there is no storage of one field so
00:27:36.360
really we only want to do this
00:27:37.960
conversion from line three to line two
00:27:41.080
if that's the right order a relative yes
00:27:44.080
yes so if we would have tests I think
00:27:46.200
this code wouldn't be even that bad if
00:27:48.279
it does what it what it should be doing
00:27:50.679
the main problem is the main method on
00:27:52.519
line 29 which is just too complicated to
00:27:55.320
grasp so if we were to structure what it
00:27:58.240
actually does like first pick out what
00:27:59.799
kind of URL it is see if it's valid and
00:28:02.559
then do the replacement and then return
00:28:04.840
it if you just have more step-by-step
00:28:06.679
approach of this main method to make it
00:28:08.440
more readable it might be totally fine I
00:28:10.880
wouldn't do any strategy pattern because
00:28:12.480
this is one class this is it should be
00:28:14.679
as simple as that once you have another
00:28:16.919
two classes in the code you would need
00:28:18.559
to also understand them which wastes
00:28:21.320
time so I think um there's still a lot
00:28:24.279
to be done here but it's not that bad I
00:28:26.919
would say
00:28:29.679
okay yeah uh so we have very different
00:28:31.880
approaches some people want to add more
00:28:33.559
classes some people say just keep it
00:28:35.720
simple in that
00:28:38.240
regard I think you could also Define
00:28:40.600
those classes in line in the same file
00:28:42.600
and maybe make it more findable the
00:28:46.000
implementation
00:28:47.440
but uh it's interesting to see those
00:28:49.600
different tastes here I don't know if I
00:28:51.640
have a strong opinion on either of
00:28:54.679
those okay uh so that was the last
00:28:57.200
comment we are out of time so I can't
00:28:59.000
show you the code that I like
00:29:01.480
unfortunately so no boasting for me
00:29:03.760
today just I don't know I'll make two
00:29:06.720
more suggestions because this looks like
00:29:09.200
a Java method definition just get rid of
00:29:11.480
the get and instead of is valid URL just
00:29:15.440
call it valid video URL with a question
00:29:17.399
mark in the end because that's more
00:29:20.200
Z yeah I think that's it thank you very
00:29:23.760
much for participating I think you all
00:29:25.120
learned a lot