Standards - Code Generation in Visual Studio

Status
Not open for further replies.

svdsinner

Ars Legatus Legionis
15,152
Subscriptor
My department is beginning to look into ways to make standards easier and more adopted. The basic goal is to build a small number of highly useful Visual Studio tools for our team to use to make using standards easier and more efficient. As many of us know, Visual Studio has numerous features to facilitate this. (Macros, T4, Add-Ins, Custom Project Types, etc.)

Basic Goals:
  • Generate common boilerplate painlessly
  • Help cross training by encouraging code reuse and similar architechture of apps.
  • Focus the system on being highly useable and easy/desirable to adopt. Focus on a few big pain-points and don't create a gigantic monster that intimidates people new to it.
  • Deliver value immediately to transfer coders (coders transfering to the .NET toolchain coding from other tech)

I'm deliberately posting this before I bone up on T4/Macros/whatever because I'm interested more in high-level thoughts and I don't want to limit things to one code generating tech. Our goal is to create something useful and handy for every developer in IT, NOT to show-off fancy stuff Alpha-geek style. Remember this will be rolled out to dozens of developers of all skill levels, and we are only focusing on broad usage stuff.

  1. What really good uses for department-wide code generation tools have you seen?
  2. What seemingly good ideas flopped and never got used? Why didn't people use it?
  3. Any known areas that the built-in tools stink at?
  4. Any good & efficient ways to keep it documented? (So new hires can learn it quickly, and also so new functionality gets communicated to the existing developers who need it)
  5. Which tech (macros, T4, etc.) works best for multiple-project-in-a-solution boilerplate? (E.G. Boilerplate to pass n-tier calls across the tiers from UI to db) Can this be done, or are the tools limited to one assembly at a time?
  6. Any other tips/tricks to aid developer adoption?
  7. Any recommended reading on the subject? Book/blog/tutorial/etc.
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
During my time in .NET-land I spent a lot of time playing with T4, trying to find ways to improve productivity with it, and came up empty. I eventually realized I was barking up the wrong tree--generated often-repeated code doesn't solve problems, it perpetuates them. It's like a codification of the mindset behind (most) PHP--copy/paste away your problems to create new ones.

It would be a rare, bizarre, probably-broken environment (technical and cultural) where "common boilerplate" is better addressed with code templates instead of abstraction and better code. Like, if you need to route calls across an n-tier architecture, generalize your message passing system and present a sane API that provides clear ways to handle the success and failure case. This should improve developer acclimatization as well because you aren't making them wade through a bunch of always-repeated bullshit to get at what's going on.


Code standards aren't perpetuated through templates, they're perpetuated through reviews and a healthy culture.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
Why are you doing code generation in the first place?

There are occasions where is helpful but they are relatively rare, and normally it is a very specific performance need in a language where you cannot use the native toolchain to meta program your way out of it.

If you're willing to take a dependency on f# then .Net actually supports some seriously good 'transparent' code gen with TypeProviders, the 'codegen' happens at dev time, and at compile time without you needing to care about it.

For doing anything 'n-tier' and having that require significant boiler plate strongly suggests doing it wrong to me.
 

QuadDamaged

Ars Praefectus
3,983
Subscriptor++
Currently using T4 heavily and regret every moment of it. Makes refactoring extremely perilous and cumbersome (t4 tooling is a joke).

I introduced some dynamic type-generation at runtime as well as 'clever' use of RX in C#, but for what we want to do we're fighting against the language (lots of aop, expression tree parsing and reflective programming).

F# type providers are what we want to move to but currently don't have enough manpower to make the switch. Something we haven't explored yet is how painful maintaining a set of C#-compatible types from F# type providers will prove to be.
 

svdsinner

