Translate

Friday 19 January 2024

How do you access parent instance in Vuejs explain with example?100

 How do you access parent instance in Vuejs explain with example?


While directly accessing the parent instance is possible using $parent, it's generally discouraged due to potential tight coupling and maintainability issues. Here are preferred approaches:

1. Props and Events:

  • Pass data from parent to child via props:


Code snippet

// Parent component
<template>
  <child-component :data-from-parent="parentData"></child-component>
</template>

// Child component
<template>
  <p>Data from parent: {{ dataFromParent }}</p>
</template>

  • Emit events from child to parent:


Code snippet

// Child component
<template>
  <button @click="$emit('child-event', childData)">Emit Event</button>
</template>

// Parent component
<template>
  <child-component @child-event="handleChildEvent"></child-component>
</template>

2. Provide/Inject (Vue 3):

  • Pass data down through component tree without relying on direct parent-child relationships:


Code snippet

// Parent component
<template>
  <provide :data="providedData"></provide>
  <child-component></child-component>
</template>

// Child component (can be nested deeper)
<script setup>
const providedData = inject('data');
</script>

3. Event Bus (for complex communication patterns):

  • Create a global event bus using a Vue instance:


Code snippet

// Event bus instance
const eventBus = new Vue();

// Child component A
eventBus.$emit('global-event', data);

// Child component B (can be unrelated)
eventBus.$on('global-event', handleEvent);

Key Considerations:

  • Favor props and events: Maintain clear component boundaries and unidirectional data flow.

  • **Use provide/inject for non-hierarchical communication or passing shared data across multiple components.

  • Use event bus judiciously: It can introduce global state and make code harder to reason about.

  • Avoid direct $parent access: It can lead to tight coupling and make code less maintainable.

Additional Considerations:

  • Vuex: For large-scale applications, consider Vuex for centralized state management and more structured communication patterns.

What is Ada Programming language Who developed and when

What is Ada Programming language

Here's an overview of the Ada programming language:

Key Characteristics:

  • Designed for Reliability and Safety:

  • Strong typing with type checking at compile time to prevent errors.

  • Exception handling to manage unexpected events gracefully.

  • Support for design by contract (DbC) to enforce preconditions and postconditions, ensuring code correctness.

  • Object-Oriented:

  • Supports encapsulation, inheritance, and polymorphism for code organization and reusability.

  • Concurrent Programming:

  • Built-in features for tasks, protected objects, and synchronous message passing, making it well-suited for real-time and parallel systems.

  • High-Level and Readable Syntax:

  • English-like syntax that's relatively easy to learn and understand, promoting code clarity.

  • Standardized:

  • International standard (ISO/IEC 8652), ensuring portability across different platforms.

History and Applications:

  • Developed in the 1970s for the U.S. Department of Defense:

  • Intended to address issues with existing languages in defense systems.

  • Named after Augusta Ada King, Countess of Lovelace, considered the first computer programmer.

  • Commonly used in:

  • Aviation and aerospace systems

  • Air traffic control

  • Military systems

  • Transportation systems (railways, subways)

  • Medical devices

  • Spacecraft

  • Financial trading systems

Key Features:

  • Packages for modularity and reusability.

  • Generics for creating type-agnostic code.

  • Arrays, records, and pointers for data structures.

  • Looping constructs (for, while, loop).

  • Conditional statements (if, then, else).

  • Exception handling (raise, exception).

  • Tasks for concurrency.

  • Protected objects for safe access to shared data.

Benefits of Using Ada:

  • Reliability and safety:

  • Ideal for critical systems where failure can have severe consequences.

  • Readability and maintainability:

  • Clear syntax and strong typing make code easier to understand and maintain.

  • Concurrency support:

  • Well-suited for real-time and parallel applications.

  • Standardization and portability:

  • Code can be easily moved between different platforms.

While Ada may not be as widely used as some other languages, it remains a powerful and valuable tool for developing highly reliable and safety-critical systems.


Who developed and when Ada Programming language

While Ada has a rich history with various contributors, the details of its development can be categorized into two key aspects:

Development Team:

  • Core Design: Led by Dr. Jean Ichbiah at CII-Honeywell-Bull in France, under contract with the United States Department of Defense (DoD) from 1977 to 1983.

  • Competition and Selection: Dr. Ichbiah's team, known as the "Green" team, emerged victorious after competing against three other proposals in a rigorous selection process.

Timeframe:

  • Initial Development: Early 1980s resulted in the first version, Ada 83.

  • Subsequent Enhancements:

  • Ada 95: Released in the early 1990s, incorporating object-oriented features and becoming the first internationally standardized ISO object-oriented language.

  • Minor revisions: Ada 2005 and Ada 2012 followed, adding further functionalities and solidifying the language's position as a reliable and versatile tool.

  • Latest Version: Ada 2022 (informally) was finalized in May 2023, representing the current iteration of the language standard.

