CSharpFeeds - All your C# feeds in one place.

Sponsors

Feed: Eric Gunnerson's Compendium : CSharp

Site: http://blogs.msdn.com/b/ericgu/archive/category/2254.aspx Link: http://blogs.msdn.com/ericgu/rss.aspx?CategoryID=2254

Wednesday, February 23, 2011

Default parameters in C#

by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 2/23/2011 4:51:45 PM

From an internal discussion we're having on the advisability of using default parameters in C#: Currently, the pain and limitation of doing overloads forces you to rethink how a method should work. Consider the following:  Process(int a); Process(int a, float b); Process(int a, float b, string c);   If I now need to change how that works in some situations, I could add a boolean to control that behavior, but it’s not obvious how to add it to the current overload scheme. I can do ...

[ read more ]

Saturday, August 15, 2009

Introduction to HealthVault Development #13: More more than one person

by ericgu via Eric Gunnerson's Compendium : CSharp on 8/15/2009 12:47:33 AM

In the last installment, we modified our application so that it could switch between family members for data display and entry. This time, we’re going to add a table at the top that shows the current weight for all family members. We add the table right after the <h1> title: Family Summary <br /> <asp:Table ID="c_tableSummary" runat="server" BorderWidth="1px" CellPadding="2" CellSpacing="2" GridLines="Both"/> ...

[ read more ]

Friday, January 23, 2009

Introduction to HealthVault Development #4 – Storing and retrieving weights

by ericgu via Eric Gunnerson's Compendium : CSharp on 1/23/2009 5:03:28 PM

We are now ready to make our WeightTracker application do something useful. That something useful is composed of two stories: The user enters a weight, and it’s stored to the user’s HealthVault record The weight measurements in the user’s record are displayed We’ll do them in order. Entering and storing a weight Looking at default.aspx, you will find that it’s prepopulated with some controls that we’ll be using in the tutorial. Some of the ones that we don’t need yet are marked as ...

[ read more ]

Tuesday, December 02, 2008

Benchmarking, C++, and C# Micro-optimizations

by ericgu via Eric Gunnerson's Compendium : CSharp on 12/2/2008 1:01:57 AM

Two posts (1 2) on C# loop optimization got me thinking recently. Thinking about what I did when I first joined Microsoft. Way back in the spring of 1995 or so (yes, we did have computers back then, but the Internet of the time really *was* just a series of tubes), I was on the C++ compiler test team, and had just picked up the responsibility for running benchmark tests on various C++ compilers. I would run compilation speed and execution speed tests in controlled environments, so that we ...

[ read more ]

Benchmarking, C++, and C# Micro-optimizations

by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 12/2/2008 1:01:57 AM

Two posts (1 2) on C# loop optimization got me thinking recently. Thinking about what I did when I first joined Microsoft. Way back in the spring of 1995 or so (yes, we did have computers back then, but the Internet of the time really *was* just a series of tubes), I was on the C++ compiler test team, and had just picked up the responsibility for running benchmark tests on various C++ compilers. I would run compilation speed and execution speed tests in controlled environments, so that we ...

[ read more ]

Wednesday, July 02, 2008

Why does C# always use callvirt?

by ericgu via Eric Gunnerson's Compendium : CSharp on 7/2/2008 7:22:00 PM

This question came up on an internal C# alias, and I thought the answer would be of general interest. That's assuming that the answer is correct - it's been quite a while. The .NET IL language provides both a call and callvirt instruction, with the callvirt being used to call virtual functions. But if you look through the code that C# generates, you will see that it generates a "callvirt" even in cases where there is no virtual function involved. Why does it do that? I went back through the lang ...

[ read more ]

Why does C# always use callvirt?

by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 7/2/2008 7:22:00 PM

This question came up on an internal C# alias, and I thought the answer would be of general interest. That's assuming that the answer is correct - it's been quite a while. The .NET IL language provides both a call and callvirt instruction, with the callvirt being used to call virtual functions. But if you look through the code that C# generates, you will see that it generates a "callvirt" even in cases where there is no virtual function involved. Why does it do that? I went back through the lang ...

[ read more ]

Tuesday, October 30, 2007

HealthVault Data Types - a custom data type architecture

by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 10/30/2007 12:36:00 AM

