 On today's Visual Studio Toolbox, we're going to take a look at Codemade, a Visual Studio extension that cleans and simplifies your code. You are not going to want to miss this one. Hi, welcome to Visual Studio Toolbox. I'm your host Robert Green and joining me today on Skype from Indianapolis is Steve Cadwallader. Hey Steve, how are you? Doing great, how are you? Excellent. Steve is the author of Codemade, which is a Visual Studio extension that he's going to show us. It has more than a million downloads and it's very well-received and Steve, you're going to show us all about this extension and all the wonderful things it does. Yeah, I'd be excited to do that. Tell us a little bit about why you wrote it and when did you write it? Sure. Yeah, I started writing it in 2006 and first published it in 2007. I wrote it because I was very particular about the way the code is organized and cleaning up white space and little things and like most developers get tired of doing things automatically. I got into it from a friend, Derek Potter, who was starting to work on Visual Studio macros. I saw what he was doing there and I started with an add-on and eventually moved up to an extension. Cool. It's available in the marketplace. People can get it. We'll have a link forward in the show notes. All right. Show us what it can do. Great. To get started with Codemade, I recommend going to our website codemade.net. From there, you can see a high-level overview of the features. You can go down into detail documentation as well as a YouTube video demo walk-through. We also have a blog and you can see some information about getting started. This is an open-source project, so I love contributions. We've had over 25 contributors so far and it's been great. You can also of course go to the Visual Studio marketplace. Like Robert mentioned, download it, look at reviews and we do all of our work in GitHub as we can file issues or grab the source code. Excellent. If somebody wanted to know what it takes to write an extension like that, they can just go to GitHub and poke around in the code. Yeah. Absolutely. I've worked with a few other extension authors who've done this. That. Excellent. Great. I can start diving into some of the features. I'm going to hop over to a Visual Studio solution. The bread and butter codemade where it started out is code cleaning. The idea is taking code that's on the page and making it a bit more cleaned up automatically. This is really just saving you from having to do these things yourself. For example, if we look at this file, we can see we have unused using statements. We have the using statements out of order. We have classes and methods that don't have an access modifier on them, so you don't know if they're internal or private by default. We have regions that don't actually have any content in them. We've got extra whitespace at the front of the method, extra whitespace between lines, extra whitespace between arguments at the end of the lines, and so on and so forth. What I'd like to do is show you everything through a context menu that you can use in Visual Studio. Just right-click on the document. This code made where I have all of our different commands available. As an aside, everything has a keyboard shortcut, but I'll of course do everything through the menu so you can see what I'm doing. For example, just hit clean up active document, and you can see we'll go ahead and clean up everything for you. You can see the using statements are in order, the access modifiers been added, bunch of whitespaces been removed and standardized. We do this by leveraging some of the existing functionality that's inside Visual Studio. For example, removing and sorting using statements is now natively baked in. We started back in Visual Studio 2005. It was our first integration before that ever existed. Obviously, leveraging and gladly using anything, the Visual Studio starts to build in natively. So does that just mean less code that you have to maintain? Yes. Absolutely, which I'm all for. I won't mind if someday everything's as baked in natively. Likewise, for formatting document, a lot of the argument level whitespace in there is something that's already built into the Visual Studio's format document. But a lot of there's stuff around whitespace and things like that, my legal. So you can do that mainly one file at a time. A lot more powerful though is you can turn on automatic cleanup on safe. So every time you save your file, we'll automatically step in, we'll clean up the file for you before it gets written out to disk. That's a real nice way to just turn it on and forget it. That is off by default. That's what people don't get too surprised, but that's what you do when setting a recommend flipping once you get comfortable with the tool. You can also do cleanup across a whole bunch of files at once. So for example, you can clean up all of your open documents. You can clean up your entire solution, or you can also pick any level inside the solution, explore, right-click, and clean up the selected code. So for example, if you just want to clean up a specific project, like your project inside of a bigger solution, you can do it that way too. So all does the entire solution, and if you want to do one project at a time, you do it at the project level? Yeah. Yeah, or you can do it at folder levels or anything that's appropriate. Okay. Cool, so that's the heart of the cleaning feature. The next big feature is what we call the digging feature. So the idea is you have this file and you want to kind of get an overview of what you're looking at. So we've got a tool window called CodeMateSpade because it digs through your code. That'll show you kind of a visual overview of the file. So for example, we can see our constructors, our properties methods, so on and so forth. You can click on anything to navigate to it. For example, I click on this event and my editor window will jump to that file, sorry, jump to that event. You can double click on something to highlight all the codes. So if you want to put it on the clipboard, do something like that. You can middle click on regions and we'll synchronize back and forth between the two, whether they're open or collapse. So those are all kind of useful. One other thing I like to do is if you come into a file you're not real familiar with and perhaps things are kind of scattered across, first you just kind of want to look at them in a standard order. So you can actually, even though we sort by file order by default, you can switch the way you view so you can view all the types grouped together without affecting the file. So you can see all our methods have been grouped together and put in a logical order, or you can just do a straightforward alphabetical sort too if you just want to look at it that way if you know exactly what you're looking for. One other way that's handy to search is by just using the search window. So for example, I know I'm looking for something with word path in it. I can just type that in. It's just like solution explorers using the same API to be able to find a thing looking for and jump straight to it. So those are all useful. Something else that's really helpful is you can do drag and drop reorder of your code. So for example, I've got this is initialized private field at the bottom of the file. Style cop conventions are that's at the top of the file so you can click and drag to move that up to the top of your file and move those code numbers around for you. So that is cool. Yep, and one step further than that is you can do multi-select. So for example, if I want to take everything in this region I can either shift click or control click just like the windows explorer and drag those items around. So let's say I wanted those methods to both be at the top of the file for some reason. You can see that I can do that real quick through there as well. Nice. It does have a couple other items like finding references and rooting regions things like that that are hooked in as well. And then you can delete methods from there as well or members, excuse me. Yep. Yeah, we're getting rid of regions. That's popular one. People don't like regions a lot. So that's there as well. Does that get rid of everything in the region or just the region identifier? It gets rid of everything that's in the region at that time. Yep. Cool. So you can do that mainly through the digging window. Next step forwards from there is you may want to kind of set that up on auto run. Right? You don't want to mainly drag those items around. So we have another feature called reorganizing. So this will basically do that automatically for you. So for example, you can see we have this file where the fields are scattered across, the properties are scattered across, methods are scattered across. So we just want to kind of start the fresh slate. You can go in, right click, and come into reorganize active document. Refresh this. You can see that we moved all the fields to the top of the file. The file that by the constructors, the delegates, events, properties, so on and so forth. So that's a nice way to kind of clean up a file that you're going to start over with or that you've been looking into already. And do you have the ability to set custom order for the organizer? Yes, absolutely. Yep, so yeah, we'll get into options a little bit later and I can show that. But it defaults to the style cop guidelines. Right. Cool. And one other feature I didn't show in the other window with is the ability to do, we have these tool tips that show up. So for example, if you mouse over something, we'll show you any XML comments associated with it. We'll do a McCabe complexity calculation for you so you can see if something is kind of complex. As well as we'll give you like little modifiers as a static read write, things like that. Just a little cues for you to kind of work into the files. Yeah. And that shows what those icons were over to the right? Yeah, let me show that back up again. So yeah, these are just straight out of Visual Studio's icons, so the same things you'd see like in the outline window or in that class explorer. The ones over on the right, the 15, the one, the two. Yeah, sorry. So that 15 is a McCabe complexity score. Okay. It's my own rough calculation. It's not perfect, but close, pretty close. So for example, you can see this method has a whole bunch of work conditionals. So that's triggering a high McCabe complexity score within that method. And I kind of highlight those. You can configure what the thresholds are. I think I have a 10 is kind of like a warning level and 15 is an alert level. So you kind of see where's the meat of your file when you kind of look at something right away or if something's getting kind of unwieldy. Okay. Cool. Cool. So one other hello feature we have is comment formatting. So for example, let me turn off word wrap. You can see this comment just kind of goes on and on and on and it's really long. The parameters are just kind of in place. There's white space amongst them, things like that. You do have a comment formatting feature which kind of standardize that for you. You can specify what column you want it to wrap at, which tags you want to auto wrap, things like that. Nice little handy feature to use. And then below that, a lot of the features are kind of just more little small utilities. So for example, we have a join feature. So if we look at this property accessor and we want to join those lines together, and you can do that very simply. Obviously that's a very basic thing to do. You have the ability to sort code. That's, I'll show up natively sooner or later, but it's a basic alphabetical sort on the code. So you can see that when these attributes were out of order before, we can alphabetize those into a certain order if you'd like to. And then hop over to another solution for a couple other features. One other thing we have is when you're looking at a document, you can hop to that same document inside the solution explorer. This has been built in natively through the sync active document in later versions. We still have our shortcut, but we actually just turn around and invoke the native command for people who have that muscle memory. So you can see it'll hop directly to that file within the solution explorer. We also have the ability to collapse at different levels. So for example, we have a whole bunch of folders that are open. You just want to collapse them at a certain level. You can do that. You can also do it at the top level. Again, that's one that Visual Studio is now built in natively, so you can do that as well. And then one more I want to show off is when you have a large solution waiting for your build times, there isn't a lot of feedback, I think, in how far you are in your builds, what's being built right now, or is it build going well as a build aired? So I have a little tool window that I'll show you your build. So for example, if I go re-build my solution, you can see here the little build window comes up and it'll show me which product it's building as it goes. It's usually as much faster. So are you basing it on the amount of code or how long it takes to build things? How do you make that calculation? So yeah, it's coming from the Visual Studio. It does have APIs around build progress events. You can know an individual project's complete. So for example, the code made projects built, now our unit tests and integration tests can kick off and build on top of that. And so it'll show a green status or a red status, obviously as those builds are running through. We also do a little update inside the Windows task bar so you can see it down there as well. So it's based on the number of projects? Yes, yeah, I have three projects for code made, right? So there's a primary solution, integration tests and unit tests. So the integration tests and unit tests depend on the primary project before it can be built. So you can see that just that one project is building right now. And as soon as that other one fires finishes, the other two can start off concurrently. Right, so you don't have the ability to calculate it based on the amount of work the build has to do, right? No, it's really just project level. But we've had some larger solutions that have like 120 projects in them. It's really useful for those. Yeah. Cool. And so then one last area I want to show is kind of the options within code made. So when you install code made, there'll be a top level menu right up here. Shows all those different commands we had. Also, I didn't show removing all regions. That's another popular one if you just don't like any regions in your files or if you remove selected regions, things like that. If you go down in the options window, we really tried to focus on having the defaults be pretty good so you don't generally have to mess with these. Personally, of the opinion, it doesn't really matter what your coding style is. You just want your code base to be consistent. People can argue a lot about little details, but honestly, as long as it's the same, that's usually been my goal. So I try to make the settings as general for most people to keep them happy. But obviously, people have a lot of requests, a lot of very specific features that they want to have. So I think we have 170 options or so, trying to keep somewhat managed within here. And I also won't go through all those by any stretch of imagination, but I just want to go through a couple of these pains at a high level. So first one is we have the ability to have both user level settings, which would be on your machines stored in your user profile, as well as solution specific settings. A good example of this is if you have specific files, you want to exclude from operations. So for example, I don't want any of my integration test data, even though it looks like C-sharp code, I don't want it to be cleaned because of course that's what the test is supposed to be doing for me. So you can specify files that you want to exclude based on regular expressions. But that's something that's a good example of a solution specific setting versus a user level setting. And you can store that. It's just a code made.config file you store right alongside your solution file. So we support a whole bunch of languages. As you can see up here, I won't list them all. C-sharp and VB definitely get the best support because those have the most integration with Visual Studio's APIs. C++ would be behind that. We allow you to turn on operations even for text files, but it's pretty basic just in the line white space, duplicate white lines, things like that. Okay. Another high level feature that has recently been added from one of our community contributors is the ability to turn on or off any one of our features. So if you want to get rid of some feature, you don't want to see it in any of the context menus. You don't want to hook into the event handlers. You can just turn those off all together and it will disappear from the menus. Pretty straightforward, just unregisters it. Most operations in CodeMate are idle until invoked. So it's usually not too harmful to leave everything on, but if you just want to clean up the context menus, you're welcome to do that. What was the general impetus for that? That this person only wanted to see the things that they were going to use regularly? Yeah, so they thought this menu was too long. They wanted it to be smaller. All right. And same could go for this one where it does show everything, so. Sure. Yeah, it's a nice feature to have. If anyone wants to turn things off. So we talked before about the reorganizing types. So yes, you can customize those. So if you come down to reorganizing types, you'll see the default order. So fields, constructors, so on and so forth. Kind of a hint down at the bottom that you can do a lot of customization here. So for example, if we want to merge our properties and indexes together, you can just drag and drop those onto each other. We can rename those to something else if we wanted, so on and so forth. So you can customize that however you want. That will affect both what you see in the digging tool window as well as what the reorganizing functionality invokes and cleans up the file with. And you could have that at the solution level or the user level, right? So if there's a particular project you're working on where you're using a different, a non-default or non-standard order, you could do that. Yes, absolutely. Okay. And then you can always reset to default. Very important button right there, right? Oh yes, I like that one. It's super useful for debugging. And then I guess one last thing I wanted to show off in here is just we have a little bit of integration with third-party tools. So JetBrains, Resharper, Teller, Enzamel, Styler. These are all deactivated because I'm not using any of them anymore, but you can turn those on and we'll basically chain our cleanup alongside theirs, just like we're chaining alongside Visual Studio's cleanup. And you can even customize that further if you have other commands. Right. Awesome. So have you, I assume you've found over the years that more and more of the features actually get baked into Visual Studio. Yeah. Which then gives you the ability to write less code and just hook into what Visual Studio's doing. Yeah, that's been really useful. I think some of the big ones were, of course, removing and sorting and using statements was useful as well as collapsing the solution explorer. Cool. So how difficult was it to write this extension? What advice would you have for people who are thinking of doing something similar or potentially are thinking of looking at your code and either leveraging it or helping to contribute? How hard is it to figure out the model for Visual Studio and then also how hard is it to write an extension like this? Yeah, that's a great question and it's very different today than a decade ago when I wrote it. So back when I wrote it, Visual Studio 2005, it was mostly add-ons at that point. I was leaning a lot on Carlos Quintero had a blog with Visual Basic examples and that was about the main source of data I had. Back then, everybody's on SourceForge, things like that. So there wasn't a ton of available code to refer to. And nowadays, there's been a lot of push from that team to really improve the documentation. So there's stuff out there directly on MSDN and there's a ton of example repos on GitHub. Matt Christensen has a ton of extensions. He's definitely a great resource and I've leaned on him as well as he's got some examples of automation event through App Boiler so you can have an alpha channel, basically a CI channel, really easy for your extension. So I definitely recommend checking out other extensions is a good starting point. Okay, cool. So code made, awesome tool. Highly recommend people take a look at it, download it, join the ranks of the million plus people who have downloaded it and they're currently using it. That's tremendous. Thank you. Thanks a lot for coming on the show. Thank you very much for having me. All right, hope you enjoyed that. Go take a look at the tool and we will see you next time on Visual Studio Toolbox.