Single drop – (Poem)

Single drop of salty liquid –

rolled out from my right eye,

carrying all my burden away.

Single poem of sweet nectar –

rolled out from my left heart,

carrying all of me away.

My face is now a mural –

painted out on a front wall,

flashing all light railers.

My story is now forgotten –

extracted out from the back of,

all souls carrying ocean inside.

The Highly Scalable system by humans is the family

 

Apparently the highly successful high scalable system designed, evolved by humans is neither AWS nor Azure (nor Google Cloud not OCI nor FB one), rather it is the unit of family.

Imagine you are given a task to organize seven billion entities and yet –

  1. be productive
  2. be competitive
  3. be mindful
  4. survive and propagate
  5. be selfish and at the same time be helpful to other entities.
  6. etc…

Your brain is going to explode isn’t it ?

But humans did it with a simple design called the family.

Git(hub) feature request – Make Code review comments available to developers forever during their edits

One of the recent trend is to minimize quantity of comments inline in code files and improve quality of comments. This caught up like fire and moving towards the danger zone of no comment-era. This is all good provided the code is written with maintenance in mind and not for short term goals of long running product to satisfy some OKR set by somebody higher up or to meet some dead line which coincidently aligns with your performance review period 🙂

I am all for those learning of clean code. Good variable names, smaller classes, smaller methods, meaningful names to methods, highly readable code, lesser number of lines of code, let the compiler worry about optimizing my code etc…

But this comments is a tricky thing. when the code is written first time a lot of thought goes into it. compromises will be made, hard decisions will be made. Developers are moving intra-companies, inter-companies like crazy Salagars. All this context is lost for future developers. Now they are told more comments is bad pattern.

One natural place for all this information is code review description, self-comments, discussions. It is already happening there – just that this information is not easily available to future developers readily.

If Git(hub) can find a way to make this information available to editors (e.g.. VSCode, which already shows lot of Git history while you try to edit a code-file) it will be pretty useful to developers who are trying to fix that nagging bug and keep swearing “who the fuck wrote this shit and why?”

stringObject.IsNullOrWhiteSpace() a simple c# extension method

Every time doing String.IsNullOrWhiteSpace(input) is irritating. Moreover we try to input. and look for this method in intelligence. But it won’t be there, as it is static, unless we do String. we don’t see this method.

Writing an extension method will save us this trouble.

public static class MustHaveCSharpExtensions
{
	public static bool IsNullOrWhiteSpace(this string input)
	{
		return String.IsNullOrWhiteSpace(input);
	}
}

c# new feature request : AutoInitListsOnFirstUse

Another sugar coating – a compiler should easily generate code for this (?) without any side effects. why force people to do new boiler plate code ?

List<string> myListOfStrings;

myListOfStrings.Add(“firstString”);

This throws NullReferenceException until we do new List<string>();

The probability of it happening is more when this is part of another data class, which we initialized but forgot to look into all hose other initializations we need to do.

In case somebody want to avoid this behavior we should have an attribute to support old behavior.

[SansAutoInitListOnFirstUse]

Creating dotnet solution, project and test project with cli

This is a good source. https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-mstest 

mkidr MyConsoleProjectWithUnitTest
cd MyConsoleProjectWithUnitTest/
dotnet new sln
mkdir HelloWorldConsole
cd HelloWorldConsole/
dotnet new console 
(or dotnet new classlib for creating Library instead of console project)
dotnet run
cd ..
mkdir HelloWorldConsole.Tests
cd HelloWorldConsole.Tests/
dotnet new mstest 
dotnet add reference ../HelloWorldConsole/HelloWorldConsole.csproj 
cd ..
dotnet sln add HelloWorldConsole/HelloWorldConsole.csproj 
dotnet sln add HelloWorldConsole.Tests/HelloWorldConsole.Tests.csproj
code . 
# Make modifications to your tests, program. 
Cd HelloWorldConsole.Tests
dotnet test 

Monster in forest (Recursion)

Long long ago there was a thick forest,

In that forest several animals are living in balance. There are rabbits, tigers, lions, elephants, owls, eagles, snakes, foxes and what not.

One day from a far away village a cow walked into forest. The cow is grazing green pastures and didn’t realize its surroundings until it is already too late.

A red fox saw the cow entering into forest, it never saw a cow in its life. It doesn’t know what kind of animal it is. Naturally unknown things frighten foxes and this fox is much more frightened. It started running without looking back.

All of a sudden, it bumped into a tiger on the way! Tiger got annoyed – it just now finished its meal and going home.

Fox expressed its deepest regrets and also informed him of a strange monster newly entering the forest.

Tiger got worried, it met its friend lion and discussed the same. Which was overheard by a owl sitting nearby. Owl discussed about this big scary monster of gigantic size with glowing eyes, mouth as big as a mountain – who can gulp even elephants in one gobble.

Eagle dutifully informed about this elephant eating monster newly entering into forest and asked elephants to be on watch.

Elephants talked about it in detail and cancelled their lake visit for that day. This was heard by rabbit, who was simply minding his own business and hiding away from those big elephant legs.

The cow entered into a bushy area and greeted by rabbit. Rabbit stared into cows eyes, cow stared into rabbits eyes and smiled. In a hushy voice rabbit told cow about big gigantic eye glowing mountain size mouthed elephant eating monster. Asked cow to be very careful.

Cow now literally scared, already forest is new to it – without looking back ran back to village.

Back in the village cow told everybody about its small adventure and how it escaped the big scary eye glowing gigantic mountain size mouthed elephant eating monster.

Even today the people in the village were scared to enter into forest, they know there is a monster waiting for them in forest.

Even today the folks in forest doesn’t walk alone, they walk in groups. They know a monster is in forest.

c# using custom attributes to validate prerequisites for methods, controller APIs

If you have bunch of prerequisites to be validated for more than one method, we could make code more cute by using an attribute.

For normal methods, this new custom attribute’s constructor could throw exception in case of failure.

But throwing exception in Controller API is bad idea. We want to return more gracefully.

Instead of extending Attribute, extend AuthorizeAttribute and override IsAuthorized() [ or AuthorizeCore() ] method to return true or false. This is more graceful way of doing prerequisite check.

I know this AuthroizeAttribute is to check authorization, but we could mis-use it to validate any prerequisites until a better way is available.

/*****************************************************************************************/

using System;
using System.Web;
using System.Web.Mvc;

namespace WebApplication1.Controllers
{
internal class MustBeAuthorizedAttribute : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{

if (preRequsitesFail)

{
return false;

}

return true;
}
}
}

/*****************************************************************************************/

[MustBeAuthorized]
public ActionResult Index()
{
return View();
}

/*****************************************************************************************/

Thanks to @philip instead of AuthroizeAttribute  ActionFilterAttribute is better. We could return any return value (e.g.. MethodNotAllowed, InternalServerError); see https://stackoverflow.com/questions/16822365/web-api-how-to-stop-the-web-pipeline-directly-from-an-onactionexecuting-filter