>> Today on On.Net show,
Kasey is going to be showing you a bunch of
new refactorings that are in Visual Studio 2017,
15.8 version. Please check it out.
You won't want to miss it. Welcome to
another episode of the On.Net show.
Today, we have Kasey,
who's going to be showing us some
refactoring in Visual Studio.
Let's get started. So, tell
us a little bit about yourself and then we'll start.
>> Sure. I'm Kasey Uhlenhuth,
I'm a Program Manager on the.NET and Visual Studio team.
My main job is to figure out how to make developers more
productive in writing C# and
Visual Basic inside Visual Studio.
>> That sounds like a good idea.
>> It does sound like a good idea, doesn't it?
>> Yeah, and we work together.
>> Yeah, we do work together.
>> Yeah, awesome. Okay, so what do you got?
>> Right. So, here I have my standard little demo out.
That's my Alexa's skill I wrote.
So, let's go through and refactor parts of it.
So, every update to Visual Studio we're
working to add more and more
refactoring it's because when the top developer
productivity things that people say they're missing,
so like, "Oh, give me a refactoring for this and that."
So the working net. Add those all in.
>> Speaking of that, which version of
Visual Studio are you actually running here?
>> Yeah, so if you look at my Visual Studio I'm on
full preview and it's because
I'm on Visual Studio 2017,
version 15.8, preview 3.
So, if you're on 15.8
you'll get all the ones that I show,
then I going to show one that specific to15.8.
>> Okay, 15.8.
>> Yeah.
>> So, it same.
>> I'm on 15.8, but.
>> Okay. That's the same one I'm running, as well.
>> Yeah. So, we have the classic refactoring.
So, if you have your cursor
and the name of the variable or whatever,
you can do "Control RR" to rename
it in-line and we get this nice little pop up on
the right hand side that lets you include
comments or strings and see preview if you want.
We go the step further.
>> Did you do say "Control RR"?
>> Yeah, "Ctrl RR".
>> So, with that you can
hold the "Ctrl "key down and then hit R twice?
>> Yes.
>> Okay, just checking.
>> Yeah. Hold "Ctrl" down, R
twice, and then it will rename.
We have this built-in conflict resolution.
So, if we can tell that the name that you've
typed-in conflicts with another name,
that will be unresolvable,
we'll let you know in this little thing over here.
So, you know that's unresolvable,
or if it is resolvable despite having
the same name as something else
we'll also let you know as well.
So, it's like something we do in our rename,
it's classic, it's been around forever.
So, that's how you can do that. I just hit "ESC"
there to exit the rename session.
>> Then, you're back to zero, yeah.
>> Yeah, I'm back to where I started.
So, if I do want to rename it
because Dustin always gets mad
at me because I abbreviate my latitude
and longitude to lat and long
which doesn't really mean anything.
So, I can update it now
to be more explicit on what I'm doing here.
>> Yeah, don't go to the API Design Group,
they won't even let you in the door.
>> Exactly.
The others like classic when we have is extract methods.
So, if you select any chunk of code.
So, it can select all this and I can do "Control Dot".
So, "Control Dot" allows you to
access any refactoring that we have,
and they show up in this little
screwdriver icon that we have.
Some people think it looks like a paintbrush,
whatever helps you understand what it is.
So, from here, you can extract a method.
We drop you in a rename session
and you could name it whatever you want.
>> Well, you know what I think it looks like?
>> What do you think it looks like?
>> Sonic screwdriver.
>> A sonic screwdriver?
>> Yeah.
>> I don't even know what that is.
>> From Doctor Who.
>> I've never seen Doctor Who. I know.
>> Okay.
>> Unbelievable, but haven't.
So, those are the classic refactoring
that people ask for that we have built in.
They've been around since 2015.
So, you should have them from 2015.
One that we've added in 15.8,
so version 2017 15.8 is "Invert If".
So, if I'm on if statement,
you can press "Ctrl Dot"
and we'll offer to invert your if.
>> I love this line.
>> Yeah. So, you can see here we're
inverting your logic and things like that.
So, you know this is useful here
rather than having my else case throw exceptions,
it's like, "Look for a specific
case and throw my exception,
otherwise, do the rest of my logic."
So, that's what doing here.
>> Right. So, you guys must have some pretty,
I don't know if the word is sophisticated,
but some fairly smart systems
that can know that when you invert if that
it is exactly the right inverse of what
the expression was in the if statement.
>> Right. Yeah. I mean like we go through we say,
oh, like flip the logic and all that stuff. Yeah.
>> So, you must have tests for that?
>> Yeah. We have to test that.
I hoped we have test ratings. Yeah, we have lots of that.
You can go into the Roslan codebase and see all the unit
tests that we wrote to check
all the refactoring that we write and stuff.
>> Yeah. This seems conceptually more
complicated than say the rename ones.
Maybe that's not true.
>> No. Rename could go across multiple files.
Way more complicated. Well, how about that.
>> Yes. They are complicated in different ways.
>> Yeah, complicated in different ways. Yeah.
>> Okay.
>> So, that was invert If, that's the only one that I'm
showing that's in Visual Studio 2017,
15.8 only, it's a new one that we've added for that.
You can also- Actually, I lied.
Sorry. Lied. You can now add a parameter to a method.
So, from my call site here I
can add something so
like I want to have a boundary of 180.
So, if I want to do
my boundary checking when I check my boundaries,
I can now do "Ctrl
Dot" and you can add a parameter in here.
This is actually a
community contribution because they are open source.
I can't really remember who wrote this.
>> Wow.
>> So, we got it in 15.8.
So, now, add a parameter to a method here.
>> Now, when you do that my assumption
would be that it would obviously add to that parameter,
to that particular call site,
and then it changes
the signature of the method you're calling.
>> You can see it just here.
>> But if there's other call sites,
then I assume that they will be broken.
Am I thinking about that correctly?
>> Yeah. So, yeah.
In this case, I only have one.
I'm not actually sure what we do for the other ones.
I think they would be broken,
there'd be errors and you'd have to go- do like
final references whatever and visit all of them.
>> That stands to reason.
>> Yeah. We were
considering designs where we put a null for
you or like other things like that in this case.
>> Yeah, this seems good.
>> Then, what else do we do?
So, in here, we like
another classic one is to in-line a temporary variables.
So, you can see here I have two temporary variables.
Just put your cursor, and then
we'll offer to in-line them.
So, if you prefer that,
you can come over here in-line both of them.
That was the wrong one.
Sorry guys. I did change my code style,
instead, had to come down to temporary variables.
So, I in-line those another
refactoring that people use a lot.
Yeah. So, that was those if note that I've
added this boundary parameter,
I realize that I want to change my order.
We've always had a change method signature.
So, just from the signature,
press "Ctrl Dot" again, offer change signature.
We pop up this dialog to view,
you can re-sort them.
So, I can click my boundary,
make it the first one.
I could remove it if I regretted that decision.
You can see a nice code preview in here.
>> Okay. So, now, that will change all call sites.
>> Yeah, that will change all of them,
it's adding anything.
>> Right. Now, if you were to remove
a parameter, say boundary, presumably,
boundary is used as basically,
a local inside the check boundaries method.
So, presumably, you would get a compiler error for that.
Let me show you. So, here,
I can zoom it.
So, that has been zoomed.
So, now I com in here, change signature,
remove it, give you the preview that's gone.
>> Yeah.
>> Yeah. Now you wouldn't have anything here.
>> That makes complete sense.
Okay. Awesome. The nice thing about
these refactoring is in Canada speak, "Ctrl+Z".
>> It works.
>> Yeah, I just undid with,
"Ctrl+Z" Or Z, wherever you're from.
>> Yeah.
>> Yeah. Unlike the last one that
people really like that came in Visual 2017,
is like so here I have my refactoring class.
If I hover over the structure visualizer,
I can see I have the "Geohelpers"
or "Geocodehelpers" class.
So, if you believe every class should be in
its own file with
the same name and you can just put your cursor in here.
"Ctrl+dot," you can see all the different
Generate actions we have in
the interface but then we have "Move
type" to it's on file with the same name.
So, if I zoom in, you can see offers to make it with
the same name and we'll pull over
all you're using and whatever you have there.
>> Oh, nice. Now, will you
pull over only the usings that are
necessary for that particular class or
just copy the complete set?
>> We only take only the ones that are used.
>> Okay. For that class.
>> Yeah.
>> I have to admit whenever I'm doing
something and I temporarily
put another class in the same file,
I always feel like I'm like breaking some rules,
then I don't do that for too long?
>> Yeah. So, that was just like
a quick overview of refactorings that we've done.
Those two new ones 15,
8 to add a parameter to a method and
invert if statements and yeah.
We're adding more and more all the time,
and if you have a refactor you really want.
You can either find the Roslyn GitHub Repo
and have a feature suggestion there or in
Visual Studio you can go up to the little help "Send
Feedback" person up here
and click it and then provide a suggestion,
then go straight to the product team.
>> Right. Which is you and a few others.
>> Which is me and other people so.
>> Yes, a few other folks. So, on
the Roslyn GitHub Repo is there
a complete list of refactorings,
like documentation or in our docs stuff?
>> That is in our documentation.
>> Okay. Do you want to see this?
>> Yeah, let me take you to our documentation.
So, if you go to "aka.ms/vs2017 guide" as I've done here.
That's like the short link to
our productivity guide that we've
written and here it
teaches you how to do a bunch of different stuff,
and there's one of them that says,
"I need more refactorings and code fixes."
If you go there and shows
you the initial list of things that
people really like and then
links you to the rest of the documentation.
So, I can come here and now here's
the refactor code and oh yeah teach that too.
Oh, yeah, I did'n't show this one,
"Convert LINQ query to foreach statement.
>> That's pretty sweet.
>> Which is something you'll last for a while.
>> Yeah I have to admit,
I do use LINQ,
but I end up going to 101 over.
Yeah 101 LINQ samples.
>> Which was written by an intern.
>> Yeah. He's not an intern anymore.
>> No.
>> But, yeah,
having some help in that arena is super useful.
>> Yeah, and so we've gotten a lot
of feedback from developers'.
Especially people who are new to.NET,
LINQ is hard to understand and so they want a way
to take a LINQ like
expression and convert it to a foreach.
So, they can understand like what's
going on and then switch it back.
So, now I know one knows something that I didn't know.
>> Yeah.
>> Got to be sneaky.
>> Yeah, that's all good.
>> So, can you give us a sense
of if you're say still on VS 2013.
That's the last version, right? 2015.
>> Yeah.
>> It's these 15s that screw me up.
If you're on VS2015 and you haven't moved to VS2017 yet.
What's the scale of refractorings that you would get?
How man have we added from 15.0 onwards.
>> Sure. Yeah from Visual Studio 2017 15.0 to 15.8,
it's been like over 50.
>> Okay.
>> Yeah. Well it's over 50 code fixes and refactorings.
So, are the quick actions and refactoring.
So, things that show up in the Light Bulb menu or
the Screwdriver menu. Yeah.
>> Right. So, how we're going to do
the same thing in 2016?
We're going to add that many
more again to gather unknown?
>> That's the hope. I don't know if it will be
that many because we've
hit a huge chunk of the ones that
people are missing and there's the next year.
But, yeah, the more and more people send
us feedback for things that they're missing,
we'll know which ones we have.
>> I see.
>> So, we have a backlog,
but I don't think it's 50 deep, so.
>> Right.
So, we're starting to get a little bit into the tail,
that is what I hear you saying.
A little bit more into the sophisticated niche.
>> Yeah.
>> It makes sense. So, what has the feedback been like?
>> What do you mean?
>> Customer feedback.
>> On these use of refactorings?
>> Yeah.
>> People seem to like them. If you look at
the usage data, people are using them.
So, we're like here.
If you want to send us compliments we'll take them, so.
>> Flowers, chocolates.
>> No, we cannot be bribed.
>> Okay.
>> We can't be bribed, and yeah.
>> Okay. Awesome.
>> So, you select them and people
say what other ones they want.
So, we know what we have to do.
we have to finish the rest of the foreach to LINQ query,
so we do LINQ query to foreach right now.
We will soon have foreach to LINQ query.
But then people want LINQ method to foreach,
and foreach to LINQ method and then LINQ query
to LINQ method and vice versa as well.
>> I think that one will be the bomb.
I can imagine so many people wanting those,
there's a ton of value there.
>> Yeah. Then other big one we know we have to
do is adjust namespaces.
Which is like sync folder structure
with namespace structure.
So, which is like
a huge refactoring for someone to do manually.
So, it keep their namespace to match their folder.
>> That sounds big.
>> Yeah.
>> There will be a fun PR to bring to a repository.
>> It's very scary because it changes
a lot and so we have
to say we are the compiler teams
so we have to be perfect, so.
>> Yes, it's true.
It literally is true.
>> Yeah, so.
>> Okay, well thanks for coming by this was awesome.
>> Thanks for having me.
>> Yeah. I think people are going to love
to see these these few new features that are on 15.8.
>> Yeah.
>> And if they're still on 2013 or
2015 then totally upgrade.
>> Upgrade.
>> Because this would make people so much more efficient.
>> That's the idea.
>> Okay well it's been
another episode of The ON.NET Show,
Casey showed us refactorings in Visual Studio
2017 and it looks like there's a lot
there for you to go and try. Thanks for watching.