|
I like your way of thinking... Good optimization, you know.
|
|
|
|
|
depends what type of programming style you're into.
Some might find the mentioned method easier/simpler to read/understand.
"Program testing can be used to show the presence of bugs, but never to show their absence."
<< please vote!! >>
|
|
|
|
|
I'm not sure I trust computers that much. Can I suggest an improvement?
string valueStr = value.ToString();
if (valueStr.Equals("true", StringComparison.CurrentCultureIgnoreCase))
{
PDFIncludeWatermark_ = "true";
}
else if (valueStr.Equals("false", StringComparison.CurrentCultureIgnoreCase))
{
PDFIncludeWatermark_ = "false";
}
else
{
PDFIncludeWatermark_ = "maybe";
}
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
You're right, never, never rely on compiler. Damn machines If you need a job done, do it yourself.
|
|
|
|
|
Oh, I trust the compiler.
It's reality I don't trust.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
The else section should return "filenotfound" I believe!
else
{
PDFIncludeWatermark_ = "filenotfound";
}
FTFY
|
|
|
|
|
I disagree: the concepts of truth and falsehood do not have anything to do with file systems!
However, in the real world I doubt the existence of "absolute truth" and "absolute falsehood" so a "maybe" response seems reasonable...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
|
Not seen that before - thanks!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Dang! Beat me to it.
Marking it as "news" is pretty hilarious.
|
|
|
|
|
|
Dear VUnreal,
Please find below a simplified code segment that may help you in achieving your code in one line using a helper class.
please feel free to add additional checks and safeguards, and rewrite the helper as an extension to the string class.
string valueStr = value.ToString();
TruthChecker tc=new TruthChecker();
PDFIncludeWatermark_ = tc.CheckIfTrue();
class TruthChecker
{
private static List<string> _truths = null;
List<string> Truths { get { return _truths!=null ? _truths : (_truths = FindAllTruths() ); } }
TruthChecker() {
}
private static List<string> FindAllTruths() {
List<string> allTruths = new List<string>();
char[] t = {'t','r','u','e'};
for(int i=0;i<Math.Pow(2,t.Length); i++) {
StringBuilder sb = new StringBuilder();
for(int j=0; j<t.Length; j++) {
int k = (i>>j)&1;
sb.Append(t[j]+('A'-'a')*k);
}
allTruths.Add(sb.ToString());
}
return allTruths;
}
public string CheckIfTrue(string tru)
{
try {
var v =
from t in Truths
where t == tru
select t;
if (v.ElementAt(0).ToString().Length == "true".Length) {
return "true";
}
} catch (Exception ex) {
tru = ex.Message;
}
return "false";
}
}
Please visit IOCCC.org to learn more about useful coding techniques.
|
|
|
|
|
Why do so many think that try - catch blocks are just here to stop you from seeing runtime errors?
It is a plain nightmare to debug a project which has code like this sprinkled all over the place.
(Note: I removed some confidental information from the code)
try
{
if (SomeConstant != "")
{
this.comboBox.SelectedItem = this.comboBox.Items[this.comboBox.Items.IndexOf(SomeConstant)];
}
}
catch { }
Or one of my favourites:
protected override bool Exists()
{
bool returnValue = false;
try
{
product = GetProductOverWebservice()
if (product != null && product.product_id == m_RecordID.ToString())
{
_product = productinfo;
returnValue = true;
}
}
catch (Exception ex)
{
}
return returnValue;
}
|
|
|
|
|
I agree with your two examples... but there have been a couple of times where I have done the same thing because I don't want an exception.
perhaps a file access on start up that is not important if it fails, I don't want to inform the user and I certainly don't want to crash the application. it is only on rare occasions thou
Yes, I know I could log the error but maybe it really is that unimportant, plus perhaps my error logging process would have an empty catch if it fails to write to a log file (after all, can't log if the logging is failing)
This will do for now
|
|
|
|
|
|
That really is bad code. Should be...
try{
} catch { }
This will do for now
|
|
|
|
|
An idea for "oE" might be: "obscure Exception". The lowercase "o" is to keep it as obscure as possible.
|
|
|
|
|
More likely, "obvious Exception", since If the form does not start you'll notice soon enough.
Obviously.
|
|
|
|
|
The Dutch (yes, I'm from the Netherlands) word for 'unknown' is 'Onbekend' and the Dutch word for 'unexpected' is 'Onverwacht'... So maybe I should have translated oE to uE?
I love all the guesses coming in though, keep them coming!
It's an OO world.
|
|
|
|
|
Naerling wrote: Don't really know what oE is
That's obvious Enough , isn't it?
|
|
|
|
|
That's excellent.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|
|
Naerling wrote: Don't really know what oE is
I guess it means "objectException", in an extra nasty form of hungarian notation.
|
|
|
|
|
Regards,
Koushik.
Most people never run far enough on their first wind to find out if they've got a second. Give your dreams all you've got and you'll be amazed at the energy that comes out of you.
|
|
|
|
|
Awesome.
Regards,
Koushik.
Most people never run far enough on their first wind to find out if they've got a second. Give your dreams all you've got and you'll be amazed at the energy that comes out of you.
|
|
|
|
|
It once took me 2 days! to track down a bug because someone had decided to swallowed the exception catch { } . The problem is some programmers just don't get it.
The best article I've ever read regarding exception handling is Exception Handling Best Practices and it's on CodeProject.
"You get that on the big jobs."
|
|
|
|