I have been programming for over 15 years now. I consider myself a very good programmer, but I understand (like all of us) there are things that I need to work on. One of these things is code repetition when dealing with conditions. I will give a generic sample:
FWIW this whole 'universal printer driver' challenge has been around since the 1990's! Back in the day it was ADOBE that held the mantle via their portable document format (PDF) which provided the most fidelity between your-layout and your-printer's-capabilities.
By the 2000s, Microsoft went with XML-defined formats -- namely XPS. Alongside the [possibly transient] format, and combined with USB standards, the document driver models were evolving. A new generation of hardware adopting different/outdated security models prevented Microsoft from 'forcing' the industry to utilize a single 'Universal' printer driver.
Every major OS generation (and obsolescence of older hardware/vendors) moved the needle further along... until 3D Printers (esp. by mid-2010s) changed the maths again! While standard documents had attained sufficient compatibility across OS + printer scenarios (and the slow death of Fax support), there were two major shakers to the hopeful calm: open 3d model formats, and subscription-based printer resourcing (HP and Epson are mostly guilty here).
With a sense of calm in the printing industries (whatever is left), there's hope for another push for standardized printer hardware drivers... until another printer hardware trend wrecks havoc and custom drivers become requirements...
Question
xWhiplash
Hello,
I have been programming for over 15 years now. I consider myself a very good programmer, but I understand (like all of us) there are things that I need to work on. One of these things is code repetition when dealing with conditions. I will give a generic sample:
if(condition1) { //perform some logic if(condition2) { //perform some logic if(condition3) { //Perform logic } else { //MethodA(param) } } else { //MethodA(param) } } else { //MethodA() }Now, I cannot make it easy by doing the following:
if(condition1 && condition2) { } else { }I cannot do this since I need to perform some logic if condition1 is true and before I test condition2.
Is there a way to structure if...else blocks to where if you need to call a method in each else blocks, you are not repeating yourself?
Link to comment
https://www.neowin.net/forum/topic/1226783-avoid-code-repetition-in-conditions/Share on other sites
80 answers to this question
Recommended Posts