Monday, 21 September 2020

C# - LINQ | Grouping Operator | ToLooKUp

// C# program to divide the employees in 

// groups according to their gender

using System;

using System.Linq;

using System.Collections.Generic;

 

// Employee details

public class Employee

{

 

    public int emp_id

    {

        get;

        set;

    }

 

    public string emp_name

    {

        get;

        set;

    }

 

    public string emp_gender

    {

        get;

        set;

    }

 

    public string emp_hire_date

    {

        get;

        set;

    }

 

    public int emp_salary

    {

        get;

        set;

    }

}

 

class GFG

{

 

    // Main method

    static public void Main()

    {

        List<Employee> emp = new List<Employee>() {

 

            new Employee() {emp_id = 209,

                            emp_name = "Anjita",

                            emp_gender = "Female",

                            emp_hire_date = "12/3/2017",

                            emp_salary = 20000},

 

            new Employee() {emp_id = 210,

                            emp_name = "Soniya",

                            emp_gender = "Female",

                            emp_hire_date = "22/4/2018",

                            emp_salary = 30000},

 

            new Employee() {emp_id = 211,

                            emp_name = "Rohit",

                            emp_gender = "Male",

                            emp_hire_date = "3/5/2016",

                            emp_salary = 40000},

 

            new Employee() {emp_id = 212,

                            emp_name = "Supriya",

                            emp_gender = "Female",

                            emp_hire_date = "4/8/2017",

                            emp_salary = 40000},

 

            new Employee() {emp_id = 213,

                            emp_name = "Anil",

                            emp_gender = "Male",

                            emp_hire_date = "12/1/2016",

                            emp_salary = 40000},

 

            new Employee() {emp_id = 214,

                            emp_name = "Anju",

                            emp_gender = "Female",

                            emp_hire_date = "17/6/2015",

                            emp_salary = 50000},

        };

 

        // Query to divide the employees

        // in the groups according to 

        // their gender Using the 

        // ToLookup method

        var lookup = emp.ToLookup(e => e.emp_gender);

 

        Console.WriteLine("Gender: {0}", lookup["Male"]);

 

        foreach (var val in lookup["Male"])

        {

            // Here name is the value

            Console.WriteLine("Name By Gender Male: {0}", val.emp_name);

        }

 

        Console.WriteLine("Gender: {0}", lookup["Female"]);

 

        foreach (var val in lookup["Female"])

        {

            // Here salary is the value

            Console.WriteLine("Name By Gender Female: {0}", val.emp_name);

        }

 

        foreach (var val in lookup)

        {

            // Here salary is the key value

            Console.WriteLine("Group By Gender: {0}", val.Key);

 

            // Display name of the employees

            foreach (Employee e in val)

            {

                Console.WriteLine("Employee Name: {0}", e.emp_name);

            }

        }

    }

}


Saturday, 5 September 2020

C# - Stateful vs Stateless


Stateful vs Stateless

·         stateful API is one that "remembers" what functions you've called so far and with what arguments, so the next time you call a function it's going to use that information. The "remembering" part is often implemented with member variables, but that's not the only way.
·         stateless API is one where every function call depends solely on the arguments passed to it, and nothing else.

State is simply information about something held in memory.
As a simple exercise in object orientation, think of a class as a cookie cutter, and cookies as objects. You can create a cookie (instantiate an object) using the cookie cutter (class). Let's say one of the properties of the cookie is its color (which can be changed by using food coloring). The color of that cookie is part of its state, as are the other properties.
Mutable state is state that can be changed after you make the object (cookie). Immutable state is state that cannot be changed.
Immutable objects (for which none of the state can be changed) become important when you are dealing with concurrency, the ability for more than one processor in your computer to operate on that object at the same time. Immutability guarantees that you can rely on the state to be stable and valid for the object's lifetime.

Mutable vs Immutable
As far as I know, this distinction is only meaningful when you can specify an initial state. For example, using C++ constructors:
// immutable state
ImmutableWindow windowA = new ImmutableWindow(600, 400);
windowA = new ImmutableWindow(800, 600); // to change the size, I need a whole new window

