|
Do you use goto in C# ? Where do you find it usefull or not usefull ? i had never used goto in C# but now when i just saw that a collegue uses this very often, I start wondering.. :-? tell me...
|
|
|
|
|
What do you not understand about "Please do not post programming questions here"?
|
|
|
|
|
IMHO this is not a programming question.
|
|
|
|
|
It isn't a programming question. He's just asking for opinions about usage of a statement (warning: related to programming).
Ya know? Other than important things like football, bullshit politics, stiupid dradunk bdahbble, cricket, etc., people should be let free to discuss something related to programming now and then.
It's time for a new sig. Seriously.
|
|
|
|
|
Why hate football posts? At least you are a sport man right?
|
|
|
|
|
I never said I hate football - I just don't care about it enough to hate it. And at the same time I don't mind people discussing about it.
All I'm asking for is a little space for people to discuss about something that's completely valid and on topic. That's programming.
It's time for a new sig. Seriously.
|
|
|
|
|
goto here[^]
WWW, WCF, WWF, WPF, WFC .... WTF
|
|
|
|
|
ok then... sorry for posting.. i give up.
|
|
|
|
|
Lucian-aSterX wrote: i give up.
Why? You're not French...
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
We did not give up. We made a tactical counter march and just never had any strategic opportunity to go back to the front.
|
|
|
|
|
OK - to clarify. What you have asked here is more of a programming philosophy question than a programming question. Others ask these in the Lounge and get away with them so I don't see why you shouldn't.
I have never encountered a situation in .NET where a goto makes my job easier. Generally, a well structured application with small, self-contained methods should have no need for a goto. When I see them, it's generally an indication that somebody has landed themselves in an architectural muddle and they can't see the way out of the morass. This is generally when they have loops nested within loops nested within loops. The way I tend to look at this, if you've got yourself this deep into loopfuggery, it's an indication that you are using the wrong loops.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
|
If you look at oldfashioned code you will see that it generally had a considerably smaller memory footprint and executed faster (in comparison). Good design obviously costs memory and some efficiency. With today's best practices one would not rally get far on a 8 bit CPU and 4k RAM.
I don't rerally like the 'we have plenty of everything' attitude, however, only small and selected regions of the code need such a performance treatment and should then be well commented.
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.
I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
|
|
|
|
|
This article/blog[^] Shows situations where goto statements can be used to greater effect than other soloutions although I must confess I can see better ways to code some of the examples, that the author ignores. I was always taught to avoid goto's at all costs and have always stuck to this advice, however, like you, I have noticed collegues use them a lot.
|
|
|
|
|
Yep, I was taught to avoid gotos also cause they make the code harder to read and ifs, selects, whiles and fors can all get you the same results and they are easier to read. However I have noticed some of the newbies using gotos here (in my place of work) also.
It appears they have come back into fashion. Maybe because they were eradicated so well that the newbies aren't being taught how bad code can get with injudicious use of gotos?
Pete
|
|
|
|
|
Maybe they are reading unoptimised reflector code. Goto is commonplace there.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Ok, surely the first and last examples here can be done using return in a try-finally block?
Pete
|
|
|
|
|
I did say I can see better soloutions that the author chooses to ignore.
|
|
|
|
|
This is a discussion and I'm not claiming a try-finally block would be a better solution.
Pete
|
|
|
|
|
|
A break statement in C# is like a GoTo statement in VBA, except that is just takes the code out of the active loop.
GoTo statements should be forward moving (in the method) only - else spaghetti code ensues.
It's sometimes easier to use a GoTo statement in VBA (e.g., instead of a do while loop), within a standard iterator loop, to exit the loop. But VBA does have an exit do statement.
There should be no need to use a GoTo statement in C#.
|
|
|
|
|
pompeyboy3 wrote: to greater effect than other soloutions although I must confess I can see better ways to code some of the examples
to greater effect than the other solutions he provided, but not greater than real good solutions. As you started to point out, you can write his example in perfectly good code without requiring to the goto instruction. IMHO, this blog entry is rather poor.
|
|
|
|
|
There are always other solutions.
The blog was pointing out the in rare circumstances goto is the best solution....if you define best as also the simplest solution.
And yes, goto can be abused just like any other element in any language. I've seen multiple inheritance abused far more than goto's.
Steve Wellens
|
|
|
|
|
Funny how no-one even the comments could come up with a really good alternative (I agree for simplicity, the && is approach is best).
How would I do it?
bool Do(params Func<bool>[] args)
{
foreach (var a in args)
if (!a())
return false;
return true;
}
...
if (Do(Step1, Step2, Step3, Step4, Step5, Step6, Step7))
Console.WriteLine("Brillant!");
|
|
|
|
|
I was thinking about a similar construction with function pointers, but I know no C#.
This is a very cool solution.
|
|
|
|