Sunday, 5 July 2020

Model - View - ViewModel ( MVVM ) Architecture

Introduction

MVVM is one of simple and very useful architecture. It's being used in various commercial applications with great success. To understand success of MVVM we will have "Start With Why" just like Simon Sinek said. We will have to understand why do we need software architecture and how MVVM is useful. Main intension of this article is to give head-start to reader.

"What is architecture?"

Software architecture is fundamental structure for code which will define elements and relations between them. To read more in depth start from Software architecture Wiki definition. If you have architecture well-defined it gets really simple to write code.

"What is MVVM?"

Model - View - ViewModel is architecture with 3 distinct areas isolated but directly dependent on lower module.

MVVM block diagram

For more information you can start from MVVM Wiki.

I have created very simplified version of MVVM Template code that can be copied and modified for required application.

View

This is presentation module or for visual representation of main data. In multilayer view can be display of data for next layer. For example user inputs like text in a textbox, or graph created from data are example of View module. You have to take care that there is no code which is taking action on data or modifying data in any way.

This module changes only when there are changes for presentation of data, like placement of controls, font colors.

To pass data from View to VM direct function calls can be used but to pass data from VM to view dependency property or event bindings are used.

View - Model (VM)

View - Model is module for interpretation of user data. In this module all action on data for conversion is taken. There should be nothing related to rendering or presentation.

This module changes when there are changes in interpretation of data, like user wants to change unit system in view then data conversion is added in VM. So making change in VM we can keep Model module unchanged as final unit for data is kept constant. Also, there are very few changes in view-model to add options for view.

To pass data from VM to model direct function calls can be used but to pass data from model to VM events delegates are used.

UI Services

In many cases there are user actions required for completing action. For some things user needs to be shown some dialog which are initialized from view-model. In such case UI services can be used. UI services are request for user intervention, or updating user with current state of operation. But as view thread and view model threads can be different, UI service can help VM to pass query across threads.

Model

Model module is main business logic module. Any logic specific to business like business rules or creating results from user inputs is created here in Model.

This module is modified only when there are fundamental changes in business logic.

Benefits

  • Single responsibility : Each module have single responsibility only.
  • Isolated code : Code is isolated in different modules.
  • Maintainability : Code is simple to maintain.

Conclusion

MVVM is simple segregation of code in three different modules, with rules of engagement between each module. Due to these simple rules, code created is very easy to maintain. These simple rules can be extended to any big or small application and still it will perform very well.


References

[1] "https://twitter.com/simonsinek"
[2] "https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel"
[3] "https://en.wikipedia.org/wiki/Software_architecture"
[4] "https://github.com/deorerohan/MVVM_Template"

Friday, 3 July 2020

Videos for programmer

As I was not going to get time to demonstrate new concept I have created to senior management, I thought there are other ways to demo without asking for time. Hence, I thought of creating video using things I have learnt so far. Due to lockdown and working from home situation I was looking at how to stream videos. While doing that I reached to OBS software and Twitch.tv.

In my case there were 3-4 slides and each slide had 4-5 sentences regarding a topic. Then there was demo of concept application created and a conclusion for demo. For very long time I was trying to get complete 5-10 mins video in single go but there would always happen something wrong which will destroy everything. After trying same thing again and again I got frustrated. While trying to create a single 5-min video for 3-4 hours I had AH-HA moment. Each scene in film or video is a small function. A scene is used as single block which should be perfect and to create final video you just have to put all functions in correct sequence. After I got the idea about it, I recorded everything in single go. If I made mistake I would start same sentence from start but never stopped video. I made the lot of mistakes, but when I was done I was sure that I have whatever I wanted to say there in video in perfect way. It was just part of post processing video. Later I just decided which minutes are to be cut from complete video. In just 1 hr I had my video ready.
I know 1 hr for 5 min video is too much but it was first time I had to learn each small thing on my own. I am sure next time when I want to create similar video I can do it in just 15-20 mins.

OBS software

I love open source software. People are giving you extraordinary software for free and still you want to pay for crappy software that doesn't make sense to me. You can use a software if you feel it's great then you just have to use it more, try to help people who are creating any way you want. You can contribute some money to them for maintaining servers, you can create buzz about it in social media, if possible you can help with software creation itself. Only think creator of software expects is some appreciation or small help.
I have used OBS software for video recording and OpenShot software for video editing. I have used them for creating presentations in office. You can download software from official website. There is a lot of information on official blogs

OBS software is created for streamers but it contains very good option of recording to file. You just have to configure it as per your requirements.
For current demo I was sure that I was not going to use any shortcut keys, so I set very simple shortcut keys for starting and stopping of recording (Ctrl + 0). While I was showing presentation I wanted to connect to my audience, so I added small size video of me from webcam in one side. But when I was showing application I needed complete screen so stopped my video. To accomplish that there is scene option in OBS, you can define multiple scene and each scene can have set of sources which can be video from webcam, or scene capture or audio input from any device. For above scenarios I created 2 scenes with and without my video and put shortcut keys like Ctrl + 1 and Ctrl + 2. So it was very easy to switch between scenes.
You have to careful about creating setup and shortcut keys. If you are going to play games then Ctrl + 1/2 are wrong options are you might be using it in games. For that you can use function key. If you are going to record video regarding programming then using function keys is wrong idea as you may click those keys accidentally while doing development work. You can use some complex combination or may not use any shortcut keys.

