When should we override WindowProc and when should we override DefWindowProc? - windows-messages

My doubt is that,
in what all situations we should override WindowProc?
in what all situations we should override DefWindowProc?
Environment: VC++, MFC

Related

How does the Kotlin/Native compiler handle polymorphism?

In a personal project of mine on Kotlin/JVM, I was told that I should avoid polymorphic method calls in performance sensitive code. Wondering why this was the case, I ended up finding this article which highlights why.
Naturally, I wondered why this limitation was necessary. Can Kotlin/Native avoid virtual method table lookups by enforcing polymorphism just at compile time? Consider the following example.
interface A {
fun foo()
}
class B : A {
override fun foo() = Unit
}
class C : A {
override fun foo() = println("")
}
val bar = listOf(B(), C())
bar.forEach {
it.foo()
}
In the current version of the Kotlin/Native compiler (1.4.20), are virtual method lookups necessary for the above example? Furthermore, are they theoretically necessary? Can the above code be completely enforced by the compiler?

HK2 Proxy vs javax.inject.Provider

I have two singleton services bound to the dependency injector (via Jersey):
ResourceConfig.register(new AbstractBinder() {
#Override
protected void configure() {
bind(Foo.class)
.to(Foo.class)
.in(Singleton.class);
bind(Bar.class)
.to(Bar.class)
.in(Singleton.class);
}
});
Foo uses Bar, so I can simply do the following:
public class Foo {
#javax.inject.Inject private Bar bar;
}
If Foo only uses Bar rarely, then I can defer its construction:
public class Foo {
#javax.inject.Inject private javax.inject.Provider<Bar> bar;
}
I have also read that using Provider is recommended in general as it avoids this eager evaluation and circular dependencies (though I try to avoid those anyway).
But what about making it a proxy?:
ResourceConfig.register(new AbstractBinder() {
#Override
protected void configure() {
bind(Foo.class)
.to(Foo.class)
.in(Singleton.class)
.proxy(true)
.proxyForSameScope(true);
bind(Bar.class)
.to(Bar.class)
.in(Singleton.class)
.proxy(true)
.proxyForSameScope(true);
}
});
I am new to injection so not sure on the history. Are they effectively the same concept for the two different frameworks?
A proxy makes the code look nicer and pushes the concern to the creator of the service instead of the user of it (which may or may not be desirable). Is there any disadvantage to this versus Provider?
Note the only thing being considered here is singleton services.
This is purely an opinion, but I would prefer the proxy myself, for most of the reasons you mentioned. It is better in general to proxy interfaces because then the JDK proxies are used but as long as your Bar class follows the proxy rules you should still be ok.

How can I test a private or fileprivate function in project

I want to write some unit testing code for a manager class, the function I would write for is using some small private functions. I will prepare a lot if I testing the public function, so I want to test those private functions. But in test target I can't call the private function directly.
So I wanna ask, is there's a way to test them without change them from private to internal or public?
So I wanna ask, is there's a way to test them without change them from private to internal or public?
Add an internal function that does nothing but call the private function. Probably it's best to do it in an extension:
class Foo
{
fileprivate func myPrivateFunction(p: Int) { ... }
}
extension Foo
{
internal func testMyPrivateFunction(p: Int)
{
myPrivateFunc(p: p)
}
}
You can probably find a way of using conditional compilation to omit the extension for release builds e.g.
#if DEBUG
extension Foo
{
internal func testMyPrivateFunction(p: Int)
{
myPrivateFunc(p: p)
}
}
#endif
Not tested the conditional thing to see if it works, it's borrowed from here https://ericasadun.com/2018/04/18/forcing-compiler-errors-in-swift/
Sadly no. There isn't a "VisibleForTesting" tag in Swift as there is in java.
However you can define a protocol which your manager class then implements including only the methods you want to test.
For example if your manager has a function called createViewModel that calls several private methods testing that the viewModel created matches that of what we expect we have implicitly tested the private methods work. You can set up your manager with different initial conditions to test all varieties and edge cases
I think you are looking for #testable imports. From Apple's documentation:
When you add the #testable attribute to an import statement for a
module compiled with testing enabled, you activate the elevated access
for that module in that scope. Classes and class members marked as
internal or public behave as if they were marked open. Other entities
marked as internal act as if they were declared public.
Interfaces are the solution.
This solution is a bit more complicated than the others, but can help you for multiple purposes, like uncoupling modules on your app.
Let's say you have a class Foo which has an object of type Bar, and you need to call doStuff().
Create a Protocol for Bar. So Foo is decoupled from Bar and becomes fully testable without exposing its content to Foo. Something like this:
protocol BarProtocol {
func doStuff()
}
class Bar:BarProtocol {
func doStuff() {
print("Hello world")
}
}
class Foo {
var bar:BarProtocol
init() {
self.bar = Bar()
self.bar.doStuff()
}
}

Make a globale variable not lazy

I'm building a library in Swift and it has a global variable (global variables are automatically initialized lazy). Initializing this variable takes about one second. My problem is, I want to initialize the variable when the app is loading, so that the user doesn't have to wait later. My current approach is this:
My ViewController:
override func viewDidLoad() {
...
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), {
let _ = Foo()
})
}
My Framework File:
let myGlobalVariable = bar()
class Foo {
public init() {
myGlobalVariable
}
....
}
But this approach doesn't seam like it is the swiftlike way of doing it. How can I initialize the variable the right way?
Thx
There is no swift way to "when" you should init global vars in your framework , It depends on the flow of your framework , nothing in your framework will be called until it is used , there is no "FrameworkDidLaunch" method, it's a "static" code just like any other classes but in another module , it can even be just a bundle of resources ...
If you want to ensure that someone uses your framework the way you intented to then write it in the documentation and/or add a static method that has to be called before use like "MyFramwork.startMyFramework()" or if you need some info from user like API Key "MyFramwork.setApiKey(_:)" and use it to init global vars and assert if this method was called.

How to write Teardown for RowEntryFixture or ColumnFixture in Fitnesse

I am using RowEntryFixture to process some data, at the end of it, I want to execute some code, how can i do that?
I am using fitnesse with C#
You can override DoTable:
public override void DoTable(Parse table) {
DoRows(table.Parts.More);
DoSomeStuffAtEnd();
}

Resources