In my last post, I showed how to create custom data types, but there's an obvious problem with that approach. There's only one of them. That means that when you do a query for your custom type, you get all the custom types that meet your filter. If your application creates multiple custom types, then it needs a layer that can do the appropriate thing and give you the types that you want. As is often the case in computer science, we're going to approach it by adding in a layer of indirection. We ...

[ read more ]

Monday, October 29, 2007

HealthVault Data Types - Custom Data Types

by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 10/29/2007 11:01:00 PM

So, you're using the SDK, and it turns out that you need to store some data, and there isn't a built-in type that stores what you need. What do you do? The SDK provides a way for you to create your own custom type. There's an important limitation to this technique that I'll touch on later, so make sure to read all the way through. I would tell you now, but that would ruin the suspense. Creating the class First of all, you'll need to create the class. I'm going to be using a simplified ver ...

[ read more ]

Tuesday, July 03, 2007

Member names and UI controls

by ericgu via Eric Gunnerson's Compendium : CSharp on 7/3/2007 12:17:00 AM

A follow-on to the previous discussion about member names. There were a variety of opinions, some of which argued for using no prefix at all. For those of you who are in the group, I'm interested in how you manage things when you are doing UI work, and having to deal with your 3 member variables being swallowed by the 100 methods already defined in the base class. Is this an issue for you? If so, how do you deal with it? ...

[ read more ]

Thursday, June 28, 2007

YAGNI and unit tests...

by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 6/28/2007 7:48:00 PM

Thanks for your comments. I decided to go ahead and write the unit tests for that layer, both because I knew what not writing them would be like, and I wanted to play with wrapping/mocking a system service. I also decided - as some of you commented - to do the right thing and encapsulate it into a class. That would have happened long ago, but though I've written it several times, I don't think I've ever duplicated it within a single codebase - and the codebases where I did write it are pretty d ...

[ read more ]

YAGNI and unit tests...

by ericgu via Eric Gunnerson's Compendium : CSharp on 6/28/2007 7:48:00 PM

Thanks for your comments. I decided to go ahead and write the unit tests for that layer, both because I knew what not writing them would be like, and I wanted to play with wrapping/mocking a system service. I also decided - as some of you commented - to do the right thing and encapsulate it into a class. That would have happened long ago, but though I've written it several times, I don't think I've ever duplicated it within a single codebase - and the codebases where I did write it are pretty d ...

[ read more ]

Wednesday, June 27, 2007

Does YAGNI ever apply to tests?

by ericgu via Eric Gunnerson's Compendium : CSharp on 6/27/2007 8:03:00 PM

I've been writing a small utility to help us do some configuration setup for testing. It needs to walk a directory structure, find all instances of a specific xml file, and then make some modifications to the file. I TDD'd the class that does the XML file stuff, and I'm confident that it's working well. I'm now going to do the class to walk of the directory structure and find the files. And there is my dilemna. I don't know if I'm going to do TDD on that. I know exactly how to write it, I've wr ...

[ read more ]

Does YAGNI ever apply to tests?

by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 6/27/2007 8:03:00 PM

I've been writing a small utility to help us do some configuration setup for testing. It needs to walk a directory structure, find all instances of a specific xml file, and then make some modifications to the file. I TDD'd the class that does the XML file stuff, and I'm confident that it's working well. I'm now going to do the class to walk of the directory structure and find the files. And there is my dilemna. I don't know if I'm going to do TDD on that. I know exactly how to write it, I've wr ...

[ read more ]

Wednesday, June 20, 2007

Lost Column #2: Unsafe Image Processing

by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 6/20/2007 10:17:00 PM

(circa November 15, 2001)  I think this column stands up pretty well without caveat. I should note that I wrapped the image class to provide nicer pixel-based access in a class you can find here. I suggest basing your code on that rather than what I wrote in the column. I should also note that the grey-scale code isn't what you want. The human eye is not equally sensitive to all colors, so you should use the following to determine the intensity:  0.299 * red + ...

[ read more ]

Lost Column #2: Unsafe Image Processing

by ericgu via Eric Gunnerson's Compendium : CSharp on 6/20/2007 10:17:00 PM

(circa November 15, 2001)  I think this column stands up pretty well without caveat. I should note that I wrapped the image class to provide nicer pixel-based access in a class you can find here. I suggest basing your code on that rather than what I wrote in the column. I should also note that the grey-scale code isn't what you want. The human eye is not equally sensitive to all colors, so you should use the following to determine the intensity:  0.299 * red + ...

