WEBVTT

00:00.000 --> 00:16.600
All right, I hope I'm able to do some justice too, whatever set set, but, and I'd also like

00:16.600 --> 00:23.720
to clarify, I'm not exactly going towards the future of sketched right now, I'm just

00:23.720 --> 00:30.720
currently talking about how the refactoring that was done, so let's get to that.

00:30.720 --> 00:37.720
First of all, of course, in case you haven't heard of freecat, how are you here, but still

00:37.720 --> 00:44.720
freecat is a car, is there an open source, parametric CD modeling software, it has been

00:44.720 --> 00:56.720
like developing, in development sense, to like for like 22 degrees, a lot of years, and you

00:56.720 --> 01:04.000
can basically model things of any size, for any use, for more details, go where I point

01:04.000 --> 01:14.680
you, they have a standard at the AWS building and the website if you are not here,

01:14.680 --> 01:26.680
okay, and a bit about me, basically I'm a mechanical engineer, and I have been a contributor

01:26.680 --> 01:35.120
to freecat on and off since 2016, nowadays I've stabilized on to the sketcher, part

01:35.120 --> 01:44.600
design, FEM, all those work branches, and I also work part time as a project staff at this

01:44.600 --> 01:53.320
cool project that you probably should also look at, called Fosse, at IT Bombay, but that's

01:53.320 --> 02:01.160
all, and say about it for now, we can meet offline about it, and you just search my name

02:01.160 --> 02:11.840
on LinkedIn, hope you find me, okay, so let's move to the actual thing, so the point

02:11.840 --> 02:21.560
is, as I said, figure is like well over 20 years old, and when you develop code for that

02:21.560 --> 02:29.200
long, you, and especially on a volunteer basis, you tend to accumulate a whole bunch of spaghetti

02:29.200 --> 02:40.000
code, but just every bug basically or every feature that someone wants to add gets added

02:40.000 --> 02:50.240
as a workaround, and somebody just keeps it there rather than rewriting it, and of course

02:50.240 --> 02:56.720
there is also like the fact that there are so many standards that have changed, see the

02:56.800 --> 03:05.360
corresponding, it is not currently supported, but that's what we'll jump to, the moment

03:05.360 --> 03:14.320
we're going to 20 or 4 support ends, so we'll have like so many seamless standards,

03:14.320 --> 03:22.480
so yeah, it is about time to start looking at how to clean up the refactoring code, and

03:22.720 --> 03:32.320
last year around April, then we decided that we are ready to release the 1.0, that was a good

03:32.320 --> 03:42.400
time to start cleaning up at least on schedule, so by the budget schedule, but the first reason

03:42.480 --> 03:52.240
is of course, that is where I'm sitting, but why am I, but why am I in schedule, because

03:52.240 --> 03:57.200
that was kind of the first workbench that I had, that I worked on, like that was the first workbench

03:57.200 --> 04:03.440
that I saw, and I saw that it had something that I would like, it didn't have something that

04:03.440 --> 04:11.840
I would like, and then I started working on that, and most other people see that they don't have

04:11.920 --> 04:20.560
something that they like, and then they put an issue, so of course, not that I'm complaining,

04:20.560 --> 04:30.560
and just saying, that's the first thing that you see, so we just, so that's where a whole bunch

04:30.560 --> 04:40.880
of issues happen, yeah, first, and so you can see, if you look at the GitHub issues, you can see

04:40.960 --> 04:48.880
like about 2013, I'm not sure exactly what percentage, but definitely two days back when we

04:48.880 --> 04:59.040
had three categories, maybe like 75% of the issues were scheduled issues, so, and of course,

04:59.040 --> 05:06.400
it has large amount of, a bunch of modules, within it, basically, that interact with each other,

05:06.480 --> 05:15.680
including a whole solver, so it's a good place to start, I guess, and hopefully having more

05:15.680 --> 05:29.120
want to, or at least I'll direct to other work benches, so basically, so to start refartoring,

05:29.120 --> 05:41.920
I guess we need a set of basic things, we have like, maybe like hundreds, thousands of places

05:41.920 --> 05:47.280
where we can actually refactor, where we can actually make changes and improvements, so that things

05:47.280 --> 05:52.960
become readable, but we don't have all the time in the world, so how do we prioritize, and one

05:53.040 --> 06:02.880
measure of course was this cognitive complexity, which is like, you need to go in, I mean,

06:02.880 --> 06:08.320
I won't go into the details of it, exactly, but it basically says, don't go too deep,

06:08.320 --> 06:20.400
investing, don't go too long, don't have too many conditions, a whole bunch of things, and then

06:20.400 --> 06:27.840
it discounts a few things rather than the slightly more slightly older cyclomatic complexity, so

06:29.440 --> 06:36.800
that was the measure that we took, that's, or at least, I took, people are saying that these,

06:39.040 --> 06:48.560
okay, so, and these are the books that I follow basically, and I guess, most of you who,