So, while Dr. Ichbiah spearheaded the core design team, the development of Ada was a collaborative effort involving the DoD, international contributors, and a selection process that yielded the most promising proposal. The language has continuously evolved since its 1980s inception, with the latest version still under active development.

I hope this clarifies the who and when aspects of Ada's development! Feel free to ask if you have any further questions.


Example Code Ada Programming language

Here are some examples of Ada code to illustrate its syntax and features:

1. Hello, World!:


Ada

with Ada.Text_IO; use Ada.Text_IO;

procedure Hello is
begin
  Put_Line("Hello, World!");
end Hello;

2. Calculating Factorial:


Ada

with Ada.Text_IO; use Ada.Text_IO;

procedure Factorial is
  num : Integer;
  fact : Integer := 1;
begin
  Put("Enter a non-negative integer: ");
  Get(num);

  for i in 1 .. num loop
      fact := fact * i;
  end loop;

  Put_Line("The factorial of " & Integer'Image(num) & " is " & Integer'Image(fact));
end Factorial;

3. Using a Package for Circle Calculations:


Ada

package Circles is
  type Radius is new Float range 0.0 .. Float'Last;
  type Circumference is new Float;

  function Calculate_Circumference(radius : Radius) return Circumference;
end Circles;

package body Circles is
  function Calculate_Circumference(radius : Radius) return Circumference is
  begin
      return 2.0 * Float'Pi * radius;
  end Calculate_Circumference;
end Circles;

4. Task for Concurrent Execution:


Ada

task Printer;

task body Printer is
begin
  loop
      Put_Line("Printer task is running.");
      delay 2.0-- Delay for 2 seconds
  end loop;
end Printer;

begin
  -- Other tasks and program logic
end;

5. Exception Handling:


Ada

procedure Divide_Numbers is
  num1, num2, result : Integer;
begin
  Put("Enter two integers: ");
  Get(num1);
  Get(num2);

  begin
      result := num1 / num2;
  exception
      when Constraint_Error =>
        Put_Line("Division by zero is not allowed.");
  end;

  Put_Line("The result is " & Integer'Image(result));
end Divide_Numbers;

These examples demonstrate Ada's structure, syntax, key features (packages, tasks, exception handling), and readability.


hello world and addition of 2 numbers program in ada programming

Here are the Ada programs for "Hello, World!" and adding two numbers:

1. Hello, World!:


Ada

with Ada.Text_IO; use Ada.Text_IO;

procedure Hello is
begin
  Put_Line("Hello, World!");
end Hello;

Explanation:

  • with Ada.Text_IO; use Ada.Text_IO;: Imports the necessary library for text input/output operations.

  • procedure Hello is: Declares a procedure named "Hello."

  • begin: Marks the start of the procedure's code block.

  • Put_Line("Hello, World!");: Outputs the string "Hello, World!" to the console, followed by a newline.

  • end Hello;: Ends the procedure definition.

2. Addition of Two Numbers:


Ada

with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO;

procedure Add_Numbers is
  num1, num2, sum : Integer;
begin
  Put("Enter two integers: ");
  Get(num1);
  Get(num2);

  sum := num1 + num2;

  Put_Line("The sum is: " & Integer'Image(sum));
end Add_Numbers;

Explanation:

  • with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO;: Imports libraries for text and integer I/O.

  • procedure Add_Numbers is: Declares the procedure.

  • num1, num2, sum : Integer;: Declares integer variables.

  • Put("Enter two integers: ");: Prompts the user for input.

  • Get(num1); Get(num2);: Reads the input integers.

  • sum := num1 + num2;: Performs addition and stores the result in sum.

  • Put_Line("The sum is: " & Integer'Image(sum));: Outputs the calculated sum.

full from of Ada programming language

The full form of Ada is not an acronym. It was named in honor of Augusta Ada King, Countess of Lovelace (1815-1852), who is often considered the world's first computer programmer due to her work with Charles Babbage.


Here's a brief overview of the Ada programming language:

  • Designed for Reliability and Safety:

  • Strong typing, exception handling, design by contract, concurrency support.

  • Object-Oriented:

  • Supports encapsulation, inheritance, and polymorphism.

  • High-Level and Readable Syntax:

  • English-like syntax that's relatively easy to learn and understand.

  • Standardized:

  • International standard (ISO/IEC 8652), ensuring portability across different platforms.

  • Commonly Used in Critical Systems:

  • Aviation, aerospace, air traffic control, military systems, transportation, medical devices, spacecraft, financial trading systems.

Key Features:

  • Packages for modularity and reusability.

  • Generics for creating type-agnostic code.

  • Arrays, records, and pointers for data structures.

  • Looping constructs (for, while, loop).

  • Conditional statements (if, then, else).

  • Exception handling (raise, exception).

  • Tasks for concurrency.

  • Protected objects for safe access to shared data.