Beautiful code...
-
... discovered in a legacy app.
public string GetCode(string ProjectCode, string id) { try { int len = ProjectCode.Length + id.Length; int rem = 10 - len; switch (rem) { case 1: ProjectCode = ProjectCode + "0" + id; break; case 2: ProjectCode = ProjectCode + "00" + id; break; case 3: ProjectCode = ProjectCode + "000" + id; break; case 4: ProjectCode = ProjectCode + "0000" + id; break; case 5: ProjectCode = ProjectCode + "00000" + id; break; case 6: ProjectCode = ProjectCode + "000000" + id; break; } } catch (Exception ex) { } return ProjectCode; }
-
... discovered in a legacy app.
public string GetCode(string ProjectCode, string id) { try { int len = ProjectCode.Length + id.Length; int rem = 10 - len; switch (rem) { case 1: ProjectCode = ProjectCode + "0" + id; break; case 2: ProjectCode = ProjectCode + "00" + id; break; case 3: ProjectCode = ProjectCode + "000" + id; break; case 4: ProjectCode = ProjectCode + "0000" + id; break; case 5: ProjectCode = ProjectCode + "00000" + id; break; case 6: ProjectCode = ProjectCode + "000000" + id; break; } } catch (Exception ex) { } return ProjectCode; }
ProjectCode
should becamelCased
, other than that I don't see what's wrong with it ;pRead my (free) ebook Object-Oriented Programming in C# Succinctly. Visit my blog at Sander's bits - Writing the code you need. Or read my articles here on CodeProject.
Simplicity is prerequisite for reliability. — Edsger W. Dijkstra
Regards, Sander
-
... discovered in a legacy app.
public string GetCode(string ProjectCode, string id) { try { int len = ProjectCode.Length + id.Length; int rem = 10 - len; switch (rem) { case 1: ProjectCode = ProjectCode + "0" + id; break; case 2: ProjectCode = ProjectCode + "00" + id; break; case 3: ProjectCode = ProjectCode + "000" + id; break; case 4: ProjectCode = ProjectCode + "0000" + id; break; case 5: ProjectCode = ProjectCode + "00000" + id; break; case 6: ProjectCode = ProjectCode + "000000" + id; break; } } catch (Exception ex) { } return ProjectCode; }
-
... discovered in a legacy app.
public string GetCode(string ProjectCode, string id) { try { int len = ProjectCode.Length + id.Length; int rem = 10 - len; switch (rem) { case 1: ProjectCode = ProjectCode + "0" + id; break; case 2: ProjectCode = ProjectCode + "00" + id; break; case 3: ProjectCode = ProjectCode + "000" + id; break; case 4: ProjectCode = ProjectCode + "0000" + id; break; case 5: ProjectCode = ProjectCode + "00000" + id; break; case 6: ProjectCode = ProjectCode + "000000" + id; break; } } catch (Exception ex) { } return ProjectCode; }
Is the original author still around? umm not that wou'd want to hunt him/her down and hurt them or anything.... :^)
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
-
... discovered in a legacy app.
public string GetCode(string ProjectCode, string id) { try { int len = ProjectCode.Length + id.Length; int rem = 10 - len; switch (rem) { case 1: ProjectCode = ProjectCode + "0" + id; break; case 2: ProjectCode = ProjectCode + "00" + id; break; case 3: ProjectCode = ProjectCode + "000" + id; break; case 4: ProjectCode = ProjectCode + "0000" + id; break; case 5: ProjectCode = ProjectCode + "00000" + id; break; case 6: ProjectCode = ProjectCode + "000000" + id; break; } } catch (Exception ex) { } return ProjectCode; }
-
I have to compliment the author on writing bulletproof code - the catch all is awesome! /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
"What? It errored? Where? I don't see any errors? I'm sure I covered/hid all the errors..." ;P
-
ProjectCode
should becamelCased
, other than that I don't see what's wrong with it ;pRead my (free) ebook Object-Oriented Programming in C# Succinctly. Visit my blog at Sander's bits - Writing the code you need. Or read my articles here on CodeProject.
Simplicity is prerequisite for reliability. — Edsger W. Dijkstra
Regards, Sander
Sander Rossel wrote:
I don't see what's wrong with it
The only bit that's wrong is the stuff between the first and last bracket... ;P
-
Is the original author still around? umm not that wou'd want to hunt him/her down and hurt them or anything.... :^)
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
No, they left long ago. What confuses me the most is how you can know enough code to be able to write something like that, but not enough to know how to do it without the ridiculous switch statement. It's like a weird ignorance knife-edge.
-
The missing default handling and error handling (len >10) the mean exception handling shows me that some Visual Basic coder was on the loose. :~
Press F1 for help or google it. Greetings from Germany
It's friggin C# code and you STILL have to bash VB? Sounds to me like a C# dev who can't admit there are actually really very bad C# coders out there. C# coders who are, if I dare say so, even worse than a lot of VB programmers out there :) And that comes, of course, from an ex-VB coder, who has seen crap code in both VB and C# (and both make you want to spoon your eyes out) :)
Read my (free) ebook Object-Oriented Programming in C# Succinctly. Visit my blog at Sander's bits - Writing the code you need. Or read my articles here on CodeProject.
Simplicity is prerequisite for reliability. — Edsger W. Dijkstra
Regards, Sander
-
... discovered in a legacy app.
public string GetCode(string ProjectCode, string id) { try { int len = ProjectCode.Length + id.Length; int rem = 10 - len; switch (rem) { case 1: ProjectCode = ProjectCode + "0" + id; break; case 2: ProjectCode = ProjectCode + "00" + id; break; case 3: ProjectCode = ProjectCode + "000" + id; break; case 4: ProjectCode = ProjectCode + "0000" + id; break; case 5: ProjectCode = ProjectCode + "00000" + id; break; case 6: ProjectCode = ProjectCode + "000000" + id; break; } } catch (Exception ex) { } return ProjectCode; }
I'd post a legacy code snippet but I'd be sharing all the production connection strings they hardcoded at every single db connection. :mad: I seriously wished I could build a terminator to go back in time and shoot the coder in questions parents. :laugh:
-
... discovered in a legacy app.
public string GetCode(string ProjectCode, string id) { try { int len = ProjectCode.Length + id.Length; int rem = 10 - len; switch (rem) { case 1: ProjectCode = ProjectCode + "0" + id; break; case 2: ProjectCode = ProjectCode + "00" + id; break; case 3: ProjectCode = ProjectCode + "000" + id; break; case 4: ProjectCode = ProjectCode + "0000" + id; break; case 5: ProjectCode = ProjectCode + "00000" + id; break; case 6: ProjectCode = ProjectCode + "000000" + id; break; } } catch (Exception ex) { } return ProjectCode; }
-
I have to compliment the author on writing bulletproof code - the catch all is awesome! /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
I had to go back and look. Yes, it's awesome, and about as enlightened as ignoring the return code of a method or function. Catch exception and throw it away. Why even bother with naming it?
David A. Gray Delivering Solutions for the Ages, One Problem at a Time Interpreting the Fundamental Principle of Tabular Reporting