C++ programming on Cloud 9

Just another Microsoft MVPs site

Blast from the past

I was just deep diving in some Active Directory stuff when google took me to an AD blog on msmvps.com and I suddenly remembered that I had a blog here as well. My last article is from 2012 which is so long ago that I can’t even remember what I was exactly doing back then. I’m fairly certain that almost noone here even remembers me.

My development days are long gone. Back in the day I was at the top of my field. These days, most of what I know is probably obsolete. Working as an employee, I drifted away from actual development and spend more time doing networking and Active Directory at the infrastructure level. A good bit of SQL as well. And I am currently preparing for exam 70-742 because I want to prove to myself I haven’t entirely become a dinosaur.

I’ll probably be updating this blog a bit with interesting tidbits concerning AD, powershell, or whatever I happen to think is interesting. the key word is ‘probably’ though. Outside of my tech work, I no longer spend my evenings reading tech articles, writing detailed how-to’s or developing open source code. I quit being an MVP because I wanted to focus on being a blade smith. These days, I am running a formal business called ‘snailforge’ which is the commercial aspect of me making high end blades for collectors.

Still, if I encounter something interesting I’ll post about it here. Meanwhile I may have to rename my blog because I don’t see myself doing much C++ in the near future.


Listing all stored procedures with their security config

For a code review at work, I had to write a code review document. among other things, I had to list the different stored procedures in my database, together with the security configuration of the stored procedures. A bit of googling got me the various pieces of the puzzle, and I put them together for my purpose:


select o.NAME AS object_name,
      dp.NAME AS principal_name,
           dp.type_desc AS principal_type_desc,
           p.state_desc AS permission_state_desc
   from    sys.all_objects o
   left    OUTER JOIN sys.database_permissions p
   on     p.major_id = o.OBJECT_ID
   left outer   JOIN sys.database_principals dp
   on     p.grantee_principal_id = dp.principal_id
where o.type= ‘p’ and  is_ms_shipped=0 and o.[name] not like ‘sp[_]%diagram%’
order by object_name

I used an outer join for the database permissions instead of an inner join like the person whose example I copied, because I wanted to show all procedures, even if they did not have security configuration attached.

Blog post formatting

My apologies for yesterdays blog post. If I look at it in the preview pane or in the editor, it looks well formatted with the various options presented in a neat list. I just noticed that in the actual blog view it looked like a programming book vomited all over my blog page. The problem is that I can’t really see anything I can change to make it look good. The only way I know atm is to copy / paste from word. The online blog editor is depressingly basic. I’ll figure something out.

EDIT: I discovered that the msmvps theme is responsible for this. I have no clue about CSS so rather than try to figure out what the exact problem is, I switched to a different theme and it is ok now.

Flavors of C++ with Visual C++

This came up in a forum discussion: what flavors of C++ are there, and what do they mean?

  1. There is regular C. Not C++ of course, but it bears mentioning because C is supported by the C++ compiler. Not all features of the C standard are supported. Which ones are is mostly customer driven (customers being the people with a lot of money, not you and me probably)
  2. regular C++. Also refered to as native C++, ISO C++. Code is portable across platforms, and compiled to native machine code. There is no ABI for C++, so compiled code is not binary compatible between compilers or even different versions of the same compiler.
  3. Managed C++. Also known as Managed Extensions for C++. It was the first version of the Microsoft C++ language for dealing with the CLR. It was an abomiation upon men. It was ugly and had a hst of problems. If you’ve never seen it, consider yourself lucky. If you ever had to use it, you have my sympathy. It was deprecated with Visual Studio 2005, and we like to pretend it never existed.
  4. C++/CLI this is the current version of the C++ language which targets the CLR. Contrary to Managed C++, the language and the syntax are user friendly. It is meant to allow native C++ and .NET to interoperate.
  5. C++/CX this is the version of C++ that is used for building C++ metro apps with XAML. It looks a lot like C++/CLI. when I first saw it, I thought it actually was C++/CLI. It is something different however, and for obvious reasons, you cannot mix C++/CLI and C++/CX in the same source file. The compiler would not know which is which.

C++0x step by step: range for

Range for is another of those syntactic sugar enhancements that enables you to do the same as before, but with less code. Often, you find yourself iterating through all elements of a container and doing something with those elements. In my original example, that was done by the following code:

for(auto i = data.begin(); i< data.end(); i++)
       cout << i->a << endl;

It is the traditional way to do this, but it means you’re declaring an iterator, getting the begin and end, and then ++ing from start to finish. With C++0x, you can write this in shorthand with the construct know as ‘range for’ which means what it says ‘Do this for the entire range’. It is very similar to the foreach keyword in C#.

for(auto &i: data)
       cout << i.a << endl;

As you can see, this is just a nicer way to do the same thing you did before.

Tech-ed survival tips, 3

7)      Go easy on the coffee. People tend to drink more coffee than they normally do. This has various reasons, including the fact that the coffee at tech-ed events tends to be high quality. If you do it can mess with your body in various ways.

8)      Go easy on the sugars. Every break, there are muffins, waffles, sugared snacks, and other sweets. If you start feeding a lot of sugar into your system, your slow metabolism shuts down. When the sugar has burned up, you’ll start feeling tired, drowsy and generally bad. At that point you’ll either have to get more sugar (which only makes the problem worse) or wait for your slow metabolism to kick in again. Before the latter happens, you’ll feel like crap for a while.