[ read more ]

Saturday, June 16, 2007

To m_ or no to m_, that is the question...

by ericgu via Eric Gunnerson's Compendium : CSharp on 6/16/2007 2:03:00 AM

I apologize for shocking your system by posting more than once a month - there are reasons for that, but I unfortunately can't get into them right now - but Keith added an interesting comment to my last post. He said: Side Note: a bit disturbing you're using C++ naming conventions in C# though? :)  No doubting your a ninja coder and I love your stuff, but seriously, bringing the m_ prefixing into C# is a bit of a "cant teach an old dog new tricks" thing.   This is pretty close to a "re ...

[ read more ]

To m_ or no to m_, that is the question...

by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 6/16/2007 2:03:00 AM

I apologize for shocking your system by posting more than once a month - there are reasons for that, but I unfortunately can't get into them right now - but Keith added an interesting comment to my last post. He said: Side Note: a bit disturbing you're using C++ naming conventions in C# though? :)  No doubting your a ninja coder and I love your stuff, but seriously, bringing the m_ prefixing into C# is a bit of a "cant teach an old dog new tricks" thing.   This is pretty close to a "re ...

[ read more ]

Friday, June 15, 2007

The problem with intellisense

by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 6/15/2007 8:58:00 PM

Today I was working with some sample code, and I came across a misspelling. Not a big deal - there was a field that was named "m_postion" rather than "m_position". But that got me thinking... In the past, that sort of thing wouldn't have happened. You would have written: int m_postion; but then, when you wrote your code, you would have written: m_position = 5; and the compiler would have complained. But with intellisense, you now just pick whatever looks right in the popup list, and the mistakes ...

[ read more ]

The problem with intellisense

by ericgu via Eric Gunnerson's Compendium : CSharp on 6/15/2007 8:58:00 PM

Today I was working with some sample code, and I came across a misspelling. Not a big deal - there was a field that was named "m_postion" rather than "m_position". But that got me thinking... In the past, that sort of thing wouldn't have happened. You would have written: int m_postion; but then, when you wrote your code, you would have written: m_position = 5; and the compiler would have complained. But with intellisense, you now just pick whatever looks right in the popup list, and the mistakes ...

[ read more ]

Wednesday, June 06, 2007

App Domains and dynamic loading (the lost columns)

by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 6/6/2007 7:10:00 AM

As promised, I'm going to start republishing some of my columns that were eaten by MSDN.   I spent some time reading this one and deciding whether I would re-write it so that it was, like, correct. But it became clear that I didn't have a lot of enthusiasm towards that, so I've decided to post it as is (literally, as-is, with some ugly formatting because of how I used to do them in MSDN).   I also am not posting the source, though I might be tempted to put it someplace if t ...

[ read more ]

App Domains and dynamic loading (the lost columns)

by ericgu via Eric Gunnerson's Compendium : CSharp on 6/6/2007 4:10:00 AM

As promised, I'm going to start republishing some of my columns that were eaten by MSDN.   I spent some time reading this one and deciding whether I would re-write it so that it was, like, correct. But it became clear that I didn't have a lot of enthusiasm towards that, so I've decided to post it as is (literally, as-is, with some ugly formatting because of how I used to do them in MSDN).   I also am not posting the source, though I might be tempted to put it someplace if t ...

[ read more ]

Tuesday, February 27, 2007

Taking snapshots of WPF animation

by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 2/27/2007 7:10:00 PM

I've been playing around with WPF animation, and ended up wanting to take a snapshot of an animation at a specific place. Specifically, I have a canvas that has some pictures on it that are moving, and I want to be able to save a bitmap of what it looks like at a specific time. Getting the bitmap is pretty easy, using a RenderTargetBitmap and a VisualBrush. private BitmapSource CaptureScreen(Visual target){     Rect bounds = VisualTreeHelper.GetDescendantBounds(target);  &nb ...

[ read more ]

Taking snapshots of WPF animation

by ericgu via Eric Gunnerson's Compendium : CSharp on 2/27/2007 4:10:00 PM