06:49.120 --> 06:53.920
most of you probably have already read this, and you'll probably just say, oh, by my

06:53.920 --> 07:04.240
just repeating the book, but let's go off. So, the first thing that I would, that we need to do

07:04.240 --> 07:12.880
can be, where refartoring is basically knowing what we are refartoring, and that itself can become

07:12.880 --> 07:22.000
a challenge when you have like 800 line functions. So, then you can't just say, oh, this is going

07:22.000 --> 07:31.040
to just trim this part off, we want to say, okay, if it is this way, it will cut just this part,

07:31.040 --> 07:36.960
if it is this way, it will just cut this part, if I try to trim this part, I'm talking

07:37.040 --> 07:43.680
about the background, it will cut this part, and then we have two other parts, and a whole

07:43.680 --> 07:52.400
bunch of AFLs, AFLs cases. So, that kind of document, that kind of, at least, idea we need to have

07:54.480 --> 08:03.440
before we start going forward, and then, and once you do that, you start making tests.

08:04.400 --> 08:09.920
You don't ask the code until you have good tests, but at least that's for discipline

08:09.920 --> 08:21.600
safe, I don't follow it, but that's what we supposed to do, and by my experience, many of these

08:21.600 --> 08:30.880
methods probably like can take a dozen tests each of them, multiple dozens is like, you know,

08:31.760 --> 08:38.880
so, yeah, they just be prepared for that, I guess, and I would hope to sometimes

08:39.760 --> 08:46.560
automate, automate, writing those tests as well, but until then we give that, okay, then

08:47.600 --> 08:57.120
going to the methods, we'll start with the simplest method that I went through, and this is basically

08:57.200 --> 09:13.200
clean up all the nesting, we have the chock, yeah, so we have like this thing going on,

09:14.080 --> 09:35.600
somehow try to clean it up to something like this. So, that way we can get to like,

09:35.840 --> 09:45.760
if something, if this special case happens, do this, and we are done, and if, but if not,

09:45.760 --> 09:52.320
move on, so those kinds of things, they are kind of the simplest way, simplest to manipulate,

09:53.040 --> 09:59.200
although I have still managed to insert bugs by refactoring that, but still,

09:59.200 --> 10:08.960
it's kind of the easiest, easiest event, and basically just follow the instructions I have

10:08.960 --> 10:22.800
written here, then helper functions as such, this becomes the next step after you have seen

10:22.800 --> 10:27.600
that, oh, you can't really clean up this thing too much, make this a different function, make

10:27.600 --> 10:35.520
this a different function. So, I'm probably, you'd be able to use some parts here, some parts there,

10:38.080 --> 10:50.720
so, with there, so that's another method, and of course, the, and once you have that,

10:50.720 --> 10:59.040
you can also, you should also go for cleaning up, like using the algorithm library, so basically

10:59.040 --> 11:08.240
making C++, using the more functional aspects of C++, more like the functional programming

11:08.240 --> 11:19.440
aspects of C++, so you have, there's like a bunch of templated algorithms that you can use

11:20.720 --> 11:27.600
makes your life a whole lot easier, clearly tells what you want to do rather than having to

11:27.600 --> 11:37.120
add a comment, just before each for statement, so we go with that, and like even a simple for

11:37.120 --> 11:44.640
each can be useful, although I haven't used it myself, but I do believe that, okay, if you get

11:44.640 --> 11:52.560
nothing else, you can possibly just parallelize it in the future, or when you try to parallelize

11:52.560 --> 12:02.560
it, consider using for each, and this is like the next step that I'm planning on, as I said,

12:02.560 --> 12:09.920
there was an 800 line method, how long was the, how long was the class, 10,000 lines, so now

12:10.800 --> 12:20.240
we need to somehow repair everything in that sense, so I won't go into details of exactly

12:20.240 --> 12:28.080
what that class was, because that probably needs knowing the, hence I, entire structure of

12:28.160 --> 12:35.600
sketcher, but yeah, it's called sketch object, you who have noticed that already knows what

12:35.600 --> 12:46.160
that is, so here, and then I guess, I just briefly talk about the challenges that are faced here,

12:47.920 --> 12:54.000
of course, as I said, there's a limited amount of documentation, so you need to specify the

12:54.000 --> 13:06.080
exact, like actually make that work, probably write that documentation yourself, or get someone

13:06.080 --> 13:14.560
who actually wrote the code to tell you, so that, and then the next problem was, okay, now I have

13:14.560 --> 13:21.040
the changes ready, but they can't be merged into 1.2, and some of them are not really ready yet,

13:24.800 --> 13:32.400
there, so as soon as 1.2 comes, maybe maybe my first set of changes come, goes in, and then I

13:32.400 --> 13:38.000
work on the second set of changes, and then like 15 other developers have added 30 other changes

13:38.000 --> 13:45.760
into it, so that in, so that involves a bunch of content resolution, a content resolution,