OpenShot

OpenShot is video editing software.
You can download the latest software from official website.

It is very intuitive software even if you don't know anything about video editing you can be master by just using existing things. It's up to you to define how complex you are willing to go to get expected final video this software can let you create any video you wish to.

Main screen

If you want to learn more about OpenShot there are very good tutorials created by Jonathan Thomas. I would like to tell you about some things I liked or used while I was creating video.

Use markers

You can add markers at locations where you feel you will have to come multiple times, it's just like a breakpoint while debugging a program. It can be start of scene where you can decide whether to keep this scene or not. As you start using these markers you will understand for very long video markers are very useful as you won't have to put efforts to get to point you want to go just like in debugging breakpoint will help you to get to point from where you want to check how software is behaving.

Make sure to save project before exporting

Generally video rendering is very machine intensive task even if you have best machine it will take more time than you were expecting to take. It is good idea to keep saving your current project status to machine so that if something wrong happens you can start from last saved state and continue work. When you are rendering then it takes a lot of time so it is better that you save project status and then start video rendering.

Conclusion

Using open source software I was able to create great video in short time. OBS and OpenShot software are very good software for general use.

Hope you liked my suggestions and different approach to look at video editing. If you think you like it please give me shout out at @geeky_rd on Twitter.

Thursday, 19 March 2020

Corona Quarantine

I have been to UK for training and business meetings. It was great experience to see new country with different etiquette and life style. People there are very dedicated and very honest. Many people are from different countries so it was nice to experience lot of cultures. People in company were very nice and very knowledgeable. I was learning new things from everyone every day.

But due to Corona virus spreading everywhere, it was decided that I will travel back to India and come when everything is back to normal.

But in airplane travel there is risk of getting virus from many international travelers. Just to avoid spreading virus to anyone else in India. I am in home quarantine for 14 days. There is not much to do and company machine is also not available for few days as arrangements were in progress. I decided to start learning things in my ToDo list for years.

I have started learning Accounting, Data structures, Algorithms from edx.com. It's a great platform. You can learn from extraordinary teacher for free. Its best way to catch up with your hobbies or to gain skills required in your professional life or just to know more. I will keep records of my learning here so that I can refer it when required.

I am hoping to complete as many courses as possible during this time.

Wish me luck.

Friday, 18 September 2015

Why do I want to blog??

Simple question!! Right??
Actually when I started there wasn't any reason just tried to put some stuff online. After reading lots of blogs regarding some work they are doing I realized this is best way to organize my work. I will be publishing few things but along with that I will be keeping my things organized and accessible from any where in world.
Everything I have learned about new things some where down the line I end up on someone's blog trying to understand how and why did he do that way. So if I take some thing and try my self then I should give it back too.
I know this won't be best written perfect blog but at last I will be happy that I good thing.

I am planning to share my work around raspberry pi, linux and python. Though professionally I only work on C# and C++ but I enjoy more working on my personal projects of learning and then making something useful for myself.

I will soon share many code snippets which I refer on regular basis while doing my work.
For example sending mail, file operations, web scrapping etc.

Wednesday, 29 April 2015

One minute manager

It's a very small book about how to talk with others when you are manager. If you want to scold someone do it for just 1 min or if you want to appreciate someone do it too just for 1 min. Within one minute you can present what you want to do and explain other side too. 

Book is very small so it doesn't talk about lots of things it's just about presenting your point on shortest time. 
It's good enough to read once. 
4 ratings. 

Who moved my cheese

This is very small book about being ready for change all the time. It explains how to be prepared for our rat race using rats and cheese. It's a scientific experiment put using small story and how can we be adaptive to any situations. 

As agile technology is becoming more and more popular we will have to adapt for it. 
It's good book to make us adaptive to changes. 
Rating 4.5. 

Sunday, 11 August 2013

My world of YouTube

We all are watching YouTube since its arrival. I too used it many days for latest videos. But since many days I have started subscribing to channels and follow them regularly. This blog contains information about some of the channels I prefer and follow regularly.  

Being post graduate in engineering I prefer watching videos related to science and technology. To name the few some of the channels are vsause, minute physics , minute earth, veritosim, smarter everyday, TEDed, TEDdirectors. Each channel has its own features which keeps me interested and makes me check it again. 
Vsauce and veritosim talk about different questions and technologies. Vsauce has touched on many philosophical questions also. There are vsauce 1,2,3 too. Minute physics as name suggests creates videos about physics. Smarter everyday also has videos for general interest. I have observed that all these people from different channels are connected to each other, use each other's knowledge and resources to make better and better videos. They take great efforts to make their videos to become better and informative. These all people create videos for layman. Anyone can come and started watching their videos from any time. 

Other channels I prefer watching are created by professionals TED is big organization which arranges talks from greatest people from all different technology, background and concepts to share their thoughts to world. TEDed is channel for educational animated videos. TEDdirectors is channels for clippings from different talks conducted all over the world. 
Both channels contains great must watch content. TEDdirectors contains list of most viewed videos of  different topics. 
We all spend some time checking something which can be utilized checking these greatest videos from different videos from different backgrounds but greatest thoughts and ideas of mankind.