Ars Legatus Legionis
15,152
Subscriptor
[url=http:/civis/viewtopic.php?p=24507885#p24507885:1flgqbjv said:
wallinbl[/url]":1flgqbjv]Can you describe a scenario where you'd do this rather than simplify the API or refactor in some way?
Here are a few: (Wish list, not sure all of them are possible)
  1. Try/catch snippets with standard error handlers utilizing the standard exception logging code to make "doing it right" easier than "I don't really need logging here for this one thing, and I'm in a hurry"
  2. Adding properties to objects that use DTO patterns. (IOW, one class stores data-only and another provides validation and manipulation logic) Have one magic "add property" that stubs out the both related methods in one step.
  3. Making a custom project type that includes all the standard support classes for things like logging, exception handling, etc. so that it becomes easier to follow standards for new apps than to not.
  4. N-tier stubs. One magic "Add new method" from the UI layer that stubs the WCF Client code, the WCF contract, the WCF Service method and possibly a DAL stub for the actual SQL query code. (Not sure if that last part is standard enough to be automateable) Allow a developer working on a UI screen to simplify using WCF to communicate with the back-end
  5. Simplifying common M-V-VM viewmodel scenarios (E.G. Viewmodel that needs to be persisted after it leaves the UI, and needs basic "Save Changes or Discard" functionality)
Why are you doing code generation in the first place?
We are preparing to convert several developers from older tech (mainframe, etc.) to .NET, and want an easy system of teaching new converts basic standards and practices, and an easy way for them to use them. Our thinking is that if we say "Use our standard logging stuff. Here are the code snippets that make it easy, and here is where the classes are automatically added for you in your new apps, so all you have to do is type LogTC<tab><tab> and the standard Try/Catch with logging block instantly appears." we'll get much, much higher adoption than if we say "Use our standard logging stuff" but provide no tools to make it easy.
 

levine

Ars Tribunus Militum
1,986
[url=http:/civis/viewtopic.php?p=24508431#p24508431:1vzqow0f said:
svdsinner[/url]":1vzqow0f]We are preparing to convert several developers from older tech (mainframe, etc.) to .NET, and want an easy system of teaching new converts basic standards and practices, and an easy way for them to use them. Our thinking is that if we say "Use our standard logging stuff. Here are the code snippets that make it easy, and here is where the classes are automatically added for you in your new apps, so all you have to do is type LogTC<tab><tab> and the standard Try/Catch with logging block instantly appears." we'll get much, much higher adoption than if we say "Use our standard logging stuff" but provide no tools to make it easy.
"An easy system of teaching... basic standards and practices" is: pointing them to good documentation, and thorough review. Code that doesn't do e.g. "standard logging stuff" will be caught at code-review and not merged until it's up to standards. Saying that "all you have to do is type LogTC<tab><tab>" is codifying terrible behavior; it just invites those developers to shrug off the responsibility of competence.
 

svdsinner

Ars Legatus Legionis
15,152
Subscriptor
[url=http:/civis/viewtopic.php?p=24508605#p24508605:7ebu4y19 said:
levine[/url]":7ebu4y19]it just invites those developers to shrug off the responsibility of competence.
Sometimes. But factoring in that A) we'll be teaching a new way of doing things that is going to be alien to many of the converts and B) Some (not all) of the converts haven't learned a new language or programming pattern since they learned mainframe programming in college. Some of them just aren't guys who will read programming books at home to learn the newest skills. They're still valuable assets, but converting by simply telling them to read the manual then zapping them in code reviews sounds like trying to drag a cat backwards across carpet by its tail.

A little bit of a helping hand at the start can make converting these developers less painful for all involved.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
LogTC<tab><tab> and the standard Try/Catch with logging block instantly appears."

If you have to do this often enough that you want it macro'd then I seriously believe you are doing something wrong...

Likewise
(IOW, one class stores data-only and another provides validation and manipulation logic)
Why separate the two in that context?
Unless you wish one to have access to code/resources that the other tier cannot what's the point?

There are occasions when you really do need to have linked classes A and B when everything in A has a duplicate in B (with some transform applied). Normally this is indicating a lack of something in the language. For example this sort of separation is useful for a Mutable construction/immutable final result, often expressed as "Builder" patterns. This is definitely an area where imperative/mutable by default languages currently have a serious lack IMO. Lot's of library level serialisation tooling of object graphs requires mutability for example, when in actual fact all the time the developer will be referencing instances of those types they are intended to be immutable.

For a library/platform to bother dealing with the hassle of hand coding/code gen may well make sense. The significant cost to the developers of the library is offset by the savings in time/bugs of the end users (which you presume to be greater in number, and possibly of less capability within this domain).

Reflection, (with runtime code gen if you want to only pay the reflection cost once), can often get round this. But at the cost of compile time sanity checking (hence f#'s TypeProviders being awesome).
 

svdsinner

Ars Legatus Legionis
15,152
Subscriptor
NOTE: I'd like to keep this on topic of "What have you seen than worked" and "What have you seen that stunk" and avoid sidetracking on any particular code pattern.

Quote:

LogTC<tab><tab> and the standard Try/Catch with logging block instantly appears."


If you have to do this often enough that you want it macro'd then I seriously believe you are doing something wrong...
??? :confused:

Methinks the real hurt comes when people don't do this enough. I've wasted too much time debugging exceptions on servers some idiot decided NOT to pass the exception to the ExceptionLogger because adding that one line of:
Code:
Logging.LogException(ex)
was just too hard for them to remember so their code had to be debugged ultra painfully because they didn't use the tools to make things easy. :mad:
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
debugging exceptions on servers some idiot decided NOT to pass the exception to the ExceptionLogger because adding that one line of:

The only reason to log an exception is if you are about to die (and thus adding additional context to it via nesting would be pointless), and you know where you want it to go. Or you are just swallowing the exception (If you're doing that a lot you're definitely doing something wrong).

There are legitimate reasons to swallow exceptions (security boundaries, application domain boundaries) but the way to make such boundaries manageable (for everything) is to have as few 'gets' in them as possible so as to keep it manageable.
Unhandled exception events are supplied by the runtime, so unless you have specific information you require the developer to supply at the boundary what else do you need to do?

If you really must have lots of these boundaries, and be adding them a lot, then sort out whatever framework it is you're using that calls into these entry points to just do the try catch directly, or if you really can't get into that layer for some reason, it's as trivial as providing a *method*:

Code:
// obviously use a name more appropriate to your domain
public static void PerformOperationWithinBlahSemantics(Action action)
{
    try
    {
        action();
    }
    catch (Exception e)
    {
        // do whatever you need to do.
    }
}

I should note that this is still not very pretty, and you would need overloads if parameters were required, etc, etc hence trying to push this code to be underneath you if possible. But then the 'boiler plate' is at least just a single line.

Like I said, there's other techniques that a better, but that's a start.

In general many boiler plate activities that are about *control flow* can be pretty simply be rewritten to involve higher order functions. Unless you really can't afford the cost of the delegate creations for closures (if no environment is captured the compiler is smart enough to amortise that) this is pretty much a non event.
 

svdsinner

Ars Legatus Legionis
15,152
Subscriptor
[url=http:/civis/viewtopic.php?p=24513429#p24513429:2t9py75y said:
ShuggyCoUk[/url]":2t9py75y]
The only reason to log an exception is . . .
You're missing several of the most useful reasons to log exceptions:
  1. It can give you critical inforamtion on bugs that you cannot recreate. (This is a corporate environment where users tend to appreciate bugs getting fixed rather than being told "It doesn't do that on my machine")
  2. In WPF-land unhandled exceptions inside event handlers can cause extremely hard to debug program crashes. The act of keeping all event handler code inside a try-catch block that logs makes problems much easier to track down, and prevents dreaded crash-to-desktop bugs.
  3. Exception logs are invaluable in verifying bugs and the quality of a recent release. I'm often surprised when I detect a bug via tracked exceptions that none of the users complained at all about it. You simply can't rely on users to tell you there are issues.
  4. Exception logs also work the other way as well. User Sally Smartypants misses a critical deadline and decides to cover her tracks with a fictional story of the bugs in your app. She makes a big show of complaining to upper manangement that the application bugs prevented her from making progress. It's then quite nice to be able to show Sally's boss the logs that show that Sally's machine had no bugs reported, and that she only actually logged into the application for about one hour all week, rather than "Every daay for 4+ hours" like she claimed when making up her dramatic story. :devious:

Realistically, all patterns and practices are useful if used in the right places and time wasters when used in the wrong places. This thread isn't about which patterns we're using in our particualar situation, it is about ways to make patterns easier to follow, especially for the upcoming wave of converts to the MS toolchain.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
You're missing several of the most useful reasons to log exceptions:

You are entirely missing the point, I did not say not to log exceptions, I said: The set of *places you need to do this* should be very small, and rarely change.

1. <not relevant, see above>
2. see this post
3. <not relevant, see above>
4. <not relevant, see above>

all patterns and practices are useful if used in the right places

No, they are not. What you are proposing is actively harmful, leads to more bugs[1] (exceptions not being appropriately trapped before death, exceptions being swallowed/state lost) and can be done better by the tools that exist. That I'm having to point you at ways you can solve this without DRY violations and boilerplate should be telling you something...

Now if this was in a platform/language that didn't support such mechanisms things would be a different manner. Just because "The determined Real Programmer can write FORTRAN programs in any language" doesn't mean you *should*.

You are in fact *harming* these new people (and potentially putting them off actually learning the increased power and reduced effort using a decent language idiomatically can provide.

1. You would not have started this post if this was not the case!
 
[url=http:/civis/viewtopic.php?p=24521475#p24521475:1cs0neh3 said:
ShuggyCoUk[/url]":1cs0neh3]
You're missing several of the most useful reasons to log exceptions:

You are entirely missing the point, I did not say not to log exceptions, I said: The set of *places you need to do this* should be very small, and rarely change.

1. <not relevant, see above>
2. see this post
3. <not relevant, see above>
4. <not relevant, see above>

all patterns and practices are useful if used in the right places

No, they are not. What you are proposing is actively harmful, leads to more bugs[1] (exceptions not being appropriately trapped before death, exceptions being swallowed/state lost) and can be done better by the tools that exist. That I'm having to point you at ways you can solve this without DRY violations and boilerplate should be telling you something...

Now if this was in a platform/language that didn't support such mechanisms things would be a different manner. Just because "The determined Real Programmer can write FORTRAN programs in any language" doesn't mean you *should*.

You are in fact *harming* these new people (and potentially putting them off actually learning the increased power and reduced effort using a decent language idiomatically can provide.

1. You would not have started this post if this was not the case!

May I summarize this to make sure I am understanding you correctly?

Applications should be structured in such a way that operations that--when they fail--should be recovered from, funnel through common code so try/catches aren't all over the place. If an unrecoverable is encountered, log that at the application level.

If that's what you are suggesting, I completely agree. If not, I probably still agree, but am just missing something (what "tools" are you referring to?).
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
That's pretty much it.

Tools in this context are things like the natively provided uncaught exception handlers, or framework code that is inserted for you in some 'hosted' scenarios such as web apps, plugin APIs, parallel environments (think MapReduce, TPL et al).

Really the only people that genuinely need to do this sort of boiler plate try/catch stuff are framework writers themselves. You need to be very careful about falling into that sort of trap, it can be a good idea, if you approach it as that from the get go, but having what amounts to junior developers (who may well have excellent skills/knowledge in other areas) writing it is madness.

You want them spending time where they can add value, not writing/copy pasting stuff that they can, at best, *not screw up*.
 

ronelson

Ars Legatus Legionis
21,399
Subscriptor
Instead of asking "How do I solve an actual problem?", the developer asks "How do I implement a specific bad solution?".
The worst part is that most people do not understand the difference between a root cause and a symptom and end up treating the symptom as if it is the cause.

++ to it hardly being a software development problem.
 

svdsinner

Ars Legatus Legionis
15,152
Subscriptor
[url=http:/civis/viewtopic.php?p=24521475#p24521475:351tyj65 said:
ShuggyCoUk[/url]":351tyj65]
all patterns and practices are useful if used in the right places

No, they are not. What you are proposing is actively harmful, leads to more bugs[1] (exceptions not being appropriately trapped before death, exceptions being swallowed/state lost) and can be done better by the tools that exist. That I'm having to point you at ways you can solve this without DRY violations and boilerplate should be telling you something...

Now if this was in a platform/language that didn't support such mechanisms things would be a different manner. Just because "The determined Real Programmer can write FORTRAN programs in any language" doesn't mean you *should*.

You are in fact *harming* these new people (and potentially putting them off actually learning the increased power and reduced effort using a decent language idiomatically can provide.

1. You would not have started this post if this was not the case!
Please stop the trolling, and save thread derailments for the lounge. This isn't a thread about exception handling, and you are doing nothing but building a straw man to distract from the topic of the thread. What you are describing (overuse and misuse of try/catch blocks) is not in any way what I am doing or proposing.

This thread is about a useful tool that I am COMPLETELY aware can be misused. However, claiming that there are NO useful uses for T4, snippets, templates, and code generation is mere trolling.

Please focus on constructive thoughts on these tools.
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
Shuggy is in no way trolling, and you're kind of being an asshole for saying he is. (And this is me saying that, so, y'know.)

You're wrong and you're a victim of the XY problem and that's not his or anyone else's fault. "You're fucking up" is constructive. It's not what you want to hear, but on Ars you don't own threads you start and guess what? They can go places you don't like. If you want useless feedback on your incorrect Y to solve your very extant X, there are lots of forums where nobody evaluates your Y based on what you are actually trying to do.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
claiming that there are NO useful uses for T4, snippets, templates, and code generation is mere trolling.

I never said that at all. I took your specific examples and indicated which were very poor candidates for this scenario, with detailed reasons why.

Were you aware of the WPF/System unhandle exception callbacks at all? If you were why on earth didn't you just give me a reason why they were insufficient for your needs?

Asking for help in how to shoot yourself in the foot here results in being told that. I'm glad, I'd rather know I'm doing something wrong when I ask.

That *no-one* has suggested anything that works and multiple people have given first hand experience of it *not working* surely should give you pause...

As a counter-point to the idea that templates/snippets can be useful, to work round language flaws, I find resharpers implementation of IEnumerable (where it automagically does the non generic implementations chained to the generic ones) incredibly useful because *there is no other way of doing this correctly* without injecting macro like behaviour (which is IMO more heinous than the current alternative).

Several of your examples have alternate, and IMHO better in every way, means of being dealt with that only the sort of people who write frameworks should be applying. And, it bears repeating, those people are not the ones you are describing (at least yet, who knows where they might end up if they aren't stunted in their growth).
 

svdsinner

Ars Legatus Legionis
15,152
Subscriptor
[url=http:/civis/viewtopic.php?p=24529921#p24529921:bhhuqh1l said:
ShuggyCoUk[/url]":bhhuqh1l]
claiming that there are NO useful uses for T4, snippets, templates, and code generation is mere trolling.

I never said that at all.

all patterns and practices are useful if used in the right places
No, they are not.
Sounded like it to me.

[url=http:/civis/viewtopic.php?p=24529921#p24529921:bhhuqh1l said:
ShuggyCoUk[/url]":bhhuqh1l]Were you aware of the WPF/System unhandle exception callbacks at all?
Apparently much more so than you. I've used them since WPF came out and know the places where they don't work. I've been debugging massive WPF apps for quite a while and wouldn't dream of telling someone that those two hooks are reliable enough to be counted on. They work 99%+ of the time, but certain don't prevent CTD bugs, and certainly don't execute during a CTD. And that 1% of bugs are much more painful than the other 99%. (Bonus tidbit: in all of those places I've seen, simply wrapping the code with:
Code:
try
{
}
catch (exception)
{
    throw
}
will make those CTD exceptions suddenly work properly with those hooks?)

[url=http:/civis/viewtopic.php?p=24529921#p24529921:bhhuqh1l said:
ShuggyCoUk[/url]":bhhuqh1l]If you were why on earth didn't you just give me a reason why they were insufficient for your needs?
Because it was off topic, and my time is limited?

[url=http:/civis/viewtopic.php?p=24529921#p24529921:bhhuqh1l said:
ShuggyCoUk[/url]":bhhuqh1l]Asking for help in how to shoot yourself in the foot here results in being told that. I'm glad, I'd rather know I'm doing something wrong when I ask.
Agreed. My frustration with you is that the "shoot yourself in the foot" stupid stuff is something you imagined I was thinking, and bears no resemblance to what our plan is. Where did you even get this bizarre idea that I was advocating overusing try/catch blocks? That whole thing is something you read in completely eisegetically.
[url=http:/civis/viewtopic.php?p=24529921#p24529921:bhhuqh1l said:
ShuggyCoUk[/url]":bhhuqh1l]That *no-one* has suggested anything that works and multiple people have given first hand experience of it *not working* surely should give you pause...

This is the exact reason I posted here. I'm well aware it can be misused, and that bad uses outweigh good uses at many companies. Perhaps you missed the OP, where I reitterated numerous times our focus on making useful stuff to make lives easier, not draconian "MUST USE THIS EVERYWHERE!!!!1111" non-sense.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
this bizarre idea that I was advocating overusing try/catch blocks?

That you want to script their creation?

I mean seriously, you think it's worth the effort to script the creation of 6 lines of boiler plate that you acknowledge should be done sparingly.
You don't see that as a bit of a dichotomy?

As to this:

all patterns and practices are useful if used in the right places
No, they are not.

You made a massively sweeping statement, in an attempt to deflect things. I'm not skilled in the rhetorical tools of debate but I'm pretty sure this is an Existential fallacy or at least Vacuous truth

You attempt to justify your specific practice (that we all think is bad) with something which is plainly false.
If someone out there defines a really bloody stupid pattern/practice, or just one that was valid in a different context, then it can have absolutely no use outside of that domain.

I mean several early languages function names were limited in length due to the compiler just not being up to using more. The way those names were shorted was genuinely useful pattern in the past, as there was *no other choice*. Perpetuating that idiom to other languages without that flaw would be moronic.

Likewise I have been worked at places where ludicrous 'practices' were dolled out by people with "Architect"[1] in their job title which were actively harmful, notably someone in java trying to force declaration of all local variables at the top of a method, always.

So no, your over broad statement was wrong, and I called you on it. If you want to try to narrow it in some way ("All patterns and practices svdsinner thinks are good" is what I suspect you meant in your head) feel free to try.

Lest you think I'm saying any of this because I've been told it's bad and I'm just repeating the party line let me disabuse you of that. I have attempted user initiated code gen[2] as a solution to some of my problems in the past. They have universally failed code because they tie an abstract common need to multiple, unconnected, chunks of source code that then drift (or are torn violently) apart.
If someone told you they were going to *manually* inline all calls to a specific function because it made it a bit faster would you just go "sure, that sounds reasonable, here's a really good refuctoring[3] tool to do that instead of your regex you're using" or start seeing how you could get the runtime to do that for you, what they might be doing wrong, if they were testing this in the right mode or whether this indicated that the underlying platform you were using just wasn't up to your specific needs?

1. I'm not saying everyone with that title is like that, but I suspect many of you have met the type I mean.
2. the compiler/build tools/runtime doing it is fine, I mean stuff you end up committing to your source control after running it once.
3. this is not a typo
 

svdsinner

Ars Legatus Legionis
15,152
Subscriptor
[url=http:/civis/viewtopic.php?p=24537409#p24537409:1vzyjsxj said:
ShuggyCoUk[/url]":1vzyjsxj]
this bizarre idea that I was advocating overusing try/catch blocks?

That you want to script their creation?

I mean seriously, you think it's worth the effort to script the creation of 6 lines of boiler plate that you acknowledge should be done sparingly.
You don't see that as a bit of a dichotomy?
By default, users can ALREADY script the creation of try/catch blocks. It is a default ability in VS and has been for several versions.

Think logically:
Pain point = developers while debugging during crunch time often add-in try-catch blocks where they want to inspect an exception, and often forget to take it out when it is no longer needed. Many times these "thrown in during debugging" blocks aren't done with any attempt to write good code and often do stupid things like swallow exceptions or pop-up ugly message boxes. (Fine while debugging, big issue if left in after debugging.)
Main reason for the pain = devs can add crappy try/catch blocks with less typing than adding basic stuff like calls to exception logging.
Simple solution = give devs a way to do it correctly that is just as fast as doing it wrong. Remove "wanting to do it quick" as a reason to do it wrong.


[url=http:/civis/viewtopic.php?p=24537409#p24537409:1vzyjsxj said:
ShuggyCoUk[/url]":1vzyjsxj]As to this:

all patterns and practices are useful if used in the right places
No, they are not.

You made a massively sweeping statement, in an attempt to deflect things. I'm not skilled in the rhetorical tools of debate but I'm pretty sure this is an Existential fallacy or at least Vacuous truth

You attempt to justify your specific practice (that we all think is bad) with something which is plainly false.
No, it is a tautology, a fundemental, always true statement. Oddly, while trying to say it isn't true, you then restate it as truth
If someone out there defines a really bloody stupid pattern/practice, or just one that was valid in a different context, then it can have absolutely no use outside of that domain.
You've done nothing but take a pattern I mentioned that can be mis-applied and ignored repeated clarifications that I am only advocating its valid use in its proper context.

[url=http:/civis/viewtopic.php?p=24537409#p24537409:1vzyjsxj said:
ShuggyCoUk[/url]":1vzyjsxj]Likewise I have been worked at places where ludicrous 'practices' were dolled out by people with "Architect"[1] in their job title which were actively harmful, notably someone in java trying to force declaration of all local variables at the top of a method, always.
The irony of this is that I share your utter disdain for incompetent architects, and posted repeatedly in the OP that I'm working hard to not fall down the standard traps that we both agree on 100%. Yet you seem to continue to pretend that if you keep repeating your Aunt Sally argument that somehow it will become true.
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
Think logically:
Pain point = developers while debugging during crunch time often add-in try-catch blocks where they want to inspect an exception, and often forget to take it out when it is no longer needed. Many times these "thrown in during debugging" blocks aren't done with any attempt to write good code and often do stupid things like swallow exceptions or pop-up ugly message boxes. (Fine while debugging, big issue if left in after debugging.)
Main reason for the pain = devs can add crappy try/catch blocks with less typing than adding basic stuff like calls to exception logging.
Simple solution = give devs a way to do it correctly that is just as fast as doing it wrong. Remove "wanting to do it quick" as a reason to do it wrong.

The VS debugger lets you inspect exceptions without needing to pepper your code with crap, why are you encouraging them to put such things in when tools exist to deal with it *without corrupting your code*?

Every time you bring up some reason you think is a valid one to encourage them to do something bad, 'better' via boilerplate in the source code, there appears to be an alternative that is actually better they could do instead. Yet still you persist. I mean by all means keep trying, you may well end up at something that genuinely cannot be done without it, but I (and obviously others) still maintain that you are not helping these people, you are harming them. Encouraging people to use plrintln debugging, in an evironment with a very powerful debugger is... weird. If they are doing such things because they lack (and are unaware of the possibility) of a REPL then give then LINQPad and set it up so it's already linked into their default project environment.

If they have a problem with committing bad stuff then *put in code reviews and help them*. If they won't do that then you are entering a world where, you are letting people run with scissors, and juggle with cats. By all means try to make that as pleasant as possible, but I can't image the frequenters of the Symposium are going to supply advice other than "get a new job" or "get a new toolkit for them to use that makes it impossible to put the scissors in your eye and puts toast, buttered side up on the cats to achieve levitation" in much the same way we would if someone came along saying "I'm writing entirely new code in VB 5, how can I make this work in wine, on linux".

Like Blacken says, this is the XY Problem, you're not interested in listening so that's fair enough, I'll stop bothering. But I'm hardly drowning out the legions saying "here's how to do it", so I'm not entirely sure why you're so hostile to me specifically.

As to Aunt sally, don't make sweeping statements of generality *to back up a specific position* as if it's somehow backing up your position. Someone's just going to shoot that statement down.

If you want suggestions on how to deal with migrating people to dealing with new languages, expectations you might get rather more help, up to you.
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
[url=http:/civis/viewtopic.php?p=24540369#p24540369:1uadgc6f said:
ShuggyCoUk[/url]":1uadgc6f]The VS debugger lets you inspect exceptions without needing to pepper your code with crap, why are you encouraging them to put such things in when tools exist to deal with it *without corrupting your code*?
This is the most bizarre part of Adventures in Misdevelopment to me. There are already tools that do what he wants, better, without doing tremendously dumb things to his codebase.
 

Richard Berg

Ars Legatus Legionis
43,037
Subscriptor
Pain point = developers while debugging during crunch time often add-in try-catch blocks where they want to inspect an exception
What the fuck?
big issue if left in after debugging
"Left in" meaning "committed"? If your developers have never heard of diff tools, and their managers don't have any code review or gated checkin or *some* sort of policy/rule based restrictions, you are screwed. Sorry.

give devs a way to do it correctly that is just as fast as doing it wrong
How the fuck can "catch an exception and immediately log + rethrow, for the sole purpose of converting first-chance exceptions to breakpoints" ever be correct?
 
[url=http:/civis/viewtopic.php?p=24543639#p24543639:1zu2zr3a said:
ShuggyCoUk[/url]":1zu2zr3a]
I've been in almost that exact scenario

:eek: I refer you to my first piece of advice

other than "get a new job" or ...

Actually we've established that Bourbon helps too. Bourbon helps everything. :D

Oh, this was long ago. The right answer was of course to re-write it with a more suitable toolkit. The example just amused me.
 
[url=http:/civis/viewtopic.php?p=24543427#p24543427:mabqzic4 said:
Richard Berg[/url]":mabqzic4]
How the fuck can "catch an exception and immediately log + rethrow, for the sole purpose of converting first-chance exceptions to breakpoints" ever be correct?

They work 99%+ of the time, but certain don't prevent CTD bugs, and certainly don't execute during a CTD.

No further explanation of what these exceptions are or how putting an exception handler further down in the call stack catches it when they otherwise escape with a crash to desktop, but that's the purported reason. What these Heisen-ceptions actually are are and how they elude normal global exception handling is left as an exercise to the imagination.
 

Richard Berg

Ars Legatus Legionis
43,037
Subscriptor
I'm not even arguing about where to put his "real" global exception handlers that intentionally log + swallow. The post I quoted claimed that additional try/catch/rethrow aided debugging somehow. Um, all .Net exceptions raise a kernel transition and go thru SEH. Literally any Windows debugger can catch such events without needing to muck up the code.
 
[url=http:/civis/viewtopic.php?p=24544491#p24544491:2x2vdy4d said:
jxl[/url]":2x2vdy4d]What these Heisen-ceptions actually are are and how they elude normal global exception handling is left as an exercise to the imagination.

Probably asynchronous exceptions such as StackOverflowException. Unfortunately I have the privilege of working on a WPF application that has thrown these before in the wild. The last one I traced back to a curious interaction with a set of radio buttons and their backing properties. Always nice to find another Easter egg left for me by the original dev. ;)
 
Status
Not open for further replies.