|
Think bigger:
whales.Save();
If you're having a bad day, stare at your feet and smile.
|
|
|
|
|
I recently started a new job and my first project it to do a maintenance release of one of the companies products. Yesterday I found code like this...
if ((CString)presuffixS.GetAt(i) == "%") { if ((CString)presuffixS.GetAt(i+1) == "i") {
presuffix = presuffix + szDeviceID;
i++;
}
else if ((CString)presuffixS.GetAt(i+1) == "t") {
presuffix = presuffix + szType;
i++;
}
else if ((CString)presuffixS.GetAt(i+1) == "n") {
presuffix = presuffix + szId;
i++;
}
}
Could it be any less efficient? I also found this technique used several other places too!
Thanks,
Robin.
|
|
|
|
|
It could. You could, in addition, convert the CString to a std::sting, then copy everything to a char* which has previously been allocated with malloc, and allocate it in the loop, but don't use free. Before you do that translate everything to Klingon.
If you're having a bad day, stare at your feet and smile.
|
|
|
|
|
Thanks,
Robin.
|
|
|
|
|
I have recently adopted a new laptop to the dismay of my desktop. The laptop comes equipped with a touchpad. I'm not one of those raised wrist typists, I always rest my wrists on the surface below the keyboard. More times than I can count I've wound up accidentally touching the touchpad moving the mouse pointer to parts unknown and destroying whatever it was I was typing.
I searched for a solution but didn't find anything that looked promising as a good solution so I gave up and contacted the laptop manufacturer's online help "chat". Had a solution in very short order: "fn" + "f9" to toggle on/off. I'm using W/8.1 and don't know if it is part of the standard OS functionality or an extension of some sort by ASUS. Regardless I wass pleased with the solution and thought I'd share.
Mike - typical Euro-American (white guy).
onagerware.com
tarkingtontower.org
Thomas Mann - "Tolerance becomes a crime when applied to evil."
As American as: hot dogs, apple and Sarah Palin.
|
|
|
|
|
|
That might be better as a Tip.
|
|
|
|
|
Thanks - but how do I post it?
Mike - typical Euro-American (white guy).
onagerware.com
tarkingtontower.org
Thomas Mann - "Tolerance becomes a crime when applied to evil."
As American as: hot dogs, apple and Sarah Palin.
|
|
|
|
|
Go through this and then, Menu - articles - Submit an Article or Tip.
Programmer : A machine that converts coffee into code !
|
|
|
|
|
|
Sounds like you need to swop the positions of the keyboard and touchpad.
There are a few laptops that do this. One I found was the Acer Aspire R7. Good luck in your search.
|
|
|
|
|
I terminated the touch pad on my laptop (with extreme prejudice) via the BIOS.
Software Zen: delete this;
|
|
|
|
|
I spent over an hour yesterday trying to figure out why reading in an encrypted configuration file created in another program produced the wrong results. First try looked like this:
Using sr As New IO.StreamReader(strPath)
which didn't work, so I tried the next overload that takes an encoding parameter. I tried all of them with no joy until I tried this one:
Using sr As New IO.StreamReader(strPath, System.Text.Encoding.Default)
which worked perfectly.
"Go forth into the source" - Neal Morse
|
|
|
|
|
The default behaviour is to attempt to detect the encoding based on the Byte Order Mark[^] within the stream's content. If no BOM is found, it falls back to UTF8.
It's mentioned in the remarks on the class:
StreamReader defaults to UTF-8 encoding unless specified otherwise, instead of defaulting to the ANSI code page for the current system. UTF-8 handles Unicode characters correctly and provides consistent results on localized versions of the operating system. If you get the current character encoding using the CurrentEncoding property, the value is not reliable until after the first Read method, since encoding auto detection is not done until the first call to a Read method.
And on the constructor:
This constructor initializes the encoding to UTF8Encoding and the buffer size to 1024 bytes.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You probably shouldn't use my initials in your code like that
|
|
|
|
|
Today i come across this two lines of code (i changed the naming of the functions):
if(GetA() && GetB())
*GetA() = *GetB();
took me nearly two hours of figuring out WHY DOES THIS CODE WORK, since i realised thatGetA() returns a Pointer and Pointers are IValue...
Looked deeper inside the code, i found a SetA(int) -Method...
Why to use something like
*GetA() = *GetB() if you could use
SetA(*GetB())
|
|
|
|
|
A possibly better (and much clearer) implementation would be to have GetA() and GetB() return references. You could then write the code without the idirection.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
That's even worse:
GetA() = GetB();
And due to if statement we must assume that A and B can be nulls. GetA and GetB should return const pointers.
|
|
|
|
|
My bad; I missed the if statement.
IMO, if code needs such a test, it probably has a poor architecture to begin with. It is much better to have a special dummy instance of a type to represent 'not present', and reserve the null pointer for truly bad situations that crash the program.
Reasonable people may differ on this.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
Sorry, that's not my code, an i cant change it. I just saw it in some code and where surprised what's that
Returning references would make it much harder to read:
GetA() = GetB()
looks like What the hell? Assignment to a Function?
|
|
|
|
|
C3D1 wrote: Returning references would make it much harder to read
We'll just have to agree to disagree on that. IMO, this is a quite useful C++ paradigm.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
Daniel Pfeffer wrote: IMO, this is a quite useful C++ paradigm. ...and that makes me even happier to barely being able to read C++
|
|
|
|
|
De gustibus non est disputandum
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
That's what I like about this forum. You go in thinking programming and you get a bit of Latin training. Hope I remember what the phrase means next time I see it.
|
|
|
|
|
Me too. There are plenty of sites around that merely answer programming questions, but only a few with the range of highly intelligent, humorous, and opinionated contributors that you find here. Amazingly, the amount of sniping and backbiting is kept to a minimum!
Long may it last!
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|