|
I feel your pain Rob. I've spent the last three weeks on a refactoring job that was supposed to last two days at most. The guy who wrote the original code was pretty sharp, with a deep background in embedded development in C. Unfortunately, the code in question is for a Windows service written in C++. Unsafe pointer casts everywhere, no attempt to follow the group naming convention, class member variables that were unused, lots of pointer arithmetic rather than straightforward array indexing, locals that were initialized and never referenced, the list goes on. The worst was the mix of MFC and STL collection classes. I spent four days alone getting the thing to shutdown without throwing exceptions or locking up due to threading issues.
Software Zen: delete this;
|
|
|
|
|
In many ways I suspect that's worse - at least VB doesn't tend to just bomb when an error occurs (at least while debugging) - in C/C++ unhandled exceptions tend to be, well, fatal.
I don't envy you.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.
|
|
|
|
|
Agreed, porting someone else's c++ can be one step closer to the insanity abyss (compared to VB).
When i did a port/rewrite, it felt like peeking into that other fellow's brain, wondering how he could function with that strange wiring of his brain. I remember he used to start for example an event loop with a delete xxx call (except if it's the first time) followed by a new xxx call...
|
|
|
|
|
Not only does the SQL query get assembled by string concatenation but yes indeed - there is even a bit of it commented out ...in the SQL concatenation string....
Quote: "" + _
"/* " + _
",( " + _
" SELECT " + _
|
|
|
|
|
/ = stick
*= his head
Author is literally begging you to hit him with a stick on his head.
|
|
|
|
|
Oh, I was Reading it as: / up his *
|
|
|
|
|
No, that's just evil. Fear the God or broken un-fixable build (whatever scares you).
|
|
|
|
|
Just discovered that gem:
private string DoSomething(string input)
{
int len = input.Length;
for (int i = len; i < len; i++)
input = "0" + input;
|
|
|
|
|
Cool. An O(zero) loop.
/ravi
|
|
|
|
|
Brilliant note, Ravi.
—SASergey A Kryukov
|
|
|
|
|
/ravi
|
|
|
|
|
On the positive side, there's no bugs in code that's never executed.
|
|
|
|
|
I like the positive outlook you have.
Don't comment your code - it was hard to write, it should be hard to read!
|
|
|
|
|
jeron1 wrote: there's no bugs
That's not a correct statement, there could still be undetected bugs
|
|
|
|
|
If the code is never executed, it'll go undetected for a really looooong time.
|
|
|
|
|
I'd like a list of all the undetected bugs, please!
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein
|
|
|
|
|
Ooops, I must correct my statement: that code is not thread-safe, it might be executed, and bad things would happen...
|
|
|
|
|
Even if the loop was set up right that is not a great way to prepend zeros.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
What a fast algorithm!
[Flags]
public enum Bool {
True, False, ForSure, Maybe, ProbablyNot, Depends, NotDecidedYet, Undefined
}
|
|
|
|
|
Very funny . It happens sometimes!
|
|
|
|
|
So here i am with my task (if you can say that) to do a documentation on 2 of the projects. And while doing it i saw a just brilliant piece of code. For my defense i will say its not mine.
try
{
}
catch (Exception ex)
{
throw ex;
}
So what's your memories of your first documentation? I guess i will have what to tell about mine
Microsoft ... the only place where VARIANT_TRUE != true
|
|
|
|
|
It is always good to see properly implemented try/catch. Too bad the example from your project doesn't have any.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
You know, that's not so bad if there was just on little change. Handle the exception.
As for first retro-documentation my fav was working on a project and for some fupped reasoning we sold the source code. The PHB said that all modules had to be commented with file headers stating the author.
When we came across anything that was [0] of unknown origin or [b] too embarrassing to admit to, we used one of the SysAdmins' names.
|
|
|
|
|
Nagy Vilmos wrote: When we came across anything that was [0] of unknown origin or [b] too
embarrassing to admit to, we used one of the SysAdmins' names.
Quite interesting numbering scheme. Was documentation created from the project organized similarily?
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
[a] Considering how long you've been and [ii] that you read a lot of forum posts I'd assume you [3] know the convention.
|
|
|
|