9)      An important point for people with one or more food allergies: do not assume that familiar dishes will be made with familiar ingredients. Case in point is the Berliner rolls they had for desert, 2 days ago. In Belgium, these are made only from buns, powdered sugar, and custard. The ones here also had a thick slice of strawberry between the bun and the custard. If I hadn’t checked, there is a possibility I might have eaten it. That would have been bad. In the same vein: if you allergic to some spices or herbs, do not assume that the ones in the dish are the ones you are familiar with.

Tech-ed survival tips, 2

4)      Take your notes during the session. You get so much information that you will have forgotten a lot by the end of the session if you don’t. You’ll also forget the structure in which it was presented. Writing things down as you go along makes it much easier. If you make your notes directly on your laptop, it is even more efficient because you can write down most of the text while you are there. You’ll only need a couple of minutes after the session for editing, instead of spending 15 minutes per session. Also, while taking and editing notes into blog posts is a lot of work, it forces you to make summaries for later reference, and you’ll remember things better.

5)      Read the summaries of the sessions you are thinking to go to. Sometimes, session titles are a bit deceptive, and it is annoying if you have to leave a session after 10 minutes and then find another session to go to while they are already in progress.

6)      Session summaries are not always clear, and sometimes there are sessions scheduled in the same timeslot. Adapt your planned schedule as the week goes by. If sessions on topics A and B are scheduled the same time, and topic A was already covered in an earlier session (even if that wasn’t known in advance from the summary)it makes sense to go to session B, even if you had originally planned to go to session A.

C++0x step by step: context sensitive shift operator >>

With C++0x, the >> operator has become context sensitive. If you don’t use templates you may wonder what the point is, but this is a very useful little feature that makes things a bit more readable and will save you many compiler errors if you use templates.

If you look at my previous C++ post, you’ll see that I declared a template variable like this:

vector < MyData < int> > data;

You’ll notice that there is a space between the ‘>’ symbols. This is because in previous versions of the standard, 2 consecutive ‘>’ symbols will always be considered to be a shift operator. It would be perfectly natural for the > symbols to be placed right next to each other. It would be more readable, and certainly more intuitive. In the new standard, this has been fixed. >> will now be interpreted context sensitive. If they are part of a template declaration, they are considered to be 2 individual symbols. If they are part of an expression, they are considered to be the shift operator. So from now on, you can do the following and it will finally compile cleanly.

vector < MyData < int>> data;

It is indeed a small thing, but anyone working with templates for a while has bumped into this more than oncce.

Tech-ed survival tips, 1

Over the years I’ve made a short list of things that help me survive tech ed.

1)      Arrive early. Travel the day before the event. It means you’ll sacrifice your Sunday afternoon. However, it also means you avoid the rush traffic, you can register and check in without needing to hurry, and if something goes wrong during travel, you have enough time to deal with that. Additionally, you can start the seminar well rested after a good night’s sleep and a relaxing breakfast

2)      If you have a choice in the matter, pick your hotel as close to the event as possible. This way, you don’t lose time in the mornings and evening on public transportation. Your schedule is busy enough already without adding additional hassles to it. And if you can walk to the event center, you are not bound to transportation schedules.

3)      Don’t party. Paying attention throughout the day, making notes and talking to people is tiring. You’ll need to unwind and recover if you want to be able to give it your all the next day. If you’ve only had 4 hours of sleep and a lot of rich food and alcohol the day before, you’ll have trouble to stay alert. Then again, tech-ed is also an excellent moment to network and talk with other people, so find a balance.

C++0x step by step: auto

With this short post, I am kicking off my new series of articles on the new C++ standard implementation in Visual C++ 2012. These articles will all be short, covering a single new thing each. This way you can see the impact of each change or improvement all by itself. That is easier to read, and of course also easier for me to write.

For the first article, I picked auto, simply because its impact on existing code bases is huge, and literally every C++ programmer can take advantage of it. For those who don’t yet know it: auto can be used as the variable type when declaring local variables, instead of the explicit type. The end result is still a strongly typed variable, because the compiler knows what the type of that variable has to be. It just doesn’t force you to type it yet again.

So you can use

 auto localvar = foo();

Instead of

MyType* localvar = foo();

It is much more convenient to use auto, because you no longer have to think about typing the right name. What makes it doubly useful is if during development, the return type of ‘foo’ changes, the change is transparent in your code. As long as the semantics of that return type stay the same, it will compile properly.

To give a more practical example: consider a simple vector with a template data type such as can be found in many C++ projects that make use of the STL. The really ugly thing about it is the need for an iterator. Even for such a simply example, the iterator type declaration is ugly. And if you ever need to update the type, it will involve a lot of work. Consider the following type: vector < MyData < int> > data; In order to iterate through that vector, we need the following loop:

for(vector < MyData< int > > ::iterator i = data.begin(); i< data.end(); i++)
    cout << i->a << endl;



As you can see, it is ugly. A traditional way to deal with this is to create typedefs for all iterator types that you use in your code. This works, but you still need to do that work. The typedefs are just a way to move the ugliness into a header file where you don’t notice it. And with typedefs you can still introduce some errors. C++0x otoh can use the auto keyword.




(auto i = data.begin(); i< data.end(); i++)
    cout << i->a << endl;

And this makes the resulting source code not only much easier to read (for the maintainer) but also easier to write, and if the type of ‘data’ should change, then as long as the public interface is compatible with before, the code will just compile without needing syntax modifications.


« Older posts