Python vs C#, a REAL answer

Python vs C#, Dynamic vs Static, Imperative vs. Declarative, Compiled vs. Interpreted.

and each philosophy. which also puts the design of the language, and open source or not, cross-platform. ohh and lets not forget Strong vs Weak.

these are the real comparisons you need to thing about when thinking c# vs python.

so lately i'm getting more and more interested in python, for many reasons, it being open-source/linux oriented, its power and ability to be a script and therefor its loved by hackers (i mean pin testers lol), dynamic, ect. ect.

problem is that googling something like "C# vs Python" or "why python is better that C#", most answers, including stack, will result in "its more fun", "its dynamic", "less code", "free", "Microsoft is the evil spreading and we must fight it".

well, as all that may be true, its not the reason why python is better, but why would I as a programmer would like to start using it.

so lets start describing the languages.

C# : Static, Declarative, Compiled, Safe, Strong, closed-source, commercial.

Python: Dynamic, half Imperative half Declarative (duck-typing), 1/2 Strong, open-source, community.

so what all that mean?

Dynamic vs Static

static means, before you can run your program, it wants to know if Variable "name" is a string, or an integer, or a reference to an object. you also can't change it along the program. a string will be forever a string.

dynamic means it doesn't. it doesn't care if its a string, nor that while the program is running you'll change it.

Compiled vs. Interpreted

USUALLY a static language is compiled and a dynamic is not, but there are exceptions, like Javascript which is a dynamic language but is still compiled.

compiled means that before you can run your code a thing called "compiler" builds your code. when you run the code you know ALL your lines can run.

interpreted means that it runs line by line and do whatever you told it to do.

Imperative vs. Declarative

declarative means if you want a class person in you program, please pre-define it with all its properties like name and age, and everything you want it to do (methods or functions).

imperative means that you can push a "dog_name" variable to the object wherever you want in the program, same for doing.

python, BTW, is NOT imperative at all, but has imperative features, as you can add the "dog_name" variable whenever you want, but only AFTER you define person.

Javascript is imperative for real. read more about that here.

Weak vs. Strong

you might find it as a surprise, but python is also strong, since all that means is how bad the language will respond to 1 + "1". 2? 11? error?

11 means weak, error is strong. python, at print() for example will throw an error. on the other hand:
a=1
b="2"
c=a+b   =>> 12
python here will accept that, while c# will throw an error.

open source/community vs closed source commercial, PHILOSOPHY 

yes, every language has a philosophy behind it, while c# is simple, we are Microsoft, and we will give you anything you need at the best level and interest for payment. so only MS touches the code, and they will look at the market and add what the market demands. that's why C# is now also dynamic. and therefor can be imperative.

python's philosophy is that the language belongs to us, the community, therefor we build it. also it believes that the language must be simple and therefor the readability and easy to learn. it also believes in "one right way to do one thing", therefor usually it will give one solution, or one way to do something. although that's never true in programming.



so now we must ask ourselves what are the PRO's and CON's ?

with a language that is static, declarative and compiled, commercial, I:
- must sweat a bit more while writing a program.
- must think when writing my types and methods, and i am strict to it.
- my code gets compiled, which:
   - takes time but then runs much much faster.
   - force me to handle compile errors.
- for every change/bug i must re-compile, change everything that has a dependency on my type.
- can't help change/improve the language.
- have someone that keeps the thing up and running and improving. when C# upgrades from 3 to 4 to 5 everything still works and exists. also support. and today there is a community (like stack), and 3rd party support (nuget).
- must do things their way.

with a language that is dynamic, a bit imperative, interpreted, community I:
- write much faster and fluently .
- not strict to types and methods, and can add them while moving on.
- my code is interpreted so:
   - run is runs, no waiting for something.
   - put me faster in front of logical errors. 
- change is just a few lines wherever is the problem, and that's it.
- can help change/improve the language.
- DON'T have someone that keeps the thing up and running. example is the slumber of python 2 until python 3 came, and still a lot of things still don't work with 3. for everything wrong i need the help of the community.
- can do things my way, or more exactly the community's way, which is still closer to choosing.



