Learner Learning Software Engineering

Coding blog with colored code snippets(.md posts)

We can make our code snippets more interesting and readable by sharing code with color formatting. To turn on colors, just add language short name 😉 For C# code, add cs after ```. ```cs write your code here ``` Example: static void Main(string[] args) { Logging logger = new Logging(); logger.Log("login success"); }

Adapter Design Pattern

This design patterns guides to create a wrap around existing class to reuse existing class for a new requirement. Assume, I have two logging classes named WriteLogsToLocalFile and WriteLogsToServer. class WriteLogsToLocalFile { public void Log(string fileName, string message) { //write logs to file } } class WriteLogsToServer { public void Log(string urL, string message, string token) { //call rest API with oAuth // Note: here token is used for oAuth } } static void Main(string[] args) { WriteLogsToLocalFile fileLogs = new WriteLogsToLocalFile(); fileLogs.Log("hello.xml", "login success"); WriteLogsToServer serverLogs = new WriteLogsToServer(); serverLogs.Log("https://server.logs/upload", "login success", "oAuthToken"); } Here user is manually creating objects to write logs separately to local file and server.

Code Review

Code reviews plays an important role to keep code consistent and readable. Code reviews are conducted to maintain quality and simplicity. The bugs should be taken care by automated tests. Code reviews are the best way to learn coding skills from your team members. In this post, I want to share my opinion on how to write code reviews comments. I read a document Google code review. This document is really helpful to write code reviews comments and how to fix, reply on code review comments. The variable name, function name or class name style formatting This type of comments should be taken care by compile time code validation.

Composite Design Pattern

The Composite Design pattern is structural design pattern. This design pattern is used when we want to treat a group of objects in same way. The composite design pattern has following elements. Component This is a class that contain all the members that needs to be implemented by all the objects. Composite This class is used to add, remove and traverse components. Leaf The leaf object in tree structure is defined as leaf element. Code Sample I want to print salaries of all employees in my organization with names and designation. The root of organization tree is CEO. The CEO has directors as child composite.

Android Application implementing Azure Active Directory Authentication to call protected Azure Function

In this post, I am writing about how to setup Azure Active Directory Android application login to access Azure functions protected with Azure Active Directory authentication. Create an Android Application Open Android Studio and create new Project with Empty Activity. Configure project with below settings Get SHA1 & package name Open powershell and cd to C:\Users<username>.android Execute below command, if prompted for password enter android or leave blank keytool -list -v -keystore debug.keystore -alias androiddebugkey -storepass android -keypass android Copy SHA1 -> Navigate to https://base64.guru/converter/encode/hex and convert SHA1 to Base64 Copy package name from AndroidManifest.xml Now you have packagename & Base64 SHA1 hash

Android Studio Enable Checkstyle (Gradle)

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. Steps to enable checkstyle for Android Project Create checkstyle.xml Create folder checkstyle inside Android Project app folder. Create file checkstyle.xml Reference <?xml version="1.0"?> <!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd"> <!-- Checkstyle configuration that checks the sun coding conventions from: - the Java Language Specification at http://java.sun.com/docs/books/jls/second_edition/html/index.html - the Sun Code Conventions at http://java.sun.com/docs/codeconv/ - the Javadoc guidelines at http://java.sun.com/j2se/javadoc/writingdoccomments/index.html - the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html - some best practices Checkstyle is very configurable. Be sure to read the documentation at http://checkstyle.

Generation of Sequence Diagram using Mermaid

I use online tools to generate sequence diagrams. Recently, my colleague at work guided me about Mermaid to generate sequence diagrams. This is an awesome tool. Mermaid Mermaid has online editor Editor. However, I did not use online editor for confidentiality reasons. I created index.html and opened in browser. <html> <body> <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script> <script> mermaid.initialize({ startOnLoad: true }); </script> <div class="mermaid"> sequenceDiagram participant A participant B A->>B:How are you? B-->> A: I am good loop test loop A->>B:How are you? B-->> A: I am good end </div> </body> </html>

2020 Review

The year 2020 was a year of unpredicted event Covid-19. In January, my wife travelled to Toronto for her co-op and I planned to spend my evenings studying algorithms and software engineering concepts alongside full time job. I planned to complete most of the study-topics in March and completed as planned. In mid-March my office shared guidelines to work from home. My wife was also back from Toronto and started a co-op remotely. I saved two hours of commute time. My office had layoffs. Some of my teammates were laid off. It was a hard time to see teammates leaving, and I got worried about myself.

Accessing Azure Pipeline variables in Webpack Node.js

Recently, I struggled a bit to figure out a way to access Azure-Pipeline Variables in Node.js JavaScript/TypeScript project. However, it is easy. .yml Pipeline code - task: Npm@1 displayName: "Run project" env: MyVariableName: $(MYVARIABLENAME) // this is pipeline variable name, in Capital letters inputs: commands: 'custom' CustomCommand: 'run test' npm Package install package string-replace-loader TypeScript/JavaScript File Create a file with any name “test.ts” test.ts const test = () => { const myVariable = "My-Variable"; }; Setup webpack.config.js module: { rules: [ { test: /test\.ts$/, loader: 'string-replace-loader', options: { search: 'My-Variable', replace: process.env['MyVariableName'] // from .yml env } } ] } } Finally "scripts" :{ "test": "webpack --config webpack.


To understand Double Dispatch, understanding of Overloading and Overriding is must. I already talked about Overloading and Overriding in post Overloading & Overriding. One level of virtual dispatching derived types override a base types: as shown below class Farms { public virtual void Irrigation() { Console.WriteLine("Farm Type"); } } class WheatFarm : Farms { public override void Irrigation() { Console.WriteLine("WheatFarm"); } } class RicaFarm : WheatFarm { public override void Irrigation() { Console.WriteLine("RicaFarm"); } } static void Main(string[] args) { var a = new Farms(); var b = new WheatFarm(); var c = new RicaFarm(); a.Irrigation(); b.Irrigation(); c.Irrigation(); } //output Farm Type WheatFarm RicaFarm Two level of virtual dispatching (Double Dispatch) This concept is used in Visitor Design Pattern.