|
raddevus wrote: When I was in QA if a dev ticked me off, I would just test his code, find a critical bug and then post it Friday afternoon.
That is evil.
I love it
|
|
|
|
|
Viewing this as a old C programmer, it all makes sense, is quite clear and does the job.
C++ version seems to introduce fuzziness and obfuscation (although straight C can do the same thing).
Cute or clever does not always = maintainable code.
Just saying.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
raddevus wrote: What do you think? I think this "belongs" on one of the technical forums ... but, given the general neglect of many forums, and the free-for-all the Lounge has become, I am just "blowing smoke"
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch
|
|
|
|
|
|
Cut and Paste?
Sorry it's Sunday and I couldn't resist.
PartsBin an Electronics Part Organizer - An updated version available!
JaxCoder.com
|
|
|
|
|
Well, in C# I have a whole bunch of extension methods to make life easier for string manipulation, looping, matching, assertions, encoding/decoding, etc. I guess that's not exactly a coding trick, more of a re-usable library. And the only "discomfort" is that C# newbies think these things are built-in classes and methods on their respective data types.
|
|
|
|
|
I have one I just made the other day in C# for reading and writing structs over a serial port using marshalling. WriteStruct and ReadStruct on a SerialPort class. =)
It doesn't make *me* uncomfortable, but people might puke at the idea of using marshalling for sending data over serial rather than using something like binary serialization.
Marshalling requires less code. I'm nothing if not lazy.
To err is human. Fortune favors the monsters.
|
|
|
|
|
honey the codewitch wrote: Template-instance statics I've done that for cases where I didn't want to pass around a singleton instance:
class API
{
public:
static void DoThing();
private:
API();
static API *_This;
};
API *API::_This = NULL;
void API::DoThing()
{
if (_This == NULL) _This = new API();
} It's useful for create-only-if-needed scenarios. For us, those arise fairly often adapting to different hardware. They're also useful when the creation process is expensive or time-consuming.
In C++ I like the idea that API::DoThing() is a blatant syntax for a singleton concept.
I've also had cases where the public static functions define the 'API' for a collection, while the instance members and values are the elements in the collection.
Now, I know that singletons are a 'code smell', but trust me... I know what I'm doing.
Software Zen: delete this;
|
|
|
|
|
I totally get what you're saying. Just for clarity though template-instance statics add another dimension to statics because they are not shared between different instantiations of the same template.
template<int A> struct foo final {
static int value;
};
...
...
foo<1>::value = 5;
foo<2>::value = 4;
printf("%d + %d = %d\n",foo<1>::value,foo<2>::value,foo<1>::value+foo<2>::value);
To err is human. Fortune favors the monsters.
|
|
|
|
|
Congratulations, your Witch-ness! You have successfully taught an Old Dog a wonderful new trick!
Software Zen: delete this;
|
|
|
|
|
I didn't tell you the downside. You must initialize the statics to avoid a linker error, and I don't know about C++20 but previous versions require declarations like this for statics:
template <uint8_t Pin, uint32_t DebounceMS , bool OpenHigh, size_t Events>
int_button<Pin, DebounceMS, OpenHigh, Events>*
int_button<Pin, DebounceMS, OpenHigh, Events>::m_this = nullptr;
To err is human. Fortune favors the monsters.
|
|
|
|
|
I don't think that's a downside, really. I'd expect that to be required initialization, since non-template static members require it.
Software Zen: delete this;
|
|
|
|
|
I'm referring to the nasty syntax required.
To err is human. Fortune favors the monsters.
|
|
|
|
|
Maybe the "Named parameter idiom"[^]. Instead of:
Rectangle r(10, 15, 24, 42);
you can write:
Rectangle r;
r.left(10).top(15).width(24).height(42); Makes a world of difference when you have complicated objects with lots of parameters.
Mircea
|
|
|
|
|
yikes!
I've done similar, but mostly for constructing Abstract Syntax Trees.
To err is human. Fortune favors the monsters.
|
|
|
|
|
|
In C:
a^=b^=a^=b;
...will swap the values of a and b by XORing them a couple of times, assuming a and b are the same size. Works for large data structures just as well as for ints: quite fast, too. Back in the days before proper video cards, this was good for swapping in entire screen contents, or faking sprites or whatever...
Note that this doesn't work in C#: you have to go...:
a^=b;
b^=a;
a^=b;
...because unlike C, C# uses the original values of the variables throughout the evaluation of the expression, so what happens if you try to run the original statement is that one variable receives the swap, but the other one is garbage. And really, it only works for ints. But it does let you swap the variables without using a third one.
|
|
|
|
|
Use Background worker report progress to trigger different conditions on the main thread.
*** Ya Ya I know..background workers But I didn't architect the project
Private Sub Go(myList as list(of String))
bgw1.RunWorkerAsync(me,myList)
End Sub
Private Sub bgw1_DoWork(sender As Object, e As DoWorkEventArgs) Handles bgw1.DoWork
Dim myList As List(Of String) = e.Argument
Dim listCount As Integer = myList.Count
For i As Integer = 0 To listCount
Dim resultInteger = DoWork(myList(i))
bgw1.ReportProgress(resultInteger,myList(i))
Next
End Sub
Private Sub bgw1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles bgw1.ProgressChanged
Dim p As Integer = e.ProgressPercentage
Dim s As String = CStr(e.UserState)
Select Case P
Case 1
lbl1.Text = s
Case 2
lbl2.Text = s
Case Else
lbl1.Text = "Invalid Result for " & s
lbl2.Text = "Invalid Result for " & s
End Select
End Sub
modified 10-Jan-23 11:06am.
|
|
|
|
|
Always wrap any third party or sufficiently complicated built-in API with your own API.
The original API or third party will change or become deprecated in about 10 years.
A good rule for code that you expect to last 20 years or more.
If you expect a five year life span then it might not be worth it.
|
|
|
|
|
To toggle a flag variable that has values of 0 and 1:
Flag = 1 - Flag
FormerBIOSGuy
|
|
|
|
|
This has been happening for me for quite a while on Windows 10...I never inquired about it, and just now, Google searches returned nothing relevant (or my keywords aren't good enough).
Every once in a while...I'll try to RDP (by launching mstsc.exe) into a system I have on my LAN...I provide the machine name, hit Connect, then the standard (Windows 10) credentials window does NOT come up. But it's there - if I move the mouse over the RDP icon on the taskbar, there's a Remote Desktop Connection entry in its popup menu, and if I just move the mouse over it, the credentials window comes up...only, the layout is completely messed up:
I have a 4K monitor, and the window is resized to such extremely large proportions, I only see the Remember Me checkbox in the top-left corner, then on the bottom of the screen, the OK button has a normal height, but is so wide it occupies half the screen (at 4K!); the Cancel button looks the same; normal height, but the width takes up the other half of the screen. The password textbox is "out of bounds", and I have to have the mouse hover over/leave the icon on the taskbar repeatedly and/or try to cancel (Esc)/hit Connect again, so the credentials window might eventually resize itself correctly on its own.
Has anyone else seen this? It's been going on for years, and whether it'll work correctly or not on the first attempt is anyone's guess.
|
|
|
|
|
This rather plain vanilla operation in terms of a user view point is surprising complicated in Windows.
This is used to be easy to do using grep or some version of it.
Hey, Microsoft how about this command
search for "text" in all text files "on my disk"
and I mean that simple.
No ??..xxgreppx */*/.*(*dmmd
Grrrr.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
Try Google - maybe they are wrong, but it is a start.
|
|
|
|
|
Google used have a search engine one could use search you own system (can't recall it's exact name google_something). They don't have it anymore.
It was great.
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
I believe you are talking about this: Google Desktop - Wikipedia. I think it was known for sending lots of data back to Google, if my memory serves, but everyone liked it. It also became redundant when Windows added about the same thing with its file search capabilities where it databased everything (which is what Google also did I believe).
I'll also add my two cents for Agent Ransack, which I use occasionally.
|
|
|
|