It's nothing big. The extension method allows me to call this method from any IEnumerable object:

Code:

List<int> myInts = new List<int>(); myInts.Inspect();

The only caveat is that because I'm using a generic type, any of my custom types won't be able to utilize this. So, I ask the user to override the ToString() method. I also created another property that exposes the name and value of the property:

I created another extension method that is accessible through any object. Now, I'm only exposing properties (not methods) and getting their values. I do this because I write a lot of State Bags (POCO) that I use to shuttle data between my BLL and DAL's.

Tell me what you think! I'd like to start a discussion on the things that you do that make your dev day-to-day easy.

I'd like to start a discussion on the things that you do that make your dev day-to-day easy.

I'd be down like a clown, but I'd change the title

I haven't been too bothered by that. I haven't found a need to output the contents of an array like that. I know in Classic ASP and PHP I had to do that ALL the time, because their wasn't a good way to debug it. I have overridden .ToString() a few times, but typically it hasn't been a big deal.

Can you help me understand where this would be used? If I am debugging in .NET I just throw up a breakpoint and watch/quick watch the array.

Dumping the raw array like that isn't usually the prettiest way so I wouldn't use it for output to the user, personally.

Can you help me understand where this would be used? If I am debugging in .NET I just throw up a breakpoint and watch/quick watch the array.Dumping the raw array like that isn't usually the prettiest way so I wouldn't use it for output to the user, personally.

When I debug, I just call the Inspect method in the immediates window. I like watch/quickwatch, but I often have too many things I'm watching or if the array is too big then I actually search. I'm still building out the inspect method so that it's overloaded and can search items in the array (gonna try to improve it to do partial searches).

It's come in handy already. I built a small control where I'm returning a list of items. The problem is, the collection I'm returning is pretty big and I want to verify the contents so I use it to search through it in the immediates window.

Any and Empty are inverses that really do the same thing. What it is, however, is syntactic sugar. Code that's easy to read is code that's easy to maintain. While these two are simply icing on the cake, I'm sure that your successor will love you when they see:

One of the things I love about Ruby is inspect(). Suppose you have an object that returns an array:

Code:

result_of_query = Products.find_by_type('Power Tools')

One of the cool things about Ruby is that you can view the contents of the array in interactive ruby (irb):

Code:

puts results_of_query.inspect

By calling the inspect method, you get a nifty output, say like this:

Code:

['Drill','Nail Gun', ...]

Wow, the more you bring up Ruby examples, the more I see Lisp in Ruby. How does the inspect method know to print the product name and exclude any other fields in the class? Or is it slots in the structure like in CL?

From the CL hyperspec:every returns false as soon as any invocation of predicate returns false. If the end of a sequence is reached, every returns true. Thus, every returns true if and only if every invocation of predicate returns true.

some returns the first non-nil value which is returned by an invocation of predicate. If the end of a sequence is reached without any invocation of the predicate returning true, some returns false. Thus, some returns true if and only if some invocation of predicate returns true.

notany returns false as soon as any invocation of predicate returns true. If the end of a sequence is reached, notany returns true. Thus, notany returns true if and only if it is not the case that any invocation of predicate returns true.

notevery returns true as soon as any invocation of predicate returns false. If the end of a sequence is reached, notevery returns false. Thus, notevery returns true if and only if it is not the case that every invocation of predicate returns true.

Can you help me understand where this would be used? If I am debugging in .NET I just throw up a breakpoint and watch/quick watch the array.

Transaction logging, report generation, serialization, etc.

Debuggers are great when working with a compiled language and IDE, but interactive development benefits tremendously from useful information being printed to the screen. I'm not sure how this applies to C# though. Are there interactive C# environments? For the testing example that DJSpin has given, I'd think that he'd also want to be able to filter (yeah, steal that one too you thief!) a list and print the actual constructor code instead of just a pretty-print type of output.

Wow, the more you bring up Ruby examples, the more I see Lisp in Ruby. How does the inspect method know to print the product name and exclude any other fields in the class? Or is it slots in the structure like in CL?

Because Ruby was inspired by CL. Matz had a lot of respect for CL, so when he was developing Ruby he really kept a lot of these things in mind.

Quote:

I think that you should find a job programming in Ruby! You seem to like the language features. You're also a good candidate for CL.

I'm looking, actually. I've been unsuccessful, but the more I write Ruby and get better at it (and developing Rails apps), the better it'll be for me. I'm working on a pro-bono project right now, I figured nothing bad will come out of it.

Debuggers are great when working with a compiled language and IDE, but interactive development benefits tremendously from useful information being printed to the screen. I'm not sure how this applies to C# though. Are there interactive C# environments? For the testing example that DJSpin has given, I'd think that he'd also want to be able to filter (yeah, steal that one too you thief!) a list and print the actual constructor code instead of just a pretty-print type of output.

C# has an interactive environment, it's called Visual Studio. But since C# is compiled, we can debug/breakpoint and see what's happening.

The problem occurs in production environments. I tend to lean towards data rich exceptions; the more info I can read, the better my debugging becomes. The inspect methods I wrote are to simplify debugging in production. In my orgs case, even though I can touch production, I don't like to make changes to it. So if I can debug my app by reading through logs then all the better. I should be able to see the contents of an object in my logs and be able to determine why it failed.

Oh and to answer your question about generics and custom type.

Generics in C# are, for a lack of a better example, template types in C++.

Code:

List<T>

In C#, your objects can have multiple generic types.

Code:

public TResult MyMethod<TResult, TInput>(TInput t)

Unlike custom types, a generic type is just that - generic. You can plug in your custom type as the type that the method/class will operate on.

Haha... good one. Now I'm going to spend the next month correcting all the .NETters about VS and interactive programming. Curse you!

DJSPIN80 wrote:

Generics in C# are, for a lack of a better example, template types in C++.

Gotcha. Java also has generics. The 'custom type' lingo confused me as you're not actually 'customizing' anything. In Java lingo, a generic class or generic type declaration is instantiated using a 'type variable' or 'type parameter'. More MS naming confusion -- It's not called a thread; It's a fiber (unless you're using Win64 where it is called an osFiber64).

In Java 7, they've added operators and wildcards for 'simplifying' generics. Things like <? extends MyClass> and <? super MyClass> where the ? is a wildcard operator allowing me to extend my generic type, the <> operator for when I'm too lazy to type in <SomeClass> a second time, and quite a few other 'features'. Personally, I've felt for quite a while now that OOP in mainstream languages is becoming rather cumbersome, and less expressive, as it moves farther away from the message passing design that Alan Kay had originally envisioned. Objects are the (not so) new square peg.

Who is online

Users browsing this forum: No registered users and 3 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum