|
Nope. I'm mostly working in Silverlight, but this is backend code for a webservice, so ASP.NET.
I don't see any reason to 'force' you to write bad exception handling code, ie catching Exception, then testing type.
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
|
|
|
|
|
I made the following code, and I stand by it (kind of):
var numTweets = parseInt("<%= NumTweets.ToString() %>", 10);
Can you figure out why I would do such a thing?
|
|
|
|
|
Because your tweets were numb?
|
|
|
|
|
While most tweeters are numskulls, that is not the reason.
|
|
|
|
|
Because you really don't wanna know and don't care about the number of twits?
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.
|
|
|
|
|
While true, it's not the reason.
|
|
|
|
|
What's the type of NumTweets? Perhaps it is not an int type and the conversion of it's type to var is different from the conversion of int to var.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
It's an int. This is an ASP.Net page, so the code inside the string is VB.Net and the outside code is JavaScript.
|
|
|
|
|
Because you have written this in a JavaScript function in ASP.NET, and NumTweets could be any base number, but you want it translating back to base 10. Or, you're a masochist.
|
|
|
|
|
All true (and that's sado-masochist to you!), but not the reason.
|
|
|
|
|
I've made worse... in cases i were asleep:
@{
var style = "style=\"color=@color;\"";
}
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
|
|
|
|
|
just realized that this way you still get code formatting to your javascript, while if you'd used:
var numTweets = <%= NumTweets.ToString() %>;
the formatting from visual studio and the intellisense would've blown up
I'm brazilian and english (well, human languages in general) aren't my best skill, so, sorry by my english. (if you want we can speak in C# or VB.Net =p)
|
|
|
|
|
That is exactly correct!
|
|
|
|
|
Fortunately there were three cases alone, other wise he would have ended up parsing the same enum multiple times! Comments are mine, rest remains the same!
foreach (string name in names)
{
if (StringValueOf((Enum)Enum.Parse(enumType, name)).Equals(value))
{
return Enum.Parse(enumType, name);
}
else if (AlternateStringValueOf((Enum)Enum.Parse(enumType, name)).Equals(value))
{
return Enum.Parse(enumType, name);
}
else if (name.Equals(value))
{
return Enum.Parse(enumType, name);
}
}
modified 14-Sep-12 2:06am.
|
|
|
|
|
I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image.
Stephen Hawking
|
|
|
|
|
He made his solution future-proof: somewhen in the future, Enum.Parse might return different results depending on the cases he described here. Be prepared!
|
|
|
|
|
That is rather sad code.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
Because sometimes it's not enough to evaluate it once. I suppose, for good measure, he could have put an Enum val = (Enum)Enum.Parse(enumType, name); immediately after the for .
|
|
|
|
|
[start rant]
I had to debug some logic code written by a colleague this morning. Now, the guy usually writes his code properly, but this one...
Basically, it drew some 50000 rows from a MySQL table, emptied an Oracle one, inserted those 50000 into the Oracle table, called a stored procedure, updated some stock and price info in the same Oracle table, and then logged the operation info.
Now, all would be well, IF THE GODDAMN THING WASN'T GROUPED IN SINGLE GODDAMN ELEPHANTING 250 LINES METHOD!!!!
And then, those inserts were done 20 by 20 rows, with NOT EVEN FRICKIN' MANUALLY ESCAPED STRINGS!!!
And then, of course those product codes had funky chars in there (\, ', /, " everything you may think of)
And then, of course it had no comments, besides what it was doing with those 20 by 20 inserts!
And just to get a feel of what I'm saying:
string query = "INSERT INTO product_sync_queue_log (price, sku, stock, log_refference) VALUES";
bool first = true;
foreach(Dictionary<string, string> row in rows) {
insert_data = new StringBuilder();
if(first) {
first = false;
} else {
insert_data.Append(", ");
}
try {
insert_data
.Append("(")
.Append(row["price"].ToString()).Append(", ")
.Append("\'").Append(row["sku"].ToString()).Append("\', ")
.Append("\'").Append(row["stock"].ToString()).Append("\', ")
.Append(log_refference)
.Append(")");
insert_rows = insert_data.ToString();
if((counter % MAX_INSERT_ROWS) == 0 && counter != 0) {
command = new MySqlCommand(query + insert_rows + ";", conn);
command.ExecuteNonQuery();
command = new MySqlCommand(log_query + insert_rows + ";", conn);
command.ExecuteNonQuery();
first = true;
}
counter++;
} catch(Exception e) {
Helper.treatException(this.GetType().ToString(), "copyKimProductList - ", e.Message + "\r\n" + e.StackTrace);
Helper.treatException(this.GetType().ToString(), "copyKimProductList - DEBUG - SQL Text:", "\r\n" + query + insert_rows + ";");
counter++;
}
}
The first lines in the try - catch are there to make the table insert syntax correct, i.e.
if it's the first row, do not append "," to query if it's not, do the "," append. Which of course fails!
I've just lost almost an hour, which I'll never get back!
[/end rant]
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.
|
|
|
|
|
public void WriteCode(ICodeContext ctx, ICodeFile file)
{
throw new ProgrammerIsAnIdiotException("I know not I do", new BrainNotFoundException("ERROR 404: Brain Not Found. It may have been deleted or removed."));
}
I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image.
Stephen Hawking
|
|
|
|
|
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.
|
|
|
|
|
So I wrote a short message to Lonmin (the platinum mine owners in SA) earlier this morning, with aim of expressing my displeasure at recent events.
You can imagine my surprise when upon clicking 'Submit Feedback', Outlook Express opened up, complete with 3 email addresses - one each in the TO, CC and BCC fields.
Having checked the source for the page, it's just a form. I Don't know if there's a cheaper, nastier way of doing it than like this (it's an ASPX page) - Not bad for a platinum mine eh?
<form method="post" action="mailto:nmsimang@deloitte.co.za ?subject=Lonmin Site Feedback&cc=evermaakv@dtss.co.za &bcc=GregoryN@dtss.co.za " enctype="text/plain">
See here for the live website: https://www.lonmin.com/contact_us/feedback.aspx[^]
Make it work. Then do it better - Andrei Straut
|
|
|
|
|
public void WriteContactForm(IContactFormInfo info)
{
throw new BrainNotFoundException("Brain not found", new BadProgrammerException(
"Bad programmer", new ProgrammerIncompetentException()));
}
I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image.
Stephen Hawking
|
|
|
|
|
So, has little Bobby Tables sent them anything yet? Or his HTML-encoded mates?
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
:smirk:
Nah, nothing malicious - though 15 or 20 years ago the story may have been significantly different. For entertainment purposes though, here's what I did send.
name=Simon
email=peterpan@disney.com [spam-bot friendly address]
comments=All I can say is, I hope you're happy with yourselves.
I can tell you right now, here in Australia we pay our gold-miners a more per week than these guys were asking per month. Yes that's right - we get their current monthly wage every couple of days - about 3 or 4 times each week.
AUD $70,000 per year would be considered an insult.
You have metaphorical blood on the grubby hands with which you grip your money with so tightly.
If the crazy legal motion is successful, you may well have a very nasty time ahead. Africa isn't a factory, where you can pay people like FoxConn employees - it's a country that has the natural resource that you want. You certainly can't move the reserves offshore, call-centre style. You're bound to play nice, leave the country, or act like a bunch of total so-and-so's. It's your choice.
Obviously I'm some fool writing to you from afar, without all of the facts and without having consulted you for your side of the story. I will not be the only 'fool' that holds these views.
That said - it's likely a situation beyond your control now. I can only hope that the saga influences future decisions to the benefit of ALL involved parties.
Regards & Good Day,
Simon Beeching.
PS - you may wish to fix your website - there's no excuse for a Contact Us form to open MS Outlook (or any other client-side email program for that matter)
You're using ASP.NET for the website. This has the required tools to make posting this message on your website a seamless experience for your (other) commenters
The current solution is a cheap, half-assed method. Professional is not an appropriate work to use here.
It also means I have the 3 direct email addresses. These could be passed around and the inboxes filled with hateful comments the world over. I have no interest in doing anything of the sort. It is however a glaring example of a cheap, unprofessional approach. Seriously guys?!
And no, I'm not entirely stupid - I sent the email to each of the 3 addresses as email, CC and BCC (9 copies of the email in total) since I understand that people typically have rules setup on their Outlook inboxes.
I felt the matter was important enough to warrant attention - this is more likely to be gained when any inbox rules are side-stepped. Again - this is information I shouldn't have but do, on account of the poor website implementation.
nmsimang@deloitte.co.za, evermaakv@dtss.co.za, GregoryN@dtss.co.za
EDIT: Did a couple of back-of-the-envelope calcs to better assess just what the demands equated to, I'm even more disgusted than I was earlier..
Lonmin annual production: 750,000 oz @ $1500ea (2,054 oz/day) - $1,125,000,000
3000 miners - paid $400/month - $14,400,000
3000 miners - paid $1,600/month - $57,600,000
Demanded increase - (1,600 - 400) / 400 = 1,200 / 400 = 3x or 300%
Current miner payroll as % of value of annual production of Pt: $14,400,000 / $1,125,000,000 = 1.28%
Demanded miner payroll as % of value of annual production of Pt: $57,600,000 / $1,125,000,000 = 5.12%
Make it work. Then do it better - Andrei Straut
modified 3-Sep-12 21:22pm.
|
|
|
|
|