hey everyone welcome to Microsoft Connect my name is Nina Zakharchenko I'm a senior cloud developer advocate at Microsoft focusing on Python and today I'm going to show you how to build productive Python web applications with Visual Studio code Azure and as your DevOps let's get started I've set up a repository that has all the code and the steps that you need to follow along just grab it from the URL get do slash connect appear I'm I've already set up my local development environment I've cloned this repository I've also set up a virtual environment by running Python 3 - M the end and then activating that virtual environment by running source and have been activate if I do a pip freeze we'll see that I've already installed all the packages from requirements txt in this environment let's take a look at this project in Visual Studio code code has an amazing and easy shortcut that lets us open up a whole workspace at once all we need to do is type code dot in the directory we'll see I have all my files here if I look here at the bottom I'll notice something interesting yes code has automatically picked up my Python virtual environment I didn't have to do anything to get this app running locally you're gonna have to set up a few secrets the guidelines for that live in the em-dash sample file here you'll see everything that you need to setup in order to get this pop working in production I've already set up a Postgres database I've run my migrations on it I've loaded in a little bit of fixture data let's make sure that our app runs locally to do that hit ctrl and backtick to open up the python terminal we'll see that V s code automatically activates the virtual environment for us we don't have to do anything to check out our app locally we'll need to run Python manage py run server to bring up the django web server and that's kicking off now let's take a look Oh we'll see we have a local Twitter application have our tweets we can even say a new tweet if we'd like hello connect everything is working as expected now if we run into issues how do we debug our jingo app going back to vs code let's kill our development server for now let's take a look and see what our request looks like by setting a breakpoint tap to the left of the line number two create a red breakpoint dot in the gutter next open the debug panel we'll see that we have no configurations here all we need to do is click add configuration and yes code knows that we have a Python project open it creates a new Python configuration for us super easy if we want to debug our Django what we need to do now is select the Python Django debug configuration and then hit this green button right here as our debugger starts we'll see that the bottom bar has turned orange instead of blue now if we hit our URL again we'll see that the debugger has stopped at the breakpoint we have a few options here we can continue we can step over we can step into or step out but I want to show you one of my favorite features and that's the debug console if we click here to the left of the terminal we'll see this little window pop open and I have a fully featured debug environment here I have autocomplete if I wanted to take a look at the request I can just type that in there I can also interactively work with this object I can click on the arrow here I can take a look at the body any of the content parameters examine anything that I want to about the request I can also take a look at our user Bob and check out any attributes about him I'm going to continue here that's great but what about debugging Django templates our templates can get really complex and hard to navigate thankfully the s code provides that too let's open up our index.html we'll see some template code here all I have to do is click to the left of that and that our debugger breakpoint triggered here I can look at the user in the debug console like I did before I can also setup watched variables here so every time a breakpoint stops these watched variables will populate I don't have to do anything I always want to see what user is coming up on my index view I can set up the user ID or the user in the watch here super-easy it makes debugging Python web applications a complete breeze now we've got everything working locally what if we want to deploy our application to the cloud well thankfully yes code has an answer for that too check out the extensions tab here on the left hand side in order to kick this off you'll need to install a handful of them the Python extension of course along with as your account to sign into your azor account and as your app service to do the deployment once you have these extensions installed you'll see on the left-hand side here a new icon that as your icon if you click into that you'll see your app service subscription all I need to do to set up a new deploy is hit this plus button right here I need to enter a globally unique name and I'm going to select an operating system Linux along with the Python 3 7 runtime see in the corner here that the web app is being created if an resource group isn't found it'll create one along with an app service plan let's just give this a few minutes to run here I have a pre-existing deployment what did I need to do to get this going I needed to configure our application settings so our production environment needs to know how to connect to this database you you can set these application settings straight from vs code here I click here you'll see all the ones that I've set you can even right click on an individual setting and hit edit rename delete it or you can do it from the portal to easily access the portal component of this application all we need to do is right click and hit open in portal and that will pop open the portal for us and open up the specific app service if I'm once my deployment is completed to set up that deployment I would want to right-click and configure the deployment source I would want the deployment source to be local get all I would need to do is right click again and hit deploy to web app that's it just a few clicks and you have an application running let's take a look at my existing app okay right click and hit browse website and it will go straight to that URL for me here we'll see our tweet our application running in the cloud on as your website's net this is great for smaller applications smaller uses maybe you're doing a little bit of work in development or QA what if we wanted to set up a CI NCD pipeline for our application we can do that with Azure DevOps pipelines to set those up go to dev azure calm here I have an existing as your DevOps project with a few pipelines set up I have two individual pipelines one for my continuous integration one for my continuous deployment let's take a look at the continuous integration one if I edit it here we'll see that there's a yamo file path as your - CI - pipeline Dhamma that exists in or git repository we can take a quick look at that here so the siamo file describes everything that we need to do we're going to be using in a bun - image we're going to be using Python 37 we're going to install all of our requirements and then we're going to run our tests and make sure that those paths before continuing onwards with a deploy going back to our pipelines let's take a look at the continuous deployment pipeline this is also configured with another llamo file this one is also in the repository right here the deploy pipeline we're using Ubuntu again Python setting up our Python version and then setting up a few environment variables our deployment URL our deployment username and a deployment password we set those up in the portal going back to our project here opening it in the portal going to our deployment center and grabbing those environment variables from here we're going to grab does get clone URL and then we're also going to make a set of user deployment credentials setting a username and password that were then going to configure in our pipeline another important thing about this pipeline is the triggers here we'll see that we're disabling continuous integration for our deployment pipeline but we're depending on the build completion step of our CI task having set this up once I deploy to master my CI build kicks off if it goes successfully I get a deployment super quick easy and really understandable that's all I have to show you today if you want to learn more about Python as your check out this URL you can also take a look at the Django on visual studio code tutorial or take a look at the demo repo all the steps that you need are right there all laid out and I hope you all have an excellent connect it was great talking TTA bye
Wednesday, 23 October 2024
Bringing Big Data Analytics through Apache Spark to .NET
hello everyone welcome to bringing big data analytics through pachi spark to dotnet I'm Bridgette Murtagh and I'm a program manager here at Microsoft on the dotnet team so let's start off with what is apache spark so big data means that there's an increase in volume velocity and variety of data so let's take for instance a factory there can be thousands of internet-of-things sensors in a factory each producing petabytes of data now while it's great to have that much data so you can understand how our factory is performing and ways to improve the equipment how can we actually process it all when we have that much and more than just that how can we process it all quickly and efficiently well welcome to the world of Apache spark so what is Apache spark Apache spark is a general-purpose distributed processing engine for analytics over large data sets typically terabytes or petabytes of data put a little bit more simply Apache spark is your great tool we can use to analyze a large amount of data and a quick and easy to understand way so we don't have to be data science experts to understand or use it there's quite a few different things that we can do with the Apache spark that are all super interesting and exciting but just to touch on a few of them one of them is spark sequel which means analyzing data that's structured in some way so maybe data from a CSV or from a database there's also spark streaming which means analyzing data in real time as it's being produced so in our factory example it means analyzing data live as it's coming from those IOT sensors so we can go and detect maybe if there's a malfunction on our data and we can go and address it right away there's also machine learning capabilities with Apache spark so you can combine the powers of big data and ml to scale and have faster more efficient training and prediction of machine learning algorithms so to understand how Apache spark works there's only three main components that we really need to take a look at the first one is the driver the driver consists of the user's program so for instance if you wrote a c-sharp console up that would be part of the driver the driver also consists of a spark now what the spark session does is it takes that users program so for instance it takes that c-sharp console up and it divides it into smaller pieces known as tasks now those tasks are divided amongst our second component which are the executors or the worker nodes and the executors are the workers are on something known as a cluster so each of those executors takes one small task so one small piece of our users program and finishes executing it and the third component of our architecture is the cluster manager which helps with dividing up the tasks and allocating resources amongst our driver and our executors so how can I use the pachi spark it sounds super great super useful so how can I get started with it so it's quite a different there's different api's that we can use that are popular with spark and they're written in languages like Scala Python Java and AR but up until this point there weren't any dotnet api's for spark sort of I wanted to use Apache spark combined with my pre-existing dotnet knowledge or extensive code base and business logic well we now have an awesome tool that we can all use and it's known as dotnet for Apache spark so dotnet for Apache spark is a free open source and cross-platform big data analytics framework it allows us to reuse the knowledge skills and code we already have as dotnet developers so anywhere that you maybe have an extensive C sharp F sharp codebase now you can go ahead and introduce big data analytics within it dotnet for Apache spark is also designed for high-performance the overall goal for dotnet fair patchy spark is to provide dotnet developers a first-class experience when working with Apache spark so we have had several customers expressed a lot of interest and actually see success those net faire Apache spark and one of them is the Microsoft search assistance and intelligence team who's working towards modernizing workspaces in office 365 their job is to work with different ml models on top of substrate data to infuse intelligence into office 365 products their data resides in a deal and interns gets fed into their models why they were looking towards dotnet spark was because a lot of their business logics such as the different features or tokenizer z' were all written in c-sharp meaning it would be ideal to be able to use big data analytics still within the dotnet ecosystem and so far their experience has been extremely promising stable and they've really loved the vibrant open source big data analytics ecosystem within the dotnet community the scale of their jobs has been about 50 terabytes so quite a bit of data and they really started seeing success with it so now that we've seen a little bit about what dotnet for Apache spark is and why it's such an exciting new solution for us let's take a look at a few different scenarios that we can complete in some really exciting applications we can build using dotnet for Apache spark so one of the most fundamental Big Data apps is batch processing so what is batch processing or what is batch data batch data means that we're working with data that's already been stored so for instance we could be doing something called log processing which means looking at and gaining insights from logs from maybe a website or a server or a network of some sort so we can understand what actions our users are taking or what pages of our website are the most popular we can also do data warehousing which means taking in data maybe from a variety of different sources and then performing a large-scale analysis on it maybe that data is all stored in Azure storage and then gaining different meaningful insights from it so in the example that we're going to be looking at today we're going to take a look at some github projects data so you can see here in the snippet of that data that our projects data includes the URL of our projects the author a description what language it is things like that and we want to know on average how many Forks does each language have and the number of times each project has been fork is represented by that column each there so let's go ahead and take a look at our first coding example with dotnet fair Apache spark so I'm going to open up visual studio 2018 here and we can see here that I'm just dealing with a c-sharp console application that I've already created and I've already installed the Microsoft spark nougat package oh there it is cool and we can see that it's also installed because I have these great jar files over here in the solution Explorer and at the top I'm using Microsoft spark sequel and Microsoft's piped sequel functions because as I had mentioned spark sequel helps us work with structure data so if I'm reading in github products data that data does have some sort of pattern or structure to it so I want to use spec sequel so to start off with in my main method here the way that we start off any dotnet fair pachi spark app is by creating a spark session that's what's dividing our program into the smaller tasks to be distributed amongst the executors so we can see I've created a spark session called spark I went ahead and built the session and I just called my app github and spark batch pretty appropriate name now after doing that the next step we typically want to do in our apps is to actually read in our data so I have our data is stored in a CSV and we want to read that CSV into an object called a data frame so a data frame is going to be the basic object that we store our data in when we're working with structured data in spark so if I open up this region here we can see that I'm working with a data frame here and I just called it projects DF to stand for my projects data frame I go ahead and called the read method and then I also called schema which means that I'm working with whatever pattern my data has so for instance I know that my data has an ID column a URL an owner ID I also know the type of data that's stored in there whether it's an inter string or something like that and it's a rather long schema because I do have quite a few columns and then I can call dot CSV since I know that my data is stored in a Commons comma separated values file and then another popular method that's good to use is dot Show which allows us to actually print that data frame to the screen so I continue on another popular step that we'll want to do when working with batch data is to do some data prep or data preparation and that means that we're kind of cleaning up our data so maybe if there's some Knoll or missing values or if there's some extra values maybe like a few extra columns we don't need we can go ahead and remove those so that our data is easier to read and easier to work with so one of my first steps of data prep was working with the data frame na functions and with that I chose to drop any values that are null so any role any rows that have missing or null values I chose to removes that when I go and perform calculations later I'm not accidentally trying to perform calculations on a missing value also with my data prep I chose to drop a couple of columns that I don't think will be important for my final calculations so I dropped the idea the URL and the owner ID columns so after doing some data prep we can actually go ahead and perform the functionality that we wanted to which was finding on average which languages have been forked from the most often so the first thing I wanted to do was group my projects by language so what I've done here is I've created a new data frame that'll represent now my group two data and I called the group by method which allows me to choose which column of my data I want to organize by or to group by so I chose the language column and then whenever I do a group by I also need to call aggregate or this dot AGG method and with aggregate it allows me to perform some sort of functionality across every row or every entry of my data so in my case I performed the average of the forked from column on each row of data so essentially I'm grouping by language and then finding on average how many times each language has been forked and then finally I don't want to just display my data as is I want to do one final step to make it a little easier to understand and read so I've chosen here to order my data frame in descending order so that way I have the top forked languages at the top of my data frames so I can see those first and then a final good step to do is to go ahead and stop our SPARC contexts so I went and went ahead and called sparked off stop just to clean up resources and make sure everything finishes executing correctly okay so now I have a few steps here that I'll need to be able to build and run my program so one of the steps and working with the.net for patchy spark app is to make sure that we have one of our environment variables set correctly so there is a dotnet assembly search paths variable and we'd want to make sure to set it to specifically my apt so in this case batch and then the bin debug folder and then whatever version of net core app that you're using and then also one other thing you can check is the level of logging that you have in your output so I go ahead and open this up so there's a file called log4j dot properties and here I've set the logging level or whatever is going to be output to my console to be the error level so rather than displaying maybe some extraneous warnings or info or debug messages I'm only going to display messages that are actually an error which will help make sure that my output isn't too confusing or crowded in my console okay so now it can actually be time to go ahead and build and run our program so fortunately I've already done that with for us here to save some time so I'm going to open up the terminal not that one that one will be later okay so here I moved into my batch directory using CD batch and then I just went ahead and built my project using dotnet build we can see that build succeeded so now let's go ahead and see how we actually run a dotnet for patchy spark app we use something called spark submit or the spark submit command and it every time we use spark submit there's a few different components to it so we you say spark - submit and then we're also going to reference the dotnet runner we're going to specifically reference one of those jar files in our case for using apache spark version 2.4 and dotnet for apache spark version zero point 4.0 and then also we want to have a path to our apps dll so it can actually build and run correctly so after running sparks submit let's see how our program did so first we're expecting just to see the data frame with our csv data in it so just the raw github prod so let's take a look alright so we can see it here we see that it has all the columns we expected but we can also see that the data is kind of overlapping with itself there's a few too many columns like updated at is all the way over here instead of continuing to the right and then there's also a lot of null and missing values so it seems like it was definitely a good idea to go ahead and do that data prep we did if I scroll down now we can go ahead and look at our data prep result and so now this data frame is a lot easier to read and understand we can see the data doesn't overlap with itself and all the data actually exists there's no longer all of those null values so it's a lot easier to work with so next we can go ahead and see the output of when we were trying to calculate the average number of times each language has been forked so let's take a look and so we can see we have a column here for language and a column here for the average number of times it's been forked and it all looks correct and we can see that it did sort in descending order because language is at the top havin forked on average more often than the languages down here and then it's also worth noting that for all of those data frames it's only showing the top 20 rows and so this is really useful because in case we're working with terabytes and petabytes of data we want we don't want to be stuck trying to show those data frames and then having it take forever or getting confused and too crowded on the console okay so we have successful yet run our first dotnet for a patchy SPARC app so let's go ahead and go back to our presentation already so we have already done that demo so let's move on to our next scenario which is combining machine learning with Big Data so when we combine machine learning with Big Data it means that we want to scale the training and prediction of machine learning algorithms one great framework we can use for the machine learning when we're combining ml with Big Data is ml net which is a free cross-platform open-source machine learning framework in our example that we'll be looking at we're going to be performing sentiment and Alice which means that if we're given a piece of text we want to determine if it represents something positive or something negative so in our case we're going to analyze a set of online reviews and we want to know which are positive and which are negative if we were given reviews such as I love dotnet for Apache spark that would be considered positive and we could maybe see either a true or a one depending if we're using a boolean to represent positive or negative sentiment if we saw a statement like I hate running inefficient big data queries that would be considered a negative sentiment so let's go ahead and take a look at our sentiment analysis demo where we combine Mission ml donut and dotnet for Apache spark okay so I've opened up Visual Studio 2019 once again and in this case when I look at the nougat packages I've installed I haven't only installed Microsoft spark I've also installed Microsoft ml which is the nougat package we need to use ml dotnet and then we can see at the top here I'm using statements both related to ml net and net fare pachi spark so you can see Microsoft ml ml data we can also see Microsoft spark sequel if I scroll down here we can see that just like we had done in the batch example we start off by creating a spark session for our program and I've just gone ahead and given my app a different name compared to the batch app next it's also going to be similar to our batch example since we are still technically working with batch data we're just taking it a step further by also performing machine learning so in our case we want to read a review data into a data frame so I have some Yelp reviews so I have it in a Yelp csv file and i've also set a few options for my data frame here so for instance I know my data has a header and so the two different columns in my data which include the text and if it's a positive or negative review those columns are labeled that's a header and I don't want spark to treat that header is part of the data because I could throw off my results and then I just went ahead called show so I could see my raw review data as is before we go ahead and actually predict using ML dotnet so now it's time for the fun part where we can actually start combining machine learning with big data so how would we actually start calling the ML dotnet code so how we can do that is using something called a UDF or a user-defined function and so UDF's are a popular solution so that we can perform some sort of function on let's say each row in our data frame so if I open this up here we can see that we create a new UDF by calling the UDF method and then register and within the angled brackets I have string to represent the input that I'm working with which is text or reviews and then boolean to represent what my output is going to be which is a true or false for negative or positive sentiment I've decided to call my UDF ml UDF and what I'm doing within this function is passing the text into a method called sentiment so we may be asking so what is the sentiment method where do we where do we create it what do we do within it so within sentiment if I scroll down here we can see that sentiment actually contains our machine learning codes the code that was generated from ml dotnet and I got this code and I actually also trained my sentiment analysis ml net model by using something called model builder the model builder is a really useful UI tool that we can use within Visual Studio that helps us train and work with machine learning and a much easier and understand way so just to see what model builder looks like if I right click on my project and say add machine learning I can see that within here I can choose a scenario so I can choose things like issue classification sentiment analysis price prediction so my case I would have chosen sentiment analysis and then I can just go ahead and choose my input file so I could choose my input review dataset to do some training on and then m/l net does all of the training for me and generate some really awesome code for me so if I go back here this was actually code generated from that melt from model builder using ml and what it's doing is essentially creating a way to start predicting so it calls the ml model that was trained and created and then it creates a prediction based on whatever strings I pass to it and then down here I've created classes to represent my review data since I do need to pass that or work with that when I'm using ml dotnet okay so now that I've gone ahead and created a function where I can call that ml dotnet code I want to actually call that function so what I've done here is there's this really neat functionality in dotnet fair Apache spark where we can actually execute sequel queries so if you're familiar with sequel syntax at all we can have those sequel queries within our code so in my case I've gone ahead and selected column 1 which represents my input review text and then past column 1 so past each review to my ml net method and what I can do here is then just go ahead and print that out essentially and then I called Show so that I can see the output of my operations and then similarly just like we had done using the batch app you'll want to make sure you set your environment variable correctly so that bin-debug net core app folder and then we can go ahead and go into our apps directory and build and run it so let's take a look at how that came out ok so you can see here I had built my project and built succeeded and then I ran sparks submit using pretty much the same types of parameters just in this case it had to be to my current apps to yellow if I scroll down what we see here for the first data frame is that was just the raw review data so this is these are all the reviews that were in my Yelp dataset and this is the true answer if it's a negative or a positive sentiment so we can see when someone loved something that represented with a 1 that means it was a positive sentiment and if someone said something was not good that was a zero so negative sentiment so now the next data frame that we're going to see is going to represent the prediction from our ml net code so let's scroll down and see you and we can see here we're dealing with the same reviews but now this is the predicted sentiment so you can see here that it looks like it was pretty accurate we can see when someone loved something if his predicted true so positive and then again when something was not good it was false so negative sentiment so you can see here that we were successfully able to combine dotnet fair pachi spark and ml dotnet let's go back here it's now that we've done that demo we have one final quick scenario to go through and this is with structured streaming or real time data analysis so in structured streaming or real time analysis we're working with live data so data that's maybe coming in from a sensor so like an IOT factory sensor or a phone or a network and structured streaming uses the principle of micro batch processing so essentially it takes our continuous stream of data and divides it into smaller little chunks so maybe every five seconds represents a new batch and then it can perform functionality on each of those smaller batches and then appended the result essentially to a table that already exists so then if let's say another five seconds passes well have another batch perform functionality on it and append it another batch should perform some functionality on it append it and so on and so forth as our stream still exists so in the quick demo that I'll show you here we can actually do live or real-time sentiment analysis so still using don''t for pachi spoke with ml dotnet now we can see that if I type a string into a console let's say we can determine in real time if it represents a positive or a negative sentiment so let's go ahead and take a quick look at that demo okay so I still have the Microsoft ml at Microsoft spark new get packages installed I start off creating a spark session but instead of reading into a data frame from a CSV or stored data now I'm doing something where I'm reading a stream and I have to set up the host and port information my stream is coming from and then I still use ml net with a UDF and I can still call the ml dotnet code in a very similar way and then finally as on like working with the data and displaying it I used something called a streaming query and I can go ahead and call write stream and determine that I want to write my stream to the console and instead of saying spark stop we can do query dot await termination so I go over here I can see here that I've set up a quick netcat terminal so just an easy way to read to or write from a network connection and for instance I could write something like I love spark and then in my other tab over here I've already built and run my dotnet for Apache spark app if I scroll down you can see that I've been working with my different batches here so every time I hit enter is considered a new batch and it determines in real time if my line was a positive or negative sentiment so you can see when I said I love spark it was considered true a positive sentiment so that's awesome we have real-time streaming working ok so a couple quick steps for how you can get started with dotnet for a Pachi spark we have if you go to the dotnet website so do T net slash spark you can go ahead and read even more about dotnet fair patchy spark you can go through a really neat getting started tutorial we have for you can get up and running with dotnet spark on your local machine in 10 minutes or less and you can also visit our Docs and see some other learning resources we have you can also visit our github so github.com slash dotnet slash spark so you can go ahead and view some of the documentation you can see how things are implemented you can participate in the open source community it with spark so thank you so much and now I guess we'll turn to questions fantastic so that was an amazing presentation Brigid now help me out because I am a little dense spark isn't like a database is it is it where the data is stored or is it a medium for transferring data over help me outs to set the context from these questions sure yeah so spark isn't a database so it's not where the data is stored so you'll already have your data stored in something like somewhere in Azure so maybe and Azure data leak storage or in a blob or something like that so spark is actually kind of like the framework or the tools that we can use to start analyzing that data so it allows us to read it in and to process it more quickly and to make different calls to it so that we can gain meaningful insights rather amazing so it's like that it's like the pipe then that takes data from any scenario and then moves it over is that right yeah that's a good way to think of it that's good so you mentioned a lot of stuff with with.net we didn't have dotnet isms for spark when did this start and if you were to point because you pointed out a tons of cool things but if you were to tell people one thing look at this first and see why it's powerful what would you suggest to them okay so we started this project we first started a towards the beginning of this year so I would say about in April even though we did have a predecessor to this project a few years ago but yeah I would say as of this year's when we actually started having like these awesome dotnet bindings to Apache spark and for something really awesome I would say if you check out that landing page though d-o-t net slash spark you can see really that you can really start processing terabytes and petabytes of data at a manageable scale so you don't have to spend like days and weeks and months and years processing all this data you can actually start gaining insights from it in like a matter of hours that's pretty cool does dotnet for Apache spark support support using f-sharp instead of c-sharp yes I believe it does so dotnet ecosystem in general fantastic well this is amazing and thank you so much Bridgette now here's a couple of things though before we go I want to remind everybody about I'm not finding it but the the actual tech challenges that are available let me get my might handing notes out here because they're they're pretty good and if you have more questions for Bridgette make sure you get them in make sure you participate in the technical treasure hunt it's happening all day tons of technical problems that you can solve maybe even do a little bit of code if you solve all of them you will get a ton of wonderful prizes it's pretty cool to go to dotnet comp front slash party that's what we're gonna if you go to Dinah comp front slash party sorry they're talking in my ear you'll be able to see all the cool things and there's a ton of things happening today make sure you go to the Apache spark coolness for net which i think is pretty cool we're gonna go to a commercial break here in a second but and after that we're gonna have more servers less with a Jeff Holland is going to talk about durable functions 2.0 server less actors orchestrations and a stateful functions
Bring VS Code Themes to Visual Studio
hi everyone today we're going to be talking about how you can convert a vs code theme to work in visual studio we've been on a journey to make visual studio as flexible as possible so that you can code the way you want and now if you're a theme author you can convert your theme to work in visual studio so that a wider audience can get access to your theme let's get started here are the things you'll need in order to convert your theme i'll note that you'll want visual studio 2022 preview 4 or later because it has fallback colors which you'll want just in case the json doesn't cover that area of the ui let's navigate to visual studio to configure our install i have the.net desktop development workload i also have the visual studio extension development workload in components i have net 5 runtime now i'm ready to go i'm going to be converting the winter is coming theme today i've gone ahead and applied it to my visual studio code instance on my keyboard i'm going to press ctrl shift p to bring up the command palette i'm going to select generate color scheme from current settings this is going to give me all the tokens inside this theme that describe the colors i'm going to save this in a folder that i previously created it's going to be a json file not a json c file next i'm going to navigate to our converter tool this is a free open source converter tool and if there's anything you'd like to see improved you're welcome to create a pr or create an issue i'm going to go ahead and clone this tool i'll navigate over to my command line opened in admin mode i'm going to clone using the git clone command after i clone this tool i'm going to navigate over to the folder that i've just created then i'm going to build the tool using.net build next i'm going to navigate into this folder i can run the tool using this command with the flag dash h this is going to give me instructions on how to use the tool i'm going to go ahead and convert my theme the flag dash i is the folder that i've created which contains my json file i can convert several themes at once by including several json files inside this folder the flag dash t is the target visual studio which will open and patch my theme so that i can take a look at it i also have the option of just creating the package def file without opening visual studio after it's loaded i'm going to navigate to tools theme and select my theme it's going to get applied there you are winter is coming next i can package my theme up inside a v6 in order to upload to the marketplace or share with friends i can navigate to file new project or ctrl shift n next i'm going to search for v6 and create an empty v6 project i'm going to name my project and then select create then i'll navigate to properties right click add existing item i'm going to select the package def file that i've just created this is going to be in the same output folder as my json file i'm going to select all files in order to see my package def file once i've selected that it's going to show up in the tree i'm going to select the package chef file and expand the project properties window for copy to output directory i will select copy always and for include in v6 i will select true then i'm going to navigate to the v6 manifest i'll navigate to assets and new then for type i'm going to select microsoft visual dot for source i'll select file on file system and then for path again i'm going to select the package stuff file that i've created and i'll select ok finally i can adjust the metadata inside my theme like my theme name author and version now the last step is to build it i'm going to go ahead and build the extension you can see it's working after i've built the theme i'll see a v6 file inside my output folder i can now upload this theme to the marketplace where there are a lot of other great themes already available and there you are winter is coming on the marketplace if you try the converted tool or if you try any converted themes we'd love to know what you think this process is always iterative always changing and we're always looking to improve thanks everyone
Bridging C++ and Rust
hey everyone welcome to my lightning talk bridging C plus plus and rust my name is Yash um I work as a rest developer Advocate at Microsoft um and today I'll be walking you through three different ways of Bridging the rust and C plus plus languages um just as a heads up I am very much a Sleepless novice I have been programming C plus plus for about a week now um so forgive me if anything's unergonomic unclear not the best uh I haven't been doing this for very long my expertise is more uh rust which I have been doing for half a decade now longer um I'm also involved in the development of rust so that that's where my strengths lie um C plus plus not so much but still it's important to make the two work together so let's dive in all right so in this talk we'll briefly cover what rust is why it is then cover some of the syntax and semantics and then talk about bridging C plus plus and rust I will be assuming you're familiar here with C plus plus but maybe less so with rust so Russ is at this point nearly 20 years old um but it's only been stable for since 2018 which makes it about eight years now so it's it's a pretty recent language about 10 years or 20 years younger than C plus plus and 30 or so years younger than c um it was incubated at Mozilla research in order to help make the Firefox browser parallel because they were trying to do that and it turned out to be very difficult um and they decided a programming language might be a good solution for that so rust in a nutshell is a programming language with a very high level type system similar to Haskell or ocamel it's a henley Milner type system which means that pipe safety is is a big thing but unlike ocam on Haskell it uses a c like interface so C like syntax which you know if you've written Java JavaScript C C plus plus Etc it should be a lot more familiar to you it's sort of Hallmark feature is it provides memory safety without runtime overhead so it checks uh memory like moves and borrows and landings and all these things completely at compile time and it compiles it away and it leaves you with code that is as fast SC or C plus plus um it also has native C interop so you can piecemeal replace components that have been written in C today that may be difficult for numerous reasons say memory sensitive or a safety safety critical sensitive to bugs perhaps very old you know all these things uh rust can help you with and you can replace it you can interop it that's one of its strengths so it doesn't try and reinvent the entire world instead it fits into the existing ecosystems and and systems that people build it also has a very modern like async IO facilities it has async await notation um this is the the thing that I help work with so it makes parallelism easy it makes concurrent systems easy to write and it prevents data races uh which which is great when you're dealing with multi-threading um so who's using rust many places including us here at Microsoft but also it's being used all throughout AWS cloudflare uh evening kernels uh since this week it is in the windows 11 Insider build uh inside of the kernel but it's also being introduced inside of Linux I believe Android has components such as their Bluetooth stack which they have uh Rewritten and rest um for its its performance and safety safety aspects so that's it for what rust is now let's take a look at rust itself um here's a little cheat sheet for syntax we use the FN keyword for functions we use a little little arrow to return types A Name colon type notation for for names and types uh kind of like um I believe typescript does it this way and then you can declare um methods on struct using impul blocks um that's that's the syntax um the semantics are maybe a bit more interesting here where by default all rust values are by move which is move semantics and C plus although we don't support move Constructors but that's a whole thing um and we we have uh two types of references as well which is uh unique and shared references um unique reference can be mutated a shared reference can only be read and you can only either have a single unique reference or multiple shared references but but never both at the same time and this is compile time and force and this is what allows rust to be Memory safe um with without runtime overhead so here here's the way you define a struct and rust which is a struct with a name and then members inside of it so key like name type pairs um here's how you define functions in rusts in this case uh it returns a zero size unit type rust is also entirely expression based so you know it evaluates the unit expression here um and this this just prints me out to standard out and then here's how you implement methods first we have a getter for the the type name which takes self by reference it's a shared reference and returns a string slice and then we have a Setter which takes a new string and that mute itself so you can see that the cell parameter we're just like C plus plus is this but inside of the argument list it says hey we need a mutable reference to self because we're going to update value here okay so to dive into binding C plus plus and rust entirely by hand the the first one is we're gonna uh take rust and C plus plus make them both talk uh c a b i to each other and then link them together and that just works that is maximally flexible but it is kind of inconvenient because both rust and C plus plus we like are smart pointers we like our abstractions and if you're going to see ABI um you don't get access to all of that so you you need to oftentimes wrap it in code which is a bit difficult but you know it works and that is pretty great so let's take a look at that here we have our cats HPP file which is a struct cat it has a name and it has a bowl whether it's hungry or not then we can construct our cat we can get the cat name we can feed our cat and we can make our cat meow now here's the implementation uh if our cat has not been fed it will meow I'm hungry and if it has been fed it will meow I'm sleepy so yep then on the Rough Side of this that was our C plus plus code on Rough Side of this we'll be reusing this example everywhere so you know we just go through it like once um on on the Rough Side of this we have a bill arrest file which is like a make file but native to the rust tool chain um where we invoke the the cmake file uh or this sorry the cmake library to to use cmake to build the the C plus code then we say hey please build the C plus code and it builds it and then I haven't printed the invocations here but there's ways of saying like Okay and then please also link it as part of the build um the full example which I'll link at the end includes all of this so you can like go through and browse it yourself then the rust code itself it redeclares the same struct it says hey this struct is not rep or rust it is wrapper C so please use C ABI and then we create ffi bindings for all of the methods inside of an extern C block um and that gives us access and then we can invoke this using all of this which is just C methods and raw pointers these are not compiler checked by the way so unsafe blocks mean uh you're on the hook for validating that the semantics hold but you still need to uphold the exact same rust semantics you don't get to not uphold them it's just sometimes you you like with ffi the compiler cannot check it for you so you have to check it yourself this is pretty rare it's only at the ffi boundaries and for some Primitives that this needs to be done um but yeah here we're doing ffi stuff so uh we take our cat we create our cat and then we call meow then we call feed and we go meow again and that just works um okay intermediate level rather than needing to like we saw here uh redeclare destruct and also here you know earlier have the multiple definitions um what we can do instead is use a tool called bindgen which will read the header files from C plus plus and auto generate rust bindings we can then use that to call things and it will just be less work so here is again our cats.hp file in this case we no longer need to use struct because we're not using extern C anymore we are just using negative C plus plus classes so here's our class with all the methods like earlier but in class form and then we create the implementation there still same logic but then in the rust build file we do something different namely we call it bindgen tool to generate our bindings and then we build a c plus code and then it gets Linked In the bindings get generated and then in our main file we can take those bindings and just use those so rather than doing the free functions like we saw earlier we can now see that our cat has methods on it so we can call meow and cat.feed which is a lot more convenient so buying chain is great when you can use it I highly recommend using it there's also the inverse tool called C by engine if you want to create rust take rust and like create C binding C headers for it um yes okay so for the final example what if we wanted to go like all the way through so far we've been seeing uh things like Carstar Char star strings but rust and C plus plus both have access to Native strings like high level string representations which are nicer to use other types such as smart pointers and the cxx library allows you to to create a bridge between the two using these high level types so it is aware of rest and C plus plus libraries and it makes sure that those like like ergonomic you can create ergonomic like bridging between the two so uh in this example what we'll be doing is we'll be round tripping so we created definition and rest call that from C plus plus and then export a function again from uh to rust which we then invoke so our header now is just the void function test we just gave it a something name doesn't matter because this is what we'll be using from Russ then in our implementation tests calls or rust types here we say hey please uh create a cat and then call meow and feed again unfortunately cxx is not yet aware of how Constructors work so this is a free function to create our our struct or a class um but then from there it's it's you know the methods do work in order to build it what we can do is we can use the cxx build um Library we can give it some flags and that just works now on the right side rather than defining the the types on the C side or sorry on the C plus plus side um we're now doing it on the rough side and we say hey extern rust within this like cxx Bridge construction we say hey here's an extern rust block with all the methods and a shared struct named cat with um a name and is hungry and then importing from C plus plus we say hey there's a function called test that we would like to have access to and then the actual implementation so those were the headers the actual implementation here is like we have neocat which implements all logic and it's it's pretty much the same logic rest in C plus plus look look pretty similar in in many cases um so yeah the the only thing that probably stands out here is that fee takes a mutable reference to self because it mutates it updates that is hunger field everything else takes a shared reference and then here we call ffi test which invokes the C plus plus code and that works um okay just the the final bits here um there are more options that you can investigate if you're interested uh cxx can be combined with buying gen to make things more convenient unfortunately uh ran out of time to try it as well as I said they've only been doing this for a week um the Google auto cxx project which is an unofficial project um takes both libraries and is intended to make that more convenient I have also not tried it but I I really like the premise of that because I've found myself needing when using cxx which is what you would want to be using if you could um there's some repetition involved but Auto cxx removes that repetition which seems very promising there's also cxx async which adds support for async types and finally C by engine as mentioned earlier if you want to create um like wrap rust code into like uh C headers and make that like automate that project um yes so in conclusion rust is a memory safe programming language it has native interrupt with c and with with some use of tooling you can also make it interrupt with C plus those tools are being actively developed and they're improving um all the time so hopefully this will become easier over time and I'm very excited for where this is going I hope this was useful um if you're interested in seeing these examples trying them out building them yourself you can go to this URL on GitHub where you can find all three examples checked in and my slides as well so you can read those over if you want to thank you so much
Breakpoint Groups in Visual Studio
hello everyone I'm Isadora I'm an engineer in the visual studio debugger team at Microsoft and for this demo I'm going to show you what breakpoint groups are and how they can be very useful when you're context switching between different bugs in the same project so for this particular demo what I have here on the right you can see it's a very chaotic city which is authenticity so this is a fort from transport icon which is a very cute and sweet game that I wanted to use for this demo this project as you can see has a lot of files so if I just want to keep track and have a debugging workflow here I'm quickly going insane but before we can go on and say let's just try to understand what this actually does just we can have some context because context is pretty important when you are debugging something so here you have a poses it's picking up people and going back this is like one of my favorites they have this pretty training that's going here and pick you up around and getting back to the city and you also have this Mayo buses that are just delivering mayo and coming back to it so they are all different doing different stuff and one thing that you may have noticed is that through all these different kind of things there are different things that I want to make one of the book so if you look here I already have a set of breakpoints that I picked just for this demo so here I have stuff like order trace and check and you can already have seen here that these are actually a group of breakpoints that point your other ones so it's much quicker if I'm debugging a particular context but let's say that I just want to debug order comments so every time someone has an order I'm going to stop here and then I can just step through and see what's doing oh for example here it's asking this guy this phone call here to go to this particular station and I can see oh this is and then I can just be super confused about it or maybe I can just pick this group idea and say that's his name now and if I hit continue I'm just going to stay here and let's say that I don't want to debug orders anymore and what I actually want to do is I want to debug traits so I can just click this right and it's automatically enable all these other breakpoints and then I can just hit continue and then you can see that I already checked if the train stay in Depot or not but I say I don't actually want to be here I want to be somewhere else so I can just drag this breakpoint around maybe around here before it even has a chance to return and then you can see that I even reverse my train and it's a different thing and it's all part of this breakpoints here and then I can just quickly keep stepping and going through different things and I have all the things that I want evolving trains and I can even do other stuff like let's say they only want to debug trainings when order has been emitted so what I can do here is actually set that I only want this to be hit when this breakpoint for order has also been chosen so you can see that they are all disabled and then I actually have to enable my parent breakpoint and as soon as an order has been updated here right here you can see that all these other breakpoints were just activated so this can also be very useful to have a function that SD cost several hundred thousands of times and just want to enable them in a particular context and similarly I have this other I can do like check orders so like every time someone's updating the order I'm doing something or just when someone is unloading the cargo I can go ahead and see whatever they are doing and yes just so useful when you're sharing like projects with like a huge team or like a huge code base and you just want to keep your debugging workflow saved somewhere and actually persisted and actually being able to jump through different context switches around one of my favorite things that even has support for emojis so you can put Emojis anywhere you want I highly recommend it if you ever want to try something else in your debugging workflow and that's pretty much it so for follow-ups I highly recommend checking out the Twitter handle for vs debugger or the blog post for breakpoint groups you can find much more information about how to create them how to use them or just how to improve your debugging experience in general
Branches Merging, Rebasing, and Squashing in Visual Studio and GitHub [Ep 2] Advanced Series
hi everyone thanks for joining this session on integrating branches merging rebasing and squashing in visual studio and GitHub where we'll cover the different ways you can integrate changes from other branches using git and how each Works in vs and on the web in GitHub whether you merge or rebase a secondary Branch you'll end up with the same changes being added to your primary Branch the different lies in how the commits are connected in your git history when merging your primary Branch will get a new merge commit and you'll have the entire history of the second Branch preserved as a detour in your graph as shown in the graph here when rebasing every commit in your secondary Branch gets replayed on top of your primary Branch as if you made those commits on your primary Branch to begin with as shown in the graph here you can see they have the same commits but are connected differently compared with merging you get a cleaner history and a linear commit graph which is helpful for rolling back changes sometimes these actions result in merge conflicts which we covered in more detail in another video Once you pick your method it's easy to either merge into current Branch or rebase current Branch onto from the context menu when you complete a poll request on GitHub you can choose from the following options and your organization can configure which merge type it allows on a given Branch when either of these strategies are combined with squashing you lose the individual commits from the secondary branch and the result is a single commit with a new commit message this is useful if you want to throw away the source Branch completely going from a branch with multiple commits into a single commit to squash simply hold control and select a set of commits you'd like to combine into a single commit and rightclick and select squash commits thanks for watching everyone
Basics of Debugging
[Music] hey everyone welcome to another episode of Visual Studio toolbox I'm your host Leslie Richardson and today I'm excited because we're talking about one of my favorite topics good old debugging you know the the topic that everyone dreads but we're all having to do as developers but uh yeah we're going to start from square one today talking to all about how to get started debugging for the first time in visual studio and joining me to do that today is Nick hey Nick hi Leslie nice to see you nice to see you too so before we uh jump into debugging do you want to tell us a little bit about yourself yeah sure so um my name is Nick I'm a software developer from the UK uh near Manchester uh I'm currently working as a director of software engineering for a uh robotic process automation company we use a lot of net in our stack um and yeah just excited to talk about uh debu B okay awesome I'm excited too I used to work on the visual studio debugger so yeah debugging is near and dear to my heart yeah definitely yeah so for those who don't know what that is or maybe are getting started in their coding Journey what is debugging and why are we stuck doing it yeah yeah so unfortunately like it will be like a really common practice for you you know so many times people say what you working on I'm just debugging this I'm bugging that um and it's it's kind of quite a negative connotation to it but it's actually it's essential and um it the the simplest way I could describe it is you're tracking down that pesky buug you know you're trying to find the root cause of a behavior that's um happening that's unexpected uh and so using visual studio we can um rather than let the code just run through in its normal State we can actually pause the code and inspect it to see what the current state is and how that might be contributing to the issue that you see awesome yeah I think that's a great definition so yeah should we hop into visual studio and see how to get started yeah let's go for [Music] it so I've just created uh a typical console application so whenever I do a demo I find it really easy to just build a a normal C console application with a main method uh and then to to jump right into it and so the first thing that I want to talk about is um the compilation modes that you can see in visual studio uh so you've probably seen already that you've got this debug drop down and you get the debug or release options in there and now for the purposes of what we're doing we obviously want to be in debug but it's not obvious what the reason for that is um so there's different modes of compilation for uh for C in particular um in visual studio and the difference being that when you're in debug mode which will be your um default mode there's a there's a little bit of a difference in terms of the way things are compiled we have things called symbols uh that allow the application will allow Visual Studio to know where you are in the code uh and it's less optimized it's quite I mean as you know Leslie it's quite a complicated subject I won't go too deep on that but just so you're aware of its existence the default mode will be debug uh and then on the flip side of that release mode is it's kind of the opposite of that there's less optimiz there's sorry more optimization uh you don't have those symbols uh that are telling you where you are in the code simply because you aren't expected to be debugging in release mode uh so so that's the difference between the two um and the reason I talk about this is because one of the uh debugging aspects that you can take advantage of in Visual Studio is something called uh pre-processor directives uh so these are the lines you see here where we've got this little hashtag symbol um and this is where you're adding a condition into the way the application is being compiled so it's not the same as like a conventional if statement uh it's something that sort of sits outside of the code it's more for visual studios's benefit uh so for here for example we're simply saying that if the current mode is debug then we want to execute some spefic specific code uh otherwise it's going to be in release mode and we can execute this code so I can demonstrate that and it will also demonstrate a break point so we're kind of killing two birds with one stone there hopefully great so I'm currently in debug so I would expect to uh put a breakpoint in here um a breakpoint is what we were saying before about pausing your code it say um it's a point in the code where you can say I don't want you to run further than this point I want you to stop at that point so I can take a look around and see what's happening in the application now obviously if your breakpoint is inside an if statement and that if statement uh doesn't evaluate to true you won't hit your breakpoint so we're kind of testing the if debug scenario by saying we're expecting this to hit that break point because we're in debug Y and so in Visual Studio to kick the program off uh and start debugging we can go to the top here and click the play button and let the application fire up and then as you can see we've hit our break point and as we said the reason we've hit that is because we're saying only go to that break point sorry only write out this line to the console if we're in debug and we are and we've also put a break point there so we're now paused great pretty simple also I gotta say shout out to the debugger team for uh make for adding the ability to see that you can actually add a breakpoint in the first place by hovering over the gutter where you just added that break point that used to not exist and I can imagine if you're like brand new because a lot of schools and a lot of uh classes that you take don't always teach debugging so if you're just trying to figure this out on your own it's like not very intuitive maybe to to know that oh a breakpoint is here so yeah yeah absolutely Echo that and you know you guys uh if you're picking up visual studio for the first time you know you got kind of spoiled to be honest the featur feature sets amazing I was writing uh VB6 in the old Visual Basic and it was a fantastic tool but it's come so far the debugging experience has since then so oh yeah yeah it's super powerful uh and obviously if um we want to test our theory around um whether the release uh breakpoint would hit we can add another break point here uh and then change the mode over to release so now this pre-process cessor uh for if debug it should evaluate to false so we shouldn't see it hit that break point so I'll just click play there and there we go we've hit the other break point instead because we're now in release mode so you can see the way that break points can be affected by the position you you put them in if they're inside some logic which wouldn't normally be hit in the code you can guarantee the break point won't be hit either Okay so we've talked a lot about break point um so along this part of Visual Studio you can tap those in and they'll uh appear and disappear um you can also um this quite a handy function that you can use in the debug um part of the ribbon where you can say I just want to turn off my break points I don't want to delete them uh but I just want to disable them and I find that quite useful if I've been uh debugging something um for a specific change because there's a common um misconcep ception around debugging in my opinion that it's always to do with bugs it's actually sometimes around testing as well you've got a a feature that you're adding you want to make sure that the codes running the way you want it to um and I find that using break points for that is a fantastic way to to verify what I'm doing and so when I've made that change I want to see that it carries on through without um me stopping it all the time so being able to disable things in one place and then reenable them is really really useful so I want to talk about uh steps so there's lots of different ways uh you can perform these steps and steps for me um essentially are ways that you can move around uh the code once you've break pointed so once you paused the execution of your overall application you've got lots of different options you can either step into something you can step over something and you can step out of something when I say step into something it has to be something that you're capable of stepping into so if it's a variable if it's just a uh a variable like this where we're specifying or defining an integer um you're not going to be able to step into that because there's nothing inside to uh step into as far as debugging goes but for a method or a function you've got code inside that so you can choose to either step over it and Skip uh going through every single bit of code inside that method or you can step into it but don't forget that the code inside it if you go over it it will still run it will it's not saying we're not going to run this code we're just not going to follow it through for the purposes of debugging so I've got a method here called step into method and if I go to the definition of that everything I'm doing here is really super simple I'm just writing things out to the console uh but if I'm debugging I can choose whether I want to see uh the code go into this method or if I want to just step over it so I'm going to set a breakpoint here and then I'm going to run the application and let it just breakpoint onto that method and then up on the top left here are your step actions uh and as you get really good at debugging um and it becomes second nature I'm sure Leslie this is you you're just tapping the key combination F10 F10 F10 f11 step in it just becomes like muscle memory right it's just it's amazing how quickly that can just become uh done without thinking oh yeah and plus I mean again you're probably gonna be de debugging a lot in your coding career coding Journey so yeah you're probably gonna learn those keyboard shortcuts very quickly as somebody who does not usually remember keyboard shortcuts f 10 F 11 yeah yeah because I was thinking about the um disable all break points and delete all break points all that sort of stuff and I was like what is the keyboard but yeah stepping in stepping around is that is like just one tap it's and it's sometimes you can go a little bit too fast as well I can just step through things and go oh I've gone past it and yeah luckily there are additional Advanced debugging Tools in VSS that can help you backtrack if you do that but we won't get into it that's thinking of everything [Laughter] great so for this one um I want to step into it so I want to actually go in and see the code that's going to execute so um I'm going to hit this step into button or I can press f11 and you can see we've actually gone into that method and then we can do the same thing for the lines of code that are inside the method so you may have a method within a method and so you step into the first method and then you decide actually I want to look inside that method as well or you might think no I I know that one's good I've tested that one I'm going to step over it in which case you can just do the step over here so you can see these arrows handy little arrows that just explain uh what kind of Step we're doing and there you go we've come out of that now because it was the last line of code for that method and we're on to our next one so I I'm sure you can guess what I'm going to do next for step over method uh I'm going to decide that I don't want to look inside this so I'm just going to click step over and the last one is one that I I think a lot of developers in my opinion I don't know what what you think Leslie but they potentially use the least yeah yeah it scared me a little bit when I first uh when I first got into into code because I was I wasn't sure where it was going to go even though now it's more obvious to me with experience but um I don't know I think there's a tendency to rather than stepping out once you've decided that your code is good um that I you just keep going through is that the same for you yeah I kind of feel the same way I I Rely you step out and Par because I get worried I'm like I mean I think I'm pretty sure I know where it's gonna go but let's just go through the rest of this method anyway exactly it's just safer to keep going yeah that 2% un uncertainty is like yeah but that's really interesting because it it shows that there's people have their own debugging habits there's different debugging Styles and um you will get that person who will be stepp to everything and that's fine you know that's absolutely fine uh because if that's going to give you the the information you need that's that's the way but just to explain step out essentially it's whichever um method or function you stepped into uh by pressing step out you can essentially go back up into the um the next uh level up basically so like with um if I look at at step into so another handy thing you can do just press the method and then press F12 and you can go to its definition we stepped into this but say this had a a long um block of code and we got halfway down um and thought you know I'm I'm okay I don't need to look at this anymore you can press step out and it would go back up to the point you were in the next level up uh obviously not me and Leslie because we want to play it safe yeah but it's cool something I do want to point out is that um breakpoints and the stepping tools those are pretty commonplace in the IDE world so yeah if for whatever reason you're deciding to use something other than visual cudio whether that's vs code or uh another IDE or Advanced editor experience like BS code those tools will at the very least be there in some Capac capacity so you'll always have break points you'll always have ways to step through to see what you want to see yeah and in the in the browser as well that's a that's one that a lot of um I find that a lot of developers that I I bring in who are fairly new um they're less exposed to the browser debugging experience but the concept is the same essentially a lot of the same tools too cool right this is one of my favorite features because it helps is so good it helps you to debug very very specific uh edge cases you might be trying to figure out what would be causing a bug but you know that it's only in a very specific situation and this is the conditional breakpoints um and this is a breakpoint where it starts off as a normal breakpoint um but then once you've created it you can then specify that it is conditional so I'm just going to get rid of this one here and I'm going to put a a conditional break point inside this for Loop uh so this is a loop where we're going to be iterating until we've reached uh our top index and inside the body of this loop we're going to be multiplying a variable by two um but what I want to do is say I don't want to be hitting this breake point for every single iteration I only want to hit the breake point if a certain condition is true uh and that condition for me could be uh that the variable condition demo value is greater than five because for some reason I've got a theory that something breaks when it gets to that that value essentially so the way we can do this is once you've already set your uh break point you can hover over it and you'll see there's a settings button uh and if you click that settings button you get some uh really cool features that you can uh take advantage of so in here we want to first look at conditions so I can check this conditions box and it will give you lots of different options for the condition but I think the most common one is going to be conditional expression so this is a condition Builder that you can use to say if this condition is true that's the only time I expect you to hit the break point you can also do it based on how many times it it's already hit that line of code so that's a similar sort of sort of deal you could say if this line of code gets hit x times then stop the flow of the application I want to debug it um filter this is one I I don't think I've ever used it Leslie do you want to share some insights into this one oh goodness oh filter I because I barely demo that one either so um I'm blinking out I feel like it's a slightly it's it's kind of like hit count and that it's a slightly different variation of a conditional expression last time I I checked except okay it it looks like it's like um a com just hit my mic sorry it looks like it's a combination of conditional Expressions yeah based on because the debugging team put a handy example in there so there you go pretty great and uh I do want to point out you can add multiple conditions if you want so like there is the add condition uh yeah the add condition button right below it where you can add more than one condition for whatever reason that is an option as well I think I need to I think I need to put one in before I can do that don't I so if I did I think so yeah so if I said so it's kind of like a Boolean expression isn't it so it would be condition demo value is greater than five and then press enter and then I should be able to add another one and the hit count is two um which it would be or at least one yeah math is is failing on me today it's nearly nearly night time in the UK but but yeah for this one we're essentially saying the condition is I only want you to hit that break point if my variable condition demo value is greater than five um so for that uh we can test that out you can see oh I've just deleted it that's always good put that in again okay Enter and then close there we go and you can see when you've got a conditional break point because you'll have a little cross in the middle of it uh so from that you'll always be able to see uh that it's slightly different and also hovering over it gives you uh the conditions that you set up as well uh so I'm going to let this continue to run so because we're already breakpoint um the play button says that we want to gives you the option to continue um and then you might be thinking how do we know that it's actually a above five at this point sure could it not just be highlighting it uh on its first iteration and this brings us to inspecting variables so what we can do to verify that it is actually hitting that condition is we can hover over a variable while we're break pointed uh and you can see here that it shows a little tool tip telling you what the current value of that variable is so we have indeed met that condition that variable is 10 so it's greater than five and it hasn't breakpoint did before that so our conditional breakpoint was successful okay so I'm going to stop the application otherwise we're going to be constantly shifting down also before you uh go on as we pivot away from break points those aren't the only break points fun fact so the lesson here is to definitely take a minute to explore the visual studio debugger because there's tons of additional break points yeah we got like Trace points uh which is what Nick just highlighted there's dependent break points there's uh function breakpoints data breakpoints so many to explore that can help you be a lot more productive in your debugging Journey that are worth checking out absolutely absolutely it's um it's so important isn't it you know it's all very well and good being good at of solving problems through your design of code but if you don't know how to use the debugging features you're going to be a a little bit of a disadvantage um but um the the sort of the very there's so many Advanced features like you said yeah like I can't speak for every IDE but Visual Studio I mean the debugger is a lot of what makes Visual Studio really cool if you take the the time to check out some of its more advanced features it's awesome yeah it it blows my mind because it it's the team has has built something that's working on a running application that's like next level for me um how how do you interrupt the flow of the comp of the application I I wouldn't even know where to start uh so another really cool feature um is uh the watch feature and a watch is essentially where you've got uh a variable of some sort um and you want to know while the application is running uh what its value is so it's the it's similar to where we hovered over that variable and said you know what's the value U but we were only doing it for that specific point that break point we were on um but if you're break pointing something else or you're debugging something else in the application and you want to keep one eye on another value to see if something's changing it and a watch is often a good shout um so for example if if I wanted to just keep an eye on this variable and make sure that it's definitely just 10 uh while things are running I can rightclick it and then I can go over to I may need to be debugging to actually see this so I'll just put a break point on it um there's several ways of doing it as is always the case with visual studio um but if I get to I'm in release now that's probably why there we go so I can actually see it in this watch window here but I'll just demonstrate here if you right click while you're break pointed you can see there's an add watch uh option if you just click that it will take you to the watch screen I already had it in there by the looks of it so I think I can rightclick it and delete Watch there we go um but essentially that's a screen that gives you all your watches so it's everything you've flagged as I want to keep an eye on that basically uh so we've got the the the variable name the current value and its type um now obviously we've set that to 10 and we're break pointed on it and this is really uh interesting the value here is zero which is not the same as what the value is in the code uh and the reason for this is that because when we hit a break point we're on that line of code but the code hasn't actually executed yet so we have a watch demo value but because uh we haven't executed we haven't initialized it with a value it's got its default value which is zero for the integer so if I then step over this and go to the next line that code has then executed the variable has been initialized to its value and we can see here the value in the watches screen has also changed so you can see how this would be really useful if you had other code which could potentially affect that variable uh I find this really useful when I'm iterating through uh lots of different data structures um I think recently I had uh a big array of Json objects and I was going through it U and there was an external variable that got set based on a very particular uh field inside these Json objects uh and I wanted to see the point at which that variable changed uh and so I could just put a watch against that variable run through the iteration and then I could see ah okay it changed at that point that's the bit that's setting it [Music] basically okay so immediates um so these are probably after the sort of usual break pointing aspects this is probably one of the things I use the most uh I don't know whether it's because uh I'm more of a backend engineer um but uh I don't know whether that that affects it or not but essentially immediates are kind of like um for the web developers they're kind of like the console in the browser it's kind of like where you can interact with the uh the code base while it's paused uh so by that I mean if I was to type um a variable which is in the code that has gone past the execution point so say watch demo value we're past that point now say I type that into here I get intell sense for that as well because the compiler knows that it's part of the uh the code base and I can say watch demo value press enter if I want to and it will give me the value of that um but I can so that is essentially me interacting with the code base um while it's in a paused State uh and this is uh valuable for lots of different different reasons it allows you to test different theories uh while the the code is paused so for example uh if you haven't got a watch on uh the watch demo value and you think oh I need to make sure that that is equal to 10 and um maybe it's not in view so you can't just hover over it and see it from there I'm just trying to find an example of why you would use this um in such a small application what you could do is say watch demo value and then similar to that conditional expression we used in the uh conditional break points you can use a Boolean expression so you can say watch demo value demo value is equal to 10 and that will return a true or false so we can see here that's returned true so it's really useful I use this all the time when I'm looking to just check in on something that's still uh available to me as part of the code it's still in scope to some point uh but I'm probably halfway down the screen it's out of view I don't want to scroll back up to it I just want to quickly use the immediates to have more of a console experience you should also be able to set the value of things so you can start to um mess around with the state uh of the application while you're debugging it so if I did watch demo value equals 4 it will just return the value that I've set but then if I hover over it you can see we've just set that to four so we've intervened in the state of the application while it's paused it's so powerful uh and and that allows you to test lots of different scenarios uh so very often you could say uh you might have an application which is um running only if an invoice value is over say $10,000 but the data you've got is all just below that and you want to try and test that other scenario well you could quite easily take a variable like invoice total and then change it inside the immediates window to test that um flow of code you can also do that from the variable itself uh in most cases so you can say change it from here and then if I go back and type this in again and you can press up as well just like you can in the command line to get what you've recently typed in I can see it's six because I've just set it from elsewhere in the code base so it's again this is where debugging gets a little bit um it's not just looking for bugs you might also be using it to influence uh State mhm yeah the immediate window is pretty powerful in its own right there there are lots of people who really kind of do all of their debugging in the immediate window a lot of the time I I'm personally one of those who doesn't really use it that much but yeah again whatever floats your boat there's lots of options in Visual Studio yeah yeah I mean if you if you were looking at say again I'll use the example of Json or or XML it might be just too much to look at in the debugger but there's nothing stopping you from doing a file. write all text in the immediate window and just then dumping all that information into a text file or or XML or Json file so that you can then look at it all the same time the application is still paused just giving yourself a bit more of a an opportunity to view it in something like Visual Studio code for example so it's just for me it's just super flexible that's I've got options all the time when I'm debugging in visual studio uh so inspecting variables we' we've pretty much covered uh that is where you can just hover over them you can see as we said this is still zero until uh we actually execute it and then we get on to something that has thrown me before honestly um because they I feel like they're quite similar I don't know where you are on this Lesly gosh I still struggle with it too sometimes um honestly I I think in most cases it's okay to lump autos and locals window together but if the watch window is like your inspection window for being a but you have to manually select which variables do you want to have persist and take a look at as you're going through your code the locals and Autos Windows automatically give you the variables that are currently in the scope of where you're at so if you swapped over to the locals or AOS window right now then you'd be getting a lot of the variables that are both within a scope or in proximity and I think the Autos window is really just more proximity focused more so than so it takes the nearby variables not necessarily all the the variables that are currently relevant so yeah I sorry Leslie you go no go ahead I was just gonna say I thought that was a really good explanation um I I think I looked for a definition before the show because I like to be prepared um but you know Autos it was It was kind of defined as um a a reference to any code which is relevant to the current line but that's a really vague definition isn't it it's really hard to to make that accessible I I agree so that is my best interpretation of it anyway just through observation but I think at the end of the day a lot of the time the autos and locals are windows are pretty much one and the same I I prefer the locals window because again you usually get more uh info that you'll probably need but yeah both are giving you the most relevant variables in some capacity in addition to other default Expressions that might come about which I talk about in uh other demos that I've done that are really cool stuff like return value uh which can tell you the the value of u a return statement in your method without having to necessarily set an arbitrary variable like the locals window and the Autos window can tell you that automatically the moment you step over that line which is really nice super cool it's really nice one thing I do really love as well that you guys have put in is this idea that um you can't get away with changing something and not being found out so here if you remember I've changed these values while the application was um paused uh and visual studio is flagging those in red to say hey these were changed uh which again is it's super important I think this this idea of traceability in debugging um it's it's got to be forensic hasn't it you've got to know absolutely every single thing that's happened and has changed so just that simple feature of coloring those in red I I love that feature I think it's really Co I agree so I think we've agreed most of the time we're going to use locals but again totally your choice but you know it's just about having as much visibility as possible and um I know that when I go to I'm always going to see things that are in scope which is most of the time what I'm concerned with so this brings me on to my my last example which is um one that definitely tripped me up when I was a junior developer I hated looking at it not because it was a visual studio thing but it was just a programming thing it just a wall of text but um it becomes less scary over time but and that's the call stack uh and actually Visual Studio does a really good job of visualizing it whereas the traditional call stack is just like a big line of text um block of text sorry but the the idea on the call stack is simply um the everything that's happened up until this current point and a representation of that so you'll often see these in exceptions so when you do a try catch uh and you hit that that catch there's going to be some kind of exception object and that exception object will have a call stack in it uh and that will say that the exception threw at uh a certain point in the code but before that lots of other things happened and those things could be other threads they could be parent functions but the the common denominator there is that it's before the current Point yeah I think timeline of yeah events that are going on in your code in a lot of ways a much nicer way of referring to a timeline um so what I've done here is uh just created uh a means of viewing the call stack so we've got a method here called call stack demo and I'm going to step into it so I want to go into the actual method I pressed f11 for that uh and then I'm going to let these uh pieces of code run so I'm going to press F10 to step over I'm going to step over again to get to this method so we've got method inside a method and then I'm going to step into that and we're going to run that method and then I'm going to pause it there for a second if I wanted to see the timeline as Leslie said uh which is the the call stack uh I can go again into debug and we've got a really uh useful Windows section here which gives us loads of different features some things that are more advanced uh than than this in the scope of this uh video I think uh but uh the one we're interested in is call stack and you can see here you can select it and it will open up the call stack window uh so I'm just going to move this I'm going to try and dock it up here there we go and just bring that across and so this gives us our timeline this is the stack of events that have happened to bring us to this point and at the top you'll have the method that you currently in or the break point that you're currently on so you can see here we're in call stack sub method at line 73 but before that to get there we'd hit line 67 and if I double click it will take me to that line and again we can see at the bottom of the call stack that is going to be the first point of entry our entry point uh because it's the first thing we went into uh and that's main as it would be for our uh console application uh I think it just hasn't there we go oh sorry it's uh I am in main yes of course so it's highlighting call stack demo but that is in the scope of main so you can use this to trace back what's happened to that point uh so I often find it's a useful refreshing Tool uh if I'm doing a very long debugging session so and if I'm doing a long debugging session it's probably a pretty complicated bug um but what I mean by that is if you've spent a lot of time going through lots of different break points it's quite easy to sometimes forget what's happened up until that point and that might be really important because uh you might not be seeing any exceptions throwing but the data that you've passed through up to that point might be critical to understanding why something isn't running uh the way it should be so if you're in that really annoying situation where you know there's a bug but everything looks good uh the call Stack's really useful because you can say okay I'm going to retrace my steps uh and I guess that that's the main use case for me uh I don't know Leslie any other sort of go-to use cases for the call stack that from from your side yeah a kind of Niche one that I use it for is in the event you've got a variable that's being changed in a spot that you did not expect it to change but you act but you also don't really know where that change could be coming from there one of the breakpoints I hinted at earlier there's one called the data breakpoint that lets you break your uh at your or it lets you pause your application when a specified variable changes at any time so it's really nice because it'll take you to that exact place where that break where that variable was changed but there um there's a speci specific instance where in the event that variable is actually like a property in a class or something it's usually going to take you to like the setter that you probably set up for it but that's when you can use the call stack to figure out who you can really blame figure out what method just incremented that uh variable without your permission and navigate to it that way which is very helpful so in some ways the call stack is like the git blame equivalent of um debugging where it's like okay what what happened through my code and could there be a spot where I I didn't want that to happen or method to be called in a place that I did not expect it to be called so there you go so this no there's no escaping in Visual Studio forensic data everywhere you go everything's traceable yeah and you did mention also threads and stuff I I think the call stack is really useful for if you're dealing with multi-threaded or asynchronous applications there's lots of instances where you just want to be able to break down what is happening on a specific thread or across multiple threads uh having a call stack window for that is extremely important I think absolutely and and debugging multiple or parallel execution or concurrency is that's probably a video in itself isn't it that that's a oh yeah it's pretty Advanced but it's uh and it still hurts my brain but um you know there's a million different tools that I disposal here so it always makes it just that bit easier uh so I mean that's that's my My overall set of examples for um an introduction to debugging um but um I think key takeaways there are that uh the emphasis is as I said on being as forensic as possible and making um the state of any application available to you uh at that point in time and and I would my advice to any new developers or any uh people using uh visual studio for the first time would be to just start with breakpoints and and work your way up through these examples we've we've locked up um I'd say you know m around with the immediates figure out how you can influence the state of the application uh and break it essentially uh and maybe create some weird edge cases and I think once you've had that hands-on experience you become so much better at debugging in general um and uh and it's often a a process of elimination as well uh so you know you test your theories you you think I've got a bug I think it might be this let's try and disprove that uh and hopefully you're right and you don't have to disprove it so you can just put the fix in yeah I think something that helps me with debugging is just the whole expectations versus reality so like you're thinking about the meme like that's kind of the thought process with a lot of debugging it's like okay what did you expect to happen but what did you actually end up getting and that gives you a good starting where okay how do we get to that cake looking like what it was supposed to look like instead of my mess kind of looks like a tennis court but really it just looks like a blob that's yes definitely when I'm baking cakes for sure oh yeah yeah awesome well Nick that I thought that was a great introduction to debugging I think that's something that everyone needs like whether you're being formally taught it or not like I I was never formally taught how to use the debugger and then like I joined a debugger team fresh out of college and I was freaking out because I was like um yeah I just statements when I was debugging in school so like I don't know um yeah but I I think these are really useful tools that really you can take anywhere um whether you're in BS or in another IDE but you should totally use vs because the debugger is amazing um but yeah that's awesome so where can people go to learn even more about debugging Nick um well of course you can go over to to Microsoft learn um you've got lots of different videos there and documentation um and um I mean I think I've got a few videos on on debugging you want to head over to Nick proud programmer Shameless plug um but uh yeah the documentation for visual studio in general is is fantastic um you know I'm using Microsoft learn a lot myself uh spe specifically for the AO stuff as well um and you can you know there's nothing worse than poor documentation and I've just never had that issue uh with visual studio uh so um and obviously the help function in Visual Studio itself you can get through to all the documentation you need from the application uh in a lot of cases as well uh I've noticed in recently there's been um links to GitHub repos for specific uh items as well which is just so cool you know if you if you want to get some information on a specific element of net for example which is largely open source you can get straight through to the repo from visual studio so um you can't really go wrong with with the with the official docs and then um obviously resources on YouTube and uh places like that are probably an expert yeah awesome and then also more Shameless plugs on my end I know uh it's been a minute but this show the visual studio toolbox show actually we did do a couple episodes way back when about debugging so if you uh if you're on YouTube right now and you do vs toolbox debugging then there should be several videos that pop up including one that I did on more of those Advanced tips and tricks that we talked about most of them I I haven't done that talk on the show since BS 2019 but a lot of those tools are still very relevant uh for VSS 2022 and also if you're on Twitter go to uh make sure you subscribe to vsor debugger that is a great Twitter channel that um that's run by the debugger team on visual studio and they drop just cool tips and tricks at random or sometimes not at random sometimes they're talking about new features because we're always working on new stuff too that are worth checking out so make sure you subscribe to that and yeah I think that's all of our resources for now hopefully that gets people started so yeah Nick thank you yeah but Nick thank you so much for coming on the show super informative very important stuff absolute pleasure thank you so much awesome and thanks to everyone who's been watching this and is ready to Kickstart their debugger journey and until next time happy coding [Music] y'all
Building Bots Part 1
it's about time we did a toolbox episode on BOTS hi welcome to visual studio toolbox I'm your host Robert green and jo...
-
>> It doesn't matter if I'm short or tall. >> Anxious. >> Or obsessed. >> Loud. >> Quiet...
-
hello my name is Ron Lou and I am a program manager on the video studio team in the previous video we talked about how to inst...
-
so I'm going to show you an extension here called shifter it allows me to flip between values and the editor really really...