Programming's Foul Language
-
I agree with that, despite knowing that at Assembly level, that's exactly what your code will do.
-
goto can actually be useful (if used extremely sparingly - so sparingly that I haven't used it in over 10 years!) One example where goto is very helpful is in programming an efficient state-machine. Oh, I know you can do it without gotos by using functions and/or block escapes, but the goto is much more efficient -- and, in the case of a state-machine, actually HELPS understanding of what is going on.... FWIW (getting ready for all the thumbs-down).
-
goto can actually be useful (if used extremely sparingly - so sparingly that I haven't used it in over 10 years!) One example where goto is very helpful is in programming an efficient state-machine. Oh, I know you can do it without gotos by using functions and/or block escapes, but the goto is much more efficient -- and, in the case of a state-machine, actually HELPS understanding of what is going on.... FWIW (getting ready for all the thumbs-down).
Owen37 wrote:
if used extremely sparingly - so sparingly that I haven't used it in over 10 years!)
I guess I'm not saying that they can NEVER be useful, it's just that whenever I've seen it used abused, it had no business in the code and it's always at least a red flag.
Owen37 wrote:
(getting ready for all the thumbs-down).
Not from me. :)
-
.... right up until something changes in the library and it can throw a new exception at which point the library author has to either break every single app that consumes it, cast the new exception into a different type defeating the purpose of typed exceptions in the first place, or just have every method throw exception from the start defeating the purpose of checked exceptions from the start. X|
The European Way of War: Blow your own continent up. The American Way of War: Go over and help them.
Valid point, but if your library is very volatile, you can wrap all exceptions that happen in your method into a YourCustomException and throw the wrapper instance.
Cheers, Vikram. (Proud to have finally cracked a CCC!)
-
goto can actually be useful (if used extremely sparingly - so sparingly that I haven't used it in over 10 years!) One example where goto is very helpful is in programming an efficient state-machine. Oh, I know you can do it without gotos by using functions and/or block escapes, but the goto is much more efficient -- and, in the case of a state-machine, actually HELPS understanding of what is going on.... FWIW (getting ready for all the thumbs-down).
-
How is using
goto
better than aswitch
statement in awhile(true)
loop?The European Way of War: Blow your own continent up. The American Way of War: Go over and help them.
-
Owen37 wrote:
if used extremely sparingly - so sparingly that I haven't used it in over 10 years!)
I guess I'm not saying that they can NEVER be useful, it's just that whenever I've seen it used abused, it had no business in the code and it's always at least a red flag.
Owen37 wrote:
(getting ready for all the thumbs-down).
Not from me. :)
jeron1 wrote:
I guess I'm not saying that they can NEVER be useful, it's just that whenever I've seen it used abused, it had no business in the code and it's always at least a red flag.
Oh yeah! ALWAYS a RED FLAG! Even when I did have to use it (in the large state-machine) I felt dirty and wanted to run home and take a shower every time I looked at it. After numerous code reviews (some by the VP of development), it held up as the most efficient way to handle the data stream. And, it's in the comments/documentation for the code.
-
You do realize you can mark up which exceptions are thrown in XML comments? I forget if that junk shows up in the intellisense though...
Yes, it does.
-
goto can actually be useful (if used extremely sparingly - so sparingly that I haven't used it in over 10 years!) One example where goto is very helpful is in programming an efficient state-machine. Oh, I know you can do it without gotos by using functions and/or block escapes, but the goto is much more efficient -- and, in the case of a state-machine, actually HELPS understanding of what is going on.... FWIW (getting ready for all the thumbs-down).
One defense for the goto I've heard is from people whose programming policies require that functions have a single exit point. Aiming for a single Exit Sub/Function/Return point without goto can easily make for some complex and hard to maintain control paths, often with multiple levels of nested if/then blocks.
-
Prolific maybe, but between them and partial classes, I get quite extended.
Oh, yeah, I forgot about
partial
when I wrote that, but then I usepartial
even when I don't need it. I actually feel that classes should bepartial
by default and that there should be no keyword for it. Trying to compile an actualpartial
class with C# 1.0 will break even if there is no keyword, so I don't see the need. And I think the word I really wanted was "profligate"; I'm not sure which word works best in the context. -
Oh, yeah, I forgot about
partial
when I wrote that, but then I usepartial
even when I don't need it. I actually feel that classes should bepartial
by default and that there should be no keyword for it. Trying to compile an actualpartial
class with C# 1.0 will break even if there is no keyword, so I don't see the need. And I think the word I really wanted was "profligate"; I'm not sure which word works best in the context.I like to know when I'm partial to something.
-
I like to know when I'm partial to something.
I'm not partial to needless keywords and syntax changes.
-
Fabio Franco wrote:
knowing that at Assembly level, that's exactly what your code will do.
True, I have programmed in both languages and for some reason it seems natural (maybe because there's no choice?) in assembler and completely out of place in C++.
jeron1 wrote:
it seems natural (maybe because there's no choice?)
Yep, there is no choice. The program counter (PC) points which statement will execute next. The processor looks that up in the memory and if nothing is done, it will simply execute the next item in the stack. So in order to perform conditional tasks (if) or loops (for/while) the processor understands the MOV command which is exactly what the "goto" command does. All your ifs, whiles and fors become nothing when compiled to native machine language. They all become "goto's". Thank God nowadays we are not required to go assembly in most cases, things can get ugly. Cheers Fábio
-
Valid point, but if your library is very volatile, you can wrap all exceptions that happen in your method into a YourCustomException and throw the wrapper instance.
Cheers, Vikram. (Proud to have finally cracked a CCC!)
throws Exception
,throws MyCustomExceptionWhichWrapsEverything
, and lack of a throws statement; are equally useless at providing meaningful information to the consumer.The European Way of War: Blow your own continent up. The American Way of War: Go over and help them.
-
Oh, yeah, I forgot about
partial
when I wrote that, but then I usepartial
even when I don't need it. I actually feel that classes should bepartial
by default and that there should be no keyword for it. Trying to compile an actualpartial
class with C# 1.0 will break even if there is no keyword, so I don't see the need. And I think the word I really wanted was "profligate"; I'm not sure which word works best in the context.Unless you're suggesting replacing it with a new keyword eg
singlefile
that does the opposite I'm strongly opposed because it means I don't have any mandatory information about if a class is fully contained in a single file or if it's got implementation spread among several. If you are suggestingsinglefile
instead ofpartial
then I disagree because you're changing the implicit behavior of legacy code. The only change I'd make would be to add a warning if there was *not* a second instance of a partial class eg if you ooopsed and only renamed/renamespaced the class in one of the files instead of all of them.The European Way of War: Blow your own continent up. The American Way of War: Go over and help them.
-
Unless you're suggesting replacing it with a new keyword eg
singlefile
that does the opposite I'm strongly opposed because it means I don't have any mandatory information about if a class is fully contained in a single file or if it's got implementation spread among several. If you are suggestingsinglefile
instead ofpartial
then I disagree because you're changing the implicit behavior of legacy code. The only change I'd make would be to add a warning if there was *not* a second instance of a partial class eg if you ooopsed and only renamed/renamespaced the class in one of the files instead of all of them.The European Way of War: Blow your own continent up. The American Way of War: Go over and help them.
dan neely wrote:
a new keyword eg singlefile
No.
dan neely wrote:
if a class is fully contained in a single file or if it's got implementation spread among several
I don't need that information. And it doesn't tell you which other files anyway so I don't see the benefit. The main thing is, I may post some code here and someone may want to add something to it for their own purposes. If I include partial (even though my code doesn't need it), they don't have to touch my file. If I leave off partial, they have to add it even though they're using partial in an effort to not alter my file. Partial classes enable such easy additions to code, but the
partial
keyword hinders that ease. All classes should be partial without needing a new keyword. -
dan neely wrote:
a new keyword eg singlefile
No.
dan neely wrote:
if a class is fully contained in a single file or if it's got implementation spread among several
I don't need that information. And it doesn't tell you which other files anyway so I don't see the benefit. The main thing is, I may post some code here and someone may want to add something to it for their own purposes. If I include partial (even though my code doesn't need it), they don't have to touch my file. If I leave off partial, they have to add it even though they're using partial in an effort to not alter my file. Partial classes enable such easy additions to code, but the
partial
keyword hinders that ease. All classes should be partial without needing a new keyword.PIEBALDconsult wrote:
I don't need that information. And it doesn't tell you which other files anyway so I don't see the benefit.
I disagree about it's utility; and while I'll admit that's annoying and an obvious place for intellisence improvement, but having to search for
partial class MyClass
with a partial class to find the rest of it is less of a hassle than having to search forclass MyClass
with every class to find out if it's partial or not.PIEBALDconsult wrote:
The main thing is, I may post some code here and someone may want to add something to it for their own purposes. If I include partial (even though my code doesn't need it), they don't have to touch my file.
Within my codebase; if anything I see this as a feature since the changelog for my class will indicate that it's no longer contained in a single file. If anything I think the weakness is that adding a 3rd+ partial class file doesn't do anything to obviously indicate that the class has changed in the repositories history. So far it's never been an issue for me since I've only used partial to isolate my code from code autogenerated by a tool/designer of some sort.
The European Way of War: Blow your own continent up. The American Way of War: Go over and help them.
-
goto can actually be useful (if used extremely sparingly - so sparingly that I haven't used it in over 10 years!) One example where goto is very helpful is in programming an efficient state-machine. Oh, I know you can do it without gotos by using functions and/or block escapes, but the goto is much more efficient -- and, in the case of a state-machine, actually HELPS understanding of what is going on.... FWIW (getting ready for all the thumbs-down).
Since I barely knew Dartmouth Basic when I started designing state machines for hardware controllers i didn't know there was anything like "goto" or "gosub". In all of the microcontrollers I've ever coded all we had were JMP, CALL, and sometimes SKIP for controlling program flow. Goto and Gosub were all higher level code which had to be interpreted or compiled into code the CPU could understand. I've also made state machines with NO ALU at all and one in particular out of PLD's that had NO compiler at all. I had to design the program flow by burning fuses in the PLD. No memory, no eproms, no disks, no keyboard and no display. Also, mine is bigger than yours. :-) Edwin
-
Microsoft
-
Since I barely knew Dartmouth Basic when I started designing state machines for hardware controllers i didn't know there was anything like "goto" or "gosub". In all of the microcontrollers I've ever coded all we had were JMP, CALL, and sometimes SKIP for controlling program flow. Goto and Gosub were all higher level code which had to be interpreted or compiled into code the CPU could understand. I've also made state machines with NO ALU at all and one in particular out of PLD's that had NO compiler at all. I had to design the program flow by burning fuses in the PLD. No memory, no eproms, no disks, no keyboard and no display. Also, mine is bigger than yours. :-) Edwin