// mutable state
MutableWindow windowB = new MutableWindow(600, 400);
windowB.width = 800; // to change the size, I just alter the existing object
windowB.height = 600;

It would be hard to implement a window class that doesn't "remember" what size it is, but you can decide whether the user should be able to change a window's size after creating it.
In OOP it's true that "state" usually means "member variables", but it can be a lot more than that. For instance, in C++, a method can have a static variable, and lambdas can become closures by capturing variables. In both cases those variables persist across multiple calls to the function and thus probably qualify as state. Local variables in a regular function may also be considered state depending on how they're used (the ones I have up in main() often count).


Tuesday, 1 September 2020

C# - What’s the difference between agile, CI/CD, and DevOps


What’s the difference between agile, CI/CD, and DevOps?

While Agile, CI/CD, and DevOps are different, they support one another. Agile focuses on the development process, CI/CD on practices, and DevOps on culture.

3 different development tools for building your practice
You can’t build a house with a single tool. Nor can you enable your development practice with one. Agile, DevOps, and CI/CD are three distinct tools, each important in its own right. When a development organization uses all three for their intended purposes, the results are transformational. And in the context of security, only then—in our opinion—have you earned the right to call yourselves DevSecOps.

Agile development
Agile, now referred to by some of its manifesto authors as agility, is focused on removing process barriers and enabling the key stakeholders, folk like developers and customers, to collaborate more closely on accelerating delivery. Agile highlights the constancy of change and acknowledges that as software producers, we don’t often know everything we need to successfully conceive, develop, and deliver high-quality software in monolithic life cycles.

So, though agile has come to mean different things over the past two decades, its fundamentals remain: Remove process barriers empowering individuals, produce working software rapidly, collaborate closely with customers, and respond to (rather than resist) change.

Continuous integration/continuous delivery (CI/CD)
Continuous integration (CI) is a software engineering practice where members of a team (Software Departments) integrate their work with increasing frequency. In keeping with CI practice, teams strive to integrate at least daily and even hourly, approaching integration that occurs “continuous-ly.” Continuous integration (CI) and continuous delivery (CD) embody a culture, set of operating principles, and collection of practices that enable application development teams to deliver code changes more frequently and reliably. The implementation is also known as the CI/CD pipeline.

Historically, integration has been a costly engineering activity. So, to avoid thrash, CI emphasizes automation tools that drive build and test, ultimately focusing on achieving a software-defined life cycle. When CI is successful, build and integration effort drops, and teams can detect integration errors as quickly as practical.

Continuous delivery (CD) is to packaging and deployment what CI is to build and test. Teams practicing CD can build, configure, and package software and orchestrate its deployment in such a way that it can be released to production in a software-defined manner (low cost, high automation) at any time.

High-functioning CI/CD practices directly facilitate agile development because software change reaches production more frequently. As a result, customers have more opportunities to experience and provide feedback on change.

DevOps culture
DevOps focuses on limitations of culture and roles as agile development does process. The intention of DevOps is to avoid the negative impact that overspecialization and stovepiping roles in an organization have on preventing rapid or even effective response to production issues. DevOps organizations break down the barriers between Operations and Engineering by cross-training each team in the other’s skills. This approach improves everyone’s ability to appreciate and participate in each other’s tasks and leads to more high-quality collaboration and more frequent communication.

What is CI/CD in DevOps? And how are they related to Agile?
How are CI/CD, agile, and DevOps related in real-life development? Engineering teams often start with CI because it’s in their wheelhouse. A DevOps focus can help organizations understand what configuration, packaging, and orchestration are necessary to software-define even more of the life cycle—creating a more valuable CD practice. The practice of CI/CD in DevOps, in turn, adds to agile development.

When in doubt
Here’s a quick and easy way to differentiate agile, DevOps, and CI/CD:
Agile focuses on processes highlighting change while accelerating delivery.
CI/CD focuses on software-defined life cycles highlighting tools that emphasize automation.
DevOps focuses on culture highlighting roles that emphasize responsiveness.