|
Personally my favorite is :
LPSTR lpszName
Thos were the good old days* when there were no Internet to look that stuff up.
All you had was The Petzold and windows.h.
*Not really all that great for learning to program.
|
|
|
|
|
First time I saw something like thins in a C++ code base, I thought "That's clever!" It was only the second thought that I remembered how much I bloody hate maintaining such "clever" solutions.
We coders tend to be attracted to logical puzzles. It takes willpower to steer away from something clever in favor of something simple.
Either that or enough experience to know how much of a PITA clever code can be.
|
|
|
|
|
|
That's a very good article. I always like analogies because they help so much.
And this :
char* dest, src;
is a great example of code that once you know, you know, but after not seeing it for years kind of makes you pause and think, "wait, is src a char* too or just a char?
That's exactly like the weird for loop I was displaying.
It just makes you think extra for no reason.
And I liked Hungarian for years. I still do, but I'm kind of one the fence about it. You can tell what the types are, even if there is not intellisense. The point of the obj thing was that it wasn't helpful because I can tell you're calling a method on the thing so I can tell it's an object anyways. I prefixes like n and i did help so I didn't have to always back up the code and look to see what the thing was.
Then on the other hand, go ahead and name vars so I can tell that it will contain numeric values versus strings, etc.
modified 7-Nov-18 10:06am.
|
|
|
|
|
You're right - he totally should have used a while loop
while (objSourceSubFolders.moveNext())
{
if (objSourceSubFolders.atEnd())
goto Ended;
}
Ended:
cheers
Chris Maunder
|
|
|
|
|
Chris Maunder wrote: goto Ended;
}
Ended:
Much more straight forward.
You know exactly where he's going with that.
|
|
|
|
|
I like the first one better. I was expecting to see some horrid error-prone mess.
raddevus wrote: while (!sourceSubFolders.atEnd()){
sourceSubFolders.moveNext();
}
Classic! The proposed rewrite skips the first item. Well, I think we've all been there.
Hey, remember this ugly beauty from System.Runtime.Remoting?
static StringBuilder vsb = new StringBuilder();
internal static string IsValidUrl(string value)
{
if (value == null)
{
return "\"\"";
}
vsb.Length= 0;
vsb.Append("@\"");
for (int i=0; i<value.Length; i++)
{
if (value[i] == '\"')
vsb.Append("\"\"");
else
vsb.Append(value[i]);
}
vsb.Append("\"");
return vsb.ToString();
}
|
|
|
|
|
Baraaaaaa wrote: I like the first one better.
There's not accounting for taste.
Baraaaaaa wrote: Classic! The proposed rewrite skips the first item.
I know. It was a quick analysis of the original ugly code but I was too lazy to go back and fix it.
This is yet more proof that the original ugly code will cause problems for future maintenance devs.
|
|
|
|
|
It may have been a "fix" for even uglier code.
I have to remind myself (sometimes) not to assume what was in the minds of the those that came before.
And, if you've been coding "other" for-loops all day ... "highway hypnosis".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
My original post has been a litmus test.
What I'm doing is making a list of all the devs (very few) here at CP who actually say, "well, I understand this...life is real and code is ugly at times".
These are the people who I will accept their opinions when I write articles and post here to CP.
The rest I will ignore.
You are on the list for your understanding.
Don't let that get out or the other Engineers will harass you.
|
|
|
|
|
Your logic isn't quite the same.
The original logic does moveNext() at the end of the loop, always. While your logic does it first, before "doing something".
The for loop variant guarantees that moveNext() is done for each loop iteration. The while loop variant can be goofed up by other devs adding a continue before doing the moveNext() -- speaking from experience, having had to fix these sorts of problems.....
|
|
|
|
|
wrote: Your logic isn't quite the same.
Yes, others have pointed this out.
I just wrote the code sample real fast.
Now, the subtle error is bait for people with OCD.
Even the explanation of using the for loop in this case actually stinks the place up, because the original code writer probably didn't use critical thinking to consider that the loop will run once and then only increment to the next file after it gets to the bottom (after the first time through the loop).
I could've made it a do...while.
NOte: I'm not directing this criticism at you, just at any explanation of using the for loop for that reason.
modified 7-Nov-18 13:32pm.
|
|
|
|
|
This goes back to the (bad) old C days. To be cool, one would use fewer statements. For example, a forever loop we could use:
for (;;)
{
}
or
while (1)
{
}
It became in style to use the for. Besides, back in the days, C was done in Unix and code wasn't meant to be read by humans. And, the compiler didn't care how you formed your code.
|
|
|
|
|
... The bartender says: "Wow, I've never served a weasel before. What can I get you?"
"Pop," goes the weasel!
Yeah, yeah, I know! The door is thataway =>
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- Never argue with a fool. Onlookers may not be able to tell the difference. Mark Twain
|
|
|
|
|
Come on, do we really need another lawyer joke?
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
Forogar wrote: Come on, do we really need another lawyer joke?
FTFY
"If we don't change direction, we'll end up where we're going"
|
|
|
|
|
Boom!
|
|
|
|
|
A weasel walks onto a landmine...
Ron Anders wrote: Boom!
|
|
|
|
|
Seems like the Boom has been lowered!
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- Never argue with a fool. Onlookers may not be able to tell the difference. Mark Twain
|
|
|
|
|
Doh! Some things you just can un-see or un-read.
|
|
|
|
|
Perfect! My work here is done (for today!)
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- Never argue with a fool. Onlookers may not be able to tell the difference. Mark Twain
|
|
|
|
|
That's the way the money goes!
"Go forth into the source" - Neal Morse
|
|
|
|
|
A topical one for Londoners
Stab and die maybe you would be safer here (7)
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
"A Bedsit"?
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Good effort but nope
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|