# Monday, December 07, 2015

The first keynote at CppCon this year was Bjarne Stroustrup (who invented the C++ language) announcing the C++ Core Guidelines. They are on Github and once he announced them, as Herb Sutter reported in the second keynote the very next day, they quickly became a trending topic across all languages. Here is a description of the guidelines from there:

The C++ Core Guidelines are a collaborative effort led by Bjarne Stroustrup, much like the C++ language itself. They are the result of many person-years of discussion and design across a number of organizations. Their design encourages general applicability and broad adoption but they can be freely copied and modified to meet your organization's needs.

The aim of the guidelines is to help people to use modern C++ effectively. By "modern C++" we mean C++11 and C++14 (and soon C++17). In other words, what would you like your code to look like in 5 years' time, given that you can start now? In 10 years' time?

The guidelines are focused on relatively higher-level issues, such as interfaces, resource management, memory management, and concurrency. Such rules affect application architecture and library design. Following the rules will lead to code that is statically type safe, has no resource leaks, and catches many more programming logic errors than is common in code today. And it will run fast - you can afford to do things right.

To me, these guidelines are the key to getting across my fundamental message that C++ does not have to be hard, scary, complicated, or dangerous. The language may still say “it’s your foot!” but the guidelines, and the tools they can drive, are quite the opposite.

You probably know that Visual Studio has a static analyser built in. (You should, anyway, I’ve blogged about it.) It will catch things like this:

    int* p = nullptr;
    *p = 10;   

But it doesn’t mind things like this:

    int arr[10];        
    int* p2 = arr;

Two lines, two violations of the guidelines – I’m not initializing any of the elements of arr, and then I am using its address as a regular old pointer. Now, there’s nothing wrong with regular old pointers – some people have got quite a hate on for them with the rise of genuinely smart pointers, but pointers are fine. Using pointers to control lifetime isn’t fine, because it’s impossibly difficult. But pointers themselves are fine. What’s not fine here is the “decay” of an array into a pointer – folks from other languages don’t expect that at all, and some marvelous bugs have hidden behind this simple bit of helpfulness from the compiler. So there’s a guideline that says don’t do that. Specifically:

(I’m giving you a picture of code because if you want to copy and paste you should go to the live, always updated, guidelines on github.)

This guideline is part of a “profile” – a particular set of rules that are designed to be enforced and that are supported by tools. Well, when I say tools I might be overstating the case a little. There’s just one tool at the moment, but that could be enough!

This tool, C++ Core Checker, is on the NuGet Gallery. You don’t have to get it from there though. You get it, and use it, from inside Visual Studio 2015. Any version will do. If you don’t use Visual Studio normally, just get and install the Community Edition, which is free and is ok to use for commercial purposes, from https://www.visualstudio.com/ . (Need the fine print? if you’re using it as a person, you can do whatever you like. If you work for a company with less than 250 PCs and less than a million dollars US in revenue, again you and up to 4 of your coworkers can use it for whatever you like. If you work for an “enterprise” company then any and all of the employees can still use it for learning purposes or to work on open source.) Note that Visual C++ isn’t part of the Typical install, so you’ll need to choose Custom and select Visual C++:

So once you have Community Edition or some edition of Visual Studio, make a console application and put in the two bad lines of code. Build it and then also run static analysis on it (On the Analyze menu, choose Run Code Analysis, On Solution.) You won’t get any warnings or errors. That’s your pre-guidelines life. You’re doing something inappropriate and nobody is telling you.

Now, add the checker to your solution. This is solution-by-solution, not a change to how Visual Studio does static analysis. On the Tools menu, choose NuGet Package Manager, Package Manager Console. In the console window that appears, type Install-Package Microsoft.CppCoreCheck and press enter. You will see output like this:

Attempting to gather dependencies information for package 'Microsoft.CppCoreCheck.14.0.23107.2' with respect to project 'ConsoleApplication1', targeting 'native,Version=v0.0'
Attempting to resolve dependencies for package 'Microsoft.CppCoreCheck.14.0.23107.2' with DependencyBehavior 'Lowest'
Resolving actions to install package 'Microsoft.CppCoreCheck.14.0.23107.2'
Resolved actions to install package 'Microsoft.CppCoreCheck.14.0.23107.2'
Adding package 'Microsoft.Gsl.0.0.1' to folder 'c:\users\kate\documents\visual studio 2015\Projects\ConsoleApplication1\packages'
Added package 'Microsoft.Gsl.0.0.1' to folder 'c:\users\kate\documents\visual studio 2015\Projects\ConsoleApplication1\packages'
Added package 'Microsoft.Gsl.0.0.1' to 'packages.config'
Successfully installed 'Microsoft.Gsl 0.0.1' to ConsoleApplication1
Adding package 'Microsoft.CppCoreCheck.14.0.23107.2' to folder 'c:\users\kate\documents\visual studio 2015\Projects\ConsoleApplication1\packages'
Added package 'Microsoft.CppCoreCheck.14.0.23107.2' to folder 'c:\users\kate\documents\visual studio 2015\Projects\ConsoleApplication1\packages'
Added package 'Microsoft.CppCoreCheck.14.0.23107.2' to 'packages.config'
Successfully installed 'Microsoft.CppCoreCheck 14.0.23107.2' to ConsoleApplication1
PM>

This changes your project settings so that analysis runs this Core Checker for you. Repeat the analysis step and this time the new tool will run and you will get output like this:
------ Rebuild All started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
  stdafx.cpp
  ConsoleApplication1.cpp
  ConsoleApplication1.vcxproj -> c:\users\kate\documents\visual studio 2015\Projects\ConsoleApplication1\Debug\ConsoleApplication1.exe
c:\users\kate\documents\visual studio 2015\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(9): warning C26494: Variable 'arr' is uninitialized. Always initialize an object. (type.5: http://go.microsoft.com/fwlink/p/?LinkID=620421)
c:\users\kate\documents\visual studio 2015\projects\consoleapplication1\consoleapplication1\consoleapplication1.cpp(10): warning C26485: Expression 'arr': No array to pointer decay. (bounds.3: http://go.microsoft.com/fwlink/p/?LinkID=620415)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Where it says "type.5" and there's a link, that's to the specific rule in the "type" profile that this code breaks. And where it says "bounds.3", the same - I showed a picture of bounds.3 up above.

Isn’t that great? Come on, it’s great! The tool will add more rules as we move through 2016. I’m going to have a lot more to say about the Guidelines as well. But this is a great place to start.Why not point it at some of your own code and see what happens?

Kate

Monday, December 07, 2015 1:54:57 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]
# Thursday, November 26, 2015

If you have an MSDN subscription, you know that it provides a number of benefits besides software licenses - you get Azure hours, you can use Visual Studio Online, and so on. Those are well worth the price of the subscription. But it also gives you access to a number of Pluralsight courses, completely free. If you have a Professional Subscription, you get access to 30 courses, and if you have an Enterprise subscription, you get access to 45 courses.  (You want one of the over 4500 other courses? You'll need a full subscription, but you can buy that at 30% off, which helps.)

And yes, my latest course, Visual Studio 2015: Essentials to the Power-User is one of the ones you'll get access to. So go, check it out!

Kate

Thursday, November 26, 2015 1:29:22 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]
# Monday, November 09, 2015

I have a new Pluralsight course on Visual Studio called Visual Studio 2015: Essentials to the Power-User. It starts at the beginning, so if you're new to Visual Studio it will help you get started, but carries on "to 11" as it were, covering things many everyday users of Visual Studio don't know. Here are the modules, each with their length:

  1. Getting Started (42:08)
  2. Projects and Solutions (13:23)
  3. Namespaces, Folders, and Files(27:03)
  4. Understanding and Personalizing Visual Studio UI Components (26:57)
  5. Exploring Relationships in Your Code(36:41)
  6. Using Search and Find Effectively(28:15)
  7. Letting Visual Studio Help You (46:28)
  8. Basic Debugging Features (24:04)
  9. Additional Debugging Features (44:30)
  10. Working with Designers (39:37)
  11. Useful Extensions (39:54)
  12. IntelliTrace and Code Map (25:57)

If you don't have a Pluralsight subscription, click the Author link over on the right hand side of this blog - click Subscribe, then Start 10-Day trial. That should give you a good idea of how valuable the subscriptions can be. (My company buys subscriptions for my staff, and I use my free author one all the time. It's a great way to learn a new technology.)

