share & subscribe
https://www.youtube.com/@ChaiWithCode
In the below example, we have listed different type of transactions along with the type of accounts and details of debit/credit after applying the accounting rules.
Sl No. | Accounting Transaction | Accounts Involved | Type of account | Debit/ Credit |
1. | Mr Sham started a business with Rs.60,000 cash. | Cash A/c | Real | Debit what comes in |
2. | Purchased goods for cash 25,000 Tk | Purchase A/c Cash A/c | Real Real | Debit what comes in |
3. | Sold goods for cash 20,000 Indo Rupiah | Cash A/c | Real | Debit what comes in |
4. | Purchased goods from Mr Bhasha for cash 10,000 dirham | Purchase A/c (Inventory Purchased) | Real | Debit what comes in |
5. | Sold goods to Mr Sam 8,000 KES on credit. | Mr Sam A/c | Personal | Debit the receiver |
6. | Purchased furniture for Rs.6,000 | Furniture A/c | Real | Debit what comes in |
7. | Paid rent 1,500 Tk | Rent A/c | Nominal | Debit expenses |
8. | Paid wages 10,000 Indo rupiah from Bank | Wages A/c | Nominal | Debit expenses |
9. | Purchased goods from Ali Ltd on credit | Purchase A/c ( Inventory purchased ) | Real | Debit what comes in |
10. | Dividend received in cash | Cash A/c | Real | Debit what comes in |
11. | Salary outstanding | Salary A/c | Nominal | Debit expenses |
Functional programming has the following problems.
Reusability:
In Functional Programming, we need to
write the same code or logic at multiple places which increases the code
duplication. Later if we want to change the logic, then we need to change it at
all places.
Extensibility:
It is not possible in functional programming
to extend the features of a function. Suppose you have a function and you want
to extend it with some additional features then it is not possible. You have to
create a completely new function and then change the function as per your
requirement.
Simplicity:
As extensibility and reusability are
not possible in functional programming, usually we end up with lots of
functions and lots of scattered code.
Maintainability:
As we don’t have Reusability,
Extensibility, and Simplicity in functional Programming, so it is very
difficult to manage and maintain the application code.
How we can overcome Functional
Programming Problems?
We can overcome the functional
programming problems (Reusability, Extensibility, Simplicity, and
Maintainability) using Object-Oriented Programming. OOPs provide some
principles and using those principles we can overcome the functional
programming problems.
What Is Object-Oriented Programming?
Let us understand Object-Oriented
Programming i.e. OOPs Concepts using C#. Object-Oriented Programming (OOPs) in
C# is a design approach where we think in terms of real-world objects rather
than functions or methods. Unlike procedural programming language, here in
oops, programs are organized around objects and data rather than action and
logic. Please have a look at the following diagram to understand this better.
To address reusability, object-oriented
programming provides something called Classes and Objects. So, rather than
copy-pasting the same code again and again in different places what you can do
here is, create a class and make an instance of the class which is called
object, and reuses them whenever you want.
Suppose you have a function and you want to
extend it with some new features that were not possible with functional
programming. You have to create a completely new function and then change the
whole function whatever you want. In OOPs, this problem is addressed by using
some concepts called Inheritance, Aggregation, and Composition. In our upcoming
article, we will discuss all these concepts in detail.
Because we don’t have extensibility and
reusability in functional programming, we end up with lots of functions and
lots of scattered code. In OOPs, this problem is addressed by using some concepts
called Abstraction, Encapsulation, and Polymorphism.
As OOPs address Reusability, Extensibility,
and Simplicity, we have good maintainable code and clean code which increases
the maintainability of the application.
OOPs, provide 4 principles. They are
OOP stands for Object-Oriented Programming.
Procedural programming is about writing procedures
or methods that perform operations on the data, while object-oriented
programming is about creating objects that contain both data and methods.
Object-oriented programming has several advantages
over procedural programming:
·
What are Classes and Objects?
·
Classes and objects are the two main
aspects of object-oriented programming.
Class :- Car
Object volvo ,Audi,Toyota
Accept
a class is a template for objects, and an object is
an instance of a class.
When the individual objects are created, they
inherit all the variables and methods from the class.
C# is associated with classes and objects,
along with its attributes and methods. For example: in real life, a car is an
object. The car has attributes, such as weight and color, and methods,
such as drive and brake.
A Class is like an object constructor, or a
"blueprint" for creating objects.
Methods normally belongs to a class, and they
define how an object of a class behaves.
Just like with fields, you can access methods with
the dot syntax. However, note that the method must be public. And remember that we use the name of the method
followed by two parantheses () and a semicolon ; to call (execute) the method:
The public
keyword is called an access modifierThe public
keyword is an access modifier, which is used to set the access level/visibility for
classes, fields, methods and properties.
Modifier |
Description |
public |
The
code is accessible for all classes |
private |
The
code is only accessible within the same class |
protected |
The
code is accessible within the same class, or in a class that is inherited
from that class. |
internal |
The
code is only accessible within its own assembly, but not from another
assembly. |
multidimensional
arrays up to 32 dimensions. The multidimensional array can be declared by
adding commas in the square brackets. For example, [,] declares two-dimensional
array, [, ,] declares three-dimensional array, [, , ,] declares
four-dimensional array, and so on. So, in a multidimensional array, no of
commas = No of Dimensions - 1.
The following declares multidimensional arrays.
int[,] arr2d; //
two-dimensional array
int[, ,] arr3d; //
three-dimensional array
int[, , ,] arr4d ; //
four-dimensional array
int[, , , ,] arr5d; //
five-dimensional array
int[,] arr2d =
newint
[3,2]{
{1, 2},
{3, 4},
{5, 6}
};
// or
int[,] arr2d = {
{1, 2},
{3, 4},
{5, 6}
};
A jagged
array is an array of array. Jagged arrays store arrays instead of literal
values.
A jagged array is initialized with two square brackets [][].
The first bracket specifies the size of an array, and the second bracket
specifies the dimensions of the array which is going to be stored.
int[][] jArray1 =
newint
[2][];
// can include two single-dimensional arrays
int[][,] jArray2 =
newint
[3][,];
// can include three two-dimensional arrays
int[][] jArray =
newint
[2][];
jArray[0] =
newint
[3]{1, 2, 3};
jArray[1] =
newint
[4]{4, 5, 6, 7 };
// new int[3]{1, 2, 3},
// new int[4]{4, 5, 6, 7}
//};
// Console.WriteLine(jArray[0][0]);
// Console.WriteLine(jArray[0][1]);
// Console.WriteLine(jArray[0][2]);
// Console.WriteLine(jArray[1][0]);
// Console.WriteLine(jArray[1][1]);
// Console.WriteLine(jArray[1][2]);
// Console.WriteLine(jArray[1][3]);
//int[][] jArray = new int[2][]{
// new int[3]{1, 2, 3},
// new int[4]{4, 5, 6, 7}
//};
//for (int i = 0; i < jArray.Length; i++)
//{
// for (int j = 0; j < (jArray[i]).Length; j++)
// Console.WriteLine(jArray[i][j]);
//}
It is very beneficial to store data in SQL
Server temp tables rather than manipulate or work with permanent tables. Let’s
say you want full DDL or DML access to a table, but don’t have it. You can use
your existing read access to pull the data into a SQL Server temporary table
and make adjustments from there. Or you don’t have permissions to create a
table in the existing database, you can create a SQL Server temp table that you
can manipulate. Finally, you might be in a situation where you need the data to
be visible only in the current session.
SQL Server supports a few types of SQL Server
temp tables that can be very helpful.
Before we proceed, if you want to follow along
with any code samples, I suggest opening SQL Server Management Studio:
Local SQL temp tables
Local SQL Server temp tables are created using
the pound symbol or “hashtag” followed by the table name. For example:
#Table_name. SQL temp tables are created in the tempdb database. A local SQL
Server temp table is only visible to the current session. It cannot be seen or
used by processes or queries outside of the session it is declared in.
Here’s a quick example of taking a result set
and putting it into a SQL Server temp table.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/*Insert
Databases names into SQL Temp Table*/ BEGIN
TRY DROP
TABLE #DBRecovery END
TRY BEGIN
CATCH SELECT 1 END CATCH SELECT
ROWNUM = ROW_NUMBER() OVER (ORDER BY sys.[databases]), DBName
= [name], RecoveryModel
= [recovery_model_desc] INTO
#DBRecovery FROM
sys.[databases] WHERE
[recovery_model_desc] NOT IN ('Simple') |
One of the most often used scenarios for SQL
Server temp tables is within a loop of some sort. For example, you want to
process data for a SQL statement and it you need a place to store items for
your loop to read through. It provides a quick and efficient means to do so.
See the code sample above, your loop can now reference the SQL Server temp
table and process the records that meet the criteria of your goal.
Another reason to use SQL Server temp tables
is you have some demanding processing to do in your sql statement. Let’s say
that you create a join, and every time you need to pull records from that
result set it has to process this join all over again. Why not just process
this result set once and throw the records into a SQL temp table? Then you can have
the rest of the sql statement refer to the SQL temp table name. Not only does
this save on expensive query processing, but it may even make your code look a
little cleaner.
There is one point that I want to make
however. If the session that we’re working in has subsequent nested sessions,
the SQL Server temp tables will be visible in sessions lower in the hierarchy,
but not above in the hierarchy. Please allow me to visualize this.
In this quick diagram, a SQL temp table is
created in Session 2. The sessions below it (sessions 3 and session 4) are able
to see the SQL Server temp table. But Session 1, which is above session 2, will
not be able to see the SQL Server temp table.
The SQL temp table is dropped or destroyed
once the session disconnects. Many times you’ll see developers use the “DROP
#Table_Name” command at the end of their statement just to clean up. But it is
entirely up to you and what you’re trying to accomplish.
Also note, that in the event of name conflict
(remember that SQL Server temp tables are created in the tempdb) SQL server
will append a suffix to the end of the table name so that it is unique within
the tempdb database. But this process is transparent to the developer/user. You
can use the same name that you declared as it’s confined to that session.
Global SQL temp tables
Global SQL temp tables are useful when you
want you want the result set visible to all other sessions. No need to setup
permissions. Anyone can insert values, modify, or retrieve records from the
table. Also note that anyone can DROP the table. Like Local SQL Server temp
tables, they are dropped once the session disconnects and there are no longer
any more references to the table. You can always use the “DROP” command to
clean it up manually. Which is something that I would recommend.
To create a global SQL temp table, you simply
use two pound symbols in front of the table name. Example: ##Global_Table_Name.
Table Variables
Table variables are created like any other
variable, using the DECLARE statement. Many believe that table variables exist
only in memory, but that is simply not true. They reside in the tempdb database
much like local SQL Server temp tables. Also like local SQL temp tables, table
variables are accessible only within the session that created them. However,
unlike SQL temp tables the table variable is only accessible within the current
batch. They are not visible outside of the batch, meaning the concept of
session hierarchy can be somewhat ignored.
As far as performance is concerned table
variables are useful with small amounts of data (like only a few rows).
Otherwise a SQL Server temp table is useful when sifting through large amounts
of data. So for most scripts you will most likely see the use of a SQL Server
temp table as opposed to a table variable. Not to say that one is more useful
than the other, it’s just you have to choose the right tool for the job.
Here is a quick example of setting up and
using a table variable.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
DECLARE
@TotalProduct AS TABLE (ProductID
INT NOT NULL PRIMARY KEY, Quantity INT NOT NULL) INSERT INTO @TotalProduct
( [ProductID], [Quantity] ) SELECT A.[ProductID], [Quantity]
= SUM(B.Quantity) FROM
dbo.Product AS A INNER
JOIN dbo.SalesDetails AS B ON A.ProducitID = B.ProductID |
We’ve created a table variable that will hold
information regarding total quantities of a certain product sold. This is a
very simplified example, and we wouldn’t use it if it contained a lot of rows.
But if we were only looking at a few products this could really well. Once the
table variable is populated you can then join this as a table to yet another
table and gather whatever information you need. So there is a lot of
flexibility and allows the developer to be quite creative.
Also, on a final note, in terms of
transactions on table variables. If a developer rolls back a transaction which
includes changes to the table variables, the changes made to the table
variables within this particular transaction will remain intact. That is to
say, other parts of this transaction in question will be rolled back, but
anything referencing the table variable will not, unless that portion of your
script is in error.