36 points · by Xelom · 12y ago · 69 comments
I am a .Net developer. I love C#, I think it is a great language with fantastic features. I'm looking at new startups job offerings and open source projects source codes a lot. I see a lot of Python or Ruby generally.
I know C# is not open source. That is not the case. You can use Java even Scala. But when I look at performance Python is not near C# or Java. And I can't seem the find features of C# in Python. In my opinion, I feel more comfortable writing C# than Python. What is the reason behind choosing Python if it is slower and lack a lot of features when compared to my preferred language?
I'm not trying to say Python is bad or anything. If a lot of people using it there must be a reason. But I can't see that reason. I'm trying to find it so I can give my time to the langauge.
Thanks
Secondly, with Python, the most popular implementation of the language is supported on all the main platforms. Compare this to C# and .Net where, although you can use Mono on Linux and Mac, you'd not be using the same runtime that folks would be using on Windows. Call me paranoid but I still don't wouldn't trust Mono as much as I would trust CPython or Microsoft's .Net runtime.
Having said all that, and despite the fact that I've written little C# code in anger, I still do like the look of C#. Microsoft seem to have done a pretty good job of updating the language over the years to support stuff like generics and functional programming. They've certainly done a better job on this front than Sun/Oracle have done with Java. If C# works better for you than Python does on the platform that you use then I wouldn't worry about sticking with it.
(EDIT - typo)
Personally, I don't like Python. If I want a dynamically typed language, I use Ruby, but I came to this conclusion after spending time with both languages, and it wasn't the feature set that sold me of one over the other, but rather how I felt while working in the language and its ecosystem. In other words, whether or not Python or Ruby are worth your time is a decision you'll only be able to make after using the language.
I believe in being language agnostic whenever possible. Don't hold strong opinions about languages. People invest a lot of time and energy into their tools. This is a "sunk cost." Their time and energy can't be reclaimed. So it's no surprise that, when asked, they will praise their tools -- even if they aren't objectively all that great -- solely to justify the costs. They aren't trying to convince you, they're trying to convince themselves. So don't waste time trying to find feature comparisons. All languages have redeemable values, and learning a new one is always a valuable exercise.
So give Python and Ruby a shot. You might find you actually like them, but not for the reasons you expected to. And if you don't like them, at least you'll know why.
(1) Ecosystem. Choice of language is often not dictated by language features, but what library features and especially third party libraries are available.
(2) Simplicity. It's a lot easier to teach Python to non-programmer domain experts than C# or Java (a major reason, I think, why Python is used so extensively in scientific computing).
(3) Not being dependent on an IDE. Using an IDE is not always an option (e.g., system administration on the far end of an SSH connection).
(4) Prototyping. Especially when doing exploratory programming, a static type system can get in the way of drafting your ideas.
(5) Extensibility. It allows you to easily provide scriptability or configurability via Python.
(6) Portability. Like most interpreted languages, Python is extremely portable across a great many architectures.
(7) Interfacing with C. While P/Invoke is much better than the JNI, Cython is easier than both.
Speed, incidentally, isn't as much of an issue in many application domains as people seem to think. If it's needed, it's frequently just a few inner loops that dominate execution time, which can be implemented easily enough in Cython.
As for Python (or any other language) lacking features that you find in C#, I think you'll find that some programmers will think the opposite (e.g., much more cumbersome metaprogramming in C#).
In short, which language to pick (insofar as that choice isn't dictated by your job anyway) is influenced by a large number of factors, which different people will weigh differently.
Contrived example: If it will take you 8 hours to write something in Language A that takes 30 seconds to run, or 30 hours to write it in Language B and have it run in 15 seconds, which do you choose? If raw performance isn't the thing that's valuable to your company, maybe Language A is a better choice (even if it's slower than Language B).
using System;
public class Hello
{
public static void Main()
{
Console.WriteLine("Hello, World!");
}
}
vs print "Hello, World!"
Everything is just simpler in python and ruby.Worry about the things that matter, the number of lines required to get to an entry point is not one of them. Neither is printing to the console.
And to be fair, if you are doing python seriously you would probably also have an ´if __name__ == "__main__":´ line, and a ´main()´ function called immediately from there to avoid shadowing of module variables. Assuming also you want to use the command line arguments you will have to ´import sys´ and suddenly the lines required are almost exactly equivalent short of the braces in C#.
Don't get me wrong, i absolutely love the conciseness of python but i frequently see this silly example being used which in the big picture doesn't mean anything. List comprehensions on the other hand is an excellent example of where the conciseness really shines. Really, you can do things in 1 line that in other languages takes 30. Although C# also has similar feature through LINQ so that's not a killer feature to convert someone from C# to python in particular.
This is a pretty big assumption, no pun intended.
Getting started on prototyping ideas is most of my life. I rarely use the code I write.
Console.WriteLine("Hello, World!");
That's all. So I'm not even talking about the greatness of the C# IDE.
(read: there is just a MASSIVE culture gap. It's just as unfathomable to Ruby/Python people why you'd ever use C#.)
That's the thing, you need an IDE to be able to skip the boilerplate, whereas both Python and Ruby have a great REPL that is available from virtually every terminal emulator.
Fortunately if there's no need for a lot of .net ecosystem, you can run .net on linux and similar systems using mono. (I have and it's a great platform to write for) But as soon as you want something more than the bare .net you'll realise the pieces are hard to find.
Regarding the missing features - I don't think there's anything missing, you just need to know where to look. Only linq may not be available since relies on specific syntax, but due to what you can do dynamically, it's not that needed in the first place.
In my case, that's python.
It's portable (cross platform), the final product is (usually) the script files themselves vs. an architecture specific "executable", and the language includes "batteries" I find useful in the standard distribution: XML, JSON, and (a limited amount of) HTML parsing, URL parsing and retrieving, regular expressions - stuff that makes what I love to do (data wrangling) easy.
Additionally it has the benefit of being pre-installed on my OS of choice, OS X, and in that specific distribution a very useful third-party library comes pre-bundled: pyobjc
This means that I can write what is, in essence, a plain text file that "runs" on most any recent version of OS X and has almost full access to Apple's ObjC (and C) APIs for controlling their systems. Talk about power!
And if someone on OS X wants to change the program? Nothing more than a text editor is needed. No need to re-compile, install an IDE, or a set of developer tools (outside of the python interpreter itself, which is pretty much on everything but Windows out of the box).
This last reason is specifically why python is very popular in the OS X sysadmin world right now. A large number of great open source OS X tools are written in python.
There's also the build/test/deployment cycle when developing, which pudquick touched on indirectly. With scripting languages, deploying a new build to test is usually as simple as saving and restarting the process. Sometimes you don't have to go past saving. The last time I dealt with C# and languages in that space (C/Java/ etc..) a build cycle involved a compiling a potentially several more steps. If you've worked with languages that don't require that, having to use one that does can get annoying pretty quickly. Especially if the project is of any size.
Another big point is the availability of libraries to do things you want to do. Most of the open source language platforms have large repositories of libraries that you can pull into your project with ease (pip, rubygems, cpan, pear, clojars, etc ...) and management tools (gem, bundler, cpan, perl-lib, composer, leiningen, pip, etc ...) to simplify installing/using those libraries.
One other thing, and this is one I see as absolutely huge, python, ruby, php, etc encourage pull people into a larger community if you get beyond anything trivial. This exposes a developer to other languages, other platforms, and other ways of looking at software. Of course, that means the developer has to go looking as well.
Still, there are four (non-comprehensive) big reasons to use any language:
* It pays the bills
* Its a good technical choice for the "job"/project
* You like working with it
* You have to maintain someone else's toys
If so, you owe it to yourself to diversify your language set. Which way you go does not matter so much as going somewhere. So don't over analyze it, just write some stuff in Python for a couple of months and see how it feels. The learning curve is not steep.
As you do this, don't waste energy trying to write C# code using Python, or giving up because feature X is not there.
I think there are some people who see C# as a "Microsoft Thing" and won't have anything to do with it.
As for Python, I don't particularly care for it, but many people find it to be a satisfactory language in the sense that you find C# satisfactory. That is, there are lots of good libraries that you can do to get many tasks done quickly. Performance doesn't matter much in applications that are limited by network latency, disk I/O or waiting for database calls to come back.
But if LINQ is what you need, well, Python may have a similar or not, depending on how you use it, but there is no reason for you to start writting C# in Python.
But if possible, I still just prefer looking at a full sql statement.
My workplace has mostly C#, whereas I'm not part of the software development team, and am free to choose my own tools.
For me, a problem with proprietary IDE's is that the forced distinction between "development" and "run time" environments encourages centralized development, which invariably becomes bureaucratic. When I need something from the programming department, they hand me a program which I have to carry to the target computer, test, and report back to them on any bugs or further changes. This cycle can take days or weeks if they're busy with other projects at the same time.
In contrast, most of my work happens to be decentralized because it occurs in labs where the physical problem to be solved is located. Some of this work now occurs overseas. Much of it is done on computers that are off-network because the IT department rations connections. Locating the full development tools on each computer lets me quickly write and debug programs. And if I share a program with somebody else, it's not prohibitive for them to learn how to make their own changes. I had a total non-programmer say to me: "I think I found a bug in your code, and fixed it."
My situation is one where I actually have a reason to keep and share my programs in the form of source code rather than as an installable / executable package.
As well, I found Python to be easy for an old geezer to learn, and to write reasonably bug free code. And I love the packages.
Python requires less LOCs than C#
Less code to maintain and it's quicker to write. Binding to C is no problem either when you need raw performance.
You can run it on a wide range of systems too.
(Context: I am not a 'hardcore programmer'. I don't use vim or emacs because I'm simply faster/more productive with an editor that I don't need to go through a learning curve for. I am not averse to the command line, but GUIs can be advantageous at times too.)
Python is great. It's free, and available on every platform I care about. It has libraries that do absolutely everything in the world right out of the box. C#/.NET is great too. It keeps everything structured, the syntax just makes sense, and Visual Studio is the best IDE I've ever used, with great debugging tools and smooth integration of everything you require (I've even started using the built-in git control at times). However, when I was previously using a Mac as my main machine, .NET programming was largely ruled out for practical purposes. For similar reasons, finding web hosts for my ASP.NET MVC applications (which is an AWESOME framework btw) was harder and costlier. Visual Studio was free for me as a student, but the pricing would be absolutely ridiculous if I had to pay for it myself. On Python, I have a ton of choice, eg for a web framework I could choose a barebones HTTP server, or web.py, or something as heavy-weight as Django. On .NET, I'm pretty much restricted to ASP.NET, and if I don't like its defaults or the convention over configuration aspect, I'm so outta luck. In fact, for less common things, like client API libraries for specific websites, I might only find implementations in Python and Ruby, not C#. If I want help or to find documentation, the Python docs suck IMHO, but the community is amazing, whereas the community for ASP.NET isn't as robust in my opinion. There are many python experts who will happily explain obvious-in-retrospect things, whereas with .NET I'll sometimes get stuck with configuration files and what not that make no sense to me or to anyone willing to help. Lastly, if I want to quickly throw a script together for a puzzle or online coding competition, Python feels a lot more light-weight and easy to get started with than C#.
Python has a lot of downsides too, but I've got to cut this comment short now. The point is, each language has its own pros and cons - try Python for a few weeks and you might find that it isn't as one-sided as you think.
In my experience as a sysadmin running hundreds of different applications written in a wide variety of languages over the years, I've seen some of the worst performing apps written in the "fast" languages you mention, and some of the best performing written in Ruby and Python. Of course, it can go the other way as well. My point is that the quality of the code has as much to do with "speed" as the language chosen.
And I could go on and on about maintainability, ease of refactoring, and more. But I think you probably get the point.
If you're curious about why people like Python, the best way to understand it is to learn it yourself. There are lots of free tutorials online and if you are already a skilled OO programmer, you should have no trouble picking it up. Spend a few weeks investigating it, and you might find that you prefer it, too!
I have found that developer productivity is higher, especially when it comes to maintenance. For me, all the tools in an IDE help offset Python or Ruby's simplicity when working in say, Java, when writing new code. But when reasoning about old code I haven't touched in a while, or looking at others' code, Python is easier for me to reason about.
If casting about for a reason to learn any new language, I can think of a few. Understanding another language and how you approach problems with it may provide insight on how to better use your main language. Your career may be long, and your main language may not be popular forever. When acting as a hiring manager, I look for people who know multiple languages, even if I only need one. Especially if they tackled learning them outside of school. It shows both passion and initiative.
We replaced an old perl-cgi web site with it, and I wouldn't touch anything related to perl with a 10 foot pole ever again in my life time (cough, cough, ruby). Perl is astounding at hiding bugs.
Python integrates pretty well with Unix kernel apis, and the unchecked exception handling is fantastic IMHO. If you want, you can also do exactly what GO does and have multiple return values (for apis you define), but I haven't felt the need to do that too many times.
I also like pythons string and regex methods. C++ std::string is a freaking pile of crap. (even in c++11, I believe).
Where python annoys me is on a large code base (30K lines+). This is where a very bad contradiction in python's zen appears: staying readable. I should be able to read all the call sites of a function, or method, or references of an attribute, and python makes that impossible compared to what I'm sure you can do in c#. Frankly, I was considering whether using mono/c# would be more appropriate, what is holding me back is clearly microsoft's 'intentions' and I don't like being a second class citizen.
It is also frustrating to have many classes of error appear only at run time, which would have been caught by a statically typed language. Edit: I've used pylint and pyflakes, and currently just use pyflakes regularly, but that's a bare minimum of checking.
So I would be very careful about choosing python on a large project. The problem is, it's just so damn good at doing quick development.
Python/Ruby projects cost less fixed cost to develop and maintain. They cost more to run and scale.
Startups lack development and maintenance costs and generally scaling dollars are followed by revenue or additional funding to finance that cost.
--
Additionally Python/Ruby have a lot more features, frameworks, extensions that specially deal with modern startup issues.
- The REPL. I 'm so used to play around with newly installed libraries or certain features in the REPL that I'm always kind of lost when coding in a language where there is none:)
- I can do almost everything I need in one language. From simple scripts to web applications. This makes it great for rapid prototyping. I can replace parts later if there is a benefit.
- Readability of code. I really like the uncluttered visual layout and the use of English keywords instead of punctuation.
- The vast amount of solid libraries available.
- No need for an IDE. I use emacs, but I think it's great for collaboration if everybody can start right away without having to install or buy anything (at least on systems, containing python out of the box). Not really important in a business environment, but it lowers the entry threshold for people new to the language or programming.
I think learning java made me better ad designing classes (I never explicitly used a singleton in python before) and helped a bit in my thinking about concurrency.
For python or ruby try to follow the common idioms rather than programming in a familiar style. I'd recommend avoiding classes altogether at first, trying to get as much done with the built-in data structures and functional aspects of the languages.
For me the thing I miss most in java is the interactive interpreter. I usually develop with an ipython instance open so I can test out different ideas and explore the features of a new package quickly. I believe that is why scripting languages are favored by hackers and startups.
And that's the right way to do it. Python has global functions, Java needs singletons.
Surely, "Hello world" style programs are simpler in Python. It's probably easier to maintain and refactor C# programs due to the better tool support. The list goes on like this, with pros and cons on either side, but all in all, the differences are actually rather small: both are imperative (with some functional sauce added later), but are object-oriented, both allow you to express a large amount of logic in relatively little space (compared to e.g. Java or C++), both have a large ecosystem and both come with batteries included.
The biggest difference, really, is culture. Python has a very nice community, but unfortunately a sizeable part of this community learned Python as their first non-crap language, and thus can't imagine anything better than Python. These are the people who keep raging that non-Python programmers aren't as smart, or good, somehow, as them. It's from these people that you get the vibe that C# is somehow inferior, but you can safely ignore them.
The C# community doesn't have many such people, but in exchange it has it's own flavour of idiot: a large share of mediocre programmers who can't actually really code well, but just get by because the IDE helps them so much. These people completely depend on libraries and tools made by Microsoft and a small amount of commercial suppliers, not looking to any of the great open source stuff out there. They weren't productive doing databases until Microsoft released Entity Framework. They weren't productive doing web apps until Microsoft released ASP.NET MVC. They can't fathom sharing their work, and they think certifications are more important than great software. In the companies they work, people like this easily make manager, which makes the problem worse.
Clearly, I'm generalizing strongly with respect to both communities. I'm mostly trying to make clear that even on the community level, the difference is very small. There's awesome folks, and there's mindless morons. The kinds of awesome that exists in both communities is pretty similar, the kinds of morons are slightly different.
You'll find that, as a C# programmer, Python is very easy to learn, should you wish to do this. There's no real technical need, because C# just about equally great (I think slightly greater, but that's for religious reasons such as typing, and this thread is full of smart people who disagree). If you want to work at a shop that happens to use Python, you'll live with it. Do spend some days getting into "Pythonic" thinking. Resist putting everything into a class. Bite the bullet of lacking editor support and more concise docs than you're used to. Look past the included batteries, there's often much better alternatives outside the standard library, much more than what you're used to in .NET.
On the negative side, Ruby and Python threading sucks, since they both have global interpreter locks. And they lack static typing.
For most websites out there it doesn't matter. Facebook ran on normal PHP (similar performance to Python) up until the point when they had 500 million users and were forced to make some changes.
Instagram and Pinterest are powered by Python. Unless your site is bigger than those, you'll be fine running Python.
And I can't seem the find features of C# in Python
Python has a huge ecosystem of libraries. Maybe you just don't know where to look?
1. OS portability (i.e. a large portion of the Internet world is not MS)
2. Open source community (You can talk to a developer of a library. Can you do that with C#)
3. Can write in simple editor or CLI (IDE's can be nice but a generally overly complex, and require a rich client, and possibly a license)
4. Access to example code is much easier in open source.
5. Extensibility. If you don't like something, you can easily adapt, even the most fundamental elements. You can't do that with a non open source product.
Which features of C# are you looking for in Python that you can't find?
Also, keep in mind that something that is written in good, idiomatic C# might need to use different idioms in Python in order to make sense as a Python program (and vice versa).
[0] http://msdn.microsoft.com/en-us/library/system.diagnostics.p...
The subprocess[0] module is probably closer to what you're looking for, though it still does not operate the way you want it to. It's also possible you may be looking for something that you can get by proper use of dtrace.
More broadly, you're not looking at the C# process library there, either. You're really looking at the Windows process library. It's predicated on a different culture and different assumptions and some of its functionality may be difficult or perhaps even impossible to implement on other systems (I note the Mono implementation has several explicit NotImplemented portions).
You're also stuck with licenses for everything from your development environment to your web server, database and not to mention operating system.
Compared to Python/Ruby where development cost can be $0.
There is also the cost hidden in "new developer? Wait a bit while I'll get another license", "what kind of replication? We don't have enough licenses", "no, you can't just create a small project (that can get huge) for solving this small problem, it can't justify the cost in licenses", and other very common situations.
It might depend on where you're living, I'm not sure.
Also, afaik C# is open source, check out Mono. (somebody correct me if wrong)
Some of the greatest living programmers are using Python to demonstrate and build amazing things, and you have the nerve to ask people to prove to you why you should "give my time to the language?". On one hand, you're right not to just follow something just because everyone else seems to be doing it. Life is short, you can't just walk down every path that appears to be open. On the other hand, you are asking people to use up their short lives explaining to you something that would better be found on your own.
You're a developer. You already know the purpose of code and how to get started in it, in any language. You also live in the age of the Internet, where learning and trying new things in the programming world costs little more than time, thanks to the herculean efforts of open-source programmers who tirelessly make coding more comfortable for the rest of us.
The kind of question you ask is understandable from someone who has never programmed before. But to be a working programmer and to ask that kind of thing? Seriously?