I've been playing around with WPF animation, and ended up wanting to take a snapshot of an animation at a specific place. Specifically, I have a canvas that has some pictures on it that are moving, and I want to be able to save a bitmap of what it looks like at a specific time. Getting the bitmap is pretty easy, using a RenderTargetBitmap and a VisualBrush. private BitmapSource CaptureScreen(Visual target){     Rect bounds = VisualTreeHelper.GetDescendantBounds(target);  &nb ...

[ read more ]

Friday, February 02, 2007

More on properties vs fields

by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 2/2/2007 7:59:00 PM

Some nice comments on what I wrote. First, a non-controversial question. Robin asked whether you would capitalize them in that case, and I think you should, as having something accessed externally that isn't properly cased will be surprising to people. Dani - and others - have pointed out that properties leave your options open in case the software is used in ways that make the property more useful. This is certainly true, and I think it comes down to how you value that flexibility over the tax ...

[ read more ]

Thursday, February 01, 2007

Properties vs public fields redux...

by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 2/1/2007 8:29:00 PM

My blog reader burped recently, and gave forth a post (and reply) than Rico wrote last September, but since I didn't comment on it then, I'll comment on it now. And, yes, I've written about this in the past... Basically, this revolves around the question of using properties, or using public fields. And I have a slightly different point to make than Rico is making, his point being that sometimes you need to break these guidelines for performance reasons (which I agree with, but which is not ...

[ read more ]

Thursday, January 04, 2007

XNA

by Eric Gunnerson via Eric Gunnerson's Compendium : CSharp on 1/4/2007 12:30:00 AM

I've been meaning to write a post about XNA for quite a while now. I mean, "XNA Game Studio Express", ably managed by ex-C#-PM Joe. I was waiting until I did something useful with it, but that apparently is going to be a while... I've never written games professionally, but I've written a few hobby games or demos in my time. A lunar lander written in Apple II BASIC (with a custom controller box hooked to the paddle port...). A multi-user networked version of SpaceWar! that ran on VMS workstation ...

[ read more ]

Wednesday, January 03, 2007

XNA

by ericgu via Eric Gunnerson's Compendium : CSharp on 1/3/2007 9:30:00 PM

I've been meaning to write a post about XNA for quite a while now. I mean, "XNA Game Studio Express", ably managed by ex-C#-PM Joe. I was waiting until I did something useful with it, but that apparently is going to be a while... I've never written games professionally, but I've written a few hobby games or demos in my time. A lunar lander written in Apple II BASIC (with a custom controller box hooked to the paddle port...). A multi-user networked version of SpaceWar! that ran on VMS workstation ...

[ read more ]

Tuesday, September 26, 2006

Sandcastle - MSDN-style docs for your assemblies

by ericgu via Eric Gunnerson's Compendium : CSharp on 9/26/2006 12:57:00 PM

For a *long* time, whenever I spent time with C# customers, I would invariably get asked, "How do I create docs for my assemblies?". And my best answer was either, "there's a XSLT file that makes the XML look a little better" or "you might want to consider NDoc". Neither of which was a great answer. The XSLT was quite inferior to what people wanted, and NDoc also had limitations. That issue was not unnoticed inside MS, but it's taken a while to address it, and I was otherwise occupied at the ...

[ read more ]

Tuesday, August 08, 2006

Other views on programming sins...

by ericgu via Eric Gunnerson's Compendium : CSharp on 8/8/2006 2:31:00 PM

At the beginning of the sin-tacular, I asked for people to come up with their own lists. And here they are: 7 Deadly Sins of Software Development (Bill's House O Insomnia) The Seven Deadly Sins of Programmers (.NET Data Practices) Seven Deadly sins of Software Development (Chris' Comments) The 7 Deadly Sins of Software Development (Jon Skeet's Coding Blog) Pet Peeves of Programming (John Meyer's Blog) My original plan was to comment on some of the individual sins that people listed, but they're ...

[ read more ]

The implementation of anonymous methods in C# and its consequences

by ericgu via Eric Gunnerson's Compendium : CSharp on 8/8/2006 2:18:00 PM

Raymond wrote a really nice series of posts on this: Part 1 Part 2 Part 3 He also points out that you might want to read Grant's anonymous method posts... ...

[ read more ]

Thursday, August 03, 2006

Seven deadly sins of programming - Sin #1

by ericgu via Eric Gunnerson's Compendium : CSharp on 8/3/2006 6:24:00 PM

