Thursday, July 4, 2019

Generate HTML5 from Java Code

Some background. All the folks who coded in ASP/JSP or similar languages will remember the painful steps to display some database records in an HTML table. 
Use server side scripting code to get the records, then start an ASP loop, creating for each row,
for each field. If editable grid, then even more pain. (ya ya, I know don't mix the server side and client side scripting etc etc. But even without that pain was still there).
I remember searching something close to desktop VB counterpart, and found some ASP widgets but those were not recommended. 
 

New Ajax based UI frameworks like Angular takes away the pain quite a lot but there is a learning curve.
 
Recently came across Vaadin. As per the site:



The description itself, reminded me of the pain faced decade back. Not saying it can be used in all applications, and definitely needs more judicial decision making if being used in production but I loved the simplicity and approach. 

Plain simple java , getting converted to beautiful HTML 5.

Thursday, April 5, 2018

when logger crashed the application

Ever heard a logging statement causing out of memory crashes in an application.

Some technical details: (Though most of the folks stopping by should already know, but I talked to few techi folks who weren't aware about it)

When you write
logger.debug("got a request to execute"); // We are good.

But when you write

logger.debug(heavyObject.toString());       // or
logger.debug("some string" + "some string" + someHeavyObject);

your application (and common sense) goes down the hill. 




One will argue that heavy operation will happen only if log level is debug. 
But that's wrong. Because, even before the flow reaches inside 'logger.debug', the object transformation is done. No, this is not because your logging library is bad, but because that's how Java is, and even most of the other languages. That's the way its suppose to be.

So please guard the heavy logging statements with log level check.
if (logger.level==debug) {
       logSomeHeavyStuff();
}

Yes that's ugly but that will save your application some precious CPU and memory.

Recently the project I was working on, was getting OutOfMemory crashes. That's what happen when you try to convert a 60,000 object array into a string for a trace level debugging. :)

Why that object grew to 60K, is another story to be told some other day. 

Tuesday, March 13, 2018

Blaming the wrong guy

I remember a Dilbert strip regarding pointy hair boss solving a wrong problem.

Saw this the other day - https://tedvinke.wordpress.com/2014/02/13/mockito-why-you-should-not-use-injectmocks-annotation-to-autowire-fields/

Though the problem regarding not using constructor is right, as it ends up giving a partially created class object in the test, but putting the blame on InjectMocks is totally wrong.

Injectmocks does what it suppose to do, if the developer is not following good programming practices, and is not aware which dependencies will get used in the unit test flow, then you cant blame the framework.

Just to go bit off topic, I had problem with InjectMocks, even after providing all the autowired beans, it jumbled them up. Reason - There were couple of prototype beans and I was injecting the Provider interface in the constructor. Here mockito was getting confused in mapping the correct providers . There I was forced to use the manual initialising of SUT using constructor. Not sure if the problem exists in the newer versions also.


Tuesday, November 21, 2017

Working out of one's functional boundary...

In recent years, rather more than a decade now, QE has emerged as a strong entity in overall SDLC cycle. Not saying it was not previously, but companies realizing the cost of fixing bugs in production, moved emphasis on having a disconnected test team, giving them more power.

But one side effect of this is - Misuse of power. 
Many times I observed QE team stepping out of their boundary and doing things like suggesting functional changes at the time of delivery (not at the time of backlog grooming, which actually is a good thing). 

I remember once multiple QE's huddled around me and were trying to arm twist me in changing a UI flow which 'they thought' was right. I didn't negate, but requested them to check with Product Owner. To my surprise they wanted the change to happen then and their !!!!

Thankfully I held my position.

But many developers are not like that. Recently something similar happened, where QA reported a UI error message appearing in unexpected flow. On analysis found that it was not required at the first place.
Dug further and was surprised by the reason -
A recent guideline was given to QAs to ensure unit test code coverage for the functional areas marked as critical. (Not sure how QAs can track unit test coverage)
Blindly following that policy they asked for the code coverage for a negative scenario in a method, which was not present as per the functional flow. And hence an error message was specifically added, to ensure what QA called a proper coverage !!!!
ahem... !!!

Obviously the developer should have stood his/her ground, but to make things worse even the team architect approved the approach.

Not sure if a single person can be blamed here, but overall teams should always take a firm stance when someone is trying to encroach out of their permissible limits. Not because of pride issues, but because of the scenarios like the one mentioned above.

As usual, happy coding...