Like fashion, computing works in cycles. Things that were once looked at as passe come back with retro vengeance. For .NET development, the console is back. Consoles combined with lightweight editors like Visual Studio Code are becoming increasingly popular. Call me a hipster, but I’m all for this change. I hate waiting around for my editor and I never have to do that in a console or Visual Studio Code.
Unfortunately, if you’re living in the world of Windows, the default command line options are lacking. Not only are CMD and Powershell ugly, they lack basic usability features found in Linux and OSX. There is a better way. Cmder is a Windows console emulator that bundles several command line tools together into one fantastic package. It’s the Cadillac of Windows consoles.
Here’s what it looks like:
Cmder has a nice tabbed interface. You can run multiple consoles without having to deal with a bunch of windows. It also supports several different types of consoles including: CMD (enhanced with Clink), Powershell, and Bash.
You also get full control of the appearance of the shells including the font, color, etc… Cmder has many themes, but the default Monokai theme is good enough for me.
More importantly, you can create custom tasks. A custom task is a specific command window that you can define. You can specify the shell, what parameters it’s called with, and what directory is opened. You can have a command line setup for each application you work on. You no longer need to open a command line and manually navigate to your app folder each time you open up the console.
To make a custom task, do the following:
From Cmder, type Win + Alt + T. This takes you the tasks windows. You can also click the arrow next to the plus sign and click “Setup Tasks”.
This window allows you to reorder and reorganize the different defaults in Cmder. Hit the plus sign to add your own.
In this case, this is a console task that opens a specific project I’m working on.
After you setup your new task, click “Save Settings”. You should see your new shell in the list of available presets. Then you can open that exact shell whenever you want.
If you want to supercharge your Windows console, check out Cmder.
I’m a huge fan of ASP.NET Core. It’s a great iteration on the ASP.NET platform and it should be your default choice for any new web development. I’m also a big fan of apps that don’t take a week to load. Fortunately, ASP.NET Core doesn’t skimp in the speed department. The framework has some great features for building fast applications. Some things that used to be hard are now easy.
In this post, I’m going to go over a few tips for building blazing fast ASP.NET applications.
One important way to help your application scale is to use asynchronous methods. The async and await keywords make building asynchronous code as easy as building synchronous code. Using async and await frees up your threads while waiting for calls to return. Because you are using up fewer threads, more people can use your application at the same time.
Async is usually a good default practice. But, it’s especially important when calling slower processes, like database calls and service requests. You don’t want to hog up a thread waiting around for database results to come back. When building your application favor async versions when they are available. Entity Framework has async versions of most data access methods, so make use of them.
One thing to keep in mind is that using async and await will help you scale, but it won’t run your requests in parallel. If you have several slow requests, consider running them in parallel using the Task Parallel Library. That will compress your wait time to the longest running call, as opposed to waiting for each one to return sequentially.
Getting data out of a database is the largest performance bottleneck in most applications. One way to reduce that cost is to cache things that are slow to retrieve or slow to change. ASP.NET Core has a few built in cache mechanisms.
The easiest cache to use is the built in memory cache. This cache stores items in the memory of your applications server. While this is easy to use, there are two downsides. The first downside is your cache goes away if your server goes down. Often, this is a non-issue, but if your application caches things are costly to calculate, this can be a real downer. The second problem is that if you want to scale your application to more than one server, your’re out of luck.
The solution to this problem is to use a distributed cache. This cache uses either a REDIS instance or a SQL Server table to hold your cached data. I’ve used both flavors and they both work great. One thing I liked about using the SQL Server cache is that I could add fields to the table to enable more detailed caching logic.
Regardless of which caching mechanism you use, you should hide it behind your own cache abstraction. (I call mine ICacheProvider) By using your own cache abstraction, you can easily swap out one caching mechanism for another. Most people start off with the memory caching, but eventually outgrow it. If you put your caching behind an abstraction, you can swap it out for a distributed cache without having to change a bunch of places in your app.
By default, ASP.NET only compresses a few types of requests by default. These include the content of Razor pages, but not the results of api calls (JSON is not compressed by default). This means that if you have an api request heavy application (ie. a SPA), you can save some serious bandwidth by compressing those responses. This is especially important if you are serving mobile customers, who may have a low bandwidth signal.
Unlike the previous version of ASP.NET, Core has a handy built in middleware that you can add to your app. You can specify the type of compression and what mime types to compress. I’ve tested this in my application and the compression saves a noticeable amount of bandwidth.
If you have a good performance tip, feel free to leave it in the comments.
The next time you give a tech talk or presentation at work, show up early and start a conversation. It’s a great way to get things moving in the right direction.
In addition to the productivity benefits of using the right tool for the right job, it’s good for your personal development to learn new programming languages. The Pragmatic Programmer recommends learning a new one each year. Learning new languages improves your thinking and makes you better at your primary development stack.
“There’s gold in them servers.”
Data is money. Large companies are using the data you generate as a goldmine. Uses range from using data to optimize advertising to using it to make even more addictive products. In addition to user generated data, we also have the mountains of data generated by IOT devices. Sometimes we can use it for small gains, like using a Nest Thermostat to optimize your heating and cooling, but sensor networks can have a much greater impact. We have access to more data than in all of human history. If you can figure out how to mine insights from that data, you will be rewarded handsomely.
“There are three kinds of lies: lies, damned lies, and statistics.”
With plenty of data comes plenty of people using that data to manipulate you. Every political cause has a stable of statistics behind it. Even if they fall apart under scrutiny, people believe them because numbers sound fancy. People trying to sell you something use numbers to appear more credible. If you want to thrive in our data soaked economy, it’s essential to become data literate, so you can spot these manipulations.
R has several features that make it a great tool for learning about data analysis. First, it’s really easy to learn. R is a simple language that you can pick up in a few hours. Additionally, R has an easy to use built in help system. If you need info on any command or method, it’s a few keystrokes away. R also has a lot of built in data sets to play with statistical techniques. This includes lots of popular demo statistical data sets that are well known in the statistics community.
As data analysis becomes more prevalent in the enterprise, you’re probably going to wind up working with data analysts and data scientists. Learning about some of the tools and techniques they use gives you common ground. It’s the same reason software developers should develop business and industry knowledge. Being able to connect with your team members on their terms makes you more than a run of the mill software developer.
If you’re an enterprise developer, R is worth a look. You can use R to learn valuable new skills using familiar tools. With a little effort, you’ll be able to slice and dice data for fun and profit.
To learn more, check out my post on R Resources
In an effort to improve my data analysis skills, I’ve been learning and speaking about the R programming language. Even if you don’t want to be a data scientist, (whatever the hell that means this week) learning some analysis skills can pay dividends. Data literacy is an essential skill in our data soaked economy and R is a good learning tool for analysis skills.
One of the harder things to do when starting in a new area is finding useful resources. It’s tough to find the digital needle in the web powered haystack. To make your life a little easier, here’s a list of the R resources I found to be useful.
There are three paths to getting R setup on your machine. If you’re a Visual Studio 2017 user, the easiest way to get R is to install the Data Science workload in Visual Studio. This will get you the Microsoft flavor of R and R Tools for Visual Studio.
If you’re not into Visual Studio, you can also install an R interpreter and R Studio. R Studio is a free R IDE. For interpreters, you can go with either the Microsoft flavor or the standard CRAN flavor of R.
If neither of those options work for you, you can also run R in a Jupyter Notebook. Jupyter is a web-based environment that makes it really easy to mix text and code. It’s used in many contexts including scientific research and virtual textbooks. To setup a local copy, start off by installing Anaconda. Anaconda is a data science environment that includes a plethora of handy analysis tools. After you install Anaconda, you’ll need to install R using the conda package manager. Then you can run Jupyter using the “jupyter notebook” command.
conda install -c r r-essentials jupyter notebook
R Studio Cheat Sheets
A collection of useful R related guides in PDF format.
R Tutor Tutorials
This site came in handy a few times while trying to find specific R issues.
Flowing data has a variety of useful articles on R and other data topics.
Don’t forget about the built-in R help system. Prefix any command with a question mark and it’ll search the R documentation for you. (Example: “?kmeans”)
I skimmed through a bunch of books on R, but the one I really liked was R: Recipes for Analysis, Visualization and Machine Learning. The writing was clear and the content was pragmatic. The task based format was easy to follow and implement. Another book that I used was R for Data Science.
R: Recipes for Analysis, Visualization and Machine Learning
R for Data Science
This list of resources is enough to help you get started in learning R. Go forth and learn how to slice and dice your data.
I’m really enjoying using R Tools for Visual Studio. It’s nice to learn something new (R) with something familiar (Visual Studio). I did, however, hit a snag when trying out the new IDE.
Upon installing the data science workload in Visual Studio (which is how you install R Tools), I couldn’t open up or create a project. File -> New Project just hung indefinitely. Usually, you expect these things to actually work, so I dropped a bug onto the R Tools for Visual Studio Github page. To my surprise, within about thirty minutes (on a Sunday night), someone asked me about my issue. While they didn’t give me an exact answer, they gave me the hint I needed to fix my issue. I was impressed by the speed and helpfulness of their response.
As some of you already know, our good friends at Microsoft maintain their own version of R. This version is faster, but it’s a point release behind the latest one. It’s a basic trade off between shiny and speedy. Turns out R Tools for Visual Studio doesn’t yet support the latest version. I had previously installed the non-Microsoft R, which was at v3.4 and Visual Studio defaulted to that version.
There are two ways to solve the issue. The easiest way is to just uninstall R 3.4 and use the Microsoft versions of R. If you are using R Studio as well, Microsoft’s R works fine. The second way is to go to R-Tools -> Windows -> Workspaces. From there, you can pick the version of R that’s being used by Visual Studio.
Regardless of which solution you go with, this issue, while vexing, is easy enough to fix.
Happy data hunting.
Update February 2018
The fine folks at Microsoft now have a template that integrates Angular CLI and .NET Core. I used it on my last Angular project and found it to be quite useful. One thing they missed is that the polyfills for Internet Explorer are not enabled by default, so you’ll want to go to polyfills.ts and enable those.
If you’re still interested in how to do this manually, continue on.
Angular is a fantastic platform for building rich client side apps, but let’s not forget about the back end. My choice for the back end is ASP.NET Core. If you’re not shy about spending a bunch of time setting up Webpack, Angular and ASP.NET Core is a fantastic combination.
As for Andy, he spent that break hunkered in the shade, a strange little smile on his face, he’d got Webpack to work. pic.twitter.com/3CHrD4ORTn
— I Am Devloper (@iamdevloper) October 29, 2016
However, I prefer to spend my time building applications, not configuring build tools. Angular CLI takes a lot of the pain out of using Angular, but it’s a self contained command line tool. Fortunately, Angular CLI and ASP.NET Core can happily co-exist. In this post, we’re going to build an application using these two technologies together. By the end, you’ll be ready to have all the goodness of Angular and ASP.NET Core without spending a week setting up Webpack.
Make sure you have .NET Core, Node.js and Angular CLI installed.
npm install -g @angular/cli
Fire up Visual Studio (I’m using VS 2017) and create a new ASP.NET Core Web Application. Select the Web API Starter. This doesn’t bring in any web stuff, which is ideal. We’re going to use Angular CLI to generate the client files.
Then go ahead and disable automatic Typescript compilation. We want CLI to compile our Typescript, not Visual Studio. Do this by adding the “TypeScriptCompilerBlocked” line to your csproj file.
Head on over to the Startup.cs and add in the static files middleware. You’ll have to install the “Microsoft.AspNetCore.StaticFiles” NuGet package. After that, add app.UseDefaultFiles() and app.UseStaticFiles() to your Configure() method.
After you get those setup, you’ll want to add some middleware to redirect those pesky 404s to the root file. This will allow you to navigate the application without having to start at the root each time you hit refresh. For this app, api routes are prefixed with “api”, so we’re excluding those routes from the check. We’re also excluding routes with a file extension since those are likely static assets.
To prevent the app from loading up the api/values endpoint by default, go to properties/launchSettings.json and change the “launchUrl” keys from “api/values” to “”.
At this point, our .NET Core app should be ready to go. Let’s move on to the Angular code.
We’re going generate our Angular app on top of our ASP.NET core app. To do this, go to the command line and navigate to the directory of your solution file. Then run “ng new <your app name>”.
You want the <app name> part to be the same as your .NET Core source folder. This will drop all of the CLI files into your ASP.NET Core root folder. It should look like this:
Angular has a default file structure, but it’s not ideal for the existing ASP.NET Core application. Fortunately, Angular CLI has some options that will allow us to change this structure. We want the client side code to be in a folder called “client-src” and the client side build artifacts to go to the wwwroot folder. To do this, rename the “src” folder to “client-src”. Then go to go to .angular-cli.json. This is the primary configuration file for Angular CLI. First, change “src” to “client-src”. Then change the “outDir” attribute from “dist” to “wwwroot”. This will drop all of the compiled assets into the wwwroot folder.
At this point, we can build the Angular application using Angular CLI. Navigate a command prompt into the main application folder and run “ng build”. This command will build the client side part of the application, dropping the build artifacts into wwwroot. The wwwroot folder should look like this:
At this point we should be able to run the app by hitting the Run button in Visual Studio. Unfortunately, we still have a two stage build pipeline. The first step being “ng build” to generate the client side files and then running the .NET Core app. To fix this, we can drop in a post build script: “ng build — aot”. This will compile the client side files (with ahead of time compiling) after the app builds.
If you’re using git, you’ll want to add the wwwroot folder to your .gitignore file. These files are generated, so you probably don’t want to check them in.
All of the demo code used in this post is available here:
This demo includes a full Angular application on top of ASP.NET core. Feel free to use this as a template or something to look at while building your own. You now have everything you need to get started building shiny applications using Angular CLI and ASP.NET Core.
Ever find yourself in high stakes situations where even the slightest miscommunication can bring everything crashing into the ground? If so, Crucial Conversations has you covered. Crucial Conversations is a book about how to better navigate high stakes conversations. Unlike most business books, Crucial Conversations is packed with actionable information.
Why is this an important skill for developers? People think software development as a process where people in a windowless basement turn pizza and caffeine into software. The reality is that software development is more about communication than technology. We build software in teams. We build software for people. We need to figure out what those people want. We need to be able to have honest conversations when things don’t go as planned (which is always). Creating a free flowing dialog is absolutely essential to creating valuable software.
Beyond building software. Developers who want a lucrative career find themselves in high stakes negotiations. These include, project scope discussions, salary negotiations, and job role discussions. Learning how navigate these situations can add thousands of dollars to your lifetime earnings. Not bad for a $10 book and a few hours of reading time.
Everyone has high stakes conversations. These include high pressure negotiations, impassioned arguments, and delicate interventions. Crucial conversations come in many different flavors. What links them together is that the results of these sorts of conversations have an out-sized impact on your life. Screw up one of these and you could be feeling the pain for years to come.
The key to navigating crucial conversations is to keep a free flowing dialog between the participants. To create free flowing dialog, maintain psychological safety. The primary goal of someone in a crucial conversation is to create and maintain a psychological safe space where both parties can express themselves without fear of anger or retribution. If everyone can get everything onto the table, you can usually figure out the correct path.
To cultivate psychological safety, you need to control your own emotions. Many people cast their own stories into “victim and villain” narratives. Playing the victim causes other people to get defensive. This defensiveness erodes psychological safety. Without psychological safety, people retreat to “silence or violence”. They either shut down or defend themselves with hostility. Usually emotional and verbal hostility, but sometimes physical hostility. Responding to a conversation with silence or aggression is “the fool’s choice”. Avoid the fool’s choice at all costs.
The book describes many techniques to maintain dialog. I’m not going to list them all out here, but a few include:
People generally have some shared goal in the conversation. Reminding people of that goal can inspire mutual cooperation.
Contrast and Clarification
Use contrast to clarify what you want. Prevent misinterpretation. Everyone has a plethora of cognitive biases. It’s easy to misinterpret wants and needs in high pressure situations. Contrast what you actually want with what people think you want.
“Start with Heart”
Figure out what you actually want from a situation and take your ego out of the equation.
Radical candor is where you are willing to challenge people directly, but with a high degree of empathy. It’s the useful alternative to being a wimp or an asshole.
Find out more about it here: https://www.radicalcandor.com/about-radical-candor/
People have a variety of intellectual distortions. These are also referred to as cognitive biases. Watch out for cognitive distortions in yourself or others. There are dozens of these, but Psychology Tools has put together handy chart detailing some of the major ones:
Ego is the Enemy
A big part of being a better negotiation is learning how to disarm your ego. Lots of people forget their mutual goal and try to “win” an argument. This is usually waste of time. Focus more on your goal and less on yourself. Ryan Holiday has a fantastic book about this.
Ego is the Enemy (Amazon)
Being able to successfully navigate tough conversations is an essential developer skill. Crucial Conversations has a variety of techniques to better navigate high stakes conversations. For the sake of yourself and everyone who has to work with you, work on your communication skills.
I recently went on a hunt for Angular (formerly known as Angular 2) profiling tools. Angular is a fantastic framework, but the component hierarchies can get a little crazy. Fortunately, there’s a way to tame the complexity. After some Google searching, I came across Augury. Augury is a debugging and profiling tool created by Google and Rangle.io.
Augury is simple to install. First, install the Augury Chrome Extension (Sorry Firefox lovers, no soup for you.) There is no step 2.
Once installed, Augury shows up as a new tab in your Chrome Developer Tools. If you have an Angular app running in debug mode (it doesn’t work on prod mode), the tab will show several visualizations of your application. The first one is the component tree, which lays out the components for whatever page you are on. Click a component to see the properties and events for it. You can also manipulate the underlying models and trigger events. Additionally, each component is has a link to its source code. If you want to set a breakpoint, just click and you’ll be right there.
You can also get a visualization of injected services by clicking on the Injector Graph. It’ll help you figure out where your dependencies come from.
If your application is using routing, click on the routing tree tab to get a visualization of the routing structure.You can click into the routes to see what url triggers them, along with other route information. If you happen to use lazy loading, those routes are marked as “lazy loaded” until you access them.
If you want to see a breakdown of your application’s module structure, click the NgModules tab. This is a good way to get a high level overview of your application.
Overall, Augury makes it easier to reason about your Angular applications. By visualizing the component trees, routing, and module structures, you get a high level overview of your application’s structure. Additionally, the extra debugging features add a layer of easy to the already fantastic Chrome Developer tools. I’ve added this to my day-to-day Angular tool belt and urge you to do the same.