So, the time has come for the worst sin. Just to recap - and so there is one post that lists them all - here are the ones that I've covered so far: Sin #7 - Excessive Coupling Sin #6 - Inappropriately Clever Code Sin #5 - Deferred Refactoring Sin #4 - Premature Optimization Sin #3 - Overuse of Virtual Sin #2 - Overuse of Inheritance Sin #1 - What, you think I would give it away now? (highlight to see hidden text) Some people have remarked that all of these are judgement calls, and re ...

[ read more ]

Monday, July 24, 2006

Seven deadly sins of programming - Sin #2

by ericgu via Eric Gunnerson's Compendium : CSharp on 7/24/2006 6:33:00 PM

One of the guys on my wing during my freshman year of college was a trust-fund kid. His great-grandfather had done well in the market, and had left some money for each the great-grandkids. Michael wasn't paying for his schooling, nor was he paying for his cars, his clothes, his nice stereo, or his ski vacations. But that was okay with us, because he *was* paying for pizza, and he *was* paying for beer. Or his trust fund was. Everything was fine until spring came around, and Michael got some bad ...

[ read more ]

Tuesday, July 18, 2006

Seven Deadly Sins of Programming - #3

by ericgu via Eric Gunnerson's Compendium : CSharp on 7/18/2006 6:19:00 PM

I'm sure this is going to be a contentious one. I don't have a good story about this one, so I'm just going to go right to the sin. Sin #3 - Overuse of Virtual There are two schools of thought when it comes to virtual. They are: Always use virtual Only use virtual when absolutely necessary The first group's argument is that original designer of a class is a poor judge of how the class might ultimately be used. Making all methods virtual allows the users of the class to easily extend/modify the ...

[ read more ]

Monday, June 26, 2006

Seven Deadly Sins of Programming - #4

by ericgu via Eric Gunnerson's Compendium : CSharp on 6/26/2006 6:38:00 PM

Our next sin is the one that I've certainly been prone to. Long ago my wife and I owned a house east of Renton, Washington (those who know about Renton at that time can probably understand why one would say "east of Renton"). Like many homes, this one had had various indignities committed on it by the previous owners. One of the most obvious was what can only be described as a "lean-to", constructed out of surplus Boeing shipping containers and shielding the washer and dryer from the rest of the ...

[ read more ]

Friday, June 02, 2006

A close escape, and more on inappropriate cleverness

by ericgu via Eric Gunnerson's Compendium : CSharp on 6/2/2006 12:53:00 PM

Monday I went on the 7 hills ride. Wednesday night, I wrote a long and detailed post about it, and hit the "Post" button. In a fit of editorial brilliance, my blog server chose that exact moment to experience a problem, and the post vanished into the ether. Few will quarrel that that event was a net positive for western civilization as a whole. So, here's the short version. HomeDownPauseUpDownUpDownUpDownUpDownUpDownPauseUpDownUpDownStrawberryShortcakeUpHome Now, that that's out of the way, th ...

[ read more ]

Wednesday, May 31, 2006

Seven Deadly Sins of Programming - #6

by ericgu via Eric Gunnerson's Compendium : CSharp on 5/31/2006 12:14:00 PM

Seven Deadly Sins of Programming - #6 Way back in my early career, I worked on a graphics program written in FORTRAN that was used to plot engineering data. It ran on Tektronix 4014 terminals. Our application - known as E.G.G. (Engineering Graphics Generator, one of a whole series of not-very-creative punny names used by the group) - used a menu-based approach. The user would place the cursor (moved by the thumbwheels on the right) over a menu option, hit the spacebar, and then the code would ...

[ read more ]

Tuesday, May 23, 2006

Seven Deadly Sin of Programing - #7 - Excessive coupling

by ericgu via Eric Gunnerson's Compendium : CSharp on 5/23/2006 12:43:00 PM

(these will be in reverse order...) #7 - Excessive Coupling We start out with a simple one. Coupling is obviously a necessary evil. The Console class, for example, wouldn't be able to send text through Win32 without being coupled to Win32. Given that, less coupling is nearly always better that more coupling. A few cases that I see: Using switch statements rather than polymorphism or interfaces. Classes that do too much, rather than being focused on a single goal. What do you think? Do you have ...

[ read more ]

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us