Sunday 25 June 2017

Review Comparison: Keweisi and USB Charger Doctor

I am currently evaluating two USB voltage/current tester : Keweisi and USB Charger Doctor.



Here is the data from the picture above:
My trusty Digital Multimeter - 8.87V
Keweisi: 8.99V/1.53A
USB Charger Doctor: 7.49V/1.50A

As some of you will wonder, why the voltage reaches more than 5V? This is because of Samsung's Fast Adaptive Charger, and it can go up to more than 5V. There are good explanations here: Link

Here, the charger switches up to to near 9V. Both the current on two USB voltage/current measurement device are almost identical so let's assume they are both ok. BUT, the voltage are different. It seems to me that the upper limit for the USB charger doctor is only up to 7.5V.

Conclusion:
Keweisi is the clear winner here. It can display the voltage and current at the same time and it can measure more voltage than the USB Charger Doctor.

Saturday 10 June 2017

Instantiator Based Programming Paradigm (C++)

Recently, I had an issue putting the uWebsockets data type on my project's headers. There were so many compiler errors by just including the datatypes of uWebsockets to my project's header file. Placing both the class declaration and definition inside the cpp source code file resolved the issue. But the next question is how will I instantiate the uWebsockets outside, this is where the instantiator came in.

I discovered by accident, and I like this new paradigm of programming. This way, everyone will be forced to do a very important principle: “Program to Interface, not to an Implementation.” And I don't need to switch to header and source everytime. I can just use the IDE's split window capability to easily edit the declaration and definition. I know this will challenge the norm because we normally separate the declaration and definition to the header and source code file. But I am ready to take criticisms and I will adjust if necessary. But as of this writing, I don't see any disadvantage and instead I only see advantages.

To illustrate here is a very simple source code on how I did it:
Websocket.cpp – Both the class declaration and definition are located here. At the end, you will see the instantiator. It will return an abstract base class pointer.
Websocket.h - This will contain only the instantiator functions.
AbaseWebSocket.h - This the abstract base class that websocket class will inherit.
main.cpp - Demonstration of how to use it.

The instantiator can produce new instances or it could produce a static instance (aka Singleton).
Again, this way, everyone will be forced to do a very important principle: “Program to Interface, not to an Implementation.” Because there is no way for you to be able to instantiate a concrete class because they will all be inside the cpp file, thus you need to go to the necessary abstractions.

Source Code Link