so what will be the real benefit here?
so with C# my junior will work slower but with less errors. with python my senior will do faster work. with C# I know everything will run clean, full support for everything, with python i can learn faster.

lets add that python has not real multi-threading capabilities, while c# is not cross-platform. that CAN be real issues sometimes.


there are now, with that knowledge endless blogs and answer you will understand a bit better why some prefer C# and why some python. a very detailed blog about what i have written is this one.

if you want to go deeper read this Programming Concepts Series

a good answer to when which is more productive is here.

other CON's and PRO's for each here.


SO WHATS BETTER??

i must say that generally, until this point, except fun and ease of the programmers use, i dont see why should i choose python, or any dynamic language.

if your case is open source, go to Java. if your case is that you enjoy it go to Ruby. you have a case as a hacker since you have scripting abilities and a language that can touch low level with no restrictions.

but lets say as a CEO, or Team Leader, of Product manager, i am not convinced.

unless i want do a fast POC or something that must change fast, within minutes.

I am not the only one saying it, read here how this is not the right question


Dynamic Programming VS Static Programming

that's something everybody forgot about. methods of programming. how I, as a programmer, approach a large project?

well, there are some methods, and the truth is that some languages were built according to those methods, and people don't know/forgot.

just like MVC is a pattern, and you have .Net MVC, angular, or Django to implement them, there are 2 main ways to look at programming as methods.

reading some heavy technical and math blogs about Dynamic Programming like in codechef and topcoder gave me a better view, and YOU should read this short definition and this Divide and Conquer explaination

1. Top-Down, also referred as Memoization or Static. that means i take a look at the problem, building the main idea to solve it, and therefor i can pre-define some reusable modules and know where and when i save data (Memoization), and now every piece of the program must fit to the main thing, or to the entire architecture.

2. Botton-Up, also referred as "Divide and Conquer" or Dynamic. that mean i break the problem into little pieces, each is a stand alone program, independent to the main program. that "guaranteed that the subproblems are solved before solving the problem" as quoted in codechef above.

now we can understand 2 things
1. why would i like to code with a dynamic language, since i want to use dynamic programming methodology.
2. why with dynamic languages Test Driven Development (TDD) is so popular, unlike with static.


Test Driven Development and choosing Python

well of course i choose python cause its fun and linux oriented, cause i want to learn it. and its cool.

but that doesn't mean i shouldn't use it for real.

the real reason to choose any dynamic language should be the "Divide and Conquer" reason, or TDD. meaning building the solution Bottom-Up, building piece after piece, so i need a language where i am not strict to the main program nor to its types (Dynamic), i can easily run every piece fast not depending on the main program (Interpreted), will get me fast to my problem and problem solving not to my "int not string" error (Dynamic), and therefor will help me work in TDD (Interperted).

or whenever i have a project where compiling can be a problem, such as versions and debugging.

or when i understand i want a language that help me write fast and fluent, and non strict (C# help me write right and strict).

choose python. its cool. just don't do it as a static developer, become a dynamic developer.





sources mentioned:

Imperative vs Declarative Programming : https://tylermcginnis.com/imperative-vs-declarative-programming/
technical dynamic vs static:  http://blogs.perl.org/users/ovid/2010/08/what-to-know-before-debating-type-systems.html
Programming Concepts Series : https://thesocietea.org/2015/11/programming-concepts-static-vs-dynamic-type-checking/
productivity comparision: https://softwareengineering.stackexchange.com/questions/122205/what-is-the-supposed-productivity-gain-of-dynamic-typing#answer-122212
other CON's and PRO's: https://www.quora.com/Can-C-do-everything-that-Python-can
Wrong Question: http://www.craigstuntz.com/posts/2016-06-18-static-vs-dynamic-wrong-question.html
Dynamic Programming: http://www.thelearningpoint.net/computer-science/dynamic-programming
divide and conquer: https://www.quora.com/What-is-the-difference-between-dynamic-programming-and-divide-and-conquer

Comments

Popular posts from this blog

OverTheWire[.com] Natas Walkthrough - JUST HINT, NO SPOILERS

SOLVED The item could not be indexed successfully because the item failed in the indexing subsystem

Asp.Net Ending Response options, Response.End() vs CompleteRequest()