13:45.840 --> 13:56.480
more or less, so that's done, and so yeah, this kind of gives you an idea of like, yeah,

13:56.480 --> 14:01.120
refartoring is an iterative process, especially when you're working with multiple people,

14:02.480 --> 14:12.880
and talking of multiple people, it would be best to, that kind of, everyone tries to refactor

14:12.880 --> 14:22.320
as they make changes to the code, and of course, as I said earlier, they could keep improving

14:22.320 --> 14:32.720
the readability, but we need to stop at some point, so that's, so basically consider stopping

14:33.600 --> 14:39.040
one example is when, oh, I'd made this change, but then I'm going to add a new feature,

14:39.040 --> 14:44.080
which will change that function again, so might as well, it might as well be factor after that,

14:44.080 --> 14:58.320
or write that in better, so yeah, that's about it, thank you.

14:58.320 --> 15:08.800
Any questions? So when, when you were analyzing the code, how much that code did you find

15:08.800 --> 15:15.520
in SketchUp, that wasn't actually used by anything? Surprisingly, little, I guess, there are

15:15.520 --> 15:27.840
some sort of screen. Okay, so as asked, what part of, how much of this, how much of this

15:27.840 --> 15:35.920
SketchUp code was dead code, because like basically not used, I don't think I encountered

15:35.920 --> 15:42.240
much of, much like that, although I could, I should say that that 800 line function, I had pretty

15:42.240 --> 15:50.160
much read it in it entirely, so there's probably a lot of code there. I think there was just one method

15:50.160 --> 15:56.960
that was dead code, that is still dead code, I'm not exactly sure, because it's part of the

15:56.960 --> 16:03.600
toponaming fixed thing, so that's going to be some work to figure out, but apart from that,

16:03.680 --> 16:19.040
it was mostly just repetitive code of the same thing, yeah. Your code revision was a done fully

16:19.040 --> 16:29.680
manually, or other tools to help and automate this refactor in. Yeah, the refactor, okay, so,

16:29.680 --> 16:40.640
he, so as asked, was the code, was the refactoring the manually or, well, there's some automation

16:40.640 --> 16:49.520
tools, so identifying the problem, identifying the places to improve the cognitive complexity,

16:49.520 --> 16:56.560
that was done by CRNTID, but yeah, mostly the refactoring was done manually, all right.

16:57.440 --> 17:05.280
Yeah, I kind of had two questions, first question would be, like, how do you make sure

17:05.280 --> 17:10.560
that the refactoring you're doing, preserve the behavior of the function, do you rely on tests

17:10.560 --> 17:16.560
and code review, or do you also rely on static code analysis or something like that?

17:16.560 --> 17:31.840
So the question was, do I rely on a test for, I can repeat it, do you rely on tests and

17:31.840 --> 17:36.160
code review to make sure that the behavior of the function is preserved that you're refactoring,

17:36.160 --> 17:40.160
or do you also have kind of other tools to help you there?

17:40.880 --> 17:47.200
So, that was just test, basically.

17:47.200 --> 17:54.880
Okay, and another question is, like, if you make all this effort to, to refactor the code,

17:54.880 --> 17:58.720
how do you make sure that it lasts? You mentioned that you have analysis for a

17:58.720 --> 18:04.720
stoichiometric complexity, do you plan to enable, like, for example, to think highly checks,

18:04.720 --> 18:10.720
let the stoichiometric complexity does not increase again in the future?

18:10.720 --> 18:20.240
So the question was, once this refactoring is done, can, okay, once this refactoring is done,

18:21.600 --> 18:27.280
how do I ensure that the, that the, that the, well, cognitive complexity,

18:27.360 --> 18:36.000
but does that increase? How does, how do we ensure that doesn't, that doesn't increase further?

18:36.000 --> 18:47.120
And I guess, we do have a C-Rang, some C-I tests that can complain, that, well, they complain about

18:47.120 --> 18:51.840
variable names, so I'm very sure they can complain about the cognitive complexity, the same

18:51.920 --> 19:10.560
tool is being used, C-Rang tidy. So, yeah, I just want to get Felix up for the next talk,

19:11.600 --> 19:17.600
but continue with the answer. Yeah, so, yeah, so I was basically just suggested to use,

19:18.560 --> 19:25.360
that C-Rang tidy can complain about cognitive complexity increasing. And, yeah, basically,

19:25.360 --> 19:36.240
I guess at some point, we will, we will activate that, as well, yeah, okay.

19:36.240 --> 19:40.640
So, for, thank you for the great presentation, if there are more questions,

19:41.360 --> 19:46.800
a ginger, you'll be outside, right? Yeah, I'll be around, I'll probably have some time at

19:47.840 --> 19:57.920
freecat booths, freecat booths in building A-W. Yeah, okay. And, yeah, so, thank you for the grants.

20:00.000 --> 20:05.360
This was basically funded through them. I should have mentioned that somewhere, but, okay.

20:10.640 --> 20:12.640
Thank you, thank you, thank you.

