Python vs Rest
By now you must have heard about Python which is being used everywhere right from Web/Windows development to Big Data and AI/ML.
There are so many open source libraries already made using Python, and that is the reason you cannot ignore power and influence of Python. Comparing all languages at once would be a difficult task, so below is an attempt to compare lines of code needed to get the same job done in C# and Python, even though below is comparison of C# and Python, same stands true for most of OOP languages like Java,F# and etc.
- Python is cross platform language and it already has so many libraries available.
- Python is easy to read/understand and requires less lines of code to get similar job done.
- Python may not be better in terms of performance but its easy to learn and more expressive.
Consider following side by side comparison of what we have
to do in C# compared to Python.
Feature
|
Python
|
C# |
Get Data From DB
|
import sqlite3
connection = sqlite3.connect("company.db")
cursor = connection.cursor()
cursor.execute("SELECT * FROM employee")
result = cursor.fetchall()
|
using System;
using System.Data.SqlClient;
namespace TestProgram
{
class Program
{
static void Main(string[] args)
{
SqlConnection conn = new SqlConnection("connectionString");
SqlCommand cmd= new SqlCommand("Select * from
Employee", conn);
conn.Open();
SqlDataReader dr= cmd.ExecuteReader();
while (dr.Read())
{
//Your Columns Here
//Print
}
}
}
}
|
Open File
|
fi = open("yourPath")
|
using System;
using System.IO;
namespace TestProgram
{
class Program
{
static void Main(string[] args)
{
File file=File.ReadAllLines("yourPath");
}
}
}
|
Add 2 numbers
|
def Add(a,b):
return a+b
print(Add(10,20))
|
using System;
namespace TestProgram
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Add(10,20));
Console.Read();
}
public static int Add(int a, int b)
{
return a + b;
}
}
}
|
Also if today you want to do MI/AL there are so many libraries already available which can do various operations(open csv file, create different graph, linear regression, non linear regression , clustering and etc) by just few lines of code, and when you have so much functionality already available in terms of libraries and framework,why not concentrate on job in hand instead of re-inventing the wheel.
Comments
Post a Comment