Using The "Using" Statement On a Method Rather Than a Class (dev102.com)

submitted by shaharyrshaharyr(4325) 3 years, 9 months ago

Have you ever tried using the "Using" statement with a method and not a class? Why not take the "Using" statement and make it more useful. The Dispose method we want to be called does not have to Dispose of stuff, it can do anything we want!

10 comments |category: |Views: 488

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by evarlastevarlast(20) 3 years, 9 months ago 0

The title alone shows a fundamental lack of understanding of what is going on.

I wish DNK had a downmod so I could downmod this.

using is not on a method or a class, it happens on an instance of an object which implements idisposable.

Reply

posted by SetsukoSetsuko(455) 3 years, 9 months ago 0

I agree with evarlast ! We seriously need an downkick button.

Reply

posted by JudahGabrielJudahGabriel(814) 3 years, 9 months ago 0

The solution presented is an interesting idea, worth kicking. But the title is misleading and I agree, shows misunderstanding.

Reply

posted by grauenwolfgrauenwolf(75) 3 years, 9 months ago 0

Why are you'all acting like assholes?

It is just a title for crying out loud. What's important is the demonstration of the using block without the need for an explicit variable.

Reply

posted by TheColonialTheColonial(0) 3 years, 9 months ago 0

I don't agree with you Grauenwolf. The demonstration of the using block without a variable is NOT obvious and I do not think that it's the intent of the post.

I also do not think that these guys are being assholes. I think they're spot on.

Reply

posted by spoulsonspoulson(327) 3 years, 9 months ago 0

Although this site is seemingly modeled after Digg (minus the downmod), I certainly wouldn't want Digg-like content popping up, let alone Digg-like comments.

I choose not to kick this article for the same reasons already mentioned. Also, I think using IDisposable for something other than disposing is an inconsistent pattern. He is just creating a meta-language within C# by bending the rules. There's plenty of blogs out there that discourage this practice and I agree with them.

Reply

posted by charrischarris(30) 3 years, 9 months ago 0

If it doesn't suit your fancy, just don't kick it. ;)

Reply

posted by SetsukoSetsuko(455) 3 years, 9 months ago 0

DotNetKicks: .NET links, "community driven"

I doubt a real community will just passively stand by when some article that just isn't correct makes it to the frontpage of their beloved site. In my humble opinion, whenever an article that endorses bad coding makes it to the frontpage, a community is responsible for pointing out the reason why this should be avoided. If anyone here seriously thinks that by simply ignoring such an article, your community will grow and people inside the community will learn from their mistakes, then I guess my whole idea of what DNK stands for just got smashed to bits. Being called an ***hole for doing so is even worse.

I'd love to see your face when the following conversation takes place at your office in a few months from now.

- You: What's this? It's not a good idea to use the IDisposable interface for anything else than disposing stuff.
- New guy: I've read somewhere that it is a great way to make your code more readable and it simplifies development.
- You: What ? Where ?
- New guy: It was on my DNK feed.
- You: Oh yeah, right, I remember that article, but... I didn't kick it so you should've figured it was bad coding.
- New guy: ...

GG
Peace out.

Reply

posted by powerrushpowerrush(3873) 3 years, 9 months ago 0

@Setsuko - since DNK is open source, I'm sure Gavin would appreciate it if you'd like to code down-mod functionality into DNK. Short of that, it is a community website that allows the users to kick .Net related articles they _think_ are good. Moderators (such as myself) are discouraged from deleting posts that are basically on-topic.

Reply

posted by charrischarris(30) 3 years, 9 months ago 0

Let me just further my comment by saying in -no- way do I feel this is a good practice.

@Setsuko
I agree, floating to the front page can make it seem as if this practice is actually accepted, and that really disturbs me. But I would hope most would actually reason on what they read, instead of blindly believing this is a good practice. Besides, that type of conversation happens regardless of DNK down kicks, right? ;)

I really just like this kind of aggregation with positive kicking because it shows me what's actually 'interesting' to read regarding .NET amongst a plethora of blogs now. I'm a big boy, so I can figure out if it's good for me or not.

Reply

information Login or create an account to comment on this story