My main goal in this course was to have Visual Studio make sense to the learner. There are so many ways to do any action that sometimes when you learn something it seems pointless, and you quickly get tired of learning an endless parade of similar features. I worked hard to put these into an order that would lead naturally through the capabilities of the tool, and put things in context. If you watch all 12 modules, you'll know more Visual Studio than most developers - and you'll have a productivity boost to show for it that should be pretty impressive! Please do give it a try.

Kate

Monday, November 09, 2015 12:18:54 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]
# Thursday, October 08, 2015

On the Pluralsight platform, subscribers can access a discussion area for each course. The traffic in mine is light enough that I have set up an alert to send me an email for each new comment. I just got one for my StackExchange course that brought a huge smile to my face:

I have actually tried not to use Stack Exchange and stick to other sites.  I had several bad experiences and have not gained any reputation at all on any questions that I asked.  I have even deleted questions due to downvotes or other negative activity.  Well after watching this, I understand the problems that I have had in the past.  I really enjoyed hearing this and knowing the mechanics of how this works [...] I now know more about it to help me find the answers that I need when I am head scratching my way through coding.

When I first started reading I was thinking "here's a comment about how StackExchange is horrible and why have a course on it" - something I hear from some of my friends. But then it took a sharp right turn to the exact reason why I wrote the course. I mean this is exactly the persona I had in mind - someone who needs answers, but because of not knowing the way the sites work, not only isn't getting them, but is having an unpleasant experience and ends up avoiding the sites.

When I decide to write a course I let myself imagine some possible outcomes. This comment is just the sort of outcome I was hoping for. It keeps me motivated to create more :-)

Kate

Thursday, October 08, 2015 5:43:35 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [1]
# Saturday, September 26, 2015
Back when I first started going to conferences, the schedules typically ran 9 or 9:30 to 4 or 4:30. I used to bring a book to read in the evenings in case I didn’t like what was on TV. Then I started getting invited to dinners and parties and planning meetings and conference days got a lot longer for me. But what I’ve noticed recently is that conference days are getting a lot longer for everyone. People have come all this way and are willing to pack a lot into each day. I’m writing this on the last day of CppCon where there is content starting at 8am and running until 10pm. There's even content over the two hour lunch break! That’s a long day, and a bunch of them in a row makes for a long long week. So here are some tips for how to handle that kind of week. I’m going to be specific to CppCon, because I think a lot of my readers should attend it, but other conferences will have equivalents to everything I’m mentioning here; I’ll let you do the mapping yourself.

First, have a schedule. Weeks before the conference, mark out what talks you want to attend. Have a goal of selecting two talks in most time slots. Then if your first choice is not as good as you expected, or the room is full and you don’t want to stand, you know exactly where to go for your second choice. Have that schedule in your pocket – on your phone, or on a piece of paper – so you have no lost time figuring out where to go. (CppCon uses Sched, which mails you each day's schedule in the morning, making it easy to have with you.) Don’t be the person who shows up at 9 only to learn there were sessions at 8. Check the schedule at least once a day during the conference in case things are being added. Tip: things are being added, you can count on it.

Second, plan ahead to take care of the physical body that is carrying your brain from session to session. It’s really a simple matter to have a few granola bars and a bottle of water in your bag. If you miss a snack, you can still have something to eat or drink. Bring a light sweater in case you are in the cold room. Bring some painkillers if you might get a headache from sitting somewhere loud. Bring whatever little comforts you need to keep yourself from getting whiny and leaving early to go to your peaceful hotel room and watch TV. (That said, there’s always one day in a one-week conference where I go back to my room for an afternoon nap. It’s the only way I can stay functional during long and intellectually-intense days. Just make sure you’re doing it for a brain recharge and not for something you could have avoided by bringing a small item with you to the conference centre.)

Third, think about how you’re going to take notes. A paper notebook? Bring a spare pen, too. Your phone? Your laptop? Or are you just going to immerse yourself in the experience and use the videos if you want to check something later? Whatever your plan is, bring what you need to be able to use it. Power is always a challenge at conferences – I like to bring an external battery for my phone so it can charge in my bag. Think about what your bag is going to weigh and consider leaving the laptop at the hotel and getting by with a phone and some paper for notes. It’s really liberating not to be lugging a heavy bag, in fact surprisingly so.

Fourth, before you arrive (at the latest, on the plane to the conference) write up your goals for the conference. Do you want to meet people? Specific people, or some number of people, or people from a particular industry? Do you want to learn something specific? (Perhaps this is the year to understand SFINAE, or be able to follow along in a talk that includes template meta programming, or “get” those Haskell jokes people are always telling.)  Maybe you want to tell people about something? Tweet some number of times? Blog some number of times?  Have a plan. Have goals. Check yourself against these goals each morning, and adjust your plan for the day if you need to, so that you move towards those goals each day.

When you arrive at the conference, scout out the amenities. Where are the bathrooms? Are there tables and chairs? Are there tables and chairs with power? On Day 1, pay close attention to the food and drink pattern. Is coffee always available, or only at certain times? Where does the food appear? Knowing this will take away any worry you may be carrying around that you may miss something and not get another chance at it. It will also save you from taking extras of things and lugging them around all day when you don’t really need them. I also like to work out patterns related to what rooms I’ll be in – that I’ll be on the same floor all afternoon, for example. It just makes me feel a little more settled and centred.

Looking after your body doesn’t stop with what you planned and what you brought. I start each day with 5 minutes of stretching which makes a big difference to how I feel all day. I also try to use the stairs instead of the escalators – less lining up and it makes me feel better too. I go ahead and eat the snacks, many of which are not part of my normal day (brownies in the afternoon? bag of chips at lunch?) but not to excess. CppCon has fruit and other options that are not all about fat, sugar, and caffeine, and it’s often a smart choice to go with those rather than the straight-up treats. Try not to get too far from normal. If you normally have 5 cups of coffee a day, then you can do that during the conference, but if you’re a one-cup-a-day person, perhaps don’t go beyond 2 or 3 a day while you’re here. Same advice for alcohol – if you dramatically increase your consumption over the course of the week, you’re likely to feel uncomfortable by the time Thursday or Friday rolls around. The one thing you should be sure to take in more of than usual is water – whether you’re eating more sugar than usual, drinking more caffeine and alcohol than usual, or just walking a lot more than usual from room to room in a conference centre, extra water is what you need to compensate. If you grab a bottle of water at a snack break, hang on to it when it’s empty – typically most conference rooms have a watercooler or bubbler by the door where you can refill that bottle whenever you want. Can’t stand water? Bring something to flavour it with – pick up some powders or drops at home and try them out to see which one you like. It’s way more efficient than hanging around hoping that this is the break they have juice at, or leaving the conference centre on a half hour walk for a convenience store.

As the conference goes on, be aware of how you are spending your time. For example, if you check your email during a session, but then take a peek at Twitter, and then at your personal Facebook – are you even really in the session anymore? Don’t be afraid to leave if this is not the session for you. You can go to another one, or talk to other attendees out in the hall, or go back to the hotel for a one hour nap. Almost anything is better than ignoring a speaker and killing time on your laptop or phone. And if you’re not prepared to leave, then perhaps you just need to start paying more attention to the session – assuming it’s material you actually are interested in. Take a look at those goals you wrote. Have you tweeted recently? Blogged? Learned that thing? Met enough people? Will staying in this session and listening meet your goals, or should you go out to the hall and work on a goal? Are you just chatting with your own coworkers, or someone you’ve known for years? Building and strengthening relationships is great, of course. That doesn’t mean that discussing the football game with your cubicle-mate is a good use of your time at a place you flew 5 hours to attend. Maybe you can walk around and find a way to join a conversation with a speaker or someone else you wouldn’t normally meet. Just standing there listening can be very enlightening even if you don’t end up saying much.

If you’re not normally a tweeter, blogger, or talker-to-strangers, a conference is a great place to start. There are immediate benefits. Perhaps your question will be answered, or your point will be repeated and quoted, or you’ll make a new friend or business connection. This will give you reinforcement for doing that, of course. As you meet your goals, make a record of that, so you can easily answer questions about what you learned or accomplished during the conference. Consider writing a summary when you’re done – for yourself, or for whoever funded the trip. A chronological structure is natural – Monday morning I went to a talk called X and learned Y or met Z, at lunch Monday I talked to A and B who encouraged me to look into C, Monday afternoon I went to a talk on C – but be sure to have an executive summary that reads a little less like a diary. Start writing it during the conference and polish it on the trip home. Once you get back to the office, writing that summary is going to get harder and harder, so don’t put it off.

Attending conferences is a great way to boost your career – when you do it well you learn a lot in a short time, meet luminaries of your industry and people just like you, raise your profile and your confidence, and have a wonderful time. When you do it poorly, you get tired, hungover, lonely, overwhelmed, and bored. Put in the effort to plan and prepare, and you will be in a great position to reap the rewards.

Saturday, September 26, 2015 11:39:17 AM (Eastern Daylight Time, UTC-04:00)  #    Comments [0]
# Thursday, June 11, 2015

One of the CppCon sponsors, Bloomberg, is running a contest for students in university or college and giving away trips to attend CppCon2015 in September in Bellevue, Washington:

The series of seven weekly challenges will kick off on June 22, 2015, and each week contestants will be provided a different set of problems to solve via Bloomberg’s cloud-based CodeCon platform. Each week’s winner will earn a trip to CppCon in September. The list of seven winners will be announced and notified via email on August 5.

Interested? You should be. CppCon is a great experience for students and one you won't soon forget.

Kate

Thursday, June 11, 2015 3:38:34 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0]
# Tuesday, January 13, 2015

ACCU has announced the schedule for their 2015 conference in Bristol, so I can announce that it includes me!

James and I are adding quite a lot of material, so if you saw this talk at CppCon, you should probably come and see it again at ACCU. Alternatively, you could come to the conferences and watch one of the conflicting talks and take excellent notes, because I really wish I could be at those as well!

I first went to ACCU two years ago, spending my own money for travel and the registration fee. I enjoyed it immensely and learned a lot, so it's a real thrill to be speaking there this year. I can't wait!

Early bird rates last till the end of February. Register as soon as you can, and I'll see you there.

Kate

Tuesday, January 13, 2015 12:48:48 PM (Eastern Standard Time, UTC-05:00)  #    Comments [1]
# Monday, January 12, 2015

My friend (and fellow Pluralsight author) Kathleen Dollard is coming to town, and will speak at the East of Toronto .NET User Group on "What's New in C# 6.0".

The next release of Visual Studio includes some major language enhancements that every developer should be aware of. Get up to speed on forthcoming enhancements quickly with this user group meeting from Microsoft MVP and language guru Kathleen Dollard.

Join us at 6pm at the Pickering Central Library! Please register at the Meetup page. See you there!

Kate


Monday, January 12, 2015